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

Last change on this file since 5786 was 5749, checked in by nmedfort, 21 months ago

updated UCD python scripts

File size: 1.7 KB
Line 
1import UCD_config
2
3header_template = r"""#ifndef %s
4#define %s
5/*
6 *  Copyright (c) 2017 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 close_header_file(f):
36   f.write("\n#endif\n")
37   f.close()
38
39def write_imports(f, import_list):
40   for i in sorted(import_list): f.write("#include %s\n" % i)
41
42def multiline_fill(item_list, separator = ",", indent = 4, max_line_length = 75):
43  lines = ""
44  sep_with_space = separator + " "
45  while len(item_list) > 0:
46    items_this_line = item_list[:1]
47    length_this_line = len(item_list[0])
48    item_list = item_list[1:]
49    while (len(item_list) > 0) and (length_this_line + len(item_list[0]) + len(sep_with_space) <= max_line_length-indent):
50      items_this_line.append(item_list[0])
51      length_this_line += len(item_list[0]) + len(sep_with_space)
52      item_list = item_list[1:]
53    lines += sep_with_space.join(items_this_line)
54    if len(item_list) > 0: lines += separator + "\n" + (" " * indent)
55  return lines
56
57
Note: See TracBrowser for help on using the repository browser.