[Git][NTPsec/ntpsec][master] Teach pythonize-header to handle a few more cases.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Oct 17 21:42:59 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
836498e0 by Eric S. Raymond at 2016-10-17T17:42:46-04:00
Teach pythonize-header to handle a few more cases.

- - - - -


1 changed file:

- wafhelpers/pythonize-header


Changes:

=====================================
wafhelpers/pythonize-header
=====================================
--- a/wafhelpers/pythonize-header
+++ b/wafhelpers/pythonize-header
@@ -1,10 +1,10 @@
 #!/usr/bin/env python
 """
-Generate a C Python module from a C file of macro definitions.
+Generate a Python module from a C file of macro definitions.
 
 Uses simple regexp transformations, so weird headers are likely to confuse it.
-Skips #include lines, struct and union declarations.  Transforms comments.
-Does not yet handle externs.
+Skips #include lines, struct and union declarations. simgle-line typedefs
+and externs.  Transforms comments. Does not yet handle multiline externs.
 """
 
 import sys, re
@@ -21,6 +21,12 @@ patterns = (
 
 skipstarters = ("struct", "union", "typedef struct", "typedef union")
 
+skippers = (
+    re.compile(r"^#include"), 
+    re.compile(r"^typedef.*;\s*$"), 
+    re.compile(r"^extern.*;\d*$"), 
+    )
+
 impossibles = ("sizeof", "offsetof")
 
 def pythonize(rfp, wfp):
@@ -30,7 +36,12 @@ def pythonize(rfp, wfp):
     skipto = False
     for line in rfp:
         # Omit include lines
-        if line.startswith("#include"):
+        skipit = False
+        for skipline in skippers:
+            if skipline.match(line):
+                skipit = True
+                break
+        if skipit:
             continue
         # Omit structure and union declarations
         for skipstart in skipstarters:



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/836498e05177093fd3627c552329c80b927c7251
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161017/4767c02b/attachment.html>


More information about the vc mailing list