Add python script that creates matching c and h files

This commit is contained in:
Mario Hüttel 2020-02-14 20:39:50 +01:00
parent 40093322c3
commit ebb95b902c

View File

@ -0,0 +1,59 @@
#!/usr/bin/env python3
import os
import sys
license_header = """/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
*/
"""
project_dir = os.path.dirname(os.path.realpath(__file__))
include_prefix = 'reflow-controller'
module_include_dir = os.path.join(project_dir, os.path.join('include', include_prefix))
if len(sys.argv) < 2:
print('Supply module name')
sys.exit()
cpath = os.path.join(project_dir, sys.argv[1]+'.c')
hfile = sys.argv[1]+'.h'
hpath = os.path.join(module_include_dir, hfile)
h_define = '__'+hfile.replace('.', '_').replace('-', '_').upper()+'__'
if os.path.exists(cpath) or os.path.exists(hpath):
print("File already exists! Abort!")
sys.exit()
print('Creating C file: %s' % (cpath))
with open(cpath, 'x') as f:
f.write(license_header)
f.write('\n')
f.write('#include <%s>' % (os.path.join(include_prefix, hfile)))
print('Creating H file: %s' % (hpath))
with open(hpath, 'x') as f:
f.write(license_header)
f.write('\n')
f.write('#ifndef %s\n' % h_define)
f.write('#define %s\n' % h_define)
f.write('\n')
f.write('#endif /* %s */\n' % h_define)