aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal_gen.py
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-10-25 19:57:06 +0000
committerGuy Harris <guy@alum.mit.edu>2001-10-25 19:57:06 +0000
commit3820d7e2a511235fd81f810bc01aec5329695bc9 (patch)
tree26a1de5ae1b1c54bc03401cc70b88675833eab31 /ethereal_gen.py
parent456a121f2ab68d6f5db995712b7cb15875e4bb53 (diff)
Update from Frank Singleton:
- Handle "short" as a union discriminant type - Handle case where union discriminant may be a typedef - Change integer template to long template - Initial code for \n and \t as union case labels. svn path=/trunk/; revision=4076
Diffstat (limited to 'ethereal_gen.py')
-rw-r--r--ethereal_gen.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/ethereal_gen.py b/ethereal_gen.py
index 3903976940..15bc8614d7 100644
--- a/ethereal_gen.py
+++ b/ethereal_gen.py
@@ -1,6 +1,6 @@
# -*- python -*-
#
-# $Id: ethereal_gen.py,v 1.13 2001/10/18 21:49:58 guy Exp $
+# $Id: ethereal_gen.py,v 1.14 2001/10/25 19:57:06 guy Exp $
#
# ethereal_gen.py (part of idl2eth)
#
@@ -1099,9 +1099,7 @@ class ethereal_gen_C:
sys.stderr.write( "Error: idl2eth does not handle recursive unions yet \n")
sys.exit(1)
- st = ntype.switchType()
-
-
+ st = ntype.switchType().unalias() # may be typedef switch type, so find real type
#std = st.decl()
@@ -1133,7 +1131,11 @@ class ethereal_gen_C:
self.addvar(self.c_s_disc + pn + ";")
elif (st.kind() == idltype.tk_long):
- self.st.out(self.template_union_code_save_discriminant_integer, discname=pn )
+ self.st.out(self.template_union_code_save_discriminant_long, discname=pn )
+ self.addvar(self.c_s_disc + pn + ";")
+
+ elif (st.kind() == idltype.tk_short):
+ self.st.out(self.template_union_code_save_discriminant_short, discname=pn )
self.addvar(self.c_s_disc + pn + ";")
elif (st.kind() == idltype.tk_boolean):
@@ -1176,9 +1178,18 @@ class ethereal_gen_C:
#
# if char, dont convert to int, but put inside single quotes so that it is understood by C.
# eg: if (disc == 'b')..
+ #
+ # TODO : handle \xxx chars generically from a function or table lookup rather than
+ # a whole bunch of "if" statements. -- FS
+
- if (st.kind() == idltype.tk_char):
- string_clv = "'" + clv + "'"
+ if (st.kind() == idltype.tk_char):
+ if (clv == '\n'): # newline
+ string_clv = "'\\n'"
+ elif (clv == '\t'): # tab
+ string_clv = "'\\t'"
+ else:
+ string_clv = "'" + clv + "'"
else:
string_clv = '%i ' % clv
@@ -2523,9 +2534,13 @@ stream_is_big_endian = is_big_endian(header); /* get stream endianess */
disc_s_@discname@ = (gint32) u_octet4; /* save Enum Value discriminant and cast to gint32 */
"""
- template_union_code_save_discriminant_integer = """\
+ template_union_code_save_discriminant_long = """\
disc_s_@discname@ = (gint32) s_octet4; /* save gint32 discriminant and cast to gint32 */
"""
+
+ template_union_code_save_discriminant_short = """\
+disc_s_@discname@ = (gint32) s_octet2; /* save gint16 discriminant and cast to gint32 */
+"""
template_union_code_save_discriminant_char = """\
disc_s_@discname@ = (gint32) u_octet1; /* save guint1 discriminant and cast to gint32 */