Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
8fe24f21bb | |||
6500a30df8 | |||
8c163e7ad4 | |||
de910b9bc2 | |||
|
beeee7ae9f | ||
|
e945c8b38d | ||
|
638b85d329 | ||
3c6fed68cf | |||
fc56973157 | |||
6d50786773 | |||
3ef75f488a | |||
19f0c466f7 | |||
d5c4030527 | |||
b30b368820 | |||
bb3203bd33 | |||
21aa6f0b12 | |||
47e3272458 | |||
74a0d25926 | |||
687f2d157d | |||
4c9f661544 | |||
f91d3efc25 | |||
e1e97bc31c | |||
bcf74e384e | |||
ba69d83e2b | |||
3ea5002ded | |||
d5044a7f1e |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
.vscode/settings.json
|
||||
gtkwindow.inc
|
||||
gtkwindow.inc
|
||||
gtkwindow.parsenized
|
||||
gtkwindow.tokenized
|
||||
__pycache__/daemon.cpython-37.pyc
|
BIN
__pycache__/lineanalyzer.cpython-37.pyc
Normal file
BIN
__pycache__/lineanalyzer.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/parser.cpython-37.pyc
Normal file
BIN
__pycache__/parser.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/tokenizer.cpython-37.pyc
Normal file
BIN
__pycache__/tokenizer.cpython-37.pyc
Normal file
Binary file not shown.
18
comment.py
Normal file
18
comment.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from metaclasses import InstanceCounterMeta
|
||||
from rply import LexerGenerator
|
||||
|
||||
class comment(object, metaclass=InstanceCounterMeta):
|
||||
def __init__(self,com):
|
||||
self.id = next(self.__class__._ids)
|
||||
self.comment_lexer = LexerGenerator()
|
||||
self.comment_lexer.add("CSTART", r"(/*)")
|
||||
|
||||
self.comment_lexer.add("CEND", r"(*/)")
|
||||
self.comment_lexer.ignore(r'\s+')
|
||||
|
||||
|
||||
def parse_comment(self):
|
||||
com = self.comment
|
||||
if com.startswith('/*'):
|
||||
self.block_comment = True
|
||||
|
121
daemon.py
Normal file
121
daemon.py
Normal file
@@ -0,0 +1,121 @@
|
||||
"""Generic linux daemon base class for python 3.x."""
|
||||
|
||||
import sys, os, time, atexit, signal
|
||||
|
||||
class Daemon:
|
||||
"""A generic daemon class.
|
||||
|
||||
Usage: subclass the daemon class and override the run() method."""
|
||||
|
||||
def __init__(self, pidfile): self.pidfile = pidfile
|
||||
|
||||
def daemonize(self):
|
||||
"""Deamonize class. UNIX double fork mechanism."""
|
||||
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
# exit first parent
|
||||
sys.exit(0)
|
||||
except OSError as err:
|
||||
sys.stderr.write('fork #1 failed: {0}\n'.format(err))
|
||||
sys.exit(1)
|
||||
|
||||
# decouple from parent environment
|
||||
os.chdir('/')
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
|
||||
# do second fork
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
|
||||
# exit from second parent
|
||||
sys.exit(0)
|
||||
except OSError as err:
|
||||
sys.stderr.write('fork #2 failed: {0}\n'.format(err))
|
||||
sys.exit(1)
|
||||
|
||||
# redirect standard file descriptors
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
si = open(os.devnull, 'r')
|
||||
so = open(os.devnull, 'a+')
|
||||
se = open(os.devnull, 'a+')
|
||||
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
|
||||
# write pidfile
|
||||
atexit.register(self.delpid)
|
||||
|
||||
pid = str(os.getpid())
|
||||
with open(self.pidfile,'w+') as f:
|
||||
f.write(pid + '\n')
|
||||
|
||||
def delpid(self):
|
||||
os.remove(self.pidfile)
|
||||
|
||||
def start(self):
|
||||
"""Start the daemon."""
|
||||
|
||||
# Check for a pidfile to see if the daemon already runs
|
||||
try:
|
||||
with open(self.pidfile,'r') as pf:
|
||||
|
||||
pid = int(pf.read().strip())
|
||||
except IOError:
|
||||
pid = None
|
||||
|
||||
if pid:
|
||||
message = "pidfile {0} already exist. " + \
|
||||
"Daemon already running?\n"
|
||||
sys.stderr.write(message.format(self.pidfile))
|
||||
sys.exit(1)
|
||||
|
||||
# Start the daemon
|
||||
self.daemonize()
|
||||
self.run()
|
||||
|
||||
def stop(self):
|
||||
"""Stop the daemon."""
|
||||
|
||||
# Get the pid from the pidfile
|
||||
try:
|
||||
with open(self.pidfile,'r') as pf:
|
||||
pid = int(pf.read().strip())
|
||||
except IOError:
|
||||
pid = None
|
||||
|
||||
if not pid:
|
||||
message = "pidfile {0} does not exist. " + \
|
||||
"Daemon not running?\n"
|
||||
sys.stderr.write(message.format(self.pidfile))
|
||||
return # not an error in a restart
|
||||
|
||||
# Try killing the daemon process
|
||||
try:
|
||||
while 1:
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
time.sleep(0.1)
|
||||
except OSError as err:
|
||||
e = str(err.args)
|
||||
if e.find("No such process") > 0:
|
||||
if os.path.exists(self.pidfile):
|
||||
os.remove(self.pidfile)
|
||||
else:
|
||||
print (str(err.args))
|
||||
sys.exit(1)
|
||||
|
||||
def restart(self):
|
||||
"""Restart the daemon."""
|
||||
self.stop()
|
||||
self.start()
|
||||
|
||||
def run(self):
|
||||
"""You should override this method when you subclass Daemon.
|
||||
|
||||
It will be called after the process has been daemonized by
|
||||
start() or restart()."""
|
275
gtk.inc
275
gtk.inc
@@ -1,275 +0,0 @@
|
||||
; GTK - The GIMP Toolkit
|
||||
; Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
;
|
||||
; This library is free software; you can redistribute it and/or
|
||||
; modify it under the terms of the GNU Lesser General Public
|
||||
; License as published by the Free Software Foundation; either
|
||||
; version 2 of the License, or (at your option) any later version.
|
||||
;
|
||||
; This library is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS A PARTICULAR PURPOSE. See the GNU
|
||||
; Lesser General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU Lesser General Public
|
||||
; License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;
|
||||
; Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
||||
; file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
; files for a list of changes. These files are distributed with
|
||||
; GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
|
||||
%ifndef __GTK_H__
|
||||
%define __GTK_H__
|
||||
%define __GTK_H_INSIDE__
|
||||
%include "gdk/gdk.inc"
|
||||
%include "gtk/gtkaboutdialog.inc"
|
||||
%include "gtk/gtkaccelgroup.inc"
|
||||
%include "gtk/gtkaccellabel.inc"
|
||||
%include "gtk/gtkaccelmap.inc"
|
||||
%include "gtk/gtkaccessible.inc"
|
||||
%include "gtk/gtkactionable.inc"
|
||||
%include "gtk/gtkactionbar.inc"
|
||||
%include "gtk/gtkadjustment.inc"
|
||||
%include "gtk/gtkappchooser.inc"
|
||||
%include "gtk/gtkappchooserdialog.inc"
|
||||
%include "gtk/gtkappchooserwidget.inc"
|
||||
%include "gtk/gtkappchooserbutton.inc"
|
||||
%include "gtk/gtkapplication.inc"
|
||||
%include "gtk/gtkapplicationwindow.inc"
|
||||
%include "gtk/gtkaspectframe.inc"
|
||||
%include "gtk/gtkassistant.inc"
|
||||
%include "gtk/gtkbbox.inc"
|
||||
%include "gtk/gtkbin.inc"
|
||||
%include "gtk/gtkbindings.inc"
|
||||
%include "gtk/gtkborder.inc"
|
||||
%include "gtk/gtkbox.inc"
|
||||
%include "gtk/gtkbuildable.inc"
|
||||
%include "gtk/gtkbuilder.inc"
|
||||
%include "gtk/gtkbutton.inc"
|
||||
%include "gtk/gtkcalendar.inc"
|
||||
%include "gtk/gtkcellarea.inc"
|
||||
%include "gtk/gtkcellareabox.inc"
|
||||
%include "gtk/gtkcellareacontext.inc"
|
||||
%include "gtk/gtkcelleditable.inc"
|
||||
%include "gtk/gtkcelllayout.inc"
|
||||
%include "gtk/gtkcellrenderer.inc"
|
||||
%include "gtk/gtkcellrendereraccel.inc"
|
||||
%include "gtk/gtkcellrenderercombo.inc"
|
||||
%include "gtk/gtkcellrendererpixbuf.inc"
|
||||
%include "gtk/gtkcellrendererprogress.inc"
|
||||
%include "gtk/gtkcellrendererspin.inc"
|
||||
%include "gtk/gtkcellrendererspinner.inc"
|
||||
%include "gtk/gtkcellrenderertext.inc"
|
||||
%include "gtk/gtkcellrenderertoggle.inc"
|
||||
%include "gtk/gtkcellview.inc"
|
||||
%include "gtk/gtkcheckbutton.inc"
|
||||
%include "gtk/gtkcheckmenuitem.inc"
|
||||
%include "gtk/gtkclipboard.inc"
|
||||
%include "gtk/gtkcolorbutton.inc"
|
||||
%include "gtk/gtkcolorchooser.inc"
|
||||
%include "gtk/gtkcolorchooserdialog.inc"
|
||||
%include "gtk/gtkcolorchooserwidget.inc"
|
||||
%include "gtk/gtkcolorutils.inc"
|
||||
%include "gtk/gtkcombobox.inc"
|
||||
%include "gtk/gtkcomboboxtext.inc"
|
||||
%include "gtk/gtkcontainer.inc"
|
||||
%include "gtk/gtkcssprovider.inc"
|
||||
%include "gtk/gtkcsssection.inc"
|
||||
%include "gtk/gtkdebug.inc"
|
||||
%include "gtk/gtkdialog.inc"
|
||||
%include "gtk/gtkdnd.inc"
|
||||
%include "gtk/gtkdrawingarea.inc"
|
||||
%include "gtk/gtkeditable.inc"
|
||||
%include "gtk/gtkentry.inc"
|
||||
%include "gtk/gtkentrybuffer.inc"
|
||||
%include "gtk/gtkentrycompletion.inc"
|
||||
%include "gtk/gtkenums.inc"
|
||||
%include "gtk/gtkeventbox.inc"
|
||||
%include "gtk/gtkeventcontroller.inc"
|
||||
%include "gtk/gtkexpander.inc"
|
||||
%include "gtk/gtkfixed.inc"
|
||||
%include "gtk/gtkfilechooser.inc"
|
||||
%include "gtk/gtkfilechooserbutton.inc"
|
||||
%include "gtk/gtkfilechooserdialog.inc"
|
||||
%include "gtk/gtkfilechooserwidget.inc"
|
||||
%include "gtk/gtkfilefilter.inc"
|
||||
%include "gtk/gtkflowbox.inc"
|
||||
%include "gtk/gtkfontbutton.inc"
|
||||
%include "gtk/gtkfontchooser.inc"
|
||||
%include "gtk/gtkfontchooserdialog.inc"
|
||||
%include "gtk/gtkfontchooserwidget.inc"
|
||||
%include "gtk/gtkframe.inc"
|
||||
%include "gtk/gtkgesture.inc"
|
||||
%include "gtk/gtkgesturedrag.inc"
|
||||
%include "gtk/gtkgesturelongpress.inc"
|
||||
%include "gtk/gtkgesturemultipress.inc"
|
||||
%include "gtk/gtkgesturepan.inc"
|
||||
%include "gtk/gtkgesturerotate.inc"
|
||||
%include "gtk/gtkgesturesingle.inc"
|
||||
%include "gtk/gtkgestureswipe.inc"
|
||||
%include "gtk/gtkgesturezoom.inc"
|
||||
%include "gtk/gtkglarea.inc"
|
||||
%include "gtk/gtkgrid.inc"
|
||||
%include "gtk/gtkheaderbar.inc"
|
||||
%include "gtk/gtkicontheme.inc"
|
||||
%include "gtk/gtkiconview.inc"
|
||||
%include "gtk/gtkimage.inc"
|
||||
%include "gtk/gtkimcontext.inc"
|
||||
%include "gtk/gtkimcontextinfo.inc"
|
||||
%include "gtk/gtkimcontextsimple.inc"
|
||||
%include "gtk/gtkimmulticontext.inc"
|
||||
%include "gtk/gtkinfobar.inc"
|
||||
%include "gtk/gtkinvisible.inc"
|
||||
%include "gtk/gtklabel.inc"
|
||||
%include "gtk/gtklayout.inc"
|
||||
%include "gtk/gtklevelbar.inc"
|
||||
%include "gtk/gtklinkbutton.inc"
|
||||
%include "gtk/gtklistbox.inc"
|
||||
%include "gtk/gtkliststore.inc"
|
||||
%include "gtk/gtklockbutton.inc"
|
||||
%include "gtk/gtkmain.inc"
|
||||
%include "gtk/gtkmenu.inc"
|
||||
%include "gtk/gtkmenubar.inc"
|
||||
%include "gtk/gtkmenubutton.inc"
|
||||
%include "gtk/gtkmenuitem.inc"
|
||||
%include "gtk/gtkmenushell.inc"
|
||||
%include "gtk/gtkmenutoolbutton.inc"
|
||||
%include "gtk/gtkmessagedialog.inc"
|
||||
%include "gtk/gtkmodelbutton.inc"
|
||||
%include "gtk/gtkmodules.inc"
|
||||
%include "gtk/gtkmountoperation.inc"
|
||||
%include "gtk/gtknotebook.inc"
|
||||
%include "gtk/gtkoffscreenwindow.inc"
|
||||
%include "gtk/gtkorientable.inc"
|
||||
%include "gtk/gtkoverlay.inc"
|
||||
%include "gtk/gtkpagesetup.inc"
|
||||
%include "gtk/gtkpapersize.inc"
|
||||
%include "gtk/gtkpaned.inc"
|
||||
%include "gtk/gtkplacessidebar.inc"
|
||||
%include "gtk/gtkpopover.inc"
|
||||
%include "gtk/gtkpopovermenu.inc"
|
||||
%include "gtk/gtkprintcontext.inc"
|
||||
%include "gtk/gtkprintoperation.inc"
|
||||
%include "gtk/gtkprintoperationpreview.inc"
|
||||
%include "gtk/gtkprintsettings.inc"
|
||||
%include "gtk/gtkprogressbar.inc"
|
||||
%include "gtk/gtkradiobutton.inc"
|
||||
%include "gtk/gtkradiomenuitem.inc"
|
||||
%include "gtk/gtkradiotoolbutton.inc"
|
||||
%include "gtk/gtkrange.inc"
|
||||
%include "gtk/gtkrecentchooser.inc"
|
||||
%include "gtk/gtkrecentchooserdialog.inc"
|
||||
%include "gtk/gtkrecentchoosermenu.inc"
|
||||
%include "gtk/gtkrecentchooserwidget.inc"
|
||||
%include "gtk/gtkrecentfilter.inc"
|
||||
%include "gtk/gtkrecentmanager.inc"
|
||||
%include "gtk/gtkrender.inc"
|
||||
%include "gtk/gtkrevealer.inc"
|
||||
%include "gtk/gtkscale.inc"
|
||||
%include "gtk/gtkscalebutton.inc"
|
||||
%include "gtk/gtkscrollable.inc"
|
||||
%include "gtk/gtkscrollbar.inc"
|
||||
%include "gtk/gtkscrolledwindow.inc"
|
||||
%include "gtk/gtksearchbar.inc"
|
||||
%include "gtk/gtksearchentry.inc"
|
||||
%include "gtk/gtkselection.inc"
|
||||
%include "gtk/gtkseparator.inc"
|
||||
%include "gtk/gtkseparatormenuitem.inc"
|
||||
%include "gtk/gtkseparatortoolitem.inc"
|
||||
%include "gtk/gtksettings.inc"
|
||||
%include "gtk/gtkshow.inc"
|
||||
%include "gtk/gtkstacksidebar.inc"
|
||||
%include "gtk/gtksizegroup.inc"
|
||||
%include "gtk/gtksizerequest.inc"
|
||||
%include "gtk/gtkspinbutton.inc"
|
||||
%include "gtk/gtkspinner.inc"
|
||||
%include "gtk/gtkstack.inc"
|
||||
%include "gtk/gtkstackswitcher.inc"
|
||||
%include "gtk/gtkstatusbar.inc"
|
||||
%include "gtk/gtkstylecontext.inc"
|
||||
%include "gtk/gtkstyleprovider.inc"
|
||||
%include "gtk/gtkswitch.inc"
|
||||
%include "gtk/gtktextattributes.inc"
|
||||
%include "gtk/gtktextbuffer.inc"
|
||||
%include "gtk/gtktextbufferrichtext.inc"
|
||||
%include "gtk/gtktextchild.inc"
|
||||
%include "gtk/gtktextiter.inc"
|
||||
%include "gtk/gtktextmark.inc"
|
||||
%include "gtk/gtktexttag.inc"
|
||||
%include "gtk/gtktexttagtable.inc"
|
||||
%include "gtk/gtktextview.inc"
|
||||
%include "gtk/gtktogglebutton.inc"
|
||||
%include "gtk/gtktoggletoolbutton.inc"
|
||||
%include "gtk/gtktoolbar.inc"
|
||||
%include "gtk/gtktoolbutton.inc"
|
||||
%include "gtk/gtktoolitem.inc"
|
||||
%include "gtk/gtktoolitemgroup.inc"
|
||||
%include "gtk/gtktoolpalette.inc"
|
||||
%include "gtk/gtktoolshell.inc"
|
||||
%include "gtk/gtktooltip.inc"
|
||||
%include "gtk/gtktestutils.inc"
|
||||
%include "gtk/gtktreednd.inc"
|
||||
%include "gtk/gtktreemodel.inc"
|
||||
%include "gtk/gtktreemodelfilter.inc"
|
||||
%include "gtk/gtktreemodelsort.inc"
|
||||
%include "gtk/gtktreeselection.inc"
|
||||
%include "gtk/gtktreesortable.inc"
|
||||
%include "gtk/gtktreestore.inc"
|
||||
%include "gtk/gtktreeview.inc"
|
||||
%include "gtk/gtktreeviewcolumn.inc"
|
||||
%include "gtk/gtktypebuiltins.inc"
|
||||
%include "gtk/gtktypes.inc"
|
||||
%include "gtk/gtkversion.inc"
|
||||
%include "gtk/gtkviewport.inc"
|
||||
%include "gtk/gtkvolumebutton.inc"
|
||||
%include "gtk/gtkwidget.inc"
|
||||
%include "gtk/gtkwidgetpath.inc"
|
||||
%include "gtk/gtkwindow.inc"
|
||||
%include "gtk/gtkwindowgroup.inc"
|
||||
%ifndef GTK_DISABLE_DEPRECATED
|
||||
%include "gtk/deprecated/gtkarrow.inc"
|
||||
%include "gtk/deprecated/gtkactivatable.inc"
|
||||
%include "gtk/deprecated/gtkaction.inc"
|
||||
%include "gtk/deprecated/gtkactiongroup.inc"
|
||||
%include "gtk/deprecated/gtkalignment.inc"
|
||||
%include "gtk/deprecated/gtkcolorsel.inc"
|
||||
%include "gtk/deprecated/gtkcolorseldialog.inc"
|
||||
%include "gtk/deprecated/gtkfontsel.inc"
|
||||
%include "gtk/deprecated/gtkgradient.inc"
|
||||
%include "gtk/deprecated/gtkhandlebox.inc"
|
||||
%include "gtk/deprecated/gtkhbbox.inc"
|
||||
%include "gtk/deprecated/gtkhbox.inc"
|
||||
%include "gtk/deprecated/gtkhpaned.inc"
|
||||
%include "gtk/deprecated/gtkhsv.inc"
|
||||
%include "gtk/deprecated/gtkhscale.inc"
|
||||
%include "gtk/deprecated/gtkhscrollbar.inc"
|
||||
%include "gtk/deprecated/gtkhseparator.inc"
|
||||
%include "gtk/deprecated/gtkiconfactory.inc"
|
||||
%include "gtk/deprecated/gtkimagemenuitem.inc"
|
||||
%include "gtk/deprecated/gtkmisc.inc"
|
||||
%include "gtk/deprecated/gtknumerableicon.inc"
|
||||
%include "gtk/deprecated/gtkradioaction.inc"
|
||||
%include "gtk/deprecated/gtkrc.inc"
|
||||
%include "gtk/deprecated/gtkrecentaction.inc"
|
||||
%include "gtk/deprecated/gtkstatusicon.inc"
|
||||
%include "gtk/deprecated/gtkstock.inc"
|
||||
%include "gtk/deprecated/gtkstyle.inc"
|
||||
%include "gtk/deprecated/gtkstyleproperties.inc"
|
||||
%include "gtk/deprecated/gtksymboliccolor.inc"
|
||||
%include "gtk/deprecated/gtktable.inc"
|
||||
%include "gtk/deprecated/gtktearoffmenuitem.inc"
|
||||
%include "gtk/deprecated/gtkthemingengine.inc"
|
||||
%include "gtk/deprecated/gtktoggleaction.inc"
|
||||
%include "gtk/deprecated/gtkuimanager.inc"
|
||||
%include "gtk/deprecated/gtkvbbox.inc"
|
||||
%include "gtk/deprecated/gtkvbox.inc"
|
||||
%include "gtk/deprecated/gtkvpaned.inc"
|
||||
%include "gtk/deprecated/gtkvscale.inc"
|
||||
%include "gtk/deprecated/gtkvscrollbar.inc"
|
||||
%include "gtk/deprecated/gtkvseparator.inc"
|
||||
%endif ; GTK_DISABLE_DEPRECATED
|
||||
%include "gtk/gtk-autocleanups.inc"
|
||||
%undef __GTK_H_INSIDE__
|
||||
%endif ; __GTK_H__
|
350
gtkwindow.inc
350
gtkwindow.inc
@@ -1,350 +0,0 @@
|
||||
; GTK - The GIMP Toolkit
|
||||
; Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
;
|
||||
; This library is free software; you can redistribute it and/or
|
||||
; modify it under the terms of the GNU Lesser General Public
|
||||
; License as published by the Free Software Foundation; either
|
||||
; version 2 of the License, or (at your option) any later version.
|
||||
;
|
||||
; This library is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS A PARTICULAR PURPOSE. See the GNU
|
||||
; Lesser General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU Lesser General Public
|
||||
; License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;
|
||||
; Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
||||
; file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
; files for a list of changes. These files are distributed with
|
||||
; GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
|
||||
%ifndef __GTK_WINDOW_H__
|
||||
%define __GTK_WINDOW_H__
|
||||
%if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
%error "Only "gtk/gtk.inc" can be included directly."
|
||||
%endif
|
||||
%include "gtk/gtkapplication.inc"
|
||||
%include "gtk/gtkaccelgroup.inc"
|
||||
%include "gtk/gtkbin.inc"
|
||||
%define GTK_TYPE_WINDOW (gtk_window_get_type ())
|
||||
%define GTK_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WINDOW, GtkWindow))
|
||||
%define GTK_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WINDOW, GtkWindowClass))
|
||||
%define GTK_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WINDOW))
|
||||
%define GTK_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WINDOW))
|
||||
%define GTK_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WINDOW, GtkWindowClass))
|
||||
; typedef struct _GtkWindowPrivate GtkWindowPrivate;
|
||||
; typedef struct _GtkWindowClass GtkWindowClass;
|
||||
; typedef struct _GtkWindowGeometryInfo GtkWindowGeometryInfo;
|
||||
; typedef struct _GtkWindowGroup GtkWindowGroup;
|
||||
; typedef struct _GtkWindowGroupClass GtkWindowGroupClass;
|
||||
; typedef struct _GtkWindowGroupPrivate GtkWindowGroupPrivate;
|
||||
; GtkWindowClass:
|
||||
; @parent_class: The parent class.
|
||||
; @set_focus: Sets child as the focus widget for the window.
|
||||
; @activate_focus: Activates the current focused widget within the window.
|
||||
; @activate_default: Activates the default widget for the window.
|
||||
; @keys_changed: Signal gets emitted when the set of accelerators or
|
||||
; mnemonics that are associated with window changes.
|
||||
; @enable_debugging: Class handler for the #GtkWindow::enable-debugging
|
||||
; keybinding signal. Since: 3.14
|
||||
|
||||
; G_SIGNAL_ACTION signals for keybindings
|
||||
; Padding for future expansion
|
||||
; GtkWindowType:
|
||||
; @GTK_WINDOW_TOPLEVEL: A regular window, such as a dialog.
|
||||
; @GTK_WINDOW_POPUP: A special window such as a tooltip.
|
||||
;
|
||||
; A #GtkWindow can be one of these types. Most things you’d consider a
|
||||
; “window” should have type #GTK_WINDOW_TOPLEVEL; windows with this type
|
||||
; are managed by the window manager and have a frame by default (call
|
||||
; gtk_window_set_decorated() to toggle the frame). Windows with type
|
||||
; #GTK_WINDOW_POPUP are ignored by the window manager; window manager
|
||||
; keybindings won’t work on them, the window manager won’t decorate the
|
||||
; window with a frame, many GTK+ features that rely on the window
|
||||
; manager will not work (e.g. resize grips and
|
||||
; maximization/minimization). #GTK_WINDOW_POPUP is used to implement
|
||||
; widgets such as #GtkMenu or tooltips that you normally don’t think of
|
||||
; as windows per se. Nearly all windows should be #GTK_WINDOW_TOPLEVEL.
|
||||
; In particular, do not use #GTK_WINDOW_POPUP just to turn off
|
||||
; the window borders; use gtk_window_set_decorated() for that.
|
||||
|
||||
GTK_WINDOW_TOPLEVEL EQU 0
|
||||
|
||||
GTK_WINDOW_POPUP EQU 1
|
||||
|
||||
/** EQU 2
|
||||
|
||||
; GtkWindowPosition:
|
||||
; @GTK_WIN_POS_NONE: No influence is made on placement.
|
||||
; @GTK_WIN_POS_CENTER: Windows should be placed in the center of the screen.
|
||||
; @GTK_WIN_POS_MOUSE: Windows should be placed at the current mouse position.
|
||||
; @GTK_WIN_POS_CENTER_ALWAYS: Keep window centered as it changes size, etc.
|
||||
; @GTK_WIN_POS_CENTER_ON_PARENT: Center the window on its transient
|
||||
; parent (see gtk_window_set_transient_for()).
|
||||
;
|
||||
; Window placement can be influenced using this enumeration. Note that
|
||||
; using #GTK_WIN_POS_CENTER_ALWAYS is almost always a bad idea.
|
||||
; It won’t necessarily work well with all window managers or on all windowing systems.
|
||||
|
||||
GTK_WIN_POS_NONE EQU 3
|
||||
|
||||
GTK_WIN_POS_CENTER EQU 4
|
||||
|
||||
GTK_WIN_POS_MOUSE EQU 5
|
||||
|
||||
GTK_WIN_POS_CENTER_ALWAYS EQU 6
|
||||
|
||||
GTK_WIN_POS_CENTER_ON_PARENT EQU 7
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 8
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 9
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 10
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 11
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 12
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 13
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 14
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 15
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 16
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 17
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 18
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 19
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 20
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 21
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 22
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 23
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 24
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 25
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 26
|
||||
|
||||
GDK_AVAILABLE_IN_3_4 EQU 27
|
||||
|
||||
GDK_AVAILABLE_IN_3_4 EQU 28
|
||||
|
||||
GDK_DEPRECATED_IN_3_8_FOR(gtk_widget_set_opacity) EQU 29
|
||||
|
||||
GDK_DEPRECATED_IN_3_8_FOR(gtk_widget_get_opacity) EQU 30
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 31
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 32
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 33
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 34
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 35
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 36
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 37
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 38
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 39
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 40
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 41
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 42
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 43
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 44
|
||||
|
||||
GDK_AVAILABLE_IN_3_4 EQU 45
|
||||
|
||||
GDK_AVAILABLE_IN_3_4 EQU 46
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 47
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 48
|
||||
|
||||
GDK_AVAILABLE_IN_3_2 EQU 49
|
||||
|
||||
GDK_AVAILABLE_IN_3_2 EQU 50
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 51
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 52
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 53
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 54
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 55
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 56
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 57
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 58
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 59
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 60
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 61
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 62
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 63
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 64
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 65
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 66
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 67
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 68
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 69
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 70
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 71
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 72
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 73
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 74
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 75
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 76
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 77
|
||||
|
||||
; If window is set modal, input will be grabbed when show and released when hide
|
||||
GDK_AVAILABLE_IN_ALL EQU 78
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 79
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 80
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 81
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 82
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 83
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 84
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 85
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 86
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 87
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 88
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 89
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 90
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 91
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 92
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 93
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 94
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 95
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 96
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 97
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 98
|
||||
|
||||
GDK_AVAILABLE_IN_3_18 EQU 99
|
||||
|
||||
GDK_AVAILABLE_IN_3_10 EQU 100
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 101
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 102
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 103
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 104
|
||||
|
||||
; Set initial default size of the window (does not constrain user
|
||||
; resize operations)
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 105
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 106
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 107
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 108
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 109
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 110
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 111
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 112
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 113
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 114
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 115
|
||||
|
||||
; Ignore this unless you are writing a GUI builder
|
||||
GDK_DEPRECATED_IN_3_10 EQU 116
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 117
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 118
|
||||
|
||||
GDK_AVAILABLE_IN_ALL EQU 119
|
||||
|
||||
; Window grips
|
||||
|
||||
GDK_DEPRECATED_IN_3_14 EQU 120
|
||||
|
||||
GDK_DEPRECATED_IN_3_14 EQU 121
|
||||
|
||||
GDK_DEPRECATED_IN_3_14 EQU 122
|
||||
|
||||
GDK_DEPRECATED_IN_3_14 EQU 123
|
||||
|
||||
GDK_AVAILABLE_IN_3_10 EQU 124
|
||||
|
||||
GDK_AVAILABLE_IN_3_16 EQU 125
|
||||
|
||||
GDK_AVAILABLE_IN_3_12 EQU 126
|
||||
|
||||
GDK_AVAILABLE_IN_3_14 EQU 127
|
||||
|
||||
G_END_DECLS EQU 128
|
||||
|
||||
%endif ; __GTK_WINDOW_H__
|
16
h2inc.py
16
h2inc.py
@@ -1,4 +1,6 @@
|
||||
"""Script for translating C-header files into nasm syntax include files"""
|
||||
'''
|
||||
Script for translating C-header files into nasm syntax include files
|
||||
'''
|
||||
import os
|
||||
import errno
|
||||
from parser import PARSER
|
||||
@@ -8,12 +10,14 @@ class H2INC:
|
||||
self.filelist = []
|
||||
self.folderlist = []
|
||||
self.sourcedir = "/usr/include"
|
||||
self.destdir = "/data/include"
|
||||
self.destdir = "~/data/include"
|
||||
self.filecnt = 0
|
||||
self.foldercnt = 0
|
||||
|
||||
def srcfilecnt(self, sourcedir):
|
||||
'''
|
||||
### Return the number of files, ending with '.h', in sourcedir - including subdirectories ###
|
||||
'''
|
||||
for folderName, subfolders, files in os.walk(self.sourcedir):
|
||||
for file in files:
|
||||
if file.lower().endswith('.h'):
|
||||
@@ -25,7 +29,9 @@ class H2INC:
|
||||
return False
|
||||
|
||||
def srcfoldercnt(self, src):
|
||||
'''
|
||||
### Return the number of folders, if it contains '*.h' files, in sourcedir - including subdirectories ###
|
||||
'''
|
||||
for folderName, subfolders, files in os.walk(src):
|
||||
if subfolders:
|
||||
for subfolder in subfolders:
|
||||
@@ -79,7 +85,7 @@ class H2INC:
|
||||
for lines in fh:
|
||||
self.tupfile.append(lines)
|
||||
fh.close()
|
||||
resultfile = parse.parseheader(self.tupfile)
|
||||
resultfile = parse.parseheader(self.tupfile, inputfile)
|
||||
print(resultfile)
|
||||
for l in resultfile:
|
||||
for w in l:
|
||||
@@ -109,5 +115,5 @@ if __name__ == "__main__":
|
||||
print(app.filecnt)
|
||||
if app.srcfoldercnt(app.sourcedir) == True:
|
||||
print(app.foldercnt)
|
||||
app.read_file("./gtkwindow.h") #testfile for comments and header includes
|
||||
#app.process_directory()
|
||||
#app.read_file("./gtkwindow.h") #testfile for comments and header includes
|
||||
app.process_directory()
|
38
h2incd.py
Normal file
38
h2incd.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import sys, time
|
||||
from daemon import Daemon
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
|
||||
class h2incDaemon(Daemon):
|
||||
def run(self):
|
||||
event_handler = MyHandler()
|
||||
observer = Observer()
|
||||
observer.schedule(event_handler, path='/usr/include', recursive=False)
|
||||
observer.start()
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
observer.stop()
|
||||
observer.join()
|
||||
|
||||
class MyHandler(FileSystemEventHandler):
|
||||
def on_modified(self, event):
|
||||
print(f'event type: {event.event_type} path : {event.src_path}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
daemon = h2incDaemon('/tmp/h2inc-daemon.pid')
|
||||
if len(sys.argv) == 2:
|
||||
if 'start' == sys.argv[1]:
|
||||
daemon.start()
|
||||
elif 'stop' == sys.argv[1]:
|
||||
daemon.stop()
|
||||
elif 'restart' == sys.argv[1]:
|
||||
daemon.restart()
|
||||
else:
|
||||
print('Unknown command')
|
||||
sys.exit(2)
|
||||
sys.exit(0)
|
||||
else:
|
||||
print('usage: %s start|stop|restart' % sys.argv[0])
|
||||
sys.exit(2)
|
123
lineanalyzer.py
Normal file
123
lineanalyzer.py
Normal file
@@ -0,0 +1,123 @@
|
||||
'''
|
||||
Contains class LINEANALYSER
|
||||
'''
|
||||
from contextlib import ContextDecorator
|
||||
from itertools import count
|
||||
|
||||
PREPROCESSOR_DIRECTIVES = ['#include','#define','#undef','#if','#ifdef','#ifndef','#error','#endif']
|
||||
|
||||
class ANALYZEOBJECT:
|
||||
_passes = count(0)
|
||||
_analyzed = []
|
||||
|
||||
def __init__(self):
|
||||
self.passes = 0
|
||||
self.analyzeline = []
|
||||
self.analyzed = []
|
||||
self.comment = False
|
||||
self.typedef = False
|
||||
self.members = False
|
||||
self.ts = ''
|
||||
|
||||
def analyze(self,l):
|
||||
if l == '' or l == '\n':
|
||||
return l
|
||||
if self.typedef == True:
|
||||
rv = self.analyze_typedef(l)
|
||||
if rv != False:
|
||||
return rv
|
||||
rv = self.analyze_comment(l)
|
||||
if rv != False:
|
||||
return rv
|
||||
rv = self.analyze_preproc(l)
|
||||
if rv != False:
|
||||
return rv
|
||||
rv = self.analyze_typedef(l)
|
||||
if rv != False:
|
||||
return rv
|
||||
return l
|
||||
|
||||
def analyze_comment(self,l):
|
||||
s = l.split()
|
||||
w = [w for w in s]
|
||||
if w[0] == '/*' or w[0] == '/**':
|
||||
self.comment = True
|
||||
if w[-1] == '*/' or w[-1] == '**/':
|
||||
self.comment = False
|
||||
return l
|
||||
if w[0] == '*/' or w[0] == '**/':
|
||||
self.comment = False
|
||||
return l
|
||||
if self.comment == True:
|
||||
if w[0] == '*':
|
||||
return l
|
||||
return False
|
||||
|
||||
def analyze_preproc(self,l):
|
||||
s = l.split()
|
||||
w = [w for w in s]
|
||||
if w[0] in PREPROCESSOR_DIRECTIVES:
|
||||
return l
|
||||
return False
|
||||
|
||||
def analyze_typedef(self,l):
|
||||
if self.typedef == False:
|
||||
self.ts = ''
|
||||
self.ts += l
|
||||
s = l.split()
|
||||
w = [w for w in s]
|
||||
if w[0] == 'typedef':
|
||||
if w[1] == 'struct':
|
||||
if w[-1].endswith(';'):
|
||||
self.typedef = False
|
||||
return self.ts
|
||||
else:
|
||||
self.typedef = True
|
||||
return 'next'
|
||||
if w[1] == 'enum':
|
||||
if w[-1].endswith(';'):
|
||||
self.typedef = False
|
||||
return self.ts
|
||||
else:
|
||||
self.typedef = True
|
||||
return 'next'
|
||||
if self.typedef == True:
|
||||
if w[0].startswith('{'):
|
||||
return self.ts
|
||||
if w[0].startswith('}'):
|
||||
self.typedef = False
|
||||
return self.ts
|
||||
return False
|
||||
|
||||
def analyze_struct(self,l):
|
||||
ts = ''
|
||||
ts += l
|
||||
s = l.split()
|
||||
w = [w for w in s]
|
||||
if w[0] == 'struct':
|
||||
if w[-1].endswith(';'):
|
||||
self.struct = False
|
||||
return ts
|
||||
else:
|
||||
self.struct = True
|
||||
return 'next'
|
||||
if self.struct == True:
|
||||
if w[0] == '{':
|
||||
if w[-1].endswith(';'):
|
||||
self.members = False
|
||||
return ts
|
||||
else:
|
||||
self.members = True
|
||||
return 'next'
|
||||
return False
|
||||
|
||||
class ANALYZER(ANALYZEOBJECT):
|
||||
_ids = count(0)
|
||||
_passes = count(0)
|
||||
|
||||
def __init__(self):
|
||||
ANALYZEOBJECT.__init__(self)
|
||||
self.id = next(self._ids)
|
||||
self.tupline = []
|
||||
self.tupfile = []
|
||||
self.passes = next(self._passes)
|
8
metaclasses.py
Normal file
8
metaclasses.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import itertools
|
||||
|
||||
class InstanceCounterMeta(type):
|
||||
""" Metaclass to make instance counter not share count with descendants
|
||||
"""
|
||||
def __init__(cls, name, bases, attrs):
|
||||
super().__init__(name, bases, attrs)
|
||||
cls._ids = itertools.count(1)
|
371
parser.py
371
parser.py
@@ -1,15 +1,24 @@
|
||||
"""Contains class PARSER"""
|
||||
'''
|
||||
Contains class PARSER
|
||||
'''
|
||||
from itertools import count
|
||||
import os
|
||||
from tokenizer import TOKENIZER
|
||||
from lineanalyzer import ANALYZER
|
||||
|
||||
#Element type definitions. Used in the parse process.
|
||||
ELEMENT_TYPE_PREPROCESS = 1
|
||||
ELEMENT_TYPE_REGULAR = 2
|
||||
|
||||
TOKENS = ['TOKEN_CSTART','TOKEN_CMID','TOKEN_CEND','TOKEN_RPAREN',
|
||||
'TOKEN_LPAREN','TOKEN_ENDLINE','TOKEN_RETVAL','TOKEN_PREPROCESS',
|
||||
'TOKEN_ID','TOKEN_PLUS','TOKEN_MINUS','TOKEN_DIV','TOKEN_MULT',
|
||||
'TOKEN_LPAREN','TOKEN_ENDLINE','TOKEN_RETVAL','TOKEN_TYPEDEF',
|
||||
'TOKEN_IF','TOKEN_PLUS','TOKEN_MINUS','TOKEN_DIV','TOKEN_MULT',
|
||||
'TOKEN_ASSIGN','TOKEN_EQUAL','TOKEN_LBRACE','TOKEN_RBRACE',
|
||||
'TOKEN_COMMA','TOKEN_SEMICOLON','TOKEN_LANGLE','TOKEN_RANGLE','TOKEN_POINTER']
|
||||
'TOKEN_COMMA','TOKEN_SEMICOLON','TOKEN_LANGLE','TOKEN_RANGLE',
|
||||
'TOKEN_POINTER', 'TOKEN_STRUCT','TOKEN_ENUM','TOKEN_MACRO',
|
||||
'TOKEN_FUNCTION','TOKEN_TYPEDEF_ENUM','TOKEN_TYPEDEF_STRUCT',
|
||||
'TOKEN_TYPEDEF_STRUCT_STRUCT','TOKEN_TAG_NAME','TOKEN_ALIAS',
|
||||
'TOKEN_ENUM']
|
||||
|
||||
RESERVED = {'auto' : 'AUTO','break' : 'BREAK','case' : 'CASE','char' : 'CHAR',
|
||||
'const' : 'CONST','continue' : 'CONTINUE','default' : 'DEFAULT','do' : 'DO',
|
||||
@@ -20,16 +29,24 @@ RESERVED = {'auto' : 'AUTO','break' : 'BREAK','case' : 'CASE','char' : 'CHAR',
|
||||
'double' : 'DOUBLE','else' : 'ELSE','enum' : 'ENUM','extern' : 'EXTERN',
|
||||
'float' : 'FLOAT','for' : 'FOR','goto' : 'GOTO','if' : 'IF'}
|
||||
|
||||
PREPROCESSOR_DIRECTIVES = {'#include' : 'TOKEN_PREPROCESS','#define' : 'TOKEN_PREPROCESS','#undef' : 'TOKEN_PREPROCESS',
|
||||
'#if' : 'TOKEN_PREPROCESS','#ifdef' : 'TOKEN_PREPROCESS','#ifndef' : 'TOKEN_PREPROCESS','#error' : 'TOKEN_PREPROCESS',
|
||||
'__FILE__' : 'TOKEN_PREPROCESS','__LINE__' : 'TOKEN_PREPROCESS','__DATE__' : 'TOKEN_PREPROCESS',
|
||||
'__TIME__' : 'TOKEN_PREPROCESS','__TIMESTAMP__' : 'TOKEN_PREPROCESS','pragma' : 'TOKEN_PREPROCESS',
|
||||
'#' : 'TOKEN_PREPROCESS','##' : 'TOKEN_PREPROCESS','#endif' : 'TOKEN_PREPROCESS'}
|
||||
PREPROCESSOR_DIRECTIVES = {'#include' : 'TOKEN_INCLUDE','#define' : 'TOKEN_DEFINE','#undef' : 'TOKEN_UNDEFINE',
|
||||
'#if' : 'TOKEN_IF','#ifdef' : 'TOKEN_IFDEF','#ifndef' : 'TOKEN_IFNDEF','#error' : 'TOKEN_ERROR',
|
||||
'__FILE__' : 'TOKEN_BASE_FILE','__LINE__' : 'TOKEN_BASE_LINE','__DATE__' : 'TOKEN_BASE_DATE',
|
||||
'__TIME__' : 'TOKEN_BASE_TIME','__TIMESTAMP__' : 'TOKEN_BASE_TIMESTAMP','pragma' : 'TOKEN_PRAGMA',
|
||||
'#' : 'TOKEN_HASH','##' : 'TOKEN_DOUBLEHASH','#endif' : 'TOKEN_ENDIF'}
|
||||
|
||||
REGULAR = {'/*' : 'TOKEN_CSTART','*/' : 'TOKEN_CEND', '*' : 'TOKEN_CMID', '=' : 'TOKEN_ASSIGN','==' : 'TOKEN_EQUAL',
|
||||
'{' : 'TOKEN_LBRACE','}' : 'TOKEN_RBRACE','\+' : 'TOKEN_PLUS','-' : 'TOKEN_MINUS',
|
||||
'\*' : 'TOKEN_MULT','/' : 'TOKEN_DIV','\(' : 'TOKEN_LPAREN','\)' : 'TOKEN_RPAREN',
|
||||
',' : 'TOKEN_COMMA',';' : 'TOKEN_SEMICOLON','\<' : 'TOKEN_LANGLE','\>' : 'TOKEN_RANGLE'}
|
||||
REGULAR = {'/*' : 'TOKEN_CSTART','/**' : 'TOKEN_CSTART','*/' : 'TOKEN_CEND', '*' : 'TOKEN_CMID', '=' : 'TOKEN_ASSIGN',
|
||||
'==' : 'TOKEN_EQUAL','{' : 'TOKEN_LBRACE','}' : 'TOKEN_RBRACE','};' : 'TOKEN_ENDBRACE','+' : 'TOKEN_PLUS','-' : 'TOKEN_MINUS',
|
||||
'*' : 'TOKEN_MULT','/' : 'TOKEN_DIV','(' : 'TOKEN_LPAREN',')' : 'TOKEN_RPAREN',',' : 'TOKEN_COMMA',
|
||||
';' : 'TOKEN_SEMICOLON','<' : 'TOKEN_LANGLE','>' : 'TOKEN_RANGLE','TYPEDEF' : 'TOKEN_TYPEDEF',
|
||||
'typedef' : 'TOKEN_TYPEDEF','enum' : 'TOKEN_ENUM','ENUM' : 'TOKEN_ENUM','struct' : 'TOKEN_STRUCT',
|
||||
'STRUCT' : 'TOKEN_STRUCT','char' : 'TOKEN_CHAR','CHAR' : 'TOKEN_CHAR','const' : 'TOKEN_CONST',
|
||||
'CONST' : 'TOKEN_CONST','int' : 'TOKEN_INT','INT' : 'TOKEN_INT','long' : 'TOKEN_LONG','LONG' : 'TOKEN_LONG',
|
||||
'short' : 'TOKEN_SHORT','SHORT' : 'TOKEN_SHORT','signed' : 'TOKEN_SIGNED','SIGNED' : 'TOKEN_SIGNED',
|
||||
'unsigned' : 'TOKEN_UNSIGNED','UNSIGNED' : 'TOKEN_UNSIGNED','void' : 'TOKEN_VOID','VOID' : 'TOKEN_VOID',
|
||||
'volatile' : 'TOKEN_VOLATILE','VOLATILE' : 'TOKEN_VOLATILE','double' : 'TOKEN_DOUBLE','DOUBLE' : 'TOKEN_DOUBLE',
|
||||
'float' : 'TOKEN_FLOAT','FLOAT' : 'TOKEN_FLOAT', '!defined' : 'TOKEN_NOT_DEFINED', '!DEFINED' : 'TOKEN_NOT_DEFINED',
|
||||
'boolean' : 'TOKEN_BOOLEAN', 'BOOLEAN' : 'TOKEN_BOOLEAN', '(*' : 'TOKEN_FUNCTION_POINTER'}
|
||||
|
||||
NASM_PREPROCESS_DIRECTIVES = {'#include' : '%include','#define' : '%define','#undef' : '%undef',
|
||||
'#if' : '%if','#ifdef' : '%ifdef','#ifndef' : '%ifndef','#endif' : '%endif',
|
||||
@@ -41,15 +58,35 @@ NASM_ENUM = "EQU"
|
||||
|
||||
NASM_REGULAR = {'/*' : ';', '*' : ';', '*/' : ''}
|
||||
|
||||
TOKENS += RESERVED.values()
|
||||
#REGULAR += RESERVED.values()
|
||||
|
||||
PARSER_TOKENS = ['PARSE_MULTILINE_COMMENT', 'PARSE_SINGLELINE_COMMENT', 'PARSE_TYPEDEF_ENUM', 'PARSE_TYPEDEF_STRUCT',
|
||||
'PARSE_TYPEDEF_STRUCT_STRUCT', 'PARSE_STRUCT', 'PARSE_TAG_NAME', 'PARSE_STRUCT_MEMBER', 'PARSE_ENDSTRUCT',
|
||||
'PARSE_ALIAS', 'PARSE_FUNCTION_POINTER', 'PARSE_FUNCTION', 'PARSE_IFNDEF']
|
||||
|
||||
COMMENT_SINGLE_LINE = 0
|
||||
COMMENT_MULTI_LINE = 1
|
||||
|
||||
inside_member = False
|
||||
inside_braces = False
|
||||
inside_typedef_struct_struct = False
|
||||
inside_typedef_struct = False
|
||||
inside_typedef_enum = False
|
||||
inside_typedef = False
|
||||
inside_struct = False
|
||||
inside_include = False
|
||||
inside_string = False
|
||||
inside_comment = False
|
||||
inside_if = False
|
||||
inside_ifndef = False
|
||||
substitute = False
|
||||
|
||||
class PARSEOBJECT:
|
||||
_passes = count(0)
|
||||
_lineanalyzer = ANALYZER()
|
||||
|
||||
def __init__(self):
|
||||
self.tokenize = TOKENIZER()
|
||||
self.parseline = []
|
||||
self.parsefile = []
|
||||
self.passes = 0
|
||||
@@ -61,17 +98,58 @@ class PARSEOBJECT:
|
||||
self.inside_comment = False
|
||||
self.inside_typedef = False
|
||||
self.typedef_enum = False
|
||||
self.typedef_struct = False
|
||||
self.struct_begin = False
|
||||
self.enum_begin = False
|
||||
self.struct = False
|
||||
self.struct_end = False
|
||||
|
||||
def inc_passes(self):
|
||||
self.passes = next(self._passes)
|
||||
|
||||
def parseheader(self, fl):
|
||||
def parseheader(self, fl, fn):
|
||||
tempfile = []
|
||||
tempfile1 = []
|
||||
templine = []
|
||||
outfile = ''
|
||||
rr = 'next'
|
||||
count = 0
|
||||
self.parse_reset()
|
||||
for l in fl:
|
||||
analyzed_line = self.analyzer(l)
|
||||
i = iter(fl)
|
||||
while i:
|
||||
try:
|
||||
rr = self._lineanalyzer.analyze(next(i))
|
||||
except StopIteration:
|
||||
i = False
|
||||
continue
|
||||
if rr == 'next':
|
||||
count += 1
|
||||
else:
|
||||
templine.append(rr)
|
||||
tempfile.append(templine)
|
||||
count += 1
|
||||
templine = []
|
||||
self.inc_passes()
|
||||
for l in tempfile:
|
||||
analyzed_line = self.token_analyzer(l)
|
||||
tempfile1.append(analyzed_line)
|
||||
for l in tempfile1:
|
||||
for w in l:
|
||||
outfile += w+" "
|
||||
outfile += "\n"
|
||||
outputfile = os.path.splitext(fn)[0]+'.tokenized'
|
||||
self.write_file(outputfile,outfile)
|
||||
self.inc_passes()
|
||||
tempfile = []
|
||||
for l in tempfile1:
|
||||
analyzed_line = self.parser_analyzer(l)
|
||||
tempfile.append(analyzed_line)
|
||||
for l in tempfile:
|
||||
for w in l:
|
||||
outfile += w+" "
|
||||
outfile += "\n"
|
||||
outputfile = os.path.splitext(fn)[0]+'.parsenized'
|
||||
self.write_file(outputfile,outfile)
|
||||
self.inc_passes()
|
||||
self.parsefile = self.parsetokens(tempfile)
|
||||
return self.parsefile
|
||||
@@ -87,6 +165,10 @@ class PARSEOBJECT:
|
||||
return tempstr
|
||||
|
||||
def tokenizer(self, w):
|
||||
global inside_comment
|
||||
global inside_string
|
||||
global inside_include
|
||||
global inside_struct
|
||||
token = ""
|
||||
if w in PREPROCESSOR_DIRECTIVES:
|
||||
token = PREPROCESSOR_DIRECTIVES.get(w)
|
||||
@@ -94,21 +176,187 @@ class PARSEOBJECT:
|
||||
if w in REGULAR:
|
||||
token = REGULAR.get(w)
|
||||
return token
|
||||
if w.startswith('/*'):
|
||||
inside_comment = True
|
||||
token = 'TOKEN_CSTART'
|
||||
return token
|
||||
if inside_comment == True:
|
||||
if w.endswith('*/'):
|
||||
inside_comment = False
|
||||
token = 'TOKEN_CEND'
|
||||
return token
|
||||
if w.startswith('"'):
|
||||
inside_string = True
|
||||
return False
|
||||
if w.endswith('"'):
|
||||
inside_string = False
|
||||
return False
|
||||
if w.isupper():
|
||||
if inside_string == True:
|
||||
return False
|
||||
else:
|
||||
token = 'TOKEN_MACRO'
|
||||
return token
|
||||
if w.islower():
|
||||
if inside_string == True or inside_include == True or inside_struct == True:
|
||||
return False
|
||||
else:
|
||||
if w.startswith('(*'):
|
||||
token = 'TOKEN_FUNCTION_POINTER'
|
||||
return token
|
||||
else:
|
||||
token = 'TOKEN_FUNCTION'
|
||||
return token
|
||||
return False
|
||||
|
||||
def analyzer(self, ln):
|
||||
global inside_include
|
||||
global inside_typedef
|
||||
global inside_typedef_enum
|
||||
global inside_typedef_struct
|
||||
global inside_typedef_struct_struct
|
||||
global inside_braces
|
||||
global inside_struct
|
||||
global inside_member
|
||||
analysed = []
|
||||
word = [w for w in ln.split()]
|
||||
for w in word:
|
||||
t = self.tokenizer(w)
|
||||
if t == 'TOKEN_INCLUDE':
|
||||
inside_include = True
|
||||
if t == 'TOKEN_TYPEDEF':
|
||||
inside_typedef = True
|
||||
if t == 'TOKEN_ENUM' and inside_typedef == True:
|
||||
inside_typedef_enum = True
|
||||
inside_typedef = False
|
||||
analysed.pop(0)
|
||||
analysed.insert(0,'TOKEN_TYPEDEF_ENUM')
|
||||
analysed.append(w)
|
||||
continue
|
||||
if t == 'TOKEN_STRUCT':
|
||||
if inside_typedef == True:
|
||||
if ln.endswith(';\n'):
|
||||
inside_typedef_struct = True
|
||||
inside_typedef = False
|
||||
analysed.pop(0)
|
||||
analysed.insert(0,'TOKEN_TYPEDEF_STRUCT')
|
||||
analysed.append(w)
|
||||
continue
|
||||
else:
|
||||
inside_typedef_struct_struct = True
|
||||
inside_typedef_struct = False
|
||||
inside_typedef = False
|
||||
analysed.pop(0)
|
||||
analysed.insert(0,'TOKEN_TYPEDEF_STRUCT_STRUCT')
|
||||
analysed.append(w)
|
||||
inside_typedef_struct_struct = False #### THIS needs to be further refined!
|
||||
continue
|
||||
else:
|
||||
inside_struct = True
|
||||
analysed.append(t)
|
||||
analysed.append(w)
|
||||
continue
|
||||
if t == 'TOKEN_LBRACE':
|
||||
inside_braces = True
|
||||
analysed.append(w)
|
||||
continue
|
||||
if t == 'TOKEN_RBRACE' and inside_struct == True:
|
||||
inside_braces = False
|
||||
inside_struct = False
|
||||
analysed.append(t)
|
||||
analysed.append(w)
|
||||
continue
|
||||
if inside_braces == True and inside_struct == True:
|
||||
if inside_member == True:
|
||||
inside_member = False
|
||||
analysed.append(w)
|
||||
continue
|
||||
else:
|
||||
t = 'TOKEN_MEMBER'
|
||||
inside_member = True
|
||||
analysed.append(t)
|
||||
analysed.append(w)
|
||||
continue
|
||||
if t == False:
|
||||
analysed.append(w)
|
||||
continue
|
||||
else:
|
||||
analysed.append(t)
|
||||
analysed.append(w)
|
||||
inside_include = False
|
||||
inside_struct = False
|
||||
return analysed
|
||||
|
||||
def token_analyzer(self, ln):
|
||||
global inside_comment
|
||||
analyzed = []
|
||||
for w in ln:
|
||||
if w == 'TOKEN_CSTART':
|
||||
inside_comment = True
|
||||
analyzed.append(w)
|
||||
continue
|
||||
if inside_comment == True:
|
||||
if w == 'TOKEN_MULT':
|
||||
analyzed.append('TOKEN_CMID')
|
||||
continue
|
||||
else:
|
||||
if w == 'TOKEN_CEND':
|
||||
analyzed.append(w)
|
||||
inside_comment = False
|
||||
continue
|
||||
else:
|
||||
if w.startswith('TOKEN'):
|
||||
continue
|
||||
analyzed.append(w)
|
||||
return analyzed
|
||||
|
||||
def parser_analyzer(self, ln):
|
||||
global inside_comment
|
||||
global inside_if
|
||||
global inside_ifndef
|
||||
global substitute
|
||||
analyzed = []
|
||||
subst = []
|
||||
for w in ln:
|
||||
if w == 'TOKEN_CSTART':
|
||||
inside_comment = True
|
||||
if ln[-1] != 'TOKEN_CEND':
|
||||
analyzed.append('PARSE_MULTILINE_COMMENT')
|
||||
continue
|
||||
else:
|
||||
analyzed.append('PARSE_SINGLELINE_COMMENT')
|
||||
continue
|
||||
if w == 'TOKEN_CMID':
|
||||
analyzed.append('PARSE_MULTILINE_COMMENT')
|
||||
continue
|
||||
if w == 'TOKEN_CEND':
|
||||
inside_comment = False
|
||||
continue
|
||||
if inside_comment == False:
|
||||
if w == '*/':
|
||||
continue
|
||||
if w == 'TOKEN_IF':
|
||||
inside_if = True
|
||||
analyzed.append('PARSE_IF')
|
||||
continue
|
||||
if inside_if == True:
|
||||
if w == 'TOKEN_NOT_DEFINED':
|
||||
substitute = True
|
||||
inside_if = False
|
||||
inside_ifndef = True
|
||||
subst.append('PARSE_IFNDEF')
|
||||
continue
|
||||
else:
|
||||
analyzed.append(w)
|
||||
continue
|
||||
if substitute == True:
|
||||
subst.append(w)
|
||||
continue
|
||||
else:
|
||||
analyzed.append(w)
|
||||
continue
|
||||
return analyzed
|
||||
|
||||
def parsetokens(self, fl):
|
||||
templine = []
|
||||
tempfile = []
|
||||
@@ -117,66 +365,111 @@ class PARSEOBJECT:
|
||||
for l in fl:
|
||||
templine = []
|
||||
tempstr = ""
|
||||
if len(l) == 0:
|
||||
templine.append("\n")
|
||||
if l == []:
|
||||
templine.append("")
|
||||
tempfile.append(templine)
|
||||
continue
|
||||
if l[0] == "TOKEN_CSTART" or l[0] == "TOKEN_CMID" or l[0] == "TOKEN_CEND":
|
||||
if "TOKEN_CSTART" in l:
|
||||
self.inside_comment = True
|
||||
tempfile.append(self.parse_comment(l))
|
||||
continue
|
||||
if l[0] == "TYPEDEF" or l[0] == "typedef":
|
||||
if "TOKEN_CMID" in l:
|
||||
self.inside_comment = True
|
||||
tempfile.append(self.parse_comment(l))
|
||||
continue
|
||||
if "TOKEN_CEND" in l:
|
||||
self.inside_comment = True
|
||||
tempfile.append(self.parse_comment(l))
|
||||
continue
|
||||
if "TYPEDEF" in l:
|
||||
self.parse_typedef(l)
|
||||
if self.typedef_enum == False:
|
||||
if self.typedef_enum == False and self.typedef_struct == False:
|
||||
templine.append("; ")
|
||||
for e in l:
|
||||
templine.append(e)
|
||||
tempfile.append(templine)
|
||||
if self.typedef_struct == True:
|
||||
templine.append('struc')
|
||||
templine.append(l[-1][:-1])
|
||||
tempfile.append(templine)
|
||||
templine = []
|
||||
templine.append('endstruc')
|
||||
tempfile.append(templine)
|
||||
continue
|
||||
if l[0] == "TOKEN_PREPROCESS":
|
||||
if "typedef" in l:
|
||||
self.parse_typedef(l)
|
||||
if self.typedef_enum == False and self.typedef_struct == False:
|
||||
templine.append("; ")
|
||||
for e in l:
|
||||
templine.append(e)
|
||||
tempfile.append(templine)
|
||||
if self.typedef_struct == True:
|
||||
templine.append('struc')
|
||||
templine.append(l[-1][:-1])
|
||||
tempfile.append(templine)
|
||||
templine = []
|
||||
templine.append('endstruc')
|
||||
tempfile.append(templine)
|
||||
continue
|
||||
if "struct" in l:
|
||||
self.parse_struct(l)
|
||||
|
||||
if "TOKEN_PREPROCESS" in l:
|
||||
tempfile.append(self.parse_preprocess(l))
|
||||
continue
|
||||
if self.inside_typedef == True:
|
||||
if self.typedef_enum == True:
|
||||
if l[0] == "TOKEN_LBRACE" and len(l) == 2:
|
||||
self.enum_begin = True
|
||||
enum_cnt = 0
|
||||
continue
|
||||
if len(l) == 1:
|
||||
if l[0].endswith(","):
|
||||
tempstr = l[0]
|
||||
templine.append(tempstr[:-1]+"\t")
|
||||
templine.append("EQU\t")
|
||||
templine.append(str(enum_cnt)+"\n")
|
||||
templine.append(str(enum_cnt))
|
||||
tempfile.append(templine)
|
||||
enum_cnt += 1
|
||||
continue
|
||||
else:
|
||||
templine.append(l[0]+"\t")
|
||||
templine.append("EQU\t")
|
||||
templine.append(str(enum_cnt)+"\n")
|
||||
templine.append(str(enum_cnt))
|
||||
tempfile.append(templine)
|
||||
enum_cnt += 1
|
||||
continue
|
||||
continue
|
||||
if len(l) == 3:
|
||||
if l[0].endswith(","):
|
||||
tempstr = l[0]
|
||||
enum_cnt = l[2]
|
||||
templine.append(tempstr[:-1]+"\t")
|
||||
templine.append("EQU"+"\t")
|
||||
templine.append(enum_cnt+"\n")
|
||||
templine.append(enum_cnt)
|
||||
tempfile.append(templine)
|
||||
continue
|
||||
continue
|
||||
if l[0] == "TOKEN_RBRACE" and len(l) == 3:
|
||||
self.enum_begin = False
|
||||
self.typedef_enum = False
|
||||
self.inside_typedef = False
|
||||
enum_cnt = 0
|
||||
continue
|
||||
continue
|
||||
continue
|
||||
return tempfile
|
||||
|
||||
def parse_struct(self, l):
|
||||
templine = []
|
||||
for w in l:
|
||||
if w == "struct":
|
||||
self.struct = True
|
||||
templine.append('struc')
|
||||
continue
|
||||
if w != "":
|
||||
templine.append(w)
|
||||
continue
|
||||
if w == "{" and self.struct == True:
|
||||
self.struct_begin = True
|
||||
continue
|
||||
return templine
|
||||
|
||||
def parse_typedef(self, l):
|
||||
templine = []
|
||||
for w in l:
|
||||
@@ -185,8 +478,12 @@ class PARSEOBJECT:
|
||||
continue
|
||||
if w == "ENUM" or w == "enum":
|
||||
self.typedef_enum = True
|
||||
self.typedef_struct = False
|
||||
continue
|
||||
if w == "STRUCT" or w == "struct":
|
||||
self.typedef_struct = True
|
||||
self.typedef_enum = False
|
||||
continue
|
||||
|
||||
|
||||
def parse_comment(self, l):
|
||||
templine = []
|
||||
@@ -216,6 +513,16 @@ class PARSEOBJECT:
|
||||
newline.append(w)
|
||||
return newline
|
||||
|
||||
def write_file(self, fn, data):
|
||||
if not os.path.exists(os.path.dirname(fn)):
|
||||
try:
|
||||
os.makedirs(os.path.dirname(fn))
|
||||
except OSError as exc: # Guard against race condition
|
||||
if exc.errno != errno.EEXIST:
|
||||
raise
|
||||
newfile = open(fn, "w")
|
||||
newfile.write(data)
|
||||
newfile.close()
|
||||
|
||||
class PARSER(PARSEOBJECT):
|
||||
_ids = count(0)
|
||||
|
92
tokenizer.py
Normal file
92
tokenizer.py
Normal file
@@ -0,0 +1,92 @@
|
||||
'''
|
||||
Contains class TOKENIZER
|
||||
'''
|
||||
from contextlib import ContextDecorator
|
||||
from itertools import count
|
||||
|
||||
class TOKENIZEOBJECT:
|
||||
_passes = count(0)
|
||||
_analyzed = []
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
def __init__(self):
|
||||
self.passes = 0
|
||||
self.analyzeline = []
|
||||
self.analyzed = []
|
||||
|
||||
class typedef_struct(ContextDecorator):
|
||||
def __enter__(self):
|
||||
TOKENIZER._analyzed.append('TOKEN_TYPEDEF_STRUCT')
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
class typedef_enum(ContextDecorator):
|
||||
def __enter__(self):
|
||||
TOKENIZER._analyzed.append('TOKEN_TYPEDEF_ENUM')
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
class enum(ContextDecorator):
|
||||
def __enter__(self):
|
||||
TOKENIZER._analyzed.append('TOKEN_ENUM')
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
class tagname(ContextDecorator):
|
||||
def __enter__(self):
|
||||
TOKENIZER._analyzed.append('TOKEN_TAG_NAME')
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
class alias(ContextDecorator):
|
||||
def __enter__(self):
|
||||
TOKENIZER._analyzed.append('TOKEN_ALIAS')
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
@typedef_struct()
|
||||
def TD_struct(self, tsl):
|
||||
'''
|
||||
Takes a Typedef Struct 'list' and appends all items (i) in that list to _analyzed.
|
||||
'''
|
||||
for i in tsl:
|
||||
self._analyzed.append(i)
|
||||
return
|
||||
|
||||
@typedef_enum()
|
||||
def TD_enum(self, e):
|
||||
'''
|
||||
Takes a Typedef enum member and appends it to _analyzed.
|
||||
'''
|
||||
self._analyzed.append(e)
|
||||
return
|
||||
|
||||
@tagname()
|
||||
def TD_tagname(self, tn):
|
||||
'''
|
||||
Takes a Typedef tagname and appends it to _analyzed.
|
||||
'''
|
||||
self._analyzed.append(tn)
|
||||
return
|
||||
|
||||
class TOKENIZER(TOKENIZEOBJECT):
|
||||
_ids = count(0)
|
||||
_passes = count(0)
|
||||
|
||||
def __init__(self):
|
||||
self.id = next(self._ids)
|
||||
self.tupline = []
|
||||
self.tupfile = []
|
||||
self.passes = next(self._passes)
|
23
watchdog_test.py
Normal file
23
watchdog_test.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python3
|
||||
import time
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
|
||||
|
||||
class MyHandler(FileSystemEventHandler):
|
||||
def on_modified(self, event):
|
||||
print(f'event type: {event.event_type} path : {event.src_path}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
event_handler = MyHandler()
|
||||
observer = Observer()
|
||||
observer.schedule(event_handler, path='/usr/include', recursive=False)
|
||||
observer.start()
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
observer.stop()
|
||||
observer.join()
|
Reference in New Issue
Block a user