aboutsummaryrefslogtreecommitdiffstats
path: root/libasn1parser/asn1p_class.c
diff options
context:
space:
mode:
authorvlm <vlm@59561ff5-6e30-0410-9f3c-9617f08c8826>2006-03-14 16:31:37 +0000
committervlm <vlm@59561ff5-6e30-0410-9f3c-9617f08c8826>2006-03-14 16:31:37 +0000
commit808411da2fce77ced6b222bb32c66eaabe3fa3f4 (patch)
tree516c3c202cb1a763f5e7c6dd8d34cfef08930a8c /libasn1parser/asn1p_class.c
parent1d2b607739b269582f5af022a0324556d38b4766 (diff)
new WITH SYNTAX clause parsing
git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@1072 59561ff5-6e30-0410-9f3c-9617f08c8826
Diffstat (limited to 'libasn1parser/asn1p_class.c')
-rw-r--r--libasn1parser/asn1p_class.c67
1 files changed, 42 insertions, 25 deletions
diff --git a/libasn1parser/asn1p_class.c b/libasn1parser/asn1p_class.c
index cd0e385a..741d98e1 100644
--- a/libasn1parser/asn1p_class.c
+++ b/libasn1parser/asn1p_class.c
@@ -18,10 +18,13 @@ asn1p_wsyntx_chunk_new() {
void
asn1p_wsyntx_chunk_free(asn1p_wsyntx_chunk_t *wc) {
if(wc) {
- if(wc->ref)
- asn1p_ref_free(wc->ref);
- if(wc->buf)
- free(wc->buf);
+ switch(wc->type) {
+ case WC_LITERAL: free(wc->content.token); break;
+ case WC_REFERENCE: asn1p_ref_free(wc->content.ref); break;
+ case WC_OPTIONALGROUP:
+ asn1p_wsyntx_free(wc->content.syntax);
+ break;
+ }
free(wc);
}
}
@@ -32,21 +35,17 @@ asn1p_wsyntx_chunk_clone(asn1p_wsyntx_chunk_t *wc) {
nc = asn1p_wsyntx_chunk_new();
if(nc) {
- if(wc->buf) {
- nc->buf = malloc(wc->len + 1);
- if(nc->buf) {
- nc->len = wc->len;
- memcpy(nc->buf, wc->buf, wc->len);
- nc->buf[nc->len] = '\0';
- }
- }
- if(wc->ref) {
- nc->ref = asn1p_ref_clone(wc->ref);
- }
-
- if(!nc->ref && !nc->buf) {
- asn1p_wsyntx_chunk_free(nc);
- return NULL;
+ switch(wc->type) {
+ case WC_LITERAL:
+ nc->content.token = malloc(strlen(wc->content.token)+1);
+ strcpy(nc->content.token, wc->content.token);
+ break;
+ case WC_REFERENCE:
+ nc->content.ref = asn1p_ref_clone(wc->content.ref);
+ break;
+ case WC_OPTIONALGROUP:
+ nc->content.syntax = asn1p_wsyntx_clone(wc->content.syntax);
+ break;
}
}
@@ -103,11 +102,15 @@ asn1p_wsyntx_chunk_fromref(asn1p_ref_t *ref, int do_copy) {
if(do_copy) {
static asn1p_wsyntx_chunk_t tmp;
- tmp.ref = ref;
+ tmp.type = WC_REFERENCE;
+ tmp.content.ref = ref;
wc = asn1p_wsyntx_chunk_clone(&tmp);
} else {
wc = asn1p_wsyntx_chunk_new();
- if(wc) wc->ref = ref;
+ if(wc) {
+ wc->type = WC_REFERENCE;
+ wc->content.ref = ref;
+ }
}
return wc;
@@ -119,17 +122,31 @@ asn1p_wsyntx_chunk_frombuf(char *buf, int len, int do_copy) {
if(do_copy) {
static asn1p_wsyntx_chunk_t tmp;
- tmp.buf = buf;
- tmp.len = len;
+ tmp.type = WC_LITERAL;
+ tmp.content.token = buf;
wc = asn1p_wsyntx_chunk_clone(&tmp);
} else {
wc = asn1p_wsyntx_chunk_new();
if(wc) {
- wc->buf = buf;
- wc->len = len;
+ wc->type = WC_LITERAL;
+ wc->content.token = buf;
}
}
return wc;
}
+
+asn1p_wsyntx_chunk_t *
+asn1p_wsyntx_chunk_fromsyntax(asn1p_wsyntx_t *syntax) {
+ asn1p_wsyntx_chunk_t *wc;
+
+ wc = asn1p_wsyntx_chunk_new();
+ if(wc) {
+ wc->type = WC_OPTIONALGROUP;
+ wc->content.syntax = syntax;
+ }
+
+ return wc;
+}
+