source: icGREP/icgrep-devel/UCD-scripts/cformat.py @ 5644

Last change on this file since 5644 was 5143, checked in by cameron, 3 years ago

Updates for Unicode 9.0; clean-ups

File size: 1.9 KB
Line 
1import UCD_config
2
3header_template = r"""#ifndef %s
4#define %s
5/*
6 *  Copyright (c) 2016 International Characters, Inc.
7 *  This software is licensed to the public under the Open Software License 3.0.
8 *  icgrep is a trademark of International Characters, Inc.
9 *
10 *  This file is generated by %s - manual edits may be lost.
11 */
12
13"""
14
15cpp_template = r"""
16/*
17 *  Copyright (c) 2016 International Characters, Inc.
18 *  This software is licensed to the public under the Open Software License 3.0.
19 *  icgrep is a trademark of International Characters, Inc.
20 *
21 *  This file is generated by %s - manual edits may be lost.
22 */
23
24#include "%s.h"
25"""
26
27
28
29def open_header_file_for_write(filename, generator_name='UCD_properties.py'):
30   f = open(UCD_config.UCD_output_dir + '/' + filename + '.h', 'w')
31   hname = filename.upper() + '_H'
32   f.write(header_template % (hname, hname, generator_name))
33   return f
34
35def open_cpp_file_for_write(filename, generator_name='UCD_properties.py'):
36   f = open(UCD_config.UCD_output_dir + '/' + filename + '.cpp', 'w')
37   f.write(cpp_template % (generator_name, filename))
38   return f
39
40def close_header_file(f):
41   f.write("\n#endif\n")
42   f.close()
43
44def close_cpp_file(f):
45   f.close()
46
47def write_imports(f, import_list):
48   for i in sorted(import_list): f.write("#include %s\n" % i)
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.