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) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 15 | TQ_INIT(&(mod->exports)); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 16 | TQ_INIT(&(mod->imports)); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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 | |
Lev Walkin | d8b8364 | 2016-03-14 02:00:27 -0700 | [diff] [blame] | 30 | free(mod->ModuleName); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | |
Lev Walkin | 13e57ef | 2016-03-14 02:05:23 -0700 | [diff] [blame] | 32 | asn1p_oid_free(mod->module_oid); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | |
| 34 | while((expr = TQ_REMOVE(&(mod->members), next))) |
| 35 | asn1p_expr_free(expr); |
| 36 | |
| 37 | free(mod); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | asn1p_t * |
| 42 | asn1p_new() { |
| 43 | asn1p_t *asn; |
| 44 | asn = calloc(1, sizeof(*asn)); |
| 45 | if(asn) { |
| 46 | TQ_INIT(&(asn->modules)); |
| 47 | } |
| 48 | return asn; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | void |
Lev Walkin | 9b5df84 | 2006-09-12 04:21:30 +0000 | [diff] [blame] | 53 | asn1p_delete(asn1p_t *asn) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 54 | if(asn) { |
| 55 | asn1p_module_t *mod; |
| 56 | while((mod = TQ_REMOVE(&(asn->modules), mod_next))) |
| 57 | asn1p_module_free(mod); |
| 58 | free(asn); |
| 59 | } |
| 60 | } |