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; |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 29 | asn1p_xports_t *xports; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 30 | |
Lev Walkin | d8b8364 | 2016-03-14 02:00:27 -0700 | [diff] [blame] | 31 | free(mod->ModuleName); |
Bi-Ruei, Chiu | 12021b5 | 2016-11-04 11:59:45 +0800 | [diff] [blame] | 32 | free(mod->source_file_name); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | |
Lev Walkin | 13e57ef | 2016-03-14 02:05:23 -0700 | [diff] [blame] | 34 | asn1p_oid_free(mod->module_oid); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 35 | |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 36 | while((xports = TQ_REMOVE(&(mod->exports), xp_next))) |
| 37 | asn1p_xports_free(xports); |
| 38 | |
| 39 | while((xports = TQ_REMOVE(&(mod->imports), xp_next))) |
| 40 | asn1p_xports_free(xports); |
| 41 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 42 | while((expr = TQ_REMOVE(&(mod->members), next))) |
| 43 | asn1p_expr_free(expr); |
| 44 | |
| 45 | free(mod); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | asn1p_t * |
| 50 | asn1p_new() { |
| 51 | asn1p_t *asn; |
| 52 | asn = calloc(1, sizeof(*asn)); |
| 53 | if(asn) { |
| 54 | TQ_INIT(&(asn->modules)); |
| 55 | } |
| 56 | return asn; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | void |
Lev Walkin | 9b5df84 | 2006-09-12 04:21:30 +0000 | [diff] [blame] | 61 | asn1p_delete(asn1p_t *asn) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 62 | if(asn) { |
| 63 | asn1p_module_t *mod; |
| 64 | while((mod = TQ_REMOVE(&(asn->modules), mod_next))) |
| 65 | asn1p_module_free(mod); |
| 66 | free(asn); |
| 67 | } |
| 68 | } |