Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 2 | #include <stdarg.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 3 | #include <string.h> |
| 4 | #include <errno.h> |
| 5 | #include <assert.h> |
| 6 | |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 7 | #include <asn1_buffer.h> |
Lev Walkin | c0e03b9 | 2017-08-22 01:48:23 -0700 | [diff] [blame] | 8 | #include <asn1_namespace.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | #include <asn1parser.h> |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 10 | #include <asn1fix_export.h> |
Lev Walkin | 9095ada | 2004-08-18 05:41:05 +0000 | [diff] [blame] | 11 | #include <asn1fix_crange.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 12 | |
| 13 | #include "asn1print.h" |
| 14 | |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 15 | static abuf all_output_; |
| 16 | |
| 17 | typedef enum { |
| 18 | PRINT_STDOUT, |
| 19 | GLOBAL_BUFFER, |
| 20 | } print_method_e; |
| 21 | static print_method_e print_method_; |
| 22 | |
Lev Walkin | 1ec7605 | 2016-03-13 17:13:20 -0700 | [diff] [blame] | 23 | #define INDENT(fmt, args...) do { \ |
| 24 | if(!(flags & APF_NOINDENT)) { \ |
| 25 | int tmp_i = level; \ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 26 | while(tmp_i--) safe_printf(" "); \ |
Lev Walkin | 1ec7605 | 2016-03-13 17:13:20 -0700 | [diff] [blame] | 27 | } \ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 28 | safe_printf(fmt, ##args); \ |
Lev Walkin | 1ec7605 | 2016-03-13 17:13:20 -0700 | [diff] [blame] | 29 | } while(0) |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 30 | |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 31 | static int asn1print_module(asn1p_t *asn, asn1p_module_t *mod, enum asn1print_flags flags); |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 32 | static int asn1print_oid(int prior_len, asn1p_oid_t *oid, enum asn1print_flags flags); |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 33 | static int asn1print_ref(const asn1p_ref_t *ref, enum asn1print_flags flags); |
| 34 | static int asn1print_tag(const asn1p_expr_t *tc, enum asn1print_flags flags); |
| 35 | static int asn1print_params(const asn1p_paramlist_t *pl,enum asn1print_flags flags); |
| 36 | static int asn1print_with_syntax(const asn1p_wsyntx_t *wx, enum asn1print_flags flags); |
| 37 | static int asn1print_constraint(const asn1p_constraint_t *, enum asn1print_flags); |
| 38 | static int asn1print_value(const asn1p_value_t *val, enum asn1print_flags flags); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 39 | static int asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level); |
| 40 | static int asn1print_expr_dtd(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 41 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 42 | /* Check printf's error code, to be pedantic. */ |
| 43 | static int safe_printf(const char *fmt, ...) { |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 44 | int ret; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 45 | va_list ap; |
| 46 | va_start(ap, fmt); |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 47 | |
| 48 | switch(print_method_) { |
| 49 | case PRINT_STDOUT: |
| 50 | ret = vprintf(fmt, ap); |
| 51 | break; |
| 52 | case GLOBAL_BUFFER: |
| 53 | ret = abuf_vprintf(&all_output_, fmt, ap); |
| 54 | break; |
| 55 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 56 | assert(ret >= 0); |
| 57 | va_end(ap); |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 58 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 59 | return ret; |
| 60 | } |
| 61 | |
| 62 | /* Pedantically check fwrite's return value. */ |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 63 | static size_t safe_fwrite(const void *ptr, size_t size) { |
| 64 | size_t ret; |
| 65 | |
| 66 | switch(print_method_) { |
| 67 | case PRINT_STDOUT: |
| 68 | ret = fwrite(ptr, 1, size, stdout); |
| 69 | assert(ret == size); |
| 70 | break; |
| 71 | case GLOBAL_BUFFER: |
| 72 | abuf_add_bytes(&all_output_, ptr, size); |
| 73 | ret = size; |
| 74 | break; |
| 75 | } |
| 76 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 77 | return ret; |
| 78 | } |
| 79 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 80 | /* |
| 81 | * Print the contents of the parsed ASN tree. |
| 82 | */ |
| 83 | int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 84 | asn1print(asn1p_t *asn, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 85 | asn1p_module_t *mod; |
Lev Walkin | c70c2ef | 2004-09-30 06:38:21 +0000 | [diff] [blame] | 86 | int modno = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 87 | |
| 88 | if(asn == NULL) { |
| 89 | errno = EINVAL; |
| 90 | return -1; |
| 91 | } |
| 92 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 93 | if(flags & APF_PRINT_XML_DTD) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 94 | safe_printf("<!-- XML DTD generated by asn1c-" VERSION " -->\n\n"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 95 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 96 | TQ_FOR(mod, &(asn->modules), mod_next) { |
Lev Walkin | 6b3ff54 | 2006-03-06 14:51:00 +0000 | [diff] [blame] | 97 | if(mod->_tags & MT_STANDARD_MODULE) |
| 98 | return 0; /* Ignore modules imported from skeletons */ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 99 | if(modno++) safe_printf("\n"); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 100 | asn1print_module(asn, mod, flags); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Lev Walkin | 112d69e | 2005-03-09 20:52:15 +0000 | [diff] [blame] | 103 | if(flags & APF_PRINT_XML_DTD) { |
| 104 | /* Values for BOOLEAN */ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 105 | safe_printf("<!ELEMENT true EMPTY>\n"); |
| 106 | safe_printf("<!ELEMENT false EMPTY>\n"); |
Lev Walkin | 112d69e | 2005-03-09 20:52:15 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 113 | asn1print_module(asn1p_t *asn, asn1p_module_t *mod, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 114 | asn1p_expr_t *tc; |
| 115 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 116 | if(flags & APF_PRINT_XML_DTD) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 117 | safe_printf("<!-- ASN.1 module\n"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 118 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 119 | safe_printf("%s ", mod->ModuleName); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 120 | if(mod->module_oid) { |
Lev Walkin | b36317c | 2005-08-12 10:09:10 +0000 | [diff] [blame] | 121 | asn1print_oid(strlen(mod->ModuleName), mod->module_oid, flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 122 | safe_printf("\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 125 | if(flags & APF_PRINT_XML_DTD) { |
| 126 | if(mod->source_file_name |
| 127 | && strcmp(mod->source_file_name, "-")) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 128 | safe_printf("found in %s", mod->source_file_name); |
| 129 | safe_printf(" -->\n\n"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 130 | |
| 131 | TQ_FOR(tc, &(mod->members), next) { |
| 132 | asn1print_expr_dtd(asn, mod, tc, flags, 0); |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 138 | safe_printf("DEFINITIONS"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 139 | |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 140 | if(mod->module_flags & MSF_TAG_INSTRUCTIONS) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 141 | safe_printf(" TAG INSTRUCTIONS"); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 142 | if(mod->module_flags & MSF_XER_INSTRUCTIONS) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 143 | safe_printf(" XER INSTRUCTIONS"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 144 | if(mod->module_flags & MSF_EXPLICIT_TAGS) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 145 | safe_printf(" EXPLICIT TAGS"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 146 | if(mod->module_flags & MSF_IMPLICIT_TAGS) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 147 | safe_printf(" IMPLICIT TAGS"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 148 | if(mod->module_flags & MSF_AUTOMATIC_TAGS) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 149 | safe_printf(" AUTOMATIC TAGS"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 150 | if(mod->module_flags & MSF_EXTENSIBILITY_IMPLIED) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 151 | safe_printf(" EXTENSIBILITY IMPLIED"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 152 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 153 | safe_printf(" ::=\n"); |
| 154 | safe_printf("BEGIN\n\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 155 | |
| 156 | TQ_FOR(tc, &(mod->members), next) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 157 | asn1print_expr(asn, mod, tc, flags, 0); |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 158 | if(flags & APF_PRINT_CONSTRAINTS) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 159 | safe_printf("\n"); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 160 | else |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 161 | safe_printf("\n\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 164 | safe_printf("END\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 170 | asn1print_oid(int prior_len, asn1p_oid_t *oid, enum asn1print_flags flags) { |
| 171 | size_t accum = prior_len; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 172 | int ac; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 173 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 174 | (void)flags; /* Unused argument */ |
| 175 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 176 | safe_printf("{"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 177 | for(ac = 0; ac < oid->arcs_count; ac++) { |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 178 | const char *arcname = oid->arcs[ac].name; |
| 179 | |
Lev Walkin | 5b7eeaf | 2005-03-28 17:52:43 +0000 | [diff] [blame] | 180 | if(accum + strlen(arcname ? arcname : "") > 72) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 181 | safe_printf("\n\t"); |
Lev Walkin | 5b7eeaf | 2005-03-28 17:52:43 +0000 | [diff] [blame] | 182 | accum = 8; |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 183 | } else { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 184 | accum += safe_printf(" "); |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 185 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 186 | |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 187 | if(arcname) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 188 | accum += safe_printf("%s", arcname); |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 189 | if(oid->arcs[ac].number >= 0) { |
Lev Walkin | da997b1 | 2017-08-04 01:38:41 -0700 | [diff] [blame] | 190 | accum += safe_printf("(%s)", |
| 191 | asn1p_itoa(oid->arcs[ac].number)); |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 192 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 193 | } else { |
Lev Walkin | da997b1 | 2017-08-04 01:38:41 -0700 | [diff] [blame] | 194 | accum += safe_printf("%s", asn1p_itoa(oid->arcs[ac].number)); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 195 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 196 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 197 | safe_printf(" }"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static int |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 203 | asn1print_ref(const asn1p_ref_t *ref, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 204 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 205 | (void)flags; /* Unused argument */ |
| 206 | |
Lev Walkin | 62d95d2 | 2017-08-06 23:41:11 -0700 | [diff] [blame] | 207 | for(size_t cc = 0; cc < ref->comp_count; cc++) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 208 | if(cc) safe_printf("."); |
| 209 | safe_printf("%s", ref->components[cc].name); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 216 | asn1print_tag(const asn1p_expr_t *tc, enum asn1print_flags flags) { |
| 217 | const struct asn1p_type_tag_s *tag = &tc->tag; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 218 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 219 | (void)flags; /* Unused argument */ |
| 220 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 221 | safe_printf("%s", asn1p_tag2string(tag, 0)); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | static int |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 227 | asn1print_value(const asn1p_value_t *val, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 228 | |
| 229 | if(val == NULL) |
| 230 | return 0; |
| 231 | |
| 232 | switch(val->type) { |
| 233 | case ATV_NOVALUE: |
| 234 | break; |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 235 | case ATV_NULL: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 236 | safe_printf("NULL"); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 237 | return 0; |
| 238 | case ATV_REAL: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 239 | safe_printf("%f", val->value.v_double); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 240 | return 0; |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 241 | case ATV_TYPE: |
| 242 | asn1print_expr(val->value.v_type->module->asn1p, |
| 243 | val->value.v_type->module, |
| 244 | val->value.v_type, flags, 0); |
| 245 | return 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 246 | case ATV_INTEGER: |
Lev Walkin | da997b1 | 2017-08-04 01:38:41 -0700 | [diff] [blame] | 247 | safe_printf("%s", asn1p_itoa(val->value.v_integer)); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 248 | return 0; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 249 | case ATV_MIN: safe_printf("MIN"); return 0; |
| 250 | case ATV_MAX: safe_printf("MAX"); return 0; |
| 251 | case ATV_FALSE: safe_printf("FALSE"); return 0; |
| 252 | case ATV_TRUE: safe_printf("TRUE"); return 0; |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 253 | case ATV_TUPLE: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 254 | safe_printf("{%d, %d}", |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 255 | (int)(val->value.v_integer >> 4), |
| 256 | (int)(val->value.v_integer & 0x0f)); |
| 257 | return 0; |
| 258 | case ATV_QUADRUPLE: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 259 | safe_printf("{%d, %d, %d, %d}", |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 260 | (int)((val->value.v_integer >> 24) & 0xff), |
| 261 | (int)((val->value.v_integer >> 16) & 0xff), |
| 262 | (int)((val->value.v_integer >> 8) & 0xff), |
| 263 | (int)((val->value.v_integer >> 0) & 0xff) |
| 264 | ); |
| 265 | return 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 266 | case ATV_STRING: |
| 267 | { |
Lev Walkin | 84fbd72 | 2005-06-15 18:41:50 +0000 | [diff] [blame] | 268 | char *p = (char *)val->value.string.buf; |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 269 | safe_printf("\""); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 270 | if(strchr(p, '"')) { |
| 271 | /* Mask quotes */ |
| 272 | for(; *p; p++) { |
| 273 | if(*p == '"') |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 274 | safe_printf("%c", *p); |
| 275 | safe_printf("%c", *p); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 276 | } |
| 277 | } else { |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 278 | safe_printf("%s", p); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 279 | } |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 280 | safe_printf("\""); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 281 | } |
| 282 | return 0; |
| 283 | case ATV_UNPARSED: |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 284 | safe_printf("%s", (char *)val->value.string.buf); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 285 | return 0; |
| 286 | case ATV_BITVECTOR: |
| 287 | { |
| 288 | uint8_t *bitvector; |
| 289 | int bits; |
| 290 | int i; |
| 291 | |
| 292 | bitvector = val->value.binary_vector.bits; |
| 293 | bits = val->value.binary_vector.size_in_bits; |
| 294 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 295 | safe_printf("'"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 296 | if(bits%8) { |
| 297 | for(i = 0; i < bits; i++) { |
| 298 | uint8_t uc; |
| 299 | uc = bitvector[i>>3]; |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 300 | safe_printf("%c", ((uc >> (7-(i%8)))&1)?'1':'0'); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 301 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 302 | safe_printf("'B"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 303 | } else { |
| 304 | char hextable[16] = "0123456789ABCDEF"; |
| 305 | for(i = 0; i < (bits>>3); i++) { |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 306 | safe_printf("%c", hextable[bitvector[i] >> 4]); |
| 307 | safe_printf("%c", hextable[bitvector[i] & 0x0f]); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 308 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 309 | safe_printf("'H"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 310 | } |
Lev Walkin | 043af0d | 2005-02-24 21:07:35 +0000 | [diff] [blame] | 311 | return 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 312 | } |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 313 | case ATV_REFERENCED: |
| 314 | return asn1print_ref(val->value.reference, flags); |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 315 | case ATV_VALUESET: |
| 316 | return asn1print_constraint(val->value.constraint, flags); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 317 | case ATV_CHOICE_IDENTIFIER: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 318 | safe_printf("%s: ", val->value.choice_identifier.identifier); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 319 | return asn1print_value(val->value.choice_identifier.value, flags); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | assert(val->type || !"Unknown"); |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 327 | const char * |
| 328 | asn1p_constraint_string(const asn1p_constraint_t *ct) { |
| 329 | size_t old_len = all_output_.length; |
| 330 | print_method_e old_method = print_method_; |
| 331 | print_method_ = GLOBAL_BUFFER; |
| 332 | asn1print_constraint(ct, APF_NOINDENT); |
| 333 | print_method_ = old_method; |
| 334 | return &all_output_.buffer[old_len]; |
| 335 | } |
| 336 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 337 | static int |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 338 | asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 339 | int symno = 0; |
| 340 | |
| 341 | if(ct == 0) return 0; |
| 342 | |
| 343 | if(ct->type == ACT_CA_SET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 344 | safe_printf("("); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 345 | |
| 346 | switch(ct->type) { |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 347 | case ACT_EL_TYPE: |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 348 | asn1print_value(ct->containedSubtype, flags); |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 349 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 350 | case ACT_EL_VALUE: |
| 351 | asn1print_value(ct->value, flags); |
| 352 | break; |
| 353 | case ACT_EL_RANGE: |
| 354 | case ACT_EL_LLRANGE: |
| 355 | case ACT_EL_RLRANGE: |
| 356 | case ACT_EL_ULRANGE: |
| 357 | asn1print_value(ct->range_start, flags); |
| 358 | switch(ct->type) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 359 | case ACT_EL_RANGE: safe_printf(".."); break; |
| 360 | case ACT_EL_LLRANGE: safe_printf("<.."); break; |
| 361 | case ACT_EL_RLRANGE: safe_printf("..<"); break; |
| 362 | case ACT_EL_ULRANGE: safe_printf("<..<"); break; |
| 363 | default: safe_printf("?..?"); break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 364 | } |
| 365 | asn1print_value(ct->range_stop, flags); |
| 366 | break; |
| 367 | case ACT_EL_EXT: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 368 | safe_printf("..."); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 369 | break; |
| 370 | case ACT_CT_SIZE: |
| 371 | case ACT_CT_FROM: |
| 372 | switch(ct->type) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 373 | case ACT_CT_SIZE: safe_printf("SIZE("); break; |
| 374 | case ACT_CT_FROM: safe_printf("FROM("); break; |
| 375 | default: safe_printf("??? ("); break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 376 | } |
| 377 | assert(ct->el_count != 0); |
| 378 | assert(ct->el_count == 1); |
| 379 | asn1print_constraint(ct->elements[0], flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 380 | safe_printf(")"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 381 | break; |
| 382 | case ACT_CT_WCOMP: |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 383 | assert(ct->el_count != 0); |
| 384 | assert(ct->el_count == 1); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 385 | safe_printf("WITH COMPONENT ("); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 386 | asn1print_constraint(ct->elements[0], flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 387 | safe_printf(")"); |
Lev Walkin | 8638f0d | 2005-03-28 07:50:06 +0000 | [diff] [blame] | 388 | break; |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 389 | case ACT_CT_WCOMPS: { |
| 390 | unsigned int i; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 391 | safe_printf("WITH COMPONENTS { "); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 392 | for(i = 0; i < ct->el_count; i++) { |
| 393 | asn1p_constraint_t *cel = ct->elements[i]; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 394 | if(i) safe_printf(", "); |
| 395 | safe_fwrite(cel->value->value.string.buf, |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 396 | cel->value->value.string.size); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 397 | if(cel->el_count) { |
| 398 | assert(cel->el_count == 1); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 399 | safe_printf(" "); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 400 | asn1print_constraint(cel->elements[0], |
| 401 | flags); |
| 402 | } |
| 403 | switch(cel->presence) { |
| 404 | case ACPRES_DEFAULT: break; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 405 | case ACPRES_PRESENT: safe_printf(" PRESENT"); break; |
| 406 | case ACPRES_ABSENT: safe_printf(" ABSENT"); break; |
| 407 | case ACPRES_OPTIONAL: safe_printf(" OPTIONAL");break; |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 408 | } |
| 409 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 410 | safe_printf(" }"); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 411 | } |
Lev Walkin | 8638f0d | 2005-03-28 07:50:06 +0000 | [diff] [blame] | 412 | break; |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 413 | case ACT_CT_CTDBY: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 414 | safe_printf("CONSTRAINED BY "); |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 415 | assert(ct->value->type == ATV_UNPARSED); |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 416 | safe_fwrite(ct->value->value.string.buf, ct->value->value.string.size); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 417 | break; |
| 418 | case ACT_CT_CTNG: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 419 | safe_printf("CONTAINING "); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 420 | asn1print_expr(ct->value->value.v_type->module->asn1p, |
| 421 | ct->value->value.v_type->module, |
| 422 | ct->value->value.v_type, |
| 423 | flags, 1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 424 | break; |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 425 | case ACT_CT_PATTERN: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 426 | safe_printf("PATTERN "); |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 427 | asn1print_value(ct->value, flags); |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 428 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 429 | case ACT_CA_SET: symno++; |
| 430 | case ACT_CA_CRC: symno++; |
| 431 | case ACT_CA_CSV: symno++; |
| 432 | case ACT_CA_UNI: symno++; |
| 433 | case ACT_CA_INT: symno++; |
| 434 | case ACT_CA_EXC: |
| 435 | { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 436 | char *symtable[] = { " EXCEPT ", " ^ ", " | ", ",", |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 437 | "", "(" }; |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 438 | unsigned int i; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 439 | for(i = 0; i < ct->el_count; i++) { |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 440 | if(i) safe_printf("%s", symtable[symno]); |
| 441 | if(ct->type == ACT_CA_CRC) safe_printf("{"); |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 442 | asn1print_constraint(ct->elements[i], flags); |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 443 | if(ct->type == ACT_CA_CRC) safe_printf("}"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 444 | if(i+1 < ct->el_count |
| 445 | && ct->type == ACT_CA_SET) |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 446 | safe_printf(")"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | break; |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 450 | case ACT_CA_AEX: |
| 451 | assert(ct->el_count == 1); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 452 | safe_printf("ALL EXCEPT "); |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 453 | asn1print_constraint(ct->elements[0], flags); |
| 454 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 455 | case ACT_INVALID: |
| 456 | assert(ct->type != ACT_INVALID); |
| 457 | break; |
| 458 | } |
| 459 | |
| 460 | if(ct->type == ACT_CA_SET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 461 | safe_printf(")"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static int |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 467 | asn1print_params(const asn1p_paramlist_t *pl, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 468 | if(pl) { |
| 469 | int i; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 470 | safe_printf("{"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 471 | for(i = 0; i < pl->params_count; i++) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 472 | if(i) safe_printf(", "); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 473 | if(pl->params[i].governor) { |
| 474 | asn1print_ref(pl->params[i].governor, flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 475 | safe_printf(":"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 476 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 477 | safe_printf("%s", pl->params[i].argument); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 478 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 479 | safe_printf("}"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static int |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 486 | asn1print_with_syntax(const asn1p_wsyntx_t *wx, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 487 | if(wx) { |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 488 | const asn1p_wsyntx_chunk_t *wc; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 489 | TQ_FOR(wc, &(wx->chunks), next) { |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 490 | switch(wc->type) { |
| 491 | case WC_LITERAL: |
Lev Walkin | 57074f1 | 2006-03-16 05:11:14 +0000 | [diff] [blame] | 492 | case WC_WHITESPACE: |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 493 | case WC_FIELD: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 494 | safe_printf("%s", wc->content.token); |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 495 | break; |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 496 | case WC_OPTIONALGROUP: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 497 | safe_printf("["); |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 498 | asn1print_with_syntax(wc->content.syntax,flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 499 | safe_printf("]"); |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 500 | break; |
| 501 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 502 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static int |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 509 | asn1print_crange_value(const asn1cnst_edge_t *edge, int as_char) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 510 | switch(edge->type) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 511 | case ARE_MIN: safe_printf("MIN"); break; |
| 512 | case ARE_MAX: safe_printf("MAX"); break; |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 513 | case ARE_VALUE: |
| 514 | if(as_char) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 515 | safe_printf("\"%c\"", (unsigned char)edge->value); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 516 | } else { |
Lev Walkin | da997b1 | 2017-08-04 01:38:41 -0700 | [diff] [blame] | 517 | safe_printf("%s", asn1p_itoa(edge->value)); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static int |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 524 | asn1print_constraint_explain_type(const char *dbg_name, asn1p_expr_type_e expr_type, asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, enum cpr_flags cpr) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 525 | asn1cnst_range_t *range; |
| 526 | int as_char = (type==ACT_CT_FROM); |
| 527 | int i; |
| 528 | |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 529 | range = asn1constraint_compute_constraint_range(dbg_name, expr_type, ct, type, 0, 0, cpr); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 530 | if(!range) return -1; |
| 531 | |
Lev Walkin | a2abcaa | 2017-07-23 21:08:49 +0400 | [diff] [blame] | 532 | if(range->incompatible) return 0; |
| 533 | |
| 534 | if((cpr & CPR_strict_OER_visibility) && range->not_OER_visible) { |
| 535 | asn1constraint_range_free(range); |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | if((cpr & CPR_strict_PER_visibility) && range->not_PER_visible) { |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 540 | asn1constraint_range_free(range); |
| 541 | return 0; |
| 542 | } |
| 543 | |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 544 | switch(type) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 545 | case ACT_CT_FROM: safe_printf("(FROM("); break; |
| 546 | case ACT_CT_SIZE: safe_printf("(SIZE("); break; |
| 547 | default: safe_printf("("); break; |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 548 | } |
| 549 | for(i = -1; i < range->el_count; i++) { |
| 550 | asn1cnst_range_t *r; |
| 551 | if(i == -1) { |
| 552 | if(range->el_count) continue; |
| 553 | r = range; |
| 554 | } else { |
| 555 | r = range->elements[i]; |
| 556 | } |
| 557 | if(i > 0) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 558 | safe_printf(" | "); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 559 | } |
| 560 | asn1print_crange_value(&r->left, as_char); |
| 561 | if(r->left.type != r->right.type |
| 562 | || r->left.value != r->right.value) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 563 | safe_printf(".."); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 564 | asn1print_crange_value(&r->right, as_char); |
| 565 | } |
| 566 | } |
| 567 | if(range->extensible) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 568 | safe_printf(",..."); |
| 569 | safe_printf(type==ACT_EL_RANGE?")":"))"); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 570 | |
| 571 | if(range->empty_constraint) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 572 | safe_printf(":Empty!"); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 573 | |
| 574 | asn1constraint_range_free(range); |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | static int |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 579 | asn1print_constraint_explain(const char *dbg_name, asn1p_expr_type_e expr_type, |
Lev Walkin | a2abcaa | 2017-07-23 21:08:49 +0400 | [diff] [blame] | 580 | asn1p_constraint_t *ct, enum cpr_flags cpr) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 581 | |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 582 | asn1print_constraint_explain_type(dbg_name, expr_type, ct, ACT_EL_RANGE, cpr); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 583 | safe_printf(" "); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 584 | asn1print_constraint_explain_type(dbg_name, expr_type, ct, ACT_CT_SIZE, cpr); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 585 | safe_printf(" "); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 586 | asn1print_constraint_explain_type(dbg_name, expr_type, ct, ACT_CT_FROM, cpr); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | static int |
| 592 | asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level) { |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 593 | int SEQ_OF = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 594 | |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 595 | if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT)) |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 596 | INDENT("-- #line %d\n", tc->_lineno); |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 597 | |
| 598 | /* Reconstruct compiler directive information */ |
| 599 | if((tc->marker.flags & EM_INDIRECT) |
| 600 | && (tc->marker.flags & EM_OMITABLE) != EM_OMITABLE) { |
| 601 | if((flags & APF_NOINDENT)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 602 | safe_printf(" --<ASN1C.RepresentAsPointer>-- "); |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 603 | else |
| 604 | INDENT("--<ASN1C.RepresentAsPointer>--\n"); |
| 605 | } |
| 606 | |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 607 | if(tc->Identifier |
| 608 | && (!(tc->meta_type == AMT_VALUE && tc->expr_type == A1TC_REFERENCE) |
| 609 | || level == 0)) |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 610 | INDENT("%s", tc->Identifier); |
| 611 | |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 612 | if(tc->lhs_params) { |
| 613 | asn1print_params(tc->lhs_params, flags); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | if(tc->meta_type != AMT_VALUE |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 617 | && tc->meta_type != AMT_VALUESET |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 618 | && tc->expr_type != A1TC_EXTENSIBLE) { |
| 619 | if(level) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 620 | if(tc->Identifier && !(flags & APF_NOINDENT)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 621 | safe_printf("\t"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 622 | } else { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 623 | safe_printf(" ::="); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
| 627 | if(tc->tag.tag_class) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 628 | safe_printf(" "); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 629 | asn1print_tag(tc, flags); |
| 630 | } |
| 631 | |
| 632 | switch(tc->expr_type) { |
| 633 | case A1TC_EXTENSIBLE: |
| 634 | if(tc->value) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 635 | safe_printf("!"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 636 | asn1print_value(tc->value, flags); |
| 637 | } |
| 638 | break; |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 639 | case A1TC_COMPONENTS_OF: |
| 640 | SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 641 | safe_printf(" COMPONENTS OF"); |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 642 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 643 | case A1TC_REFERENCE: |
| 644 | case A1TC_UNIVERVAL: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 645 | break; |
| 646 | case A1TC_CLASSDEF: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 647 | safe_printf(" CLASS"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 648 | break; |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 649 | case A1TC_CLASSFIELD_TFS ... A1TC_CLASSFIELD_OSFS: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 650 | /* Nothing to print here */ |
| 651 | break; |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 652 | case ASN_CONSTR_SET_OF: |
| 653 | case ASN_CONSTR_SEQUENCE_OF: |
| 654 | SEQ_OF = 1; |
| 655 | if(tc->expr_type == ASN_CONSTR_SET_OF) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 656 | safe_printf(" SET"); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 657 | else |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 658 | safe_printf(" SEQUENCE"); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 659 | if(tc->constraints) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 660 | safe_printf(" "); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 661 | asn1print_constraint(tc->constraints, flags); |
| 662 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 663 | safe_printf(" OF"); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 664 | break; |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 665 | case A1TC_VALUESET: |
| 666 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 667 | default: |
| 668 | { |
| 669 | char *p = ASN_EXPR_TYPE2STR(tc->expr_type); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 670 | safe_printf(" %s", p?p:"<unknown type!>"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 671 | } |
| 672 | break; |
| 673 | } |
| 674 | |
Lev Walkin | b9d0ae3 | 2005-06-02 04:06:24 +0000 | [diff] [blame] | 675 | /* |
| 676 | * Put the name of the referred type. |
| 677 | */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 678 | if(tc->reference) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 679 | safe_printf(" "); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 680 | asn1print_ref(tc->reference, flags); |
| 681 | } |
| 682 | |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 683 | if(tc->meta_type == AMT_VALUESET && level == 0) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 684 | safe_printf(" ::="); |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 685 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 686 | /* |
| 687 | * Display the descendants (children) of the current type. |
| 688 | */ |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 689 | if(TQ_FIRST(&(tc->members)) |
| 690 | || (tc->expr_type & ASN_CONSTR_MASK) |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 691 | || tc->meta_type == AMT_OBJECT |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 692 | || tc->meta_type == AMT_OBJECTCLASS |
| 693 | || tc->meta_type == AMT_OBJECTFIELD |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 694 | ) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 695 | asn1p_expr_t *se; /* SubExpression */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 696 | int put_braces = (!SEQ_OF) /* Don't need 'em, if SET OF... */ |
| 697 | && (tc->meta_type != AMT_OBJECTFIELD); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 698 | |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 699 | if(put_braces) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 700 | if(flags & APF_NOINDENT) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 701 | safe_printf("{"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 702 | if(!TQ_FIRST(&tc->members)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 703 | safe_printf("}"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 704 | } else { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 705 | safe_printf(" {"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 706 | if(TQ_FIRST(&tc->members)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 707 | safe_printf("\n"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 708 | else |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 709 | safe_printf(" }"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 710 | } |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 711 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 712 | |
| 713 | TQ_FOR(se, &(tc->members), next) { |
| 714 | /* |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 715 | * Print the expression as it were a stand-alone type. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 716 | */ |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 717 | asn1print_expr(asn, mod, se, flags, level + 1); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 718 | if((se->marker.flags & EM_DEFAULT) == EM_DEFAULT) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 719 | safe_printf(" DEFAULT "); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 720 | asn1print_value(se->marker.default_value, flags); |
| 721 | } else if((se->marker.flags & EM_OPTIONAL) |
| 722 | == EM_OPTIONAL) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 723 | safe_printf(" OPTIONAL"); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 724 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 725 | if(TQ_NEXT(se, next)) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 726 | safe_printf(","); |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 727 | if(!(flags & APF_NOINDENT)) |
| 728 | INDENT("\n"); |
| 729 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 732 | if(put_braces && TQ_FIRST(&tc->members)) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 733 | if(!(flags & APF_NOINDENT)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 734 | safe_printf("\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 735 | INDENT("}"); |
| 736 | } |
| 737 | } |
| 738 | |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 739 | if(tc->with_syntax) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 740 | safe_printf(" WITH SYNTAX {"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 741 | asn1print_with_syntax(tc->with_syntax, flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 742 | safe_printf("}\n"); |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 743 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 744 | |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 745 | /* Right hand specialization */ |
| 746 | if(tc->rhs_pspecs) { |
| 747 | asn1p_expr_t *se; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 748 | safe_printf("{"); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 749 | TQ_FOR(se, &(tc->rhs_pspecs->members), next) { |
| 750 | asn1print_expr(asn, mod, se, flags, level + 1); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 751 | if(TQ_NEXT(se, next)) safe_printf(", "); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 752 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 753 | safe_printf("}"); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 756 | if(!SEQ_OF && tc->constraints) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 757 | safe_printf(" "); |
Lev Walkin | 557f27d | 2006-03-21 07:46:48 +0000 | [diff] [blame] | 758 | if(tc->meta_type == AMT_VALUESET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 759 | safe_printf("{"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 760 | asn1print_constraint(tc->constraints, flags); |
Lev Walkin | 557f27d | 2006-03-21 07:46:48 +0000 | [diff] [blame] | 761 | if(tc->meta_type == AMT_VALUESET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 762 | safe_printf("}"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 763 | } |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 764 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 765 | if(tc->unique) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 766 | safe_printf(" UNIQUE"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | if(tc->meta_type == AMT_VALUE |
| 770 | && tc->expr_type != A1TC_EXTENSIBLE) { |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 771 | if(tc->expr_type == A1TC_UNIVERVAL) { |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 772 | if(tc->value) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 773 | safe_printf("("); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 774 | asn1print_value(tc->value, flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 775 | safe_printf(")"); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 776 | } |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 777 | } else { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 778 | if(level == 0) safe_printf(" ::= "); |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 779 | asn1print_value(tc->value, flags); |
| 780 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 783 | /* |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 784 | * The following section exists entirely for debugging. |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 785 | */ |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 786 | if(flags & APF_PRINT_CONSTRAINTS |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 787 | && tc->expr_type != A1TC_EXTENSIBLE) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 788 | asn1p_expr_t *top_parent; |
| 789 | |
| 790 | if(tc->combined_constraints) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 791 | safe_printf("\n-- Combined constraints: "); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 792 | asn1print_constraint(tc->combined_constraints, flags); |
| 793 | } |
| 794 | |
Lev Walkin | c0e03b9 | 2017-08-22 01:48:23 -0700 | [diff] [blame] | 795 | top_parent = WITH_MODULE_NAMESPACE( |
| 796 | tc->module, tc_ns, asn1f_find_terminal_type_ex(asn, tc_ns, tc)); |
| 797 | if(top_parent) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 798 | safe_printf("\n-- Practical constraints (%s): ", |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 799 | top_parent->Identifier); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 800 | asn1print_constraint_explain(top_parent->Identifier, |
| 801 | top_parent->expr_type, |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 802 | tc->combined_constraints, 0); |
Lev Walkin | a2abcaa | 2017-07-23 21:08:49 +0400 | [diff] [blame] | 803 | safe_printf("\n-- OER-visible constraints (%s): ", |
| 804 | top_parent->Identifier); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 805 | asn1print_constraint_explain(top_parent->Identifier, |
| 806 | top_parent->expr_type, |
Lev Walkin | a2abcaa | 2017-07-23 21:08:49 +0400 | [diff] [blame] | 807 | tc->combined_constraints, CPR_strict_OER_visibility); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 808 | safe_printf("\n-- PER-visible constraints (%s): ", |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 809 | top_parent->Identifier); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 810 | asn1print_constraint_explain(top_parent->Identifier, |
| 811 | top_parent->expr_type, |
Lev Walkin | a2abcaa | 2017-07-23 21:08:49 +0400 | [diff] [blame] | 812 | tc->combined_constraints, CPR_strict_PER_visibility); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 813 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 814 | safe_printf("\n"); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Lev Walkin | d0f7b91 | 2017-08-07 18:13:04 -0700 | [diff] [blame] | 817 | if(flags & APF_PRINT_CLASS_MATRIX) do { |
Lev Walkin | 62d95d2 | 2017-08-06 23:41:11 -0700 | [diff] [blame] | 818 | size_t col, maxidlen; |
Lev Walkin | 4dcf836 | 2017-08-07 20:10:05 -0700 | [diff] [blame] | 819 | if(tc->ioc_table == NULL) { |
Lev Walkin | d0f7b91 | 2017-08-07 18:13:04 -0700 | [diff] [blame] | 820 | if(tc->expr_type == A1TC_CLASSDEF) { |
| 821 | safe_printf("\n-- Information Object Class table is empty"); |
| 822 | } |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 823 | break; |
| 824 | } |
Lev Walkin | d0f7b91 | 2017-08-07 18:13:04 -0700 | [diff] [blame] | 825 | safe_printf("\n-- Information Object Set has %d entr%s:\n", |
Lev Walkin | 4dcf836 | 2017-08-07 20:10:05 -0700 | [diff] [blame] | 826 | tc->ioc_table->rows, |
| 827 | tc->ioc_table->rows==1 ? "y" : "ies"); |
| 828 | maxidlen = asn1p_ioc_table_max_identifier_length(tc->ioc_table); |
| 829 | for(ssize_t r = -1; r < (ssize_t)tc->ioc_table->rows; r++) { |
| 830 | asn1p_ioc_row_t *row; |
| 831 | row = tc->ioc_table->row[r<0?0:r]; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 832 | if(r < 0) safe_printf("-- %s", r > 9 ? " " : ""); |
Lev Walkin | bc40726 | 2017-08-23 10:03:22 -0700 | [diff] [blame^] | 833 | else |
| 834 | safe_printf("-- [%*d]", (tc->ioc_table->rows > 9) + 1, r + 1); |
| 835 | for(col = 0; col < row->columns; col++) { |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 836 | struct asn1p_ioc_cell_s *cell; |
| 837 | cell = &row->column[col]; |
| 838 | if(r < 0) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 839 | safe_printf("[%*s]", maxidlen, |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 840 | cell->field->Identifier); |
| 841 | continue; |
| 842 | } |
| 843 | if(!cell->value) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 844 | safe_printf(" %*s ", maxidlen, "<no entry>"); |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 845 | continue; |
| 846 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 847 | safe_printf(" %*s ", maxidlen, |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 848 | cell->value->Identifier); |
| 849 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 850 | safe_printf("\n"); |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 851 | } |
Lev Walkin | bc40726 | 2017-08-23 10:03:22 -0700 | [diff] [blame^] | 852 | if(tc->ioc_table->extensible) { |
| 853 | safe_printf("-- [%*s] ...\n", (tc->ioc_table->rows>9)+1, ""); |
| 854 | } |
| 855 | } while(0); |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 856 | |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 857 | if(flags & APF_PRINT_CLASS_MATRIX |
| 858 | && tc->lhs_params) do { |
| 859 | int i; |
| 860 | if(tc->specializations.pspecs_count == 0) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 861 | safe_printf("\n-- No specializations found\n"); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 862 | break; |
| 863 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 864 | safe_printf("\n-- Specializations list has %d entr%s:\n", |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 865 | tc->specializations.pspecs_count, |
| 866 | tc->specializations.pspecs_count == 1 ? "y" : "ies"); |
| 867 | for(i = 0; i < tc->specializations.pspecs_count; i++) { |
| 868 | asn1p_expr_t *se; |
| 869 | struct asn1p_pspec_s *pspec; |
| 870 | pspec = &tc->specializations.pspec[i]; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 871 | safe_printf("-- "); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 872 | TQ_FOR(se, &(pspec->rhs_pspecs->members), next) { |
| 873 | asn1print_expr(asn, mod, se, flags, level+1); |
| 874 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 875 | safe_printf("\n"); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 876 | } |
| 877 | } while(0); |
| 878 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 879 | return 0; |
| 880 | } |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 881 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 882 | |
| 883 | static int |
| 884 | asn1print_expr_dtd(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, enum asn1print_flags flags, int level) { |
| 885 | asn1p_expr_t *se; |
| 886 | int expr_unordered = 0; |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 887 | int dont_involve_children = 0; |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 888 | |
| 889 | switch(expr->meta_type) { |
| 890 | case AMT_TYPE: |
| 891 | case AMT_TYPEREF: |
| 892 | break; |
| 893 | default: |
| 894 | if(expr->expr_type == A1TC_UNIVERVAL) |
| 895 | break; |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | if(!expr->Identifier) return 0; |
| 900 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 901 | if(flags & APF_LINE_COMMENTS) |
| 902 | INDENT("<!-- #line %d -->\n", expr->_lineno); |
| 903 | INDENT("<!ELEMENT %s", expr->Identifier); |
| 904 | |
| 905 | if(expr->expr_type == A1TC_REFERENCE) { |
Lev Walkin | c0e03b9 | 2017-08-22 01:48:23 -0700 | [diff] [blame] | 906 | se = WITH_MODULE_NAMESPACE(expr->module, expr_ns, asn1f_find_terminal_type_ex(asn, expr_ns, expr)); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 907 | if(!se) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 908 | safe_printf(" (ANY)"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 909 | return 0; |
| 910 | } |
| 911 | expr = se; |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 912 | dont_involve_children = 1; |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Lev Walkin | d7963aa | 2005-03-10 15:16:56 +0000 | [diff] [blame] | 915 | if(expr->expr_type == ASN_CONSTR_CHOICE |
| 916 | || expr->expr_type == ASN_CONSTR_SEQUENCE_OF |
| 917 | || expr->expr_type == ASN_CONSTR_SET_OF |
| 918 | || expr->expr_type == ASN_CONSTR_SET |
Lev Walkin | 112d69e | 2005-03-09 20:52:15 +0000 | [diff] [blame] | 919 | || expr->expr_type == ASN_BASIC_INTEGER |
| 920 | || expr->expr_type == ASN_BASIC_ENUMERATED) { |
| 921 | expr_unordered = 1; |
| 922 | } |
| 923 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 924 | if(TQ_FIRST(&expr->members)) { |
| 925 | int extensible = 0; |
Lev Walkin | fbaeb85 | 2006-11-21 10:39:52 +0000 | [diff] [blame] | 926 | if(expr->expr_type == ASN_BASIC_BIT_STRING) |
| 927 | dont_involve_children = 1; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 928 | safe_printf(" ("); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 929 | TQ_FOR(se, &(expr->members), next) { |
| 930 | if(se->expr_type == A1TC_EXTENSIBLE) { |
| 931 | extensible = 1; |
| 932 | continue; |
| 933 | } else if(!se->Identifier |
| 934 | && se->expr_type == A1TC_REFERENCE) { |
| 935 | asn1print_ref(se->reference, flags); |
| 936 | } else if(se->Identifier) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 937 | safe_printf("%s", se->Identifier); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 938 | } else { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 939 | safe_printf("ANY"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 940 | } |
| 941 | if(expr->expr_type != ASN_CONSTR_SET |
| 942 | && expr->expr_type != ASN_CONSTR_CHOICE |
| 943 | && expr->expr_type != ASN_BASIC_INTEGER |
| 944 | && expr->expr_type != ASN_BASIC_ENUMERATED) { |
| 945 | if(expr_unordered) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 946 | safe_printf("*"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 947 | else if(se->marker.flags) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 948 | safe_printf("?"); |
Lev Walkin | fbaeb85 | 2006-11-21 10:39:52 +0000 | [diff] [blame] | 949 | else if(expr->expr_type == ASN_BASIC_BIT_STRING) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 950 | safe_printf("?"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 951 | } |
| 952 | if(TQ_NEXT(se, next) |
| 953 | && TQ_NEXT(se, next)->expr_type != A1TC_EXTENSIBLE) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 954 | safe_printf(expr_unordered?"|":", "); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | if(extensible) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 958 | safe_printf(expr_unordered?"|":", "); |
| 959 | safe_printf("ANY"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 960 | if(expr->expr_type != ASN_CONSTR_SET |
| 961 | && expr->expr_type != ASN_CONSTR_CHOICE |
| 962 | && expr->expr_type != ASN_BASIC_INTEGER |
| 963 | && expr->expr_type != ASN_BASIC_ENUMERATED) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 964 | safe_printf("*"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 967 | safe_printf(")"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 968 | if(expr->expr_type == ASN_CONSTR_SET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 969 | safe_printf("*"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 970 | |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 971 | } else switch(expr->expr_type) { |
| 972 | case ASN_BASIC_BOOLEAN: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 973 | safe_printf(" (true|false)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 974 | break; |
| 975 | case ASN_CONSTR_CHOICE: |
| 976 | case ASN_CONSTR_SET: |
| 977 | case ASN_CONSTR_SET_OF: |
| 978 | case ASN_CONSTR_SEQUENCE: |
| 979 | case ASN_CONSTR_SEQUENCE_OF: |
| 980 | case ASN_BASIC_NULL: |
| 981 | case A1TC_UNIVERVAL: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 982 | safe_printf(" EMPTY"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 983 | break; |
| 984 | case ASN_TYPE_ANY: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 985 | safe_printf(" ANY"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 986 | break; |
| 987 | case ASN_BASIC_BIT_STRING: |
| 988 | case ASN_BASIC_OCTET_STRING: |
| 989 | case ASN_BASIC_OBJECT_IDENTIFIER: |
| 990 | case ASN_BASIC_RELATIVE_OID: |
Lev Walkin | cc11653 | 2004-10-15 06:01:54 +0000 | [diff] [blame] | 991 | case ASN_BASIC_INTEGER: |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 992 | case ASN_BASIC_UTCTime: |
| 993 | case ASN_BASIC_GeneralizedTime: |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 994 | case ASN_STRING_NumericString: |
| 995 | case ASN_STRING_PrintableString: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 996 | safe_printf(" (#PCDATA)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 997 | break; |
| 998 | case ASN_STRING_VisibleString: |
| 999 | case ASN_STRING_ISO646String: |
| 1000 | /* Entity references, but not XML elements may be present */ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1001 | safe_printf(" (#PCDATA)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1002 | break; |
| 1003 | case ASN_BASIC_REAL: /* e.g. <MINUS-INFINITY/> */ |
| 1004 | case ASN_BASIC_ENUMERATED: /* e.g. <enumIdentifier1/> */ |
| 1005 | default: |
| 1006 | /* |
| 1007 | * XML elements are allowed. |
| 1008 | * For example, a UTF8String may contain "<bel/>". |
| 1009 | */ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1010 | safe_printf(" ANY"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1011 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1012 | safe_printf(">\n"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1013 | |
| 1014 | /* |
| 1015 | * Display the descendants (children) of the current type. |
| 1016 | */ |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1017 | if(!dont_involve_children) { |
| 1018 | TQ_FOR(se, &(expr->members), next) { |
| 1019 | if(se->expr_type == A1TC_EXTENSIBLE) continue; |
| 1020 | asn1print_expr_dtd(asn, mod, se, flags, level + 1); |
| 1021 | } |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | return 0; |
| 1025 | } |