Skip to content

Commit

Permalink
Merge remote-tracking branch 'johnbartholomew/scan-enums-glob-expansion'
Browse files Browse the repository at this point in the history
  • Loading branch information
robn committed Apr 5, 2012
2 parents 4a488ce + 3fa7ebd commit 136fe23
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -12,7 +12,7 @@ codedoc:

.PHONY: enums
enums:
python scripts/scan_enums.py -o src/enum_table.cpp src/*.h
python scripts/scan_enums.py -r --pattern=*.h -o src/enum_table.cpp src

EXTRA_DIST = \
AUTHORS.txt \
Expand Down
33 changes: 31 additions & 2 deletions scripts/scan_enums.py
Expand Up @@ -5,7 +5,8 @@
import os
from optparse import OptionParser
import re
import fileinput
import fnmatch
import glob

# splice lines (std: lex.phase -- Phases of translation: 2.1.1.2)
def splice_lines(lines):
Expand Down Expand Up @@ -366,6 +367,27 @@ def extract_enums(lines):
# are discarded
lastcomment = ''

def recursive_glob(basedir, pattern):
for root, dirnames, filenames in os.walk(basedir):
for name in fnmatch.filter(filenames, pattern):
yield os.path.join(root, name)

def expand_dirs(args, pattern, recursive):
for path in args:
if path != '-' and os.path.isdir(path):
if not pattern:
sys.stderr.write("Warning: skipping directory input '" + path + "'\n")
continue

if recursive:
for name in recursive_glob(path, pattern):
yield name
else:
for name in glob.iglob(os.path.join(path, pattern)):
yield name
else:
yield path

def main():
oparse = OptionParser(usage='%prog [options] headers-to-scan')
oparse.add_option('-o', '--output', type="string", dest="outfile", default='-',
Expand All @@ -375,6 +397,11 @@ def main():
help="Specify the header file to write to. If the main output file is not stdout " +
"then this defaults to a file of the same name with the extension changed to .h; " +
"otherwise, then no header content is written.")
oparse.add_option('--pattern', type='string', dest='pattern',
help="Specify a file pattern to match for the input files (e.g., *.h). " +
"This pattern is used to scan any directory inputs.")
oparse.add_option('-r','--recursive', dest='recursive', action='store_true', default=False,
help="Scan directory inputs recursively (used with the --pattern argument).")
(options, args) = oparse.parse_args()

if options.headerfile is not None and options.outfile is None:
Expand All @@ -387,7 +414,9 @@ def main():
# scan input files and record list of headers that have enums
enums = []
headers = []
for path in args:
allinputs = list(expand_dirs(args, options.pattern, options.recursive))
allinputs.sort()
for path in allinputs:
if path == '-':
es = list(extract_enums(sys.stdin))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/WorldViewCamera.h
@@ -1,4 +1,4 @@
#ifndef _WORLDVIEWCAMERA_H
#ifndef _WORLDVIEWCAMERA_H
#define _WORLDVIEWCAMERA_H
/*
* Front, rear, external etc. cameras used by WorldView.
Expand Down

0 comments on commit 136fe23

Please sign in to comment.