summaryrefslogtreecommitdiff
path: root/event_rpcgen.py
diff options
context:
space:
mode:
authorNiels Provos <provos@gmail.com>2006-11-18 21:27:42 +0000
committerNiels Provos <provos@gmail.com>2006-11-18 21:27:42 +0000
commit226fd50a99761f5e874e7376d99674ae54b1aeed (patch)
tree56bcabc5ad87c01511ff31c14f212c0a045d1818 /event_rpcgen.py
parent31ba30abfee720e49c19e7a4790854cfbe0e9d5e (diff)
downloadlibevent-226fd50a99761f5e874e7376d99674ae54b1aeed.tar.gz
use more python builtins; dont use reserved keywords
svn:r266
Diffstat (limited to 'event_rpcgen.py')
-rwxr-xr-xevent_rpcgen.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/event_rpcgen.py b/event_rpcgen.py
index d9265120..881fc08d 100755
--- a/event_rpcgen.py
+++ b/event_rpcgen.py
@@ -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':