[Redbutton-devel] SF.net SVN: redbutton: [420] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-09-24 16:03:20
|
Revision: 420
http://redbutton.svn.sourceforge.net/redbutton/?rev=420&view=rev
Author: skilvington
Date: 2007-09-24 09:03:05 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
output the DER file
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/utils.c
redbutton-author/trunk/utils.h
Added Paths:
-----------
redbutton-author/trunk/TODO
Added: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO (rev 0)
+++ redbutton-author/trunk/TODO 2007-09-24 16:03:05 UTC (rev 420)
@@ -0,0 +1,28 @@
+NewContentSize param in NewReferencedContent should compile to:
+[CONTEXT 234] { ... [UNIVERSAL 5] ... }
+not just [CONTEXT 234] { ... nothing ... }
+- ie need to add an explicit Null child node
+
+same with ConnectionTag param in TransitionTo
+
+temp fix - add "Null" to the relevent 2 places in the grammar?
+real fix - add "Identifier?" to the grammar => optional, but adds a Null if not
+ present (or perhaps "<Identifier>")
+
+---
+
+output filename should default to App/Scene GroupIdentifier rather than "a"
+(but warn if file exists - stops accidental overwrite of source!)
+
+---
+
+convert_BASE64() function
+
+---
+
+change fatal()'s to parse_error()'s in convert_STRING() et al.
+
+---
+
+clean up ccc.y
+
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/der_encode.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -274,7 +274,7 @@
* the big-endian tag value is encoded in the bottom 7-bits
*/
n->hdr_value[0] = n->asn1class;
- if(n->children)
+ if(has_real_children(n))
n->hdr_value[0] |= 0x20;
if(n->asn1tag < 31)
{
@@ -292,7 +292,7 @@
}
else if(n->asn1tag <= 0x3fff)
{
- n->hdr_value[1] = (n->asn1tag >> 7) & 0x7f;
+ n->hdr_value[1] = 0x80 | ((n->asn1tag >> 7) & 0x7f);
n->hdr_value[2] = n->asn1tag & 0x7f;
n->hdr_length = 3;
}
@@ -345,3 +345,26 @@
return n->hdr_length + val_length;
}
+void
+write_der_object(FILE *out, struct node *n)
+{
+ struct node *kid;
+
+ /* write our tag/length header */
+ if(!is_synthetic(n->asn1tag))
+ write_all(out, n->hdr_value, n->hdr_length);
+
+ /* and our value */
+ if(n->children)
+ {
+ for(kid=n->children; kid; kid=kid->siblings)
+ write_der_object(out, kid);
+ }
+ else
+ {
+ write_all(out, n->value, n->length);
+ }
+
+ return;
+}
+
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/der_encode.h 2007-09-24 16:03:05 UTC (rev 420)
@@ -43,5 +43,7 @@
unsigned int gen_der_header(struct node *);
+void write_der_object(FILE *, struct node *);
+
#endif /* __DER_ENCODE_H__ */
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/mhegc.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -24,14 +24,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
#include <strings.h>
+#include <errno.h>
#include "parser.h"
#include "der_encode.h"
#include "asn1tag.h"
#include "utils.h"
+/* default output name is 'a' */
+#define DEFAULT_OUT_NAME "a"
+
void print_node(struct node *, unsigned int);
+void print_der(struct node *, unsigned int);
void print_indent(unsigned int);
void usage(char *);
@@ -43,14 +49,20 @@
{
char *prog_name = argv[0];
int arg;
+ char *out_name = DEFAULT_OUT_NAME;
struct node asn1obj;
unsigned int nerrs;
unsigned int filesize;
+ FILE *out_file;
- while((arg = getopt(argc, argv, "v")) != EOF)
+ while((arg = getopt(argc, argv, "o:v")) != EOF)
{
switch(arg)
{
+ case 'o':
+ out_name = optarg;
+ break;
+
case 'v':
_verbose ++;
break;
@@ -100,6 +112,19 @@
filesize = gen_der_header(&asn1obj);
verbose("\nDER Object size: %u bytes\n", filesize);
+ /* write the output file */
+ if((out_file = fopen(out_name, "w")) == NULL)
+ fatal("Unable to open output file '%s': %s", out_name, strerror(errno));
+ verbose("Writing '%s'\n", out_name);
+ write_der_object(out_file, &asn1obj);
+ fclose(out_file);
+
+ if(_verbose > 1)
+ {
+ vverbose("\nDER file:\n");
+ print_der(&asn1obj, 0);
+ }
+
return EXIT_SUCCESS;
}
@@ -149,6 +174,37 @@
}
void
+print_der(struct node *n, unsigned int indent)
+{
+ struct node *kid;
+
+ /* write our tag/length header */
+ if(!is_synthetic(n->asn1tag))
+ {
+ print_indent(indent);
+ fprintf(stderr, "[%s %u]\n", asn1class_name(n->asn1class), n->asn1tag);
+ hexdump(stderr, n->hdr_value, n->hdr_length);
+ }
+
+ /* and our value */
+ if(has_real_children(n))
+ {
+ print_indent(indent);
+ fprintf(stderr, "{\n");
+ for(kid=n->children; kid; kid=kid->siblings)
+ print_der(kid, indent + 1);
+ print_indent(indent);
+ fprintf(stderr, "}\n");
+ }
+ else
+ {
+ hexdump(stderr, n->value, n->length);
+ }
+
+ return;
+}
+
+void
print_indent(unsigned int indent)
{
while(indent > 0)
@@ -193,7 +249,7 @@
void
usage(char *prog_name)
{
- fprintf(stderr, "Usage: %s [-vv] [<input_file>]\n", prog_name);
+ fprintf(stderr, "Usage: %s [-vv] [-o <output_file>] [<input_file>]\n", prog_name);
exit(EXIT_FAILURE);
}
Modified: redbutton-author/trunk/utils.c
===================================================================
--- redbutton-author/trunk/utils.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/utils.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -24,9 +24,20 @@
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
+#include <string.h>
+#include <errno.h>
#include "utils.h"
+void
+write_all(FILE *out, unsigned char *buf, size_t len)
+{
+ if(fwrite(buf, 1, len, out) != len)
+ fatal("Error writing to file: %s", strerror(errno));
+
+ return;
+}
+
/*
* returns 15 for 'f' etc
*/
Modified: redbutton-author/trunk/utils.h
===================================================================
--- redbutton-author/trunk/utils.h 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/utils.h 2007-09-24 16:03:05 UTC (rev 420)
@@ -27,6 +27,8 @@
#include <stdarg.h>
#include <stdio.h>
+void write_all(FILE *, unsigned char *, size_t);
+
unsigned int char2hex(unsigned char);
void *safe_malloc(size_t);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|