[Redbutton-devel] SF.net SVN: redbutton: [472] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-12-07 17:20:25
|
Revision: 472
http://redbutton.svn.sourceforge.net/redbutton/?rev=472&view=rev
Author: skilvington
Date: 2007-12-07 09:20:22 -0800 (Fri, 07 Dec 2007)
Log Message:
-----------
first stab at making mhegd output prettier
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-author/trunk/asn1decode.c.header
redbutton-author/trunk/ccc.y
redbutton-author/trunk/der_decode.c
Added Paths:
-----------
redbutton-author/trunk/output.c
redbutton-author/trunk/output.h
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-11-30 16:31:33 UTC (rev 471)
+++ redbutton-author/trunk/Makefile 2007-12-07 17:20:22 UTC (rev 472)
@@ -24,6 +24,7 @@
asn1decode.o \
der_decode.o \
asn1tag.o \
+ output.o \
utils.o
TARDIR=`basename ${PWD}`
Modified: redbutton-author/trunk/asn1decode.c.header
===================================================================
--- redbutton-author/trunk/asn1decode.c.header 2007-11-30 16:31:33 UTC (rev 471)
+++ redbutton-author/trunk/asn1decode.c.header 2007-12-07 17:20:22 UTC (rev 472)
@@ -4,6 +4,7 @@
#include "asn1decode.h"
#include "der_decode.h"
#include "asn1tag.h"
+#include "output.h"
void verbose(char *, ...);
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-11-30 16:31:33 UTC (rev 471)
+++ redbutton-author/trunk/ccc.y 2007-12-07 17:20:22 UTC (rev 472)
@@ -822,7 +822,7 @@
{
/* 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);
+ buf_append(&state.decode_fns, "\toutput_token(out, %s);\n\n", item->name);
/* assert */
if(item->type != IT_IDENTIFIER && item->type != IT_ONEORMORE && item->type != IT_OPTIONAL)
fatal("not IDENTIFIER, ONEORMORE or OPTIONAL");
@@ -951,7 +951,7 @@
/* assert */
if(item->type != IT_LITERAL)
fatal("Trailing non-literal");
- buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
+ buf_append(&state.decode_fns, "\toutput_token(out, %s);\n\n", item->name);
item = item->next;
}
}
@@ -964,7 +964,7 @@
buf_append(&state.decode_fns, "\t/* SET */\n");
/* 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);
+ buf_append(&state.decode_fns, "\toutput_token(out, %s);\n\n", item->name);
/* items must be in the order they are defined for SEQUENCE types */
switch(asn1type(name))
{
@@ -1112,7 +1112,7 @@
/* assert */
if(item->type != IT_LITERAL)
fatal("Trailing non-literal");
- buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
+ buf_append(&state.decode_fns, "\toutput_token(out, %s);\n\n", item->name);
item = item->next;
}
}
@@ -1140,8 +1140,6 @@
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);
/* end decode_Xxx() function */
- if(!is_synthetic(asn1tagclass(name)))
- buf_append(&state.decode_fns, "\tfprintf(out, \"\\n\");\n\n");
buf_append(&state.decode_fns, "\tif(left != 0)\n");
buf_append(&state.decode_fns, "\t\treturn der_error(\"%s: %%d bytes left\", left);\n\n", name);
buf_append(&state.decode_fns, "\tverbose(\"</%s>\\n\");\n\n", name);
@@ -1215,8 +1213,6 @@
}
/* end decode_Xxx() function */
- if(!is_synthetic(asn1tagclass(name)))
- buf_append(&state.decode_fns, "\tfprintf(out, \"\\n\");\n\n");
buf_append(&state.decode_fns, "\tif(left != 0)\n");
buf_append(&state.decode_fns, "\t\treturn der_error(\"%s: %%d bytes left\", left);\n\n", name);
buf_append(&state.decode_fns, "\tverbose(\"</%s>\\n\");\n\n", name);
Modified: redbutton-author/trunk/der_decode.c
===================================================================
--- redbutton-author/trunk/der_decode.c 2007-11-30 16:31:33 UTC (rev 471)
+++ redbutton-author/trunk/der_decode.c 2007-12-07 17:20:22 UTC (rev 472)
@@ -95,7 +95,7 @@
verbose("<Boolean value=\"%s\"/>\n", val ? "true" : "false");
- fprintf(out, "%s ", val ? "true" : "false");
+ fprintf(out, " %s", val ? "true" : "false");
return length;
}
@@ -107,7 +107,7 @@
verbose("<Integer value=\"%d\"/>\n", val);
- fprintf(out, "%d ", val);
+ fprintf(out, " %d", val);
return length;
}
@@ -123,7 +123,7 @@
verbose("<OctetString size=\"%d\">\n", length);
/* output a QPRINTABLE string */
- fprintf(out, "'");
+ fprintf(out, " '");
while(left > 0)
{
if(der_read_file(der, 1, &byte) < 0)
@@ -134,7 +134,7 @@
fprintf(out, "=%02x", byte);
left --;
}
- fprintf(out, "' ");
+ fprintf(out, "'");
verbose("</OctetString>\n");
@@ -162,7 +162,7 @@
verbose("<Enumerated value=\"%d\"/>\n", val);
- fprintf(out, "%s ", names[val - 1]);
+ fprintf(out, " %s", names[val - 1]);
return length;
}
Added: redbutton-author/trunk/output.c
===================================================================
--- redbutton-author/trunk/output.c (rev 0)
+++ redbutton-author/trunk/output.c 2007-12-07 17:20:22 UTC (rev 472)
@@ -0,0 +1,103 @@
+/*
+ * output.c
+ */
+
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "utils.h"
+
+void print_newline(FILE *);
+void print_token(FILE *, char *);
+
+int indent = 0;
+bool newline = true;
+
+void
+output_token(FILE *out, char *tok)
+{
+ /* assert */
+ if(tok[0] == '\0')
+ fatal("output_token: 0 length token");
+
+ if(tok[0] == '{' && tok[1] == ':')
+ {
+ print_newline(out);
+ print_token(out, tok);
+ indent ++;
+ }
+ else if(tok[0] == '}')
+ {
+ /* assert */
+ if(indent == 0)
+ fatal("output_token: unexpected '}'");
+ indent --;
+ print_newline(out);
+ print_token(out, tok);
+ }
+ else if(tok[0] == ':' && strcmp(tok, ":ContentRef") != 0)
+ {
+ print_newline(out);
+ print_token(out, tok);
+ }
+ else
+ {
+ print_token(out, tok);
+ }
+
+ return;
+}
+
+void
+print_newline(FILE *out)
+{
+ if(!newline)
+ fprintf(out, "\n");
+
+ newline = true;
+
+ return;
+}
+
+void
+print_token(FILE *out, char *tok)
+{
+ int i = indent;
+
+ if(newline)
+ {
+ while(i > 0)
+ {
+ fprintf(out, "\t");
+ i --;
+ }
+ newline = false;
+ }
+ else
+ {
+ fprintf(out, " ");
+ }
+
+ fprintf(out, "%s", tok);
+
+ return;
+}
Added: redbutton-author/trunk/output.h
===================================================================
--- redbutton-author/trunk/output.h (rev 0)
+++ redbutton-author/trunk/output.h 2007-12-07 17:20:22 UTC (rev 472)
@@ -0,0 +1,31 @@
+/*
+ * output.h
+ */
+
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __OUTPUT_H__
+#define __OUTPUT_H__
+
+#include <stdio.h>
+
+void output_token(FILE *, char *);
+
+#endif /* __OUTPUT_H__ */
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|