2013-10-15 18:23:10 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import re, sys
|
|
|
|
|
2014-01-07 14:43:34 +01:00
|
|
|
def hash(s):
|
|
|
|
h = 0
|
|
|
|
for c in s:
|
|
|
|
h = h * 31 + ord(c)
|
|
|
|
return h & ((1 << 32) - 1)
|
|
|
|
|
2014-01-07 15:41:09 +01:00
|
|
|
entries = []
|
2013-10-15 18:23:10 +02:00
|
|
|
for line in sys.stdin:
|
2014-06-14 15:24:47 +02:00
|
|
|
m = re.match(r'(\d+)\s+(\S+)\s+(\S.*)?', line)
|
|
|
|
val = m.group(3).strip() if m.group(3) else ''
|
2014-01-07 15:41:09 +01:00
|
|
|
entries.append((hash(m.group(2)), int(m.group(1)), m.group(2), val))
|
|
|
|
|
|
|
|
entries.sort()
|
|
|
|
|
|
|
|
print '/* Sorted by hash(name) and its table index */'
|
|
|
|
print 'static nghttp2_hd_static_entry static_table[] = {'
|
|
|
|
for ent in entries:
|
|
|
|
print 'MAKE_STATIC_ENT({}, "{}", "{}", {}u, {}u),'\
|
|
|
|
.format(ent[1] - 1, ent[2], ent[3], ent[0], hash(ent[3]))
|
|
|
|
print '};'
|
|
|
|
|
|
|
|
print ''
|
|
|
|
|
|
|
|
print '/* Index to the position in static_table */'
|
|
|
|
print 'const size_t static_table_index[] = {'
|
|
|
|
for i in range(len(entries)):
|
|
|
|
for j, ent in enumerate(entries):
|
|
|
|
if ent[1] - 1 == i:
|
|
|
|
sys.stdout.write('{: <2d},'.format(j))
|
|
|
|
break
|
|
|
|
if (i + 1) % 16 == 0:
|
|
|
|
sys.stdout.write('\n')
|
|
|
|
else:
|
|
|
|
sys.stdout.write(' ')
|
|
|
|
|
|
|
|
print '};'
|