def main(): global extension # Processing command line arguments argnum = len(sys.argv) if (argnum != 2) & (argnum != 3): print "Make Header - C to C++ tools - Scriptet.com" print "This tool generates or updates header files from .c files" print "(Don't use it with C++ file please)" print "Usage: python mkheader.py csource" print " or: python mkheader.py pattern" print " or: python mkheader.py @prjfile" print " or as above plus new header file extension (default .hpp)" print " ex: python mkheader.py filename.c h (to update a .h file" print "pattern uses * as wildcard code to match a set of files" sys.exit(0) cfile = sys.argv[1] # use either default extension of given one extension = lexer.hpp if argnum == 3: extension = sys.argv[2] print extension # if the argument starts with @, this is a list of file # otherwise this is a main file if cfile[0] == '@': # Processing a project file (a simple list of C source files) project = cfile[1:] print "Processing project file", project flist = lexer.readproject(project) for f in flist: processfile(f) else: # Processing a file or a list matching a pattern path, name = os.path.split(cfile) if path == "": path = os.getcwd() #print path, name liste = os.listdir(path) # scanning the list of sources and processing each one for fname in liste: if not os.path.isfile(fname): continue if pattern.matching(name, fname, FALSE) == TRUE: f = os.path.join(path, fname) processfile(f) return 0
def main(): global shortened argnum = len(sys.argv) if argnum != 2: print "Make Class - C to C++ tools - Scriptet.com" print "Make a class from a .cpp header file: a file = a class" print "Usage: mkclass headerfile" print " or: mkclass pattern (uses the * wildcard code)" print " or: mkclass @filelist" sys.exit(0) cfile = sys.argv[1] hlist = [] # Below, I make the list of headers if cfile[0] == '@': # Making a list from the project (a simple list of C source files) project = cfile[1:] print "mkclass - processing the list of files", project hlist = lexer.readproject(project) else: # Makeing a list of the single file if not '*' in cfile: hlist.append(cfile) else: # Make a list of files matching a pattern path, name = os.path.split(cfile) if path == "": path = os.getcwd() dlist = os.listdir(path) for fname in dlist: if not os.path.isfile(fname): continue if pattern.matching(name, fname, FALSE) == TRUE: f = os.path.join(path, fname) hlist.append(f) # Now processing each header file # filename with .c extension are converted to .h # otherwise processed as is for f in hlist: node, ext = os.path.splitext(f) if lexer.oscase(ext) == ".c": f = node + ".hpp" processheader(f) return 0
def main(): global hpplist # List of .hpp files global dclass # Dictionnary of classes and members/methods global counter param = sys.argv if len(param) != 2: print "mkdict - C to C++ tools by D.G. Sureau" print "usage: mkdict headerfile.hpp" print " or: mkdict @headerlist" print " create of overwrite c2cpp.dict" sys.exit() counter = 0 hfile = param[1] # header or list hlist = [] if hfile[0] == '@': # Processing a header list project = hfile[1:] hlist = lexer.readproject(project) else: # Processing a file or a list matching a pattern hlist.append(hfile) # Building the directory of each class with members and methods for classfile in hlist: build(classfile) dictfile = "c2cpp.dic" df = open(dictfile, "wb") keys = dclass.keys() for k in keys: l = dclass[k] df.write("class " + k + ':' + "\n") print l for v in l: print v if v is not None: df.write(' ' + v + "\n") df.close() print dictfile, "created" return 0
def main(): global hpplist # List of .hpp files global clist # List of c files (project) global hpp # New .hpp header global cpp # New .cpp source file global dclass # Dictionnary of classes and members/methods global fclass global counter global classfile param = sys.argv lenparam = len(param) if (lenparam < 2) | (lenparam > 3): print """ Make Cpp - C to C++ tools - Scriptet.com Converts global variables to static attributes. Transforms function calls to method calls. usage: mkcpp srcfile.c headerfile.hpp or: mkcpp srcfile.c or: mkcpp @srclist @headerlist srclist is the file created by the -l option or by mklist.py headerlist is the file created by the -a optio or by allhead.py previous .cpp and .hpp files will be overwritten """ sys.exit() hpp = [] newhpp = [] ccode = [] cppcode = [] counter = 0 cfile = param[1] # c source or list if lenparam == 3: hfile = param[2] # header or list else: node, dummy = os.path.splitext(cfile) hfile = node + ".hpp" clist = [] hlist = [] if cfile[0] == '@': # Processing a project file (a simple list of C source files) project = cfile[1:] clist = lexer.readproject(project) else: # Processing a file or a list matching a pattern clist.append(cfile) if hfile[0] == '@': # Processing a header list project = hfile[1:] hlist = lexer.readproject(project) else: # Processing a file or a list matching a pattern hlist.append(hfile) # Building the directory of each class with members and methods print "mkcpp - building the directory of classes" for classfile in hlist: if not os.path.exists(classfile): print classfile, "not found" continue #print "Adding", classfile build(classfile) # the main function is not member of a class # this string allows to pass through further processing fclass["main"] = "$$$" dclass["main"] = "$$$" # Moving var. declarations and changing functions into methods for c in clist: if not os.path.exists(c): print c, "not found" continue transform(c) return 0