File: generate_header.py

package info (click to toggle)
hexchat 2.16.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,252 kB
  • sloc: ansic: 60,707; xml: 3,988; perl: 1,144; python: 885; cs: 589; cpp: 307; sh: 130; makefile: 34
file content (29 lines) | stat: -rwxr-xr-x 777 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python3

import sys
from os.path import basename

out_file = sys.argv[1]
in_files = sys.argv[2:]


def escape_perl(file):
    ret = ''
    for line in file:
        # Escape " and \, strip empty space, shove in C strings.
        ret += '"' + line.strip().replace('\\', '\\\\').replace('"', '\\"') + '\\n"\n'
    return ret


with open(out_file, 'w') as o:
    o.write('"BEGIN {\\n"\n')
    for in_file in in_files:
        o.write("\"$INC{{'{}'}} = 'Compiled into the plugin.';\\n\"\n".format(basename(in_file)))
    o.write('"}\\n"\n')

    for in_file in in_files:
        o.write('"{\\n"\n')
        o.write('"#line 1 \\"{}\\"\\n"\n'.format(basename(in_file)))
        with open(in_file) as i:
            o.write(escape_perl(i))
        o.write('"}\\n"\n')