66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
# You are free to use and/or change this code for
|
|
# your own needs.
|
|
|
|
# Original code (c)2018 Jan Lerking
|
|
# Program to convert C-header (*.h) files to nasm include files (*.inc),
|
|
# for direct usage in assembly programming using nasm/yasm.
|
|
|
|
import os
|
|
import sys
|
|
from h2inc_parser import parseline, parseparsed
|
|
import h2inc_gui
|
|
|
|
tupline = []
|
|
preproc = ()
|
|
outfile = ''
|
|
filelist = []
|
|
folderlist = []
|
|
cnt = 0
|
|
|
|
def sourcedir_filecnt(sourcedir):
|
|
### Return the number of files, ending with '.h', in sourcedir - including subdirectories ###
|
|
cnt = 0
|
|
global filelist
|
|
for folderName, subfolders, files in os.walk(sourcedir):
|
|
for file in files:
|
|
if file.lower().endswith('.h'):
|
|
cnt += 1
|
|
filelist += [file]
|
|
#print(filelist)
|
|
return cnt
|
|
|
|
def sourcedir_foldercnt(sourcedir):
|
|
### Return the number of folders, if it contains '*.h' files, in sourcedir - including subdirectories ###
|
|
global cnt
|
|
global folderlist
|
|
for folderName, subfolders, files in os.walk(sourcedir):
|
|
if subfolders:
|
|
for subfolder in subfolders:
|
|
sourcedir_foldercnt(subfolder)
|
|
tempf = [file for file in files if file.lower().endswith('.h')]
|
|
if tempf:
|
|
cnt = cnt+1
|
|
print(folderName)
|
|
folderlist += [folderName]
|
|
#print(folderlist)
|
|
#print(len(folderlist))
|
|
return cnt
|
|
|
|
def process_files(sourcedir, destdir):
|
|
global folderlist
|
|
global filelist
|
|
cnt = 0
|
|
for f in folderlist:
|
|
folderlist[cnt] = str(f).replace(str(sourcedir.get()), str(destdir.get()))
|
|
print(folderlist[cnt])
|
|
if not os.path.exists(folderlist[cnt]):
|
|
os.makedirs(folderlist[cnt])
|
|
cnt += 1
|
|
#WorkPath = os.path.dirname(sourcedir)
|
|
#print(WorkPath)
|
|
#incpath = destdir
|
|
#print(incpath)
|
|
|
|
#pattern = '.h'
|
|
#inputfile = 'gtkaboutdialog.h'
|
|
#filehandle = open(WorkPath+'/'+inputfile, 'r') |