[Redbutton-devel] SF.net SVN: redbutton: [389] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-09-18 11:22:10
|
Revision: 389
http://redbutton.svn.sourceforge.net/redbutton/?rev=389&view=rev
Author: skilvington
Date: 2007-09-18 04:22:00 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
only show synthetic nodes in -vv mode
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.c
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
Modified: redbutton-author/trunk/asn1tag.c
===================================================================
--- redbutton-author/trunk/asn1tag.c 2007-09-17 16:23:18 UTC (rev 388)
+++ redbutton-author/trunk/asn1tag.c 2007-09-18 11:22:00 UTC (rev 389)
@@ -15,3 +15,9 @@
return "ILLEGAL-ASN1-CLASS-NUMBER";
}
+bool
+is_synthetic(unsigned int asn1tag)
+{
+/* TODO: only need one value for synthetic types (ie no need for separate ASN1TAG_CHOICE etc) */
+ return (asn1tag >= ASN1TAG_SYNTHETIC);
+}
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-17 16:23:18 UTC (rev 388)
+++ redbutton-author/trunk/asn1tag.h 2007-09-18 11:22:00 UTC (rev 389)
@@ -5,6 +5,8 @@
#ifndef __ASN1TAG_H__
#define __ASN1TAG_H__
+#include <stdbool.h>
+
/* tag classes */
#define ASN1CLASS_UNIVERSAL 0x00
#define ASN1CLASS_APPLICATION 0x40
@@ -12,6 +14,7 @@
#define ASN1CLASS_PRIVATE 0xc0
char *asn1class_name(unsigned int);
+bool is_synthetic(unsigned int);
/*
* a synthetic object created as a result of the grammar definition
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-17 16:23:18 UTC (rev 388)
+++ redbutton-author/trunk/mhegc.c 2007-09-18 11:22:00 UTC (rev 389)
@@ -67,6 +67,11 @@
else if(optind != argc)
usage(prog_name);
+ if(optind == argc - 1)
+ verbose("Parsing '%s':\n", argv[optind]);
+ else
+ verbose("Parsing stdin:\n");
+
bzero(&asn1obj, sizeof(struct node));
asn1obj.asn1tag = ASN1TAG_SYNTHETIC;
parse_InterchangedObject(&asn1obj);
@@ -94,17 +99,37 @@
void
print_node(struct node *n, unsigned int indent)
{
+ bool show_node;
+ bool show_kids;
struct node *kid;
- print_indent(indent);
- fprintf(stderr, "[%s %d]\n", asn1class_name(n->asn1class), n->asn1tag);
+ /* only show synthetic nodes if -vv was given on the cmd line */
+ show_node = (!is_synthetic(n->asn1tag) || _verbose > 1);
- if(n->children)
+ /* only show non-synthetic children, unless -vv was given */
+ show_kids = (has_real_children(n) || _verbose > 1);
+
+ if(show_node)
{
print_indent(indent);
- fprintf(stderr, "{\n");
+ fprintf(stderr, "[%s %d]\n", asn1class_name(n->asn1class), n->asn1tag);
+ if(show_kids)
+ {
+ print_indent(indent);
+ fprintf(stderr, "{\n");
+ indent ++;
+ }
+ }
+
+ if(show_kids)
+ {
for(kid=n->children; kid; kid=kid->siblings)
- print_node(kid, indent + 1);
+ print_node(kid, indent);
+ }
+
+ if(show_node && show_kids)
+ {
+ indent --;
print_indent(indent);
fprintf(stderr, "}\n");
}
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-17 16:23:18 UTC (rev 388)
+++ redbutton-author/trunk/parser.c.header 2007-09-18 11:22:00 UTC (rev 389)
@@ -59,6 +59,24 @@
}
/*
+ * return true if any of the node's descendants are not synthetic
+ */
+
+bool
+has_real_children(struct node *n)
+{
+ struct node *kid;
+
+ for(kid=n->children; kid; kid=kid->siblings)
+ {
+ if(has_real_children(kid) || !is_synthetic(kid->asn1tag))
+ return true;
+ }
+
+ return false;
+}
+
+/*
* parser functions for the predefined types
*/
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-09-17 16:23:18 UTC (rev 388)
+++ redbutton-author/trunk/parser.h.header 2007-09-18 11:22:00 UTC (rev 389)
@@ -24,6 +24,9 @@
/* add a child to a node */
struct node *add_child(struct node *, uint32_t);
+/* return true if any of the node's descendants are not synthetic */
+bool has_real_children(struct node *);
+
/* lexer token type */
typedef int token_t;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|