[Redbutton-devel] SF.net SVN: redbutton: [365] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-08-31 13:44:53
|
Revision: 365
http://redbutton.svn.sourceforge.net/redbutton/?rev=365&view=rev
Author: skilvington
Date: 2007-08-31 06:44:42 -0700 (Fri, 31 Aug 2007)
Log Message:
-----------
add -v (verbose) flag to mhegc
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
redbutton-author/trunk/parser.l.footer
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-31 11:18:02 UTC (rev 364)
+++ redbutton-author/trunk/ccc.y 2007-08-31 13:44:42 UTC (rev 365)
@@ -369,7 +369,8 @@
/* C code for the parse_Xxx functions */
buf_append(&state.parse_hdr, "void parse_%s(struct state *);\n", name);
buf_append(&state.parse_fns, "void parse_%s(struct state *state)\n{\n", name);
-buf_append(&state.parse_fns, "printf(\"<%s>\\n\");\n", name);
+ buf_append(&state.parse_fns, "\ttoken_t next;\n\n");
+ buf_append(&state.parse_fns, "\tverbose(\"<%s>\\n\");\n\n", name);
/* count how many items make it up */
nitems = 0;
/* skip literals at the start */
@@ -384,7 +385,6 @@
}
if(nitems == 1)
{
- buf_append(&state.parse_fns, "\ttoken_t next;\n\n");
item = state.items;
while(item && item->type == IT_LITERAL)
{
@@ -441,7 +441,7 @@
/* assert */
if(state.and_items)
fatal("CHOICE or ENUMERATED type, but and_items set");
- buf_append(&state.parse_fns, "\ttoken_t next = peek_token();\n\n");
+ buf_append(&state.parse_fns, "\tnext = peek_token();\n\n");
buf_append(&state.parse_fns, "\t/* CHOICE or ENUMERATED */\n");
item = state.items;
for(item=state.items; item; item=item->next)
@@ -467,8 +467,8 @@
buf_append(&state.parse_enum_hdr, "void parse_%s(struct state *);\n", tok_name);
buf_append(&state.parse_enum_fns, "void parse_%s(struct state *state)\n{\n", tok_name);
buf_append(&state.parse_enum_fns, "\texpect_token(%s, %s);\n", tok_name, item->name);
-buf_append(&state.parse_enum_fns, "printf(\"<ENUM value=%s/>\\n\");\n", tok_name);
- buf_append(&state.parse_enum_fns, "}\n\n");
+ buf_append(&state.parse_enum_fns, "\n\tverbose(\"<ENUM value=%s/>\\n\");\n", tok_name);
+ buf_append(&state.parse_enum_fns, "\n\treturn;\n}\n\n");
free(tok_name);
}
else
@@ -484,7 +484,6 @@
/* assert */
if(!state.and_items)
fatal("SET but and_items not set");
- buf_append(&state.parse_fns, "\ttoken_t next;\n\n");
item = state.items;
while(item && item->type == IT_LITERAL)
{
@@ -527,7 +526,6 @@
if(!state.and_items)
fatal("SEQUENCE but and_items not set");
buf_append(&state.parse_fns, "\t/* SEQUENCE */\n");
- buf_append(&state.parse_fns, "\ttoken_t next;\n");
item = state.items;
for(item=state.items; item; item=item->next)
{
@@ -537,7 +535,7 @@
if(item->type == IT_LITERAL)
{
char *tok_name = unquote(item->name);
- buf_append(&state.parse_fns, "\texpect_token(%s, %s);\n\n", tok_name, item->name);
+ buf_append(&state.parse_fns, "\texpect_token(%s, %s);\n", tok_name, item->name);
free(tok_name);
}
else
@@ -559,8 +557,8 @@
break;
}
}
-buf_append(&state.parse_fns, "printf(\"</%s>\\n\");\n", name);
- buf_append(&state.parse_fns, "}\n\n");
+ buf_append(&state.parse_fns, "\n\tverbose(\"</%s>\\n\");\n", name);
+ buf_append(&state.parse_fns, "\n\treturn;\n}\n\n");
/* C code for the is_Xxx functions */
buf_append(&state.is_hdr, "bool is_%s(token_t);\n", name);
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-08-31 11:18:02 UTC (rev 364)
+++ redbutton-author/trunk/mhegc.c 2007-08-31 13:44:42 UTC (rev 365)
@@ -20,16 +20,41 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include "parser.h"
+void usage(char *);
+
+static int _verbose = 0;
+
int
main(int argc, char *argv[])
{
+ char *prog_name = argv[0];
+ int arg;
struct state state;
+ while((arg = getopt(argc, argv, "v")) != EOF)
+ {
+ switch(arg)
+ {
+ case 'v':
+ _verbose ++;
+ break;
+
+ default:
+ usage(prog_name);
+ break;
+ }
+ }
+
+ if(optind != argc)
+ usage(prog_name);
+
parse_InterchangedObject(&state);
if(next_token())
@@ -38,3 +63,44 @@
return EXIT_SUCCESS;
}
+/*
+ * verbose functions send output to stderr so error messages get interleaved correctly
+ */
+
+void
+verbose(const char *fmt, ...)
+{
+ va_list ap;
+
+ if(_verbose)
+ {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ }
+
+ return;
+}
+
+void
+vverbose(const char *fmt, ...)
+{
+ va_list ap;
+
+ if(_verbose > 1)
+ {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ }
+
+ return;
+}
+
+void
+usage(char *prog_name)
+{
+ fprintf(stderr, "Usage: %s [-vv]\n", prog_name);
+
+ exit(EXIT_FAILURE);
+}
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-08-31 11:18:02 UTC (rev 364)
+++ redbutton-author/trunk/parser.c.header 2007-08-31 13:44:42 UTC (rev 365)
@@ -8,8 +8,7 @@
void
yyerror(const char *str)
{
-// fprintf(stderr, "Error: %s at line %d\n", str, yylineno);
-printf("Error: %s at line %d\n", str, yylineno);
+ fprintf(stderr, "Error: %s at line %d\n", str, yylineno);
}
int
@@ -27,7 +26,7 @@
if(next_token() != INTEGER)
yyerror("Expecting INTEGER");
-printf("<INTEGER value=%s/>\n", token_text());
+ verbose("<INTEGER value=%s/>\n", token_text());
return;
}
@@ -37,7 +36,7 @@
if(next_token() != BOOLEAN)
yyerror("Expecting BOOLEAN");
-printf("<BOOLEAN value=%s/>\n", token_text());
+ verbose("<BOOLEAN value=%s/>\n", token_text());
return;
}
@@ -48,7 +47,7 @@
if(next_token() != STRING)
yyerror("Expecting STRING");
-printf("<STRING value=%s/>\n", token_text());
+ verbose("<STRING value=%s/>\n", token_text());
return;
}
@@ -59,7 +58,7 @@
if(next_token() != QPRINTABLE)
yyerror("Expecting QPRINTABLE");
-printf("<QPRINTABLE value=%s/>\n", token_text());
+ verbose("<QPRINTABLE value=%s/>\n", token_text());
return;
}
@@ -70,7 +69,7 @@
if(next_token() != BASE64)
yyerror("Expecting BASE64");
-printf("<BASE64 value=%s/>\n", token_text());
+ verbose("<BASE64 value=%s/>\n", token_text());
return;
}
@@ -81,8 +80,11 @@
if(next_token() != Null)
yyerror("Expecting Null");
-printf("<Null/>\n");
+ verbose("<Null/>\n");
return;
}
+/*
+ * auto-generated parser functions follow
+ */
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-08-31 11:18:02 UTC (rev 364)
+++ redbutton-author/trunk/parser.h.header 2007-08-31 13:44:42 UTC (rev 365)
@@ -14,3 +14,5 @@
void parse_error(const char *, ...);
+void verbose(const char *, ...);
+void vverbose(const char *, ...);
Modified: redbutton-author/trunk/parser.l.footer
===================================================================
--- redbutton-author/trunk/parser.l.footer 2007-08-31 11:18:02 UTC (rev 364)
+++ redbutton-author/trunk/parser.l.footer 2007-08-31 13:44:42 UTC (rev 365)
@@ -7,7 +7,8 @@
{
token_t tok = yylex();
-printf("peek: '%s'\n", yytext);
+ vverbose("peek: '%s'\n", yytext);
+
/* return it to the input stream */
yyless(0);
@@ -26,10 +27,11 @@
token_t
next_token(void)
{
-// return yylex();
-token_t tok = yylex();
-printf("next: '%s'\n", yytext);
-return tok;
+ token_t tok = yylex();
+
+ vverbose("next: '%s'\n", yytext);
+
+ return tok;
}
char *
@@ -49,7 +51,7 @@
va_start(ap, fmt);
if(vasprintf(&err, fmt, ap) < 0)
{
- fprintf(stderr, "Out of memory or illegal format string");
+ fprintf(stderr, "Out of memory or illegal format string '%s'", fmt);
exit(EXIT_FAILURE);
}
va_end(ap);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|