• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3from __future__ import print_function
4import fileinput
5import re
6import sys
7
8
9rc_script = re.compile(r'\s*(.*\S)?\s*')
10
11def parse_dict(filename):
12	links = {}
13	for line in open(filename, 'r'):
14		m = re.match('^([^=]+)=([^\n]+)$', line);
15		if not m:
16			continue
17		name = m.group(1)
18		value = m.group(2)
19
20		# strip leading and trailing whitespace
21		m = rc_script.match(name)
22		if m:
23			name = m.group(1)
24
25		# skip special names
26		if name == '':
27			continue
28		if name == '\\':
29			continue
30
31		links[name] = "<a href=\"" + value + "\" class=\"dg\">" + name + "</a>"
32	return links
33
34links = parse_dict(sys.argv[1])
35
36def translate(match):
37	return links[match.group(1)]
38
39# match for all names, with word boundaries \b
40rc = re.compile(r'\b(' + '|'.join(map(re.escape, sorted(links, reverse=True))) + r')\b')
41
42for line in open(sys.argv[2], 'r'):
43	print(rc.sub(translate, line), end='')
44