# 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
# Globals
line_count = 0
-leading = re.compile(r'^\s+')
-trailing = re.compile(r'\s+$')
white = re.compile(r'^\s+')
cppcomment = re.compile(r'\/\/.*$')
cppdirect = []
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
def ProcessOneEntry(newstruct, entry):
optional = 0
array = 0
- type = ''
+ entry_type = ''
name = ''
tag = ''
tag_set = None
token = tokens[0]
tokens = tokens[1:]
- if not type:
+ if not entry_type:
if not optional and token == 'optional':
optional = 1
continue
array = 1
continue
- if not type:
- type = token
+ if not entry_type:
+ entry_type = token
continue
if not name:
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 = []
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':