]> granicus.if.org Git - libevent/commitdiff
use more python builtins; dont use reserved keywords
authorNiels Provos <provos@gmail.com>
Sat, 18 Nov 2006 21:27:42 +0000 (21:27 +0000)
committerNiels Provos <provos@gmail.com>
Sat, 18 Nov 2006 21:27:42 +0000 (21:27 +0000)
svn:r266

event_rpcgen.py

index d926512037ceef48b1890972d88618cf459d442a..881fc08d5930023f5a414dd8a442f1611ac09bd8 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Niels Provos <provos@citi.umich.edu>
 # All rights reserved.
 #
-# Generates marshalling code based on libevent.
+# Generates marshaling code based on libevent.
 
 import sys
 import re
@@ -16,8 +16,6 @@ _STRUCT_RE = '[a-z][a-z_0-9]*'
 # Globals
 line_count = 0
 
-leading = re.compile(r'^\s+')
-trailing = re.compile(r'\s+$')
 white = re.compile(r'^\s+')
 cppcomment = re.compile(r'\/\/.*$')
 cppdirect = []
@@ -1041,14 +1039,11 @@ class EntryArray(Entry):
         return dcl
 
 def NormalizeLine(line):
-    global leading
-    global trailing
     global white
     global cppcomment
     
     line = cppcomment.sub('', line)
-    line = leading.sub('', line)
-    line = trailing.sub('', line)
+    line = line.strip()
     line = white.sub(' ', line)
 
     return line
@@ -1056,7 +1051,7 @@ def NormalizeLine(line):
 def ProcessOneEntry(newstruct, entry):
     optional = 0
     array = 0
-    type = ''
+    entry_type = ''
     name = ''
     tag = ''
     tag_set = None
@@ -1068,7 +1063,7 @@ def ProcessOneEntry(newstruct, entry):
         token = tokens[0]
         tokens = tokens[1:]
 
-        if not type:
+        if not entry_type:
             if not optional and token == 'optional':
                 optional = 1
                 continue
@@ -1077,8 +1072,8 @@ def ProcessOneEntry(newstruct, entry):
                 array = 1
                 continue
 
-        if not type:
-            type = token
+        if not entry_type:
+            entry_type = token
             continue
 
         if not name:
@@ -1117,22 +1112,23 @@ def ProcessOneEntry(newstruct, entry):
         sys.exit(1)
 
     # Create the right entry
-    if type == 'bytes':
+    if entry_type == 'bytes':
         if fixed_length:
-            newentry = EntryBytes(type, name, tag, fixed_length)
+            newentry = EntryBytes(entry_type, name, tag, fixed_length)
         else:
-            newentry = EntryVarBytes(type, name, tag)
-    elif type == 'int' and not fixed_length:
-        newentry = EntryInt(type, name, tag)
-    elif type == 'string' and not fixed_length:
-        newentry = EntryString(type, name, tag)
+            newentry = EntryVarBytes(entry_type, name, tag)
+    elif entry_type == 'int' and not fixed_length:
+        newentry = EntryInt(entry_type, name, tag)
+    elif entry_type == 'string' and not fixed_length:
+        newentry = EntryString(entry_type, name, tag)
     else:
-        res = re.match(r'^struct\[(%s)\]$' % _STRUCT_RE, type, re.IGNORECASE)
+        res = re.match(r'^struct\[(%s)\]$' % _STRUCT_RE,
+                       entry_type, re.IGNORECASE)
         if res:
             # References another struct defined in our file
-            newentry = EntryStruct(type, name, tag, res.group(1))
+            newentry = EntryStruct(entry_type, name, tag, res.group(1))
         else:
-            print >>sys.stderr, 'Bad type: "%s" in "%s"' % (type, entry)
+            print >>sys.stderr, 'Bad type: "%s" in "%s"' % (entry_type, entry)
             sys.exit(1)
 
     structs = []
@@ -1335,6 +1331,10 @@ def BodyPreamble(name):
     return pre
 
 def main(argv):
+    if len(argv) < 2 or not argv[1]:
+        print >>sys.stderr, 'Need RPC description file as first argument.'
+        sys.exit(1)
+
     filename = argv[1]
 
     if filename.split('.')[-1] != 'rpc':