Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <string.h> |
| 3 | |
| 4 | #include "asn1parser.h" |
| 5 | |
| 6 | /* |
| 7 | * Construct a new empty module. |
| 8 | */ |
| 9 | asn1p_module_t * |
| 10 | asn1p_module_new() { |
| 11 | asn1p_module_t *mod; |
| 12 | |
| 13 | mod = calloc(1, sizeof *mod); |
| 14 | if(mod) { |
| 15 | TQ_INIT(&(mod->imports)); |
| 16 | TQ_INIT(&(mod->exports)); |
| 17 | TQ_INIT(&(mod->members)); |
| 18 | } |
| 19 | return mod; |
| 20 | } |
| 21 | |
| 22 | /* |
| 23 | * Destroy the module. |
| 24 | */ |
| 25 | void |
| 26 | asn1p_module_free(asn1p_module_t *mod) { |
| 27 | if(mod) { |
| 28 | asn1p_expr_t *expr; |
| 29 | |
| 30 | if(mod->Identifier) |
| 31 | free(mod->Identifier); |
| 32 | |
| 33 | if(mod->module_oid) |
| 34 | asn1p_oid_free(mod->module_oid); |
| 35 | |
| 36 | while((expr = TQ_REMOVE(&(mod->members), next))) |
| 37 | asn1p_expr_free(expr); |
| 38 | |
| 39 | free(mod); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | asn1p_t * |
| 44 | asn1p_new() { |
| 45 | asn1p_t *asn; |
| 46 | asn = calloc(1, sizeof(*asn)); |
| 47 | if(asn) { |
| 48 | TQ_INIT(&(asn->modules)); |
| 49 | } |
| 50 | return asn; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void |
| 55 | asn1p_free(asn1p_t *asn) { |
| 56 | if(asn) { |
| 57 | asn1p_module_t *mod; |
| 58 | while((mod = TQ_REMOVE(&(asn->modules), mod_next))) |
| 59 | asn1p_module_free(mod); |
| 60 | free(asn); |
| 61 | } |
| 62 | } |