File: findlua.py

package info (click to toggle)
boswars 2.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 96,652 kB
  • sloc: cpp: 57,250; python: 1,715; sh: 25; makefile: 17
file content (47 lines) | stat: -rwxr-xr-x 1,345 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
"Output all lua functions defined in the engine source code."

import os
import os, sys
from stat import *

# where to find the other stratagus tools
toolpath = os.path.dirname(sys.argv[0]) + '/'

def walktree(top, callback):
    '''recursively descend the directory tree rooted at top,
       calling the callback function for each regular file'''

    for f in os.listdir(top):
        pathname = os.path.join(top, f)
        mode = os.stat(pathname)[ST_MODE]
        if S_ISDIR(mode):
            # It's a directory, recurse into it
            walktree(pathname, callback)
        elif S_ISREG(mode):
            # It's a file, call the callback function
            callback(pathname)
        else:
            # Unknown file type, print a message
            print 'Skipping %s' % pathname

commands = []
reffiles = {}

def visitfile(file):
    #print 'visiting', file
    if file.endswith('.c'):
        for line in open(file).read().split('\n'):
          if not line.startswith('//'):
            for part in line.split('lua_register(Lua, "')[1:]:
              command = part.split('"')[0]
              commands.append(command)
              reffiles[command] = file
        
if __name__ == '__main__':
    walktree(sys.argv[1], visitfile)

    commands.sort()
    for command in commands:
       print command