| Last change
 on this file since 348 was             2, checked in by Yuri Dario, 15 years ago | 
        
          | 
Initial import for vendor code.
 | 
        
          | 
              
Property                 svn:eol-style
 set to                 native | 
        
          | File size:
            1.6 KB | 
      
      
| Line |  | 
|---|
| 1 | import re | 
|---|
| 2 |  | 
|---|
| 3 |  | 
|---|
| 4 | # Write the config.c file | 
|---|
| 5 |  | 
|---|
| 6 | never = ['marshal', '__main__', '__builtin__', 'sys', 'exceptions'] | 
|---|
| 7 |  | 
|---|
| 8 | def makeconfig(infp, outfp, modules, with_ifdef=0): | 
|---|
| 9 | m1 = re.compile('-- ADDMODULE MARKER 1 --') | 
|---|
| 10 | m2 = re.compile('-- ADDMODULE MARKER 2 --') | 
|---|
| 11 | while 1: | 
|---|
| 12 | line = infp.readline() | 
|---|
| 13 | if not line: break | 
|---|
| 14 | outfp.write(line) | 
|---|
| 15 | if m1 and m1.search(line): | 
|---|
| 16 | m1 = None | 
|---|
| 17 | for mod in modules: | 
|---|
| 18 | if mod in never: | 
|---|
| 19 | continue | 
|---|
| 20 | if with_ifdef: | 
|---|
| 21 | outfp.write("#ifndef init%s\n"%mod) | 
|---|
| 22 | outfp.write('extern void init%s(void);\n' % mod) | 
|---|
| 23 | if with_ifdef: | 
|---|
| 24 | outfp.write("#endif\n") | 
|---|
| 25 | elif m2 and m2.search(line): | 
|---|
| 26 | m2 = None | 
|---|
| 27 | for mod in modules: | 
|---|
| 28 | if mod in never: | 
|---|
| 29 | continue | 
|---|
| 30 | outfp.write('\t{"%s", init%s},\n' % | 
|---|
| 31 | (mod, mod)) | 
|---|
| 32 | if m1: | 
|---|
| 33 | sys.stderr.write('MARKER 1 never found\n') | 
|---|
| 34 | elif m2: | 
|---|
| 35 | sys.stderr.write('MARKER 2 never found\n') | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | # Test program. | 
|---|
| 39 |  | 
|---|
| 40 | def test(): | 
|---|
| 41 | import sys | 
|---|
| 42 | if not sys.argv[3:]: | 
|---|
| 43 | print 'usage: python makeconfig.py config.c.in outputfile', | 
|---|
| 44 | print 'modulename ...' | 
|---|
| 45 | sys.exit(2) | 
|---|
| 46 | if sys.argv[1] == '-': | 
|---|
| 47 | infp = sys.stdin | 
|---|
| 48 | else: | 
|---|
| 49 | infp = open(sys.argv[1]) | 
|---|
| 50 | if sys.argv[2] == '-': | 
|---|
| 51 | outfp = sys.stdout | 
|---|
| 52 | else: | 
|---|
| 53 | outfp = open(sys.argv[2], 'w') | 
|---|
| 54 | makeconfig(infp, outfp, sys.argv[3:]) | 
|---|
| 55 | if outfp != sys.stdout: | 
|---|
| 56 | outfp.close() | 
|---|
| 57 | if infp != sys.stdin: | 
|---|
| 58 | infp.close() | 
|---|
| 59 |  | 
|---|
| 60 | if __name__ == '__main__': | 
|---|
| 61 | test() | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.