diff options
author | Chris Little <chrislit@crosswire.org> | 2013-07-24 07:46:38 +0000 |
---|---|---|
committer | Chris Little <chrislit@crosswire.org> | 2013-07-24 07:46:38 +0000 |
commit | a4ee69d2a8f1711cc4e40bbba9cb7ed87ffff544 (patch) | |
tree | 57cfba29fd98405e42837fee13ad23314edc0168 /versification/validate_v11n.py | |
parent | 3a32b8a1f39609cb701ba98b9f492f5a580419b8 (diff) | |
download | sword-tools-a4ee69d2a8f1711cc4e40bbba9cb7ed87ffff544.tar.gz |
added a simple utility for validating v11n definitions
git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@441 07627401-56e2-0310-80f4-f8cd0041bdcd
Diffstat (limited to 'versification/validate_v11n.py')
-rw-r--r-- | versification/validate_v11n.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/versification/validate_v11n.py b/versification/validate_v11n.py new file mode 100644 index 0000000..108f18f --- /dev/null +++ b/versification/validate_v11n.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import re, sys + +files = sys.argv[1:] + +if not files: + print 'Usage: ' + sys.argv[0] + ' <canon.h-style file(s)>' + exit() + +booksChapters = 0 +vmChapters = 0 + +for fn in files: + f = open(fn).readlines() + + inBooks = False + inVm = False + + for l in f: + # This is not robust. It assumes that [on]tbooks[] precedes vm[] and + # that all of the verse counts in vm[] are part of books listed in + # [on]tbooks[]. In general, it assumes canon files that look like what + # we include in the library and generate from v11nsys.pl. + + l = re.sub(r'#.*', '', l) + l = re.sub(r'\s*$', '', l) + + if l: + if re.search(r'struct sbook [on]tbooks.*?\[\]', l): + inBooks = True + elif re.search(r'int vm.*?\[\]', l): + inVm = True + elif (inVm or inBooks) and re.search(r'};', l): + inBooks = False + inVm = False + elif inBooks: + match = re.search(r'{".+?", ".+?", ".+?", (\d+)},', l) + if match: + booksChapters += int(match.group(1)) + elif inVm: + match = re.findall(r'\d+,?', l) + vmChapters += len(match) + + print fn + ' is ' + ('' if booksChapters == vmChapters else 'not ') + 'valid: ' + str(booksChapters) + ':' + str(vmChapters) +'\n' |