Back to index

python3.2  3.2.2
Functions | Variables
fixcid Namespace Reference

Functions

def usage
def main
def wanted
def recursedown
def fix
def initfixline
def fixline
def setdocomments
def setreverse
def addsubst

Variables

 err = sys.stderr.write
 dbg = err
 rep = sys.stdout.write
string Wanted = '^[a-zA-Z0-9_]+\.[ch]$'
 f = sys.stdin
 dbg('fix(r)
' % (filename,))
 g = sys.stdout
tuple tempname = os.path.join(head, '@' + tail)
int lineno = 0
tuple line = f.readline()
 else: print 'Substituting in comment:', print found, '-->', subst print 'Line:', line,
tuple nextline = f.readline()
tuple newline = fixline(line)
tuple statbuf = os.stat(filename)
string Identifier = '\(struct \)?[a-zA-Z_][a-zA-Z0-9_]+'
string String = '"\([^\n\\"]\|\\\\.\)*"'
string Char = '\'\([^\n\\\']\|\\\\.\)*\''
string CommentStart = '/\*'
string CommentEnd = '\*/'
string Hexnumber = '0[xX][0-9a-fA-F]*[uUlL]*'
string Octnumber = '0[0-7]*[uUlL]*'
string Decnumber = '[1-9][0-9]*[uUlL]*'
string Intnumber = '\|'
string Exponent = '[eE][-+]?[0-9]+'
string Pointfloat = '\([0-9]+\.[0-9]*\|\.[0-9]+\)\('
string Expfloat = '[0-9]+'
string Floatnumber = '\|'
string Number = '\|'
tuple OutsideComment = (Identifier, Number, String, Char, CommentStart)
string OutsideCommentPattern = '('
tuple OutsideCommentProgram = re.compile(OutsideCommentPattern)
tuple InsideComment = (Identifier, Number, CommentEnd)
string InsideCommentPattern = '('
tuple InsideCommentProgram = re.compile(InsideCommentPattern)
int i = 0
 print '-->', repr(line)
tuple found = Program.group(0)
 Program = InsideCommentProgram
 if Program is InsideCommentProgram: print '...', else: print ' ', print found
tuple n = len(found)
list subst = Dict[found]
 print 'Ignored in comment:', print found, '-->', subst print 'Line:', line,
int Docomments = 0
int Reverse = 0
dictionary Dict = {}
dictionary NotInComment = {}

Function Documentation

def fixcid.addsubst (   substfile)

Definition at line 276 of file fixcid.py.

00276 
00277 def addsubst(substfile):
00278     try:
00279         fp = open(substfile, 'r')
00280     except IOError as msg:
00281         err(substfile + ': cannot read substfile: ' + str(msg) + '\n')
00282         sys.exit(1)
00283     lineno = 0
00284     while 1:
00285         line = fp.readline()
00286         if not line: break
00287         lineno = lineno + 1
00288         try:
00289             i = line.index('#')
00290         except ValueError:
00291             i = -1          # Happens to delete trailing \n
00292         words = line[:i].split()
00293         if not words: continue
00294         if len(words) == 3 and words[0] == 'struct':
00295             words[:2] = [words[0] + ' ' + words[1]]
00296         elif len(words) <> 2:
00297             err(substfile + '%s:%r: warning: bad line: %r' % (substfile, lineno, line))
00298             continue
00299         if Reverse:
00300             [value, key] = words
00301         else:
00302             [key, value] = words
00303         if value[0] == '*':
00304             value = value[1:]
00305         if key[0] == '*':
00306             key = key[1:]
00307             NotInComment[key] = value
00308         if key in Dict:
00309             err('%s:%r: warning: overriding: %r %r\n' % (substfile, lineno, key, value))
00310             err('%s:%r: warning: previous: %r\n' % (substfile, lineno, Dict[key]))
00311         Dict[key] = value
00312     fp.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def fixcid.fix (   filename)

Definition at line 117 of file fixcid.py.

00117 
def fix(filename):

Here is the caller graph for this function:

def fixcid.fixline (   line)

Definition at line 226 of file fixcid.py.

00226 
00227 def fixline(line):
    global Program

Definition at line 222 of file fixcid.py.

00222 
00223 def initfixline():
00224     global Program
00225     Program = OutsideCommentProgram

def fixcid.main ( void  )

Definition at line 62 of file fixcid.py.

00062 
00063 def main():
00064     try:
00065         opts, args = getopt.getopt(sys.argv[1:], 'crs:')
00066     except getopt.error as msg:
00067         err('Options error: ' + str(msg) + '\n')
00068         usage()
00069         sys.exit(2)
00070     bad = 0
00071     if not args: # No arguments
00072         usage()
00073         sys.exit(2)
00074     for opt, arg in opts:
00075         if opt == '-c':
00076             setdocomments()
00077         if opt == '-r':
00078             setreverse()
00079         if opt == '-s':
00080             addsubst(arg)
00081     for arg in args:
00082         if os.path.isdir(arg):
00083             if recursedown(arg): bad = 1
00084         elif os.path.islink(arg):
00085             err(arg + ': will not process symbolic links\n')
00086             bad = 1
00087         else:
00088             if fix(arg): bad = 1
00089     sys.exit(bad)
00090 
# Change this regular expression to select a different set of files

Here is the call graph for this function:

Here is the caller graph for this function:

def fixcid.recursedown (   dirname)

Definition at line 95 of file fixcid.py.

00095 
00096 def recursedown(dirname):
00097     dbg('recursedown(%r)\n' % (dirname,))
00098     bad = 0
00099     try:
00100         names = os.listdir(dirname)
00101     except os.error as msg:
00102         err(dirname + ': cannot list directory: ' + str(msg) + '\n')
00103         return 1
00104     names.sort()
00105     subdirs = []
00106     for name in names:
00107         if name in (os.curdir, os.pardir): continue
00108         fullname = os.path.join(dirname, name)
00109         if os.path.islink(fullname): pass
00110         elif os.path.isdir(fullname):
00111             subdirs.append(fullname)
00112         elif wanted(name):
00113             if fix(fullname): bad = 1
00114     for fullname in subdirs:
00115         if recursedown(fullname): bad = 1
00116     return bad

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 265 of file fixcid.py.

00265 
00266 def setdocomments():
00267     global Docomments
00268     Docomments = 1

Here is the caller graph for this function:

Definition at line 270 of file fixcid.py.

00270 
00271 def setreverse():
00272     global Reverse
00273     Reverse = (not Reverse)

Here is the caller graph for this function:

def fixcid.usage ( )

Definition at line 47 of file fixcid.py.

00047 
00048 def usage():
00049     progname = sys.argv[0]
00050     err('Usage: ' + progname +
00051               ' [-c] [-r] [-s file] ... file-or-directory ...\n')
00052     err('\n')
00053     err('-c           : substitute inside comments\n')
00054     err('-r           : reverse direction for following -s options\n')
00055     err('-s substfile : add a file of substitutions\n')
00056     err('\n')
00057     err('Each non-empty non-comment line in a substitution file must\n')
00058     err('contain exactly two words: an identifier and its replacement.\n')
00059     err('Comments start with a # character and end at end of line.\n')
00060     err('If an identifier is preceded with a *, it is not substituted\n')
00061     err('inside a comment even when -c is specified.\n')

Here is the caller graph for this function:

def fixcid.wanted (   name)

Definition at line 92 of file fixcid.py.

00092 
00093 def wanted(name):
00094     return re.match(Wanted, name) >= 0

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

string fixcid.Char = '\'\([^\n\\\']\|\\\\.\)*\''

Definition at line 198 of file fixcid.py.

Definition at line 200 of file fixcid.py.

Definition at line 199 of file fixcid.py.

Definition at line 44 of file fixcid.py.

string fixcid.Decnumber = '[1-9][0-9]*[uUlL]*'

Definition at line 204 of file fixcid.py.

Definition at line 274 of file fixcid.py.

Definition at line 264 of file fixcid.py.

fixcid.err = sys.stderr.write

Definition at line 43 of file fixcid.py.

string fixcid.Expfloat = '[0-9]+'

Definition at line 208 of file fixcid.py.

string fixcid.Exponent = '[eE][-+]?[0-9]+'

Definition at line 206 of file fixcid.py.

tuple fixcid.f = sys.stdin

dbg('fix(r)
' % (filename,))

Definition at line 121 of file fixcid.py.

Definition at line 209 of file fixcid.py.

tuple fixcid.found = Program.group(0)

Definition at line 233 of file fixcid.py.

tuple fixcid.g = sys.stdout

Definition at line 122 of file fixcid.py.

string fixcid.Hexnumber = '0[xX][0-9a-fA-F]*[uUlL]*'

Definition at line 202 of file fixcid.py.

tuple fixcid.i = 0

print '-->', repr(line)

Definition at line 229 of file fixcid.py.

string fixcid.Identifier = '\(struct \)?[a-zA-Z_][a-zA-Z0-9_]+'

Definition at line 196 of file fixcid.py.

Definition at line 218 of file fixcid.py.

Definition at line 219 of file fixcid.py.

Definition at line 220 of file fixcid.py.

Definition at line 205 of file fixcid.py.

list fixcid.line = f.readline()

else: print 'Substituting in comment:', print found, '-->', subst print 'Line:', line,

Definition at line 138 of file fixcid.py.

Definition at line 135 of file fixcid.py.

tuple fixcid.n = len(found)

Definition at line 242 of file fixcid.py.

Definition at line 146 of file fixcid.py.

tuple fixcid.nextline = f.readline()

Definition at line 142 of file fixcid.py.

Definition at line 275 of file fixcid.py.

Definition at line 210 of file fixcid.py.

string fixcid.Octnumber = '0[0-7]*[uUlL]*'

Definition at line 203 of file fixcid.py.

Definition at line 214 of file fixcid.py.

Definition at line 215 of file fixcid.py.

Definition at line 216 of file fixcid.py.

string fixcid.Pointfloat = '\([0-9]+\.[0-9]*\|\.[0-9]+\)\('

Definition at line 207 of file fixcid.py.

if Program is InsideCommentProgram: print '...', else: print ' ', print found

Definition at line 239 of file fixcid.py.

fixcid.rep = sys.stdout.write

Definition at line 45 of file fixcid.py.

Definition at line 269 of file fixcid.py.

Definition at line 176 of file fixcid.py.

string fixcid.String = '"\([^\n\\"]\|\\\\.\)*"'

Definition at line 197 of file fixcid.py.

print 'Ignored in comment:', print found, '-->', subst print 'Line:', line,

Definition at line 244 of file fixcid.py.

tuple fixcid.tempname = os.path.join(head, '@' + tail)

Definition at line 131 of file fixcid.py.

string fixcid.Wanted = '^[a-zA-Z0-9_]+\.[ch]$'

Definition at line 91 of file fixcid.py.