def main(): typesAsPrints = collections.defaultdict(list) ansiRegex = re.compile('^\"(.*)\".*?Line = (\d*).*?(\(.*?ANSI_TYPE_AS_PRINT.*?\))') for line in sys.stdin: m = ansiRegex.search(line) if m: print "Adding usage: %s to %s"%(m.group(1), m.group(2)) typesAsPrints[m.group(1)].append(int(m.group(2))) typeRegex = re.compile('t\s*y\s*p\s*e', re.IGNORECASE) # The original method for processing files, as used by Mark to correct TYPE_AS_PRINT for filename, lines in typesAsPrints.items(): if not os.path.exists(filename): print "Warning: file %s does not exist"%filename continue print "Processing file %s, line %s"%(filename, lines) for line in fileinput.input(os.path.join(filename), inplace=True): if fileinput.filelineno() in lines: subst_line = typeRegex.sub('print', line.rstrip(), count=1) for l in split_fortran_line_at_72(subst_line): print l, else: print line,
def fixFortran(filename): allLines = [] print "Processing %s" % filename f = open(os.path.join(filename), 'rt') allLines = f.readlines() f.close() print "%d lines read from file" % len(allLines) if joinLines: # Rejoin all lines. for lineno in range(0, len(allLines)): allLines[lineno] = allLines[lineno][:72] for lineno in range(0, len(allLines)): if lineno >= len(allLines): break if isComment(allLines[lineno]): print "Skipping comment line %d" % lineno continue while lineno < len(allLines) and isContinuation(allLines[lineno]): l = allLines.pop(lineno) allLines[lineno - 1] = allLines[lineno - 1].rstrip() + l[6:72] print "Removed line %d and added it to the end of the preceding line" % ( lineno) print "%d lines after rejoining" % len(allLines) # Process old-style initializers #allLines = fixOldStyleInitializers(allLines) allLines = removeImplicitStatements(allLines) allLines = joinIncludes(allLines) allLines = removeDebugComments(allLines) allLines = convertXorToNeqv(allLines) f = open(os.path.join(filename), 'wt') for l in allLines: if joinLines: for sl in split_fortran_line_at_72(l): f.write(sl) else: f.write(l) f.close()
def fixFortran(filename): allLines = [] print "Processing %s"%filename f = open(os.path.join(filename), 'rt') allLines = f.readlines() f.close() print "%d lines read from file"%len(allLines) if joinLines: # Rejoin all lines. for lineno in range(0,len(allLines)): allLines[lineno] = allLines[lineno][:72] for lineno in range(0,len(allLines)): if lineno >= len(allLines): break if isComment(allLines[lineno]): print "Skipping comment line %d"%lineno continue while lineno < len(allLines) and isContinuation(allLines[lineno]): l = allLines.pop(lineno) allLines[lineno-1] = allLines[lineno-1].rstrip() + l[6:72] print "Removed line %d and added it to the end of the preceding line"%(lineno) print "%d lines after rejoining"%len(allLines) # Process old-style initializers #allLines = fixOldStyleInitializers(allLines) allLines = removeImplicitStatements(allLines) allLines = joinIncludes(allLines) allLines = removeDebugComments(allLines) allLines = convertXorToNeqv(allLines) f = open(os.path.join(filename), 'wt') for l in allLines: if joinLines: for sl in split_fortran_line_at_72(l): f.write(sl) else: f.write(l) f.close()