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

Last change on this file since 4632 was 4632, checked in by nmedfort, 4 years ago

Modifications to UCD property object generator.

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 sorted(import_list): f.write("#include %s\n" % i)
48
49def multiline_fill(item_list, separator = ",", indent = 4, max_line_length = 75):
50  lines = ""
51  sep_with_space = separator + " "
52  while len(item_list) > 0:
53    items_this_line = item_list[:1]
54    length_this_line = len(item_list[0])
55    item_list = item_list[1:]
56    while (len(item_list) > 0) and (length_this_line + len(item_list[0]) + len(sep_with_space) <= max_line_length-indent):
57      items_this_line.append(item_list[0])
58      length_this_line += len(item_list[0]) + len(sep_with_space)
59      item_list = item_list[1:]
60    lines += sep_with_space.join(items_this_line)
61    if len(item_list) > 0: lines += separator + "\n" + (" " * indent)
62  return lines
63
64
Note: See TracBrowser for help on using the repository browser.