File: gentags.py

package info (click to toggle)
gumbo-parser 0.13.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,900 kB
  • sloc: ansic: 30,496; cpp: 3,836; python: 890; makefile: 93; sh: 15
file content (34 lines) | stat: -rw-r--r-- 971 bytes parent folder | download | duplicates (5)
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
import sys

def open_and_write_header(filename, comment_prefix):
  f = open(filename, 'w')
  f.write(comment_prefix + ' Generated via `gentags.py src/tag.in`.\n')
  f.write(comment_prefix + ' Do not edit; edit src/tag.in instead.\n')
  f.write(comment_prefix + ' clang-format off\n')
  return f

tag_strings = open_and_write_header('src/tag_strings.h', '//')
tag_enum = open_and_write_header('src/tag_enum.h', '//')
tag_sizes = open_and_write_header('src/tag_sizes.h', '//')

tag_py = open_and_write_header('python/gumbo/gumboc_tags.py', '#')
tag_py.write('TagNames = [\n')

tagfile = open(sys.argv[1])

for tag in tagfile:
    tag = tag.strip()
    tag_upper = tag.upper().replace('-', '_')
    tag_strings.write('"%s",\n' % tag)
    tag_enum.write('GUMBO_TAG_%s,\n' % tag_upper)
    tag_sizes.write('%d, ' % len(tag))
    tag_py.write('  "%s",\n' % tag_upper)

tagfile.close()

tag_strings.close()
tag_enum.close()
tag_sizes.close()

tag_py.write(']\n')
tag_py.close()