67 def __init__(self, filename, header=True, additional_filename="") :
69 self.indent_level_additional = 0
71 self.filename = filename
72 self.additional_filename_exists =
False 73 if additional_filename :
74 self.additional_filename_exists =
True 75 self.additional_filename = additional_filename
80 self.file = open(self.filename,
'w')
81 if self.additional_filename_exists :
82 self.additional_file = open(self.additional_filename,
'w')
86 def close(self, new_line=True) :
90 if self.additional_filename_exists :
91 self.additional_file.close()
93 def write_header(self) :
94 self.now = datetime.datetime.now()
97 self.write_line(
' * Copyright (c) ' + str(self.now.year) +
' Texas Instruments Incorporated')
99 self.write_line(
' * All rights reserved not granted herein.')
100 self.write_line(
' *')
101 self.write_line(
' * Limited License.')
102 self.write_line(
' *')
103 self.write_line(
' * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive')
104 self.write_line(
' * license under copyrights and patents it now or hereafter owns or controls to make,')
105 self.write_line(
' * have made, use, import, offer to sell and sell ("Utilize") this software subject to the')
106 self.write_line(
' * terms herein. With respect to the foregoing patent license, such license is granted')
107 self.write_line(
' * solely to the extent that any such patent is necessary to Utilize the software alone.')
108 self.write_line(
' * The patent license shall not apply to any combinations which include this software,')
109 self.write_line(
' * other than combinations with devices manufactured by or for TI ("TI Devices").')
110 self.write_line(
' * No hardware patent is licensed hereunder.')
111 self.write_line(
' *')
112 self.write_line(
' * Redistributions must preserve existing copyright notices and reproduce this license')
113 self.write_line(
' * (including the above copyright notice and the disclaimer and (if applicable) source')
114 self.write_line(
' * code license limitations below) in the documentation and/or other materials provided')
115 self.write_line(
' * with the distribution')
116 self.write_line(
' *')
117 self.write_line(
' * Redistribution and use in binary form, without modification, are permitted provided')
118 self.write_line(
' * that the following conditions are met:')
119 self.write_line(
' *')
120 self.write_line(
' * * No reverse engineering, decompilation, or disassembly of this software is')
121 self.write_line(
' * permitted with respect to any software provided in binary form.')
122 self.write_line(
' *')
123 self.write_line(
' * * any redistribution and use are licensed by TI for use only with TI Devices.')
124 self.write_line(
' *')
125 self.write_line(
' * * Nothing shall obligate TI to provide you with source code for the software')
126 self.write_line(
' * licensed and provided to you in object code.')
127 self.write_line(
' *')
128 self.write_line(
' * If software source code is provided to you, modification and redistribution of the')
129 self.write_line(
' * source code are permitted provided that the following conditions are met:')
130 self.write_line(
' *')
131 self.write_line(
' * * any redistribution and use of the source code, including any resulting derivative')
132 self.write_line(
' * works, are licensed by TI for use only with TI Devices.')
133 self.write_line(
' *')
134 self.write_line(
' * * any redistribution and use of any object code compiled from the source code')
135 self.write_line(
' * and any resulting derivative works, are licensed by TI for use only with TI Devices.')
136 self.write_line(
' *')
137 self.write_line(
' * Neither the name of Texas Instruments Incorporated nor the names of its suppliers')
138 self.write_line(
' *')
139 self.write_line(
' * may be used to endorse or promote products derived from this software without')
140 self.write_line(
' * specific prior written permission.')
141 self.write_line(
' *')
142 self.write_line(
' * DISCLAIMER.')
143 self.write_line(
' *')
144 self.write_line(
' * THIS SOFTWARE IS PROVIDED BY TI AND TI\'S LICENSORS "AS IS" AND ANY EXPRESS')
145 self.write_line(
' * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES')
146 self.write_line(
' * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.')
147 self.write_line(
' * IN NO EVENT SHALL TI AND TI\'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,')
148 self.write_line(
' * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,')
149 self.write_line(
' * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,')
150 self.write_line(
' * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY')
151 self.write_line(
' * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE')
152 self.write_line(
' * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED')
153 self.write_line(
' * OF THE POSSIBILITY OF SUCH DAMAGE.')
154 self.write_line(
' *')
155 self.write_line(
' */')
158 def write_comment_line(self, text_line, files=2) :
159 self.write_line(
'/* %s */' % text_line,
True,
True, files)
164 def write_line(self, text_line, new_line=True, indent=True, files=2) :
166 for i
in range(0, self.indent_level) :
167 if files == 2
or files == 0 :
168 self.file.write(self.indent)
169 if self.additional_filename_exists :
170 for i
in range(0, self.indent_level_additional) :
171 if files == 2
or files == 1 :
172 self.additional_file.write(self.indent)
173 if files == 2
or files == 0 :
174 self.file.write(text_line)
175 if files == 2
or files == 1 :
176 if self.additional_filename_exists :
177 self.additional_file.write(text_line)
179 if files == 2
or files == 0 :
180 self.file.write(
'\n')
181 if files == 2
or files == 1 :
182 if self.additional_filename_exists :
183 self.additional_file.write(
'\n')
185 def write_block(self, text_block, new_line=True, files=2) :
186 self.file.write(text_block)
187 if self.additional_filename_exists :
188 self.additional_file.write(text_block)
190 self.file.write(
'\n')
191 if self.additional_filename_exists :
192 self.additional_file.write(
'\n')
194 def write_open_brace(self, files=2) :
195 self.write_line(
'{',
True,
True, files)
196 if files == 2
or files == 0 :
197 self.indent_level = self.indent_level+1
198 if files == 2
or files == 1 :
199 self.indent_level_additional = self.indent_level_additional+1
201 def write_close_brace(self, text="", files=2) :
202 if files == 2
or files == 0 :
203 self.indent_level = self.indent_level-1
204 if files == 2
or files == 1 :
205 self.indent_level_additional = self.indent_level_additional-1
206 self.write_line(
'}%s' % text,
True,
True, files)
208 def write_include(self, include_file_name, files=2) :
209 self.write_line(
'#include "%s"' % include_file_name,
True,
True, files)
211 def write_ifndef_define(self, text, files=2) :
212 self.write_line(
'#ifndef %s' % text,
True,
True, files)
213 self.write_line(
'#define %s' % text,
True,
True, files)
214 self.write_newline(files)
216 def write_endif(self, text, files=2) :
217 self.write_line(
'#endif /* %s */' % text,
True,
True, files)
218 self.write_newline(files)
220 def write_extern_c_top(self, files=2) :
221 self.write_line(
"#ifdef __cplusplus",
True,
True, files)
222 self.write_line(
"extern \"C\" {",
True,
True, files)
223 self.write_line(
"#endif",
True,
True, files)
224 self.write_newline(files)
226 def write_extern_c_bottom(self, files=2) :
227 self.write_line(
"#ifdef __cplusplus",
True,
True, files)
228 self.write_line(
"}",
True,
True, files)
229 self.write_line(
"#endif",
True,
True, files)
230 self.write_newline(files)
232 def write_newline(self, files=2) :
233 if files == 2
or files == 0 :
234 self.file.write(
'\n')
235 if files == 2
or files == 1 :
236 if self.additional_filename_exists :
237 self.additional_file.write(
'\n')
239 def write_define_status(self, files=2) :
240 self.write_line(
"vx_status status = (vx_status)VX_SUCCESS;",
True,
True, files)
242 def write_if_status(self, files=2) :
243 self.write_line(
"if (status == (vx_status)VX_SUCCESS)",
True,
True, files)