updated
This commit is contained in:
BIN
__pycache__/h2inc.cpython-36.pyc
Normal file
BIN
__pycache__/h2inc.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/h2inc_gui.cpython-36.pyc
Normal file
BIN
__pycache__/h2inc_gui.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/h2inc_parser.cpython-36.pyc
Normal file
BIN
__pycache__/h2inc_parser.cpython-36.pyc
Normal file
Binary file not shown.
2
h2inc.py
2
h2inc.py
@@ -59,7 +59,7 @@ def process_files(gui, source, dest):
|
||||
sourcedir = source
|
||||
destdir = dest
|
||||
pool = mp.Pool(processes=num_cores)
|
||||
pool.map(process_file, filelist, gui)
|
||||
pool.map(process_file, filelist)
|
||||
|
||||
def process_file(data):
|
||||
outfile = ''
|
||||
|
||||
@@ -136,7 +136,7 @@ class h2incGUI:
|
||||
self.infofolders.config(state=NORMAL)
|
||||
self.infofiles.config(state=NORMAL)
|
||||
self.translate_button.config(state=NORMAL)
|
||||
self.cfilelabel.config(state=NORMAL)
|
||||
#self.cfilelabel.config(state=NORMAL)
|
||||
self.totallabel.config(state=NORMAL)
|
||||
|
||||
def translate(self, destdir, sourcedir, addinc):
|
||||
|
||||
173
old_h2inc/h2inc_gui_old.py
Normal file
173
old_h2inc/h2inc_gui_old.py
Normal file
@@ -0,0 +1,173 @@
|
||||
# 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.
|
||||
|
||||
from tkinter import Tk, ttk, Label, Button, LabelFrame
|
||||
from tkinter import filedialog, Entry, Checkbutton
|
||||
from tkinter import Grid, StringVar, DoubleVar
|
||||
from tkinter import N, E, S, W
|
||||
from tkinter import DISABLED, NORMAL
|
||||
from os import errno
|
||||
import os
|
||||
from os.path import expanduser
|
||||
import platform
|
||||
import sys
|
||||
from h2inc_old import sourcedir_filecnt, sourcedir_foldercnt, process_files
|
||||
|
||||
class h2incGUI:
|
||||
def __init__(self, master):
|
||||
self.sourcedir = StringVar()
|
||||
self.destdir = StringVar()
|
||||
self.addinc = StringVar()
|
||||
self.cfilevar = DoubleVar()
|
||||
self.totalvar = 0
|
||||
self.filecnt = 0
|
||||
self.infofolder = 'Number of folders: 0'
|
||||
self.infofile = 'Number of headers: 0'
|
||||
#self.currentfile = 'Current file: '
|
||||
self.totprogress = 'Total progress: '
|
||||
self.sourcedir.set('Select source directory!')
|
||||
self.destdir.set('Select destination directory!')
|
||||
|
||||
self.master = master
|
||||
self.master.title('Translate C-header files to Nasm include files!')
|
||||
self.master.grid_columnconfigure(1, weight=1)
|
||||
|
||||
self.frame = LabelFrame(master, text='Select folders')
|
||||
self.frame.grid(row=0, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
|
||||
self.frame.grid_columnconfigure(1, weight=1)
|
||||
|
||||
self.sourcelabel = Label(self.frame, text='Source: ')
|
||||
self.sourcelabel.grid(row=0, column=0, sticky=E, padx=(5, 1), pady=5)
|
||||
|
||||
self.sourceentry = Entry(self.frame, textvariable=self.sourcedir)
|
||||
self.sourceentry.grid(row=0, column=1, sticky=E+W, pady=5)
|
||||
|
||||
self.sourcedir_button = Button(self.frame, text="Source directory...", command= lambda: self.select_sourcedir(self.sourcedir))
|
||||
self.sourcedir_button.grid(row=0, column=2, sticky=W, padx=(3, 5), pady=5)
|
||||
|
||||
self.destlabel = Label(self.frame, text='Destination: ')
|
||||
self.destlabel.grid(row=1, column=0, sticky=E, padx=(5, 1), pady=5)
|
||||
self.destlabel.config(state=DISABLED)
|
||||
|
||||
self.destentry = Entry(self.frame, textvariable=self.destdir)
|
||||
self.destentry.grid(row=1, column=1, sticky=E+W, pady=5)
|
||||
self.destentry.config(state=DISABLED)
|
||||
|
||||
self.destdir_button = Button(self.frame, text="Destination directory...", command= lambda: self.select_destdir(self.destdir))
|
||||
self.destdir_button.grid(row=1, column=2, sticky=W, padx=(3, 5), pady=5)
|
||||
self.destdir_button.config(state=DISABLED)
|
||||
|
||||
self.incchkbox = Checkbutton(self.frame, text='Create "include" folder if it does not exist.', variable=self.addinc, onvalue='yes', offvalue='no')
|
||||
self.incchkbox.grid(row=2, column=0, columnspan=2, sticky=W, padx=5, pady=5)
|
||||
self.incchkbox.config(state=DISABLED)
|
||||
self.addinc.set('yes')
|
||||
|
||||
self.transframe = LabelFrame(master, text='Translation')
|
||||
self.transframe.grid(row=1, rowspan=2, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
|
||||
self.transframe.grid_columnconfigure(1, weight=1)
|
||||
self.transframe.grid_rowconfigure(1, weight=1)
|
||||
|
||||
self.infoframe = LabelFrame(self.transframe, text='Source information')
|
||||
self.infoframe.grid(row=1, rowspan=2, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
|
||||
self.infoframe.grid_columnconfigure(1, weight=1)
|
||||
|
||||
self.infofolders = Label(self.infoframe, text=self.infofolder)
|
||||
self.infofolders.grid(row=0, column=0, sticky=W, padx=5, pady=5)
|
||||
self.infofolders.config(state=DISABLED)
|
||||
|
||||
self.infofiles = Label(self.infoframe, text=self.infofile)
|
||||
self.infofiles.grid(row=1, column=0, sticky=W, padx=5, pady=5)
|
||||
self.infofiles.config(state=DISABLED)
|
||||
|
||||
self.translate_button = Button(self.transframe, text="Translate!", command= lambda: self.translate(self.destdir, self.sourcedir, self.addinc))
|
||||
self.translate_button.grid(row=3, column=0, sticky=W, padx=5, pady=5)
|
||||
self.translate_button.config(state=DISABLED)
|
||||
|
||||
self.progressframe = LabelFrame(self.transframe, text='Progress')
|
||||
self.progressframe.grid(row=4, rowspan=2, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
|
||||
self.progressframe.grid_columnconfigure(1, weight=1)
|
||||
|
||||
#self.cfilelabel = Label(self.progressframe, text=self.currentfile)
|
||||
#self.cfilelabel.grid(row=6, column=0, sticky=W, padx=5, pady=5)
|
||||
#self.cfilelabel.config(state=DISABLED)
|
||||
|
||||
#self.cfileprogress = ttk.Progressbar(self.progressframe, orient='horizontal', mode='determinate')
|
||||
#self.cfileprogress.grid(row=7, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
|
||||
#self.cfileprogress.config(variable=self.cfilevar, maximum=3)
|
||||
|
||||
self.totallabel = Label(self.progressframe, text=self.totprogress)
|
||||
self.totallabel.grid(row=8, column=0, sticky=W, padx=5, pady=5)
|
||||
self.totallabel.config(state=DISABLED)
|
||||
|
||||
self.totalprogress = ttk.Progressbar(self.progressframe, orient='horizontal', mode='determinate')
|
||||
self.totalprogress.grid(row=9, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
|
||||
self.totalprogress.config(variable=self.totalvar, maximum=self.filecnt)
|
||||
|
||||
def select_sourcedir(self, sourcedir):
|
||||
root.directory = os.path.abspath(filedialog.askdirectory())
|
||||
if root.directory:
|
||||
sourcedir.set(root.directory)
|
||||
filecnt = sourcedir_filecnt(root.directory)
|
||||
if filecnt > 0:
|
||||
tempstr = 'Number of headers: '+str(filecnt)
|
||||
temptot = 'Total progress: 0 of '+str(filecnt)
|
||||
print ('Source directory: ', sourcedir.get())
|
||||
self.destlabel.config(state=NORMAL)
|
||||
self.destentry.config(state=NORMAL)
|
||||
self.destdir_button.config(state=NORMAL)
|
||||
self.infofiles.config(text=tempstr)
|
||||
self.totallabel.config(text=temptot)
|
||||
self.filecnt = filecnt
|
||||
foldercnt = sourcedir_foldercnt(root.directory)
|
||||
if foldercnt > 0:
|
||||
tempstr = 'Number of folders: '+str(foldercnt)
|
||||
self.infofolders.config(text=tempstr)
|
||||
|
||||
def select_destdir(self, destdir):
|
||||
root.directory = filedialog.askdirectory()
|
||||
if root.directory:
|
||||
destdir.set(root.directory)
|
||||
print ('Destination directory: ', destdir.get())
|
||||
self.incchkbox.config(state=NORMAL)
|
||||
self.infofolders.config(state=NORMAL)
|
||||
self.infofiles.config(state=NORMAL)
|
||||
self.translate_button.config(state=NORMAL)
|
||||
#self.cfilelabel.config(state=NORMAL)
|
||||
self.totallabel.config(state=NORMAL)
|
||||
|
||||
def translate(self, destdir, sourcedir, addinc):
|
||||
doinc = addinc.get()
|
||||
dest = destdir.get()
|
||||
source = sourcedir.get()
|
||||
if doinc == 'yes':
|
||||
dest = dest+'/include'
|
||||
print(os.path.exists(os.path.dirname(dest)))
|
||||
if not os.path.exists(os.path.dirname(dest)):
|
||||
try:
|
||||
os.makedirs(os.path.dirname(dest))
|
||||
except OSError as exc: # Guard against race condition
|
||||
if exc.errno != errno.EEXIST:
|
||||
raise
|
||||
destdir.set(dest)
|
||||
print ('Destination directory: ', destdir.get())
|
||||
process_files(self, source, dest)
|
||||
|
||||
def cfileprogress_update(cnt):
|
||||
self.cfilevar = cnt
|
||||
|
||||
def currentfile_update(current):
|
||||
self.currentfile = 'Current file: '+current
|
||||
|
||||
root = Tk()
|
||||
root.update()
|
||||
#root.minsize(350, 210)
|
||||
#width = (root.winfo_screenwidth()/2)-(350/2)
|
||||
#height = (root.winfo_screenheight()/2)-(210/2)
|
||||
#root.geometry('+%d+%d' % (width, height))
|
||||
root.resizable(False, False)
|
||||
h2incgui = h2incGUI(root)
|
||||
root.mainloop()
|
||||
112
old_h2inc/h2inc_old.py
Normal file
112
old_h2inc/h2inc_old.py
Normal file
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3.5
|
||||
|
||||
# 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
|
||||
import multiprocessing as mp
|
||||
import io
|
||||
from h2inc_parser import parseline, parseparsed
|
||||
import h2inc_gui_old
|
||||
|
||||
tupline = []
|
||||
preproc = ()
|
||||
filelist = []
|
||||
folderlist = []
|
||||
cnt = 0
|
||||
sourcedir = ''
|
||||
destdir = ''
|
||||
num_cores = mp.cpu_count()
|
||||
|
||||
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 += [folderName+'/'+file]
|
||||
print(folderName+'/'+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(gui, source, dest):
|
||||
global sourcedir
|
||||
global destdir
|
||||
sourcedir = source
|
||||
destdir = dest
|
||||
pool = mp.Pool(processes=num_cores)
|
||||
pool.map(process_file, filelist)
|
||||
|
||||
def process_file(data):
|
||||
outfile = ''
|
||||
inputfile = data
|
||||
encodings = ['utf-8', 'latin-1', 'windows-1250', 'windows-1252', 'ascii',
|
||||
'big5', 'big5hkscs', 'cp037', 'cp273', 'cp424', 'cp437', 'cp500',
|
||||
'cp720', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp856',
|
||||
'cp857', 'cp858', 'cp860', 'cp861', 'cp862', 'cp863', 'cp864', 'cp865',
|
||||
'cp866', 'cp869', 'cp874', 'cp875', 'cp932', 'cp949', 'cp950', 'cp1006',
|
||||
'cp1026', 'cp1125', 'cp1140', 'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254',
|
||||
'cp1255', 'cp1256', 'cp1257', 'cp1258', 'cp65001', 'euc-jp', 'euc-jis-2004',
|
||||
'euc-jisx0213', 'euc-kr', 'gb2312', 'gbk', 'gb18030', 'hz', 'iso2022-jp',
|
||||
'iso2022-jp-1', 'iso2022-jp-2', 'iso2022-jp-2004', 'iso2022-jp-3',
|
||||
'iso2022-jp-ext', 'iso2022-kr', 'iso8859-2', 'iso8859-3', 'iso8859-4',
|
||||
'iso8859-5', 'iso8859-6', 'iso8859-7', 'iso8859-8', 'iso8859-9', 'iso8859-10',
|
||||
'iso8859-11', 'iso8859-13', 'iso8859-14', 'iso8859-15', 'iso8859-16', 'johab',
|
||||
'koi8-r', 'koi8-t', 'koi8-u', 'kz1048', 'mac-cyrillic', 'mac-greek',
|
||||
'mac-iceland', 'mac-latin2', 'mac-roman', 'mac-turkish', 'ptcp154',
|
||||
'shift-jis', 'shift-jis-2004', 'shift-jisx0213', 'utf-32', 'utf-32-be',
|
||||
'utf-32-le', 'utf-16', 'utf-16-be', 'utf-16-le', 'utf-7', 'utf-8-sig']
|
||||
for e in encodings:
|
||||
try:
|
||||
fh = io.open(data, 'r', encoding=e)
|
||||
fh.readlines()
|
||||
fh.seek(0)
|
||||
except UnicodeDecodeError:
|
||||
print('got unicode error with %s , trying different encoding' % e)
|
||||
else:
|
||||
#print('opening the file with encoding: %s ' % e)
|
||||
break
|
||||
#print(os.path.basename(data))
|
||||
for lines in fh:
|
||||
outfile = outfile+lines
|
||||
fh.close()
|
||||
outputfile = os.path.splitext(inputfile)[0]+'.inc'
|
||||
outputfile = str(outputfile).replace(sourcedir, destdir)
|
||||
#print(outputfile)
|
||||
if not os.path.exists(os.path.dirname(outputfile)):
|
||||
try:
|
||||
os.makedirs(os.path.dirname(outputfile))
|
||||
except OSError as exc: # Guard against race condition
|
||||
if exc.errno != errno.EEXIST:
|
||||
raise
|
||||
newfile = open(outputfile, "w")
|
||||
newfile.write(outfile)
|
||||
newfile.close()
|
||||
|
||||
def async_process(num):
|
||||
pool = mp.Pool(processes=num)
|
||||
pool.map(process_file, filelist)
|
||||
Reference in New Issue
Block a user