source: proto/charsetcompiler/UCD/cformat.py @ 4428

Last change on this file since 4428 was 4428, checked in by cameron, 4 years ago

Generator support for precompiled property cpp files

File size: 1.8 KB
Line 
1
2header_template = r"""#ifndef %s
3#define %s
4/*
5 *  Copyright (c) 2015 International Characters, Inc.
6 *  This software is licensed to the public under the Open Software License 3.0.
7 *  icgrep is a trademark of International Characters, Inc.
8 *
9 *  This file is generated by %s - manual edits may be lost.
10 */
11
12"""
13
14cpp_template = r"""
15/*
16 *  Copyright (c) 2015 International Characters, Inc.
17 *  This software is licensed to the public under the Open Software License 3.0.
18 *  icgrep is a trademark of International Characters, Inc.
19 *
20 *  This file is generated by %s - manual edits may be lost.
21 */
22
23#include "%s.h"
24"""
25
26
27
28def open_header_file_for_write(filename, generator_name='UCD_properties.py'):
29   f = open(filename + '.h', 'w')
30   hname = filename.upper() + '_H'
31   f.write(header_template % (hname, hname, generator_name))
32   return f
33
34def open_cpp_file_for_write(filename, generator_name='UCD_properties.py'):
35   f = open(filename + '.cpp', 'w')
36   f.write(cpp_template % (generator_name, filename))
37   return f
38
39def close_header_file(f):
40   f.write("\n#endif\n")
41   f.close()
42
43def close_cpp_file(f):
44   f.close()
45
46def write_imports(f, import_list):
47   for i in import_list: f.write("#include %s\n" % i)
48
49
50def multiline_fill(item_list, separator = ",", indent = 4, max_line_length = 75):
51  lines = ""
52  sep_with_space = separator + " "
53  while len(item_list) > 0:
54    items_this_line = item_list[:1]
55    length_this_line = len(item_list[0])
56    item_list = item_list[1:]
57    while (len(item_list) > 0) and (length_this_line + len(item_list[0]) + len(sep_with_space) <= max_line_length-indent):
58      items_this_line.append(item_list[0])
59      length_this_line += len(item_list[0]) + len(sep_with_space)
60      item_list = item_list[1:]
61    lines += sep_with_space.join(items_this_line)
62    if len(item_list) > 0: lines += separator + "\n" + (" " * indent)
63  return lines
64
65
Note: See TracBrowser for help on using the repository browser.