diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CMakeLists.txt | 80 | ||||
-rw-r--r-- | tools/Info.plist | 0 | ||||
-rwxr-xr-x | tools/checkcoding.py | 134 | ||||
-rw-r--r-- | tools/container_test.cpp | 132 | ||||
-rw-r--r-- | tools/property_tree.cpp | 91 | ||||
-rw-r--r-- | tools/test-nm-biu-to-ascii-mm-round-tripping.cpp | 120 |
6 files changed, 557 insertions, 0 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000..ade13d4 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,80 @@ + +set( MAKE_LINK_MAPS true ) + +if( 0 ) + + project(kicad-tools) + + cmake_minimum_required( VERSION 2.8 FATAL_ERROR ) + + set( PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../ ) + + # message( "PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}" ) + + # Path to local CMake modules. + set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules ) + + include( CheckFindPackageResult ) + + ########################## + # Find wxWidgets library # + ########################## + # Here you can define what libraries of wxWidgets you need for your + # application. You can figure out what libraries you need here; + # http://www.wxwidgets.org/manuals/2.8/wx_librarieslist.html + + # On Apple only wxwidgets 2.9 or higher doesn't need to find aui part of base + if(APPLE) + find_package(wxWidgets COMPONENTS gl adv html core net base xml QUIET) + else(APPLE) + find_package(wxWidgets COMPONENTS gl aui adv html core net base xml QUIET) + endif(APPLE) + check_find_package_result(wxWidgets_FOUND "wxWidgets") + + + # Include wxWidgets macros. + include(${wxWidgets_USE_FILE}) + + # make config.h + include( PerformFeatureChecks ) + perform_feature_checks() + + +endif() + +include_directories( + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/pcbnew + ${BOOST_INCLUDE} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ) + + +add_executable( container_test + EXCLUDE_FROM_ALL + container_test.cpp + ) +target_link_libraries( container_test + common + polygon + bitmaps + ${wxWidgets_LIBRARIES} + ) + +add_executable( test-nm-biu-to-ascii-mm-round-tripping + EXCLUDE_FROM_ALL + test-nm-biu-to-ascii-mm-round-tripping.cpp + ) + +add_executable( property_tree + EXCLUDE_FROM_ALL + property_tree.cpp + ../common/richio.cpp + ../common/dsnlexer.cpp + ../common/ptree.cpp + ) +target_link_libraries( property_tree + ${wxWidgets_LIBRARIES} + ) + diff --git a/tools/Info.plist b/tools/Info.plist new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tools/Info.plist diff --git a/tools/checkcoding.py b/tools/checkcoding.py new file mode 100755 index 0000000..7b00151 --- /dev/null +++ b/tools/checkcoding.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python +# Created for KiCad project by Miguel +# Some modifications by Edwin +# GPL2 + +import subprocess +import os +import difflib + + +# class for checking and uncrustifying files +# defaults to cpp,cxx,h,hpp and c files +class coding_checker(object): + file_filter = ["cpp", "cxx", "h", "hpp", "c"] + + # Function to call uncrustify, it returns the re-formated code and + # any errors + # + + def uncrustify_file(self, filename=None): + try: + args = ("uncrustify", "-c", "uncrustify.cfg", "-f", filename) + popen = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + popen.wait() + return [popen.stdout.readlines(), popen.stderr.read()] + except OSError as e: + print "System returned : {e}\nCould not run uncrustify. Is it installed?".format(e=e.strerror) + return [None, None] + + # This function runs bzr, and gets the list of modified files + def bzr_modified(self): + modified_files = [] + args = ("bzr", "status") + try: + popen = subprocess.Popen(args, stdout=subprocess.PIPE) + popen.wait() + output = popen.stdout.readlines() + except OSError as e: + print "System returned : {e}\nCould not run bzr. Is it installed?".format(e=e.strerror) + return None + + in_modifieds = False + for line in output: + line = line.rstrip("\r\n") + if line.endswith(":"): + in_modifieds = False + if line.startswith("modified:"): + in_modifieds = True + continue + if line.startswith("added:"): + in_modifieds = True + continue + + if in_modifieds: + modified_files.append(line.lstrip("\t ").rstrip("\t ")) + + return modified_files + + + def extension(self, filename): + return os.path.splitext(filename)[1][1:].strip().lower() + + + def read_file(self, filename): + f = open(filename, 'r') + data = f.readlines() + f.close() + return data + + + def ask_user(self, filename): + msg = 'Shall I clean %s ?' % filename + return raw_input("%s (y/N/E) " % msg).lower() + + + def main(self): + # make list of modified file names + modified_files = self.bzr_modified() + + if not modified_files: + print "No modified files\n" + else: + + for filename in modified_files: + if self.extension(filename) in self.file_filter: + self.compare_and_suggest(filename) + + def compare_and_suggest(self,filename): + # if it is a 'c' file try to uncrustify + [uncrustified, errors] = self.uncrustify_file(filename) + + if not (uncrustified and errors): + print "Program end" + # problem in uncrustify + return + + original = self.read_file(filename) + + if len(errors.split("\n")) > 2: + print "There was a problem processing " + filename + ":" + errors + return + + if uncrustified == original: + print filename + " looks perfect!, well done!" + else: + print "Suggestions for: " + filename + + diff = difflib.unified_diff(original, uncrustified, filename, filename + ".uncrustified") + + for line in diff: + print line.rstrip("\r\n") + print "" + reply = self.ask_user(filename) + + if reply in ["y", "yes"]: + f = open(filename, 'w') + for line in uncrustified: + f.write(line) + f.close() + print filename + " UPDATED" + + if reply in ["e", "ed", "edit"]: + os.system("$EDITOR " + filename) + + print "" + + +if __name__ == '__main__': + print "This program tries to do 2 things\n" \ + "1) call bzr to find changed files (related to the KiCad project)\n" \ + "2) call uncrustify on the changed files (to make the files comply with coding standards)\n" + + cc = coding_checker() + cc.main() diff --git a/tools/container_test.cpp b/tools/container_test.cpp new file mode 100644 index 0000000..3b65dad --- /dev/null +++ b/tools/container_test.cpp @@ -0,0 +1,132 @@ + +#include <base_struct.h> +#include <boost/ptr_container/ptr_vector.hpp> +#include <deque> +#include <dlist.h> +#include <time.h> +#include <common.h> + +#define TEST_NODES 100000000 + + +//typedef std::vector<EDA_ITEM*> EDA_ITEMV; +//typedef std::deque<EDA_ITEM*> EDA_ITEMV; +typedef boost::ptr_vector<EDA_ITEM> EDA_ITEMV; + +class MY_ITEM : public EDA_ITEM +{ +public: + + MY_ITEM( KICAD_T id ) : + EDA_ITEM( id ) + {} + + +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ) const + { + ShowDummy( os ); + } +#endif +}; + + +void heap_warm_up(); + +int main( int argc, char** argv ) +{ + EDA_ITEMV v; + DLIST<EDA_ITEM> dlist; + + unsigned vAllocStart; + unsigned vAllocStop; + unsigned vIterateStart; + unsigned vIterateStop; + + unsigned dAllocStart; + unsigned dAllocStop; + unsigned dIterateStart; + unsigned dIterateStop; + + heap_warm_up(); + + vAllocStart = GetRunningMicroSecs(); + + for( int i=0; i<TEST_NODES; ++i ) + { + v.push_back( new MY_ITEM( NOT_USED ) ); + } + + vAllocStop = GetRunningMicroSecs(); + vIterateStart = vAllocStop; + + for( EDA_ITEMV::const_iterator it = v.begin(); it != v.end(); ++it ) + { + if( it->Type() == -22 ) + { + printf( "never this\n" ); + break; + } + } + + vIterateStop = GetRunningMicroSecs(); + +#if 0 + for( int i=0; i<TEST_NODES; ++i ) + { + delete v[i]; + } +#endif + + v.clear(); + + + dAllocStart = GetRunningMicroSecs(); + + for( int i=0; i<TEST_NODES; ++i ) + { + dlist.PushBack( new MY_ITEM( NOT_USED ) ); + } + + dAllocStop = GetRunningMicroSecs(); + dIterateStart = dAllocStop; + + for( const EDA_ITEM* it = dlist; it; it = it->Next() ) + { + if( it->Type() == -22 ) + { + printf( "never this\n" ); + break; + } + } + + dIterateStop = GetRunningMicroSecs(); + + printf( "vector alloc: %u usecs iterate: %u usecs\n", + vAllocStop - vAllocStart, + vIterateStop - vIterateStart ); + + printf( "dlist alloc: %u usecs iterate: %u usecs\n", + dAllocStop - dAllocStart, + dIterateStop - dIterateStart ); +} + + +void heap_warm_up() +{ + // dry run allocate enough object for process to obtain all memory needed + + EDA_ITEMV vec; + + for( int i=0; i<TEST_NODES; ++i ) + { + vec.push_back( new MY_ITEM( NOT_USED ) ); + } + + for( int i=0; i<TEST_NODES; ++i ) + { + // delete vec[i]; + } + + vec.clear(); +} diff --git a/tools/property_tree.cpp b/tools/property_tree.cpp new file mode 100644 index 0000000..0386d21 --- /dev/null +++ b/tools/property_tree.cpp @@ -0,0 +1,91 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> + * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +// This is a propertytree test utility. +// It can convert XML to sexpressions or beautify s-expressions in non-specctra mode. + + +#include <assert.h> +#include <ptree.h> +#include <richio.h> +#include <dsnlexer.h> +#include <macros.h> +#include <boost/property_tree/xml_parser.hpp> + + +void usage() +{ + fprintf( stderr, "Usage: parser_gen <grammar_s-expression_file>\n" ); + exit( 1 ); +} + + +int main( int argc, char** argv ) +{ + if( argc != 2 ) + { + usage(); + } + + FILE* fp = fopen( argv[1], "r" ); + if( !fp ) + { + fprintf( stderr, "Unable to open '%s'\n", argv[1] ); + usage(); + } + + static const KEYWORD empty_keywords[1] = {}; + + DSNLEXER lexer( empty_keywords, 0, fp, FROM_UTF8( argv[1] ) ); + + try + { + PTREE doc; + +#if 0 + using namespace boost::property_tree; + + read_xml( argv[1], doc, xml_parser::trim_whitespace | xml_parser::no_comments ); +#else + Scan( &doc, &lexer ); +#endif + +#if 1 + STRING_FORMATTER sf; + Format( &sf, 0, 0, doc ); + printf( "%s", sf.GetString().c_str() ); +#else + // writing the unchanged ptree in file2.xml + boost::property_tree::xml_writer_settings<char> settings( ' ', 2 ); + write_xml( "/tmp/output.xml", doc, std::locale(), settings ); +#endif + + } + catch( const IO_ERROR& ioe ) + { + fprintf( stderr, "%s\n", TO_UTF8( ioe.errorText ) ); + } +} + diff --git a/tools/test-nm-biu-to-ascii-mm-round-tripping.cpp b/tools/test-nm-biu-to-ascii-mm-round-tripping.cpp new file mode 100644 index 0000000..0ddb383 --- /dev/null +++ b/tools/test-nm-biu-to-ascii-mm-round-tripping.cpp @@ -0,0 +1,120 @@ + +/* + A test program to which explores the ability to round trip a nanometer + internal unit in the form of a 32 bit int, out to ASCII floating point + millimeters and back in without variation. It tests all 4 billion values + that an int can hold, and converts to ASCII and back and verifies integrity + of the round tripped value. + + Author: Dick Hollenbeck +*/ + + +#include <limits.h> +#include <stdio.h> +#include <cmath> +#include <string> +#include <string.h> +#include <stdlib.h> +#include <stdint.h> + + +static inline int KiROUND( double v ) +{ + return int( v < 0 ? v - 0.5 : v + 0.5 ); +} + + +typedef int BIU; + +#define BIU_PER_MM 1e6 + + +//double scale = BIU_PER_MM; +//double scale = UM_PER_BIU; +double scale = 1.0/BIU_PER_MM; + + +std::string biuFmt( BIU aValue ) +{ + double engUnits = aValue * scale; + char temp[48]; + int len; + + if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 ) + { + len = snprintf( temp, sizeof( temp ), "%.10f", engUnits ); + + while( --len > 0 && temp[len] == '0' ) + temp[len] = '\0'; + + ++len; + } + else + { + len = snprintf( temp, sizeof( temp ), "%.10g", engUnits ); + } + + return std::string( temp, len );; +} + + +int parseBIU( const char* s ) +{ + double d = strtod( s, NULL ); + return KiROUND( double( d * BIU_PER_MM ) ); +// return int( d * BIU_PER_MM ); +} + + +int main( int argc, char** argv ) +{ + unsigned mismatches = 0; + + if( argc > 1 ) + { + // take a value on the command line and round trip it back to ASCII. + + int i = parseBIU( argv[1] ); + + printf( "%s: i:%d\n", __func__, i ); + + std::string s = biuFmt( i ); + + printf( "%s: s:%s\n", __func__, s.c_str() ); + + exit(0); + } + + // printf( "sizeof(long double): %zd\n", sizeof( long double ) ); + + // Emperically prove that we can round trip all 4 billion 32 bit integers representative + // of nanometers out to textual floating point millimeters, and back without error using + // the above two functions. +// for( int i = INT_MIN; int64_t( i ) <= int64_t( INT_MAX ); ++i ) + for( int64_t j = INT_MIN; j <= int64_t( INT_MAX ); ++j ) + { + int i = int( j ); + + std::string s = biuFmt( int( i ) ); + + int r = parseBIU( s.c_str() ); + + if( r != i ) + { + printf( "i:%d biuFmt:%s r:%d\n", i, s.c_str(), r ); + ++mismatches; + } + + if( !( i & 0xFFFFFF ) ) + { + printf( " %08x", i ); + fflush( stdout ); + } + } + + printf( "mismatches:%u\n", mismatches ); + + return 0; +} + |