parameters: (fname, func)
docstring: Replaces the part of file marked with the special comments with the
          output of func.
  
          fname is the name of the input file and func must be a function taking
          a file and language table on input and writing the appropriate chunk to
          this file, e.g. WriteEnum or WriteTable.
docstring_summary: Replaces the part of file marked with the special comments with the
          output of func.
docstring_tokens: Replaces the part of file marked with the special comments with the output of func .
function: def ReplaceGeneratedPartOfFile(fname, func):
      """
          Replaces the part of file marked with the special comments with the
          output of func.
  
          fname is the name of the input file and func must be a function taking
          a file and language table on input and writing the appropriate chunk to
          this file, e.g. WriteEnum or WriteTable.
      """
      fin = open(fname, 'rt')
      fnameNew = fname + '.new'
      fout = open(fnameNew, 'wt')
      betweenBeginAndEnd = 0
      afterEnd = 0
      for l in fin.readlines():
          if l == '// --- --- --- generated code begins here --- --- ---\n':
              if betweenBeginAndEnd or afterEnd:
                  print 'Unexpected starting comment.'
              betweenBeginAndEnd = 1
              fout.write(l)
              func(fout, table, scripttable)
          elif l == '// --- --- --- generated code ends here --- --- ---\n':
              if not betweenBeginAndEnd:
                  print 'End comment found before the starting one?'
                  break
  
              betweenBeginAndEnd = 0
              afterEnd = 1
  
          if not betweenBeginAndEnd:
              fout.write(l)
  
      if not afterEnd:
          print 'Failed to process %s.' % fname
          os.remove(fnameNew)
          sys.exit(1)
  
      fout.close()
      fin.close()
      os.remove(fname)
      os.rename(fnameNew, fname)
function_tokens: def ReplaceGeneratedPartOfFile ( fname , func ) : fin = open ( fname , 'rt' ) fnameNew = fname + '.new' fout = open ( fnameNew , 'wt' ) betweenBeginAndEnd = 0 afterEnd = 0 for l in fin . readlines ( ) : if l == '// --- --- --- generated code begins here --- --- ---\n' : if betweenBeginAndEnd or afterEnd : print 'Unexpected starting comment.' betweenBeginAndEnd = 1 fout . write ( l ) func ( fout , table , scripttable ) elif l == '// --- --- --- generated code ends here --- --- ---\n' : if not betweenBeginAndEnd : print 'End comment found before the starting one?' break betweenBeginAndEnd = 0 afterEnd = 1 if not betweenBeginAndEnd : fout . write ( l ) if not afterEnd : print 'Failed to process %s.' % fname os . remove ( fnameNew ) sys . exit ( 1 ) fout . close ( ) fin . close ( ) os . remove ( fname ) os . rename ( fnameNew , fname )