Example #1
0
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
Example #2
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