[Redbutton-devel] SF.net SVN: redbutton: [452] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-10-19 16:25:34
|
Revision: 452
http://redbutton.svn.sourceforge.net/redbutton/?rev=452&view=rev
Author: skilvington
Date: 2007-10-19 09:25:28 -0700 (Fri, 19 Oct 2007)
Log Message:
-----------
cope with optional types in sequences
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-10-19 11:06:49 UTC (rev 451)
+++ redbutton-author/trunk/asn1tag.h 2007-10-19 16:25:28 UTC (rev 452)
@@ -756,13 +756,13 @@
/* needed by mhegd */
#define FIXME 9999
#define ASN1TAGCLASS_InterchangedObject ASN1TAG_SYNTHETIC
-#define ASN1TAGCLASS_ActionSlot FIXME
-#define ASN1TAGCLASS_ActionSlotSeq FIXME
+#define ASN1TAGCLASS_ActionSlot ASN1TAG_CHOICE
+#define ASN1TAGCLASS_ActionSlotSeq FIXME
#define ASN1TAGCLASS_ButtonStyleEnum ASN1TAGCLASS_ENUMERATED
-#define ASN1TAGCLASS_Colour FIXME
-#define ASN1TAGCLASS_ContentBody FIXME
-#define ASN1TAGCLASS_DefaultAttribute FIXME
-#define ASN1TAGCLASS_ElementaryAction FIXME
+#define ASN1TAGCLASS_Colour ASN1TAG_CHOICE
+#define ASN1TAGCLASS_ContentBody FIXME
+#define ASN1TAGCLASS_DefaultAttribute ASN1TAG_CHOICE
+#define ASN1TAGCLASS_ElementaryAction ASN1TAG_CHOICE
#define ASN1TAGCLASS_EventDataBody ASN1TAG_CHOICE
#define ASN1TAGCLASS_EventTypeEnum ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_FontBody FIXME
@@ -776,18 +776,18 @@
#define ASN1TAGCLASS_JustificationEnum ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_LineOrientationEnum ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_OrientationEnum ASN1TAGCLASS_ENUMERATED
-#define ASN1TAGCLASS_OriginalValueBody FIXME
+#define ASN1TAGCLASS_OriginalValueBody FIXME
#define ASN1TAGCLASS_Parameter FIXME
#define ASN1TAGCLASS_SliderStyleEnum ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_StartCornerEnum ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_StorageEnum ASN1TAGCLASS_ENUMERATED
-#define ASN1TAGCLASS_StreamComponent FIXME
+#define ASN1TAGCLASS_StreamComponent FIXME
#define ASN1TAGCLASS_TerminationEnum ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_ComparisonValue FIXME
#define ASN1TAGCLASS_EmulatedEventData FIXME
-#define ASN1TAGCLASS_NewColour FIXME
-#define ASN1TAGCLASS_NewContent FIXME
-#define ASN1TAGCLASS_NewFont FIXME
+#define ASN1TAGCLASS_NewColour FIXME
+#define ASN1TAGCLASS_NewContent FIXME
+#define ASN1TAGCLASS_NewFont FIXME
#define ASN1TAGCLASS_NewVariableValue FIXME
#endif /* __ASN1TAG_H__ */
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-19 11:06:49 UTC (rev 451)
+++ redbutton-author/trunk/ccc.y 2007-10-19 16:25:28 UTC (rev 452)
@@ -821,25 +821,52 @@
/* output any literals at the start */
for(item=state.items; item && item->type==IT_LITERAL; item=item->next)
buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
- /* decode the item */
- buf_append(&state.decode_fns, "\tlong pretag = ftell(der);\n");
- buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
- buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
- buf_append(&state.decode_fns, "\tleft -= sublen;\n\n");
- buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
- /* if it is a synthetic or primitive type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
- buf_append(&state.decode_fns, "\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\tfseek(der, pretag, SEEK_SET);\n");
- buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t}\n");
- buf_append(&state.decode_fns, "\t\telse\n");
- buf_append(&state.decode_fns, "\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t}\n");
- buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
- buf_append(&state.decode_fns, "\t}\n\telse\n");
- buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ /* assert */
+ if(item->type != IT_IDENTIFIER && item->type != IT_ONEORMORE && item->type != IT_OPTIONAL)
+ fatal("not IDENTIFIER, ONEORMORE or OPTIONAL");
+/* is it OPTIONAL - check if length == 0 */
+/* then do the decode as for IDENTIFIER - as below... */
+/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+#if 0
+/* TextContentHook needs it to work this way... */
+ /* is it a primitive type => no extra tag to decode */
+ if(strcmp(item->name, "BOOLEAN") == 0 || strcmp(item->name, "INTEGER") == 0)
+ {
+ /* assert */
+ if(item->type != IT_IDENTIFIER)
+ fatal("Primitive but not Identifier");
+ buf_append(&state.decode_fns, "\tder_decode_%s(der, out, length);\n", item->name);
+ }
+ else
+/* ObjectNumber needs it to work this way... */
+#endif
+ {
+ /* is it ONEORMORE - need a while(left > 0) loop */
+ if(item->type == IT_ONEORMORE)
+ buf_append(&state.decode_fns, "\t\twhile(left > 0)\n\t{\n");
+ /* decode the item */
+ buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\tleft -= sublen;\n\n");
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
+ /* if it is a synthetic or primitive type, we still need the current tag */
+ buf_append(&state.decode_fns, "\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
+ buf_append(&state.decode_fns, "\t\t{\n");
+ buf_append(&state.decode_fns, "\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
+ buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\t}\n");
+ buf_append(&state.decode_fns, "\t\telse\n");
+ buf_append(&state.decode_fns, "\t\t{\n");
+ buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\t}\n");
+ buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t}\n\telse\n");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n", name);
+ /* is it ONEORMORE - need a while(left > 0) loop */
+ if(item->type == IT_ONEORMORE)
+ buf_append(&state.decode_fns, "\t}\n");
+ buf_append(&state.decode_fns, "\n");
+ }
/* is_Xxx() function */
buf_append(&state.decode_is_fns, "\t\treturn is_%s(class, number);\n", item->name);
/* output any literals at the end */
@@ -873,11 +900,9 @@
/* is_Xxx() - just match the first item */
buf_append(&state.decode_is_fns, "\t\treturn is_%s(class, number);\n", item->name);
/* decode_Xxx() - examine each non-literal item in turn */
- buf_append(&state.decode_fns, "\tlong pretag;\n\n");
while(item && item->type != IT_LITERAL)
{
/* decode the next tag */
- buf_append(&state.decode_fns, "\tpretag = ftell(der);\n");
buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
buf_append(&state.decode_fns, "\tleft -= sublen;\n\n");
@@ -886,7 +911,7 @@
/* if it is a synthetic or primitive type, we still need the current tag */
buf_append(&state.decode_fns, "\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
buf_append(&state.decode_fns, "\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\tfseek(der, pretag, SEEK_SET);\n");
+ buf_append(&state.decode_fns, "\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
buf_append(&state.decode_fns, "\t\t}\n");
buf_append(&state.decode_fns, "\t\telse\n");
@@ -894,11 +919,32 @@
buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
buf_append(&state.decode_fns, "\t\t}\n");
buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
- buf_append(&state.decode_fns, "\t}\n\n");
+ buf_append(&state.decode_fns, "\t}\n");
+ /* is it a type that is encoded as a NULL if it is not present */
+ if(item->type == IT_IDENTORNULL)
+ {
+ buf_append(&state.decode_fns, "\telse if(!is_Null(tag.class, tag.number))\n");
+ buf_append(&state.decode_fns, "\t{\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s: missing Null\");\n", name);
+ buf_append(&state.decode_fns, "\t}\n\n");
+ }
+ /* if it is optional and not present, seek back to the start of the tag */
+ else if(item->type == IT_OPTIONAL)
+ {
+ buf_append(&state.decode_fns, "\telse\n");
+ buf_append(&state.decode_fns, "\t{\n");
+ buf_append(&state.decode_fns, "\t\tfseek(der, -sublen, SEEK_CUR);\n");
+ buf_append(&state.decode_fns, "\t\tleft += sublen;\n");
+ buf_append(&state.decode_fns, "\t}\n\n");
+ }
/* if it is not optional, raise an error if it is not present */
-/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
- /* if it is optional and not present, seek back to the start of the tag */
-/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+ else
+ {
+ buf_append(&state.decode_fns, "\telse\n");
+ buf_append(&state.decode_fns, "\t{\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s: missing %s\");\n", name, item->name);
+ buf_append(&state.decode_fns, "\t}\n\n");
+ }
item = item->next;
}
break;
@@ -948,8 +994,8 @@
}
/* decode_Xxx() */
buf_append(&state.decode_fns, "\t\telse\n");
- buf_append(&state.decode_fns, "\t\t{\n\t\t\treturn der_error(\"%s: unexpected tag [%%s %%u]\", asn1class_name(tag.class), tag.number);\n\t}\n", name);
- buf_append(&state.decode_fns, "\t\t}\n\n");
+ buf_append(&state.decode_fns, "\t\t{\n\t\t\treturn der_error(\"%s: unexpected tag [%%s %%u]\", asn1class_name(tag.class), tag.number);\n\t\t}\n", name);
+ buf_append(&state.decode_fns, "\t}\n\n");
break;
default:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|