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; |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 340 | int perhaps_subconstraints = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 341 | |
| 342 | if(ct == 0) return 0; |
| 343 | |
| 344 | if(ct->type == ACT_CA_SET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 345 | safe_printf("("); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 346 | |
| 347 | switch(ct->type) { |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 348 | case ACT_EL_TYPE: |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 349 | asn1print_value(ct->containedSubtype, flags); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 350 | perhaps_subconstraints = 1; |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 351 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 352 | case ACT_EL_VALUE: |
| 353 | asn1print_value(ct->value, flags); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 354 | perhaps_subconstraints = 1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 355 | break; |
| 356 | case ACT_EL_RANGE: |
| 357 | case ACT_EL_LLRANGE: |
| 358 | case ACT_EL_RLRANGE: |
| 359 | case ACT_EL_ULRANGE: |
| 360 | asn1print_value(ct->range_start, flags); |
| 361 | switch(ct->type) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 362 | case ACT_EL_RANGE: safe_printf(".."); break; |
| 363 | case ACT_EL_LLRANGE: safe_printf("<.."); break; |
| 364 | case ACT_EL_RLRANGE: safe_printf("..<"); break; |
| 365 | case ACT_EL_ULRANGE: safe_printf("<..<"); break; |
| 366 | default: safe_printf("?..?"); break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 367 | } |
| 368 | asn1print_value(ct->range_stop, flags); |
| 369 | break; |
| 370 | case ACT_EL_EXT: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 371 | safe_printf("..."); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 372 | break; |
| 373 | case ACT_CT_SIZE: |
| 374 | case ACT_CT_FROM: |
| 375 | switch(ct->type) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 376 | case ACT_CT_SIZE: safe_printf("SIZE("); break; |
| 377 | case ACT_CT_FROM: safe_printf("FROM("); break; |
| 378 | default: safe_printf("??? ("); break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 379 | } |
| 380 | assert(ct->el_count != 0); |
| 381 | assert(ct->el_count == 1); |
| 382 | asn1print_constraint(ct->elements[0], flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 383 | safe_printf(")"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 384 | break; |
| 385 | case ACT_CT_WCOMP: |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 386 | assert(ct->el_count != 0); |
| 387 | assert(ct->el_count == 1); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 388 | safe_printf("WITH COMPONENT"); |
| 389 | perhaps_subconstraints = 1; |
Lev Walkin | 8638f0d | 2005-03-28 07:50:06 +0000 | [diff] [blame] | 390 | break; |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 391 | case ACT_CT_WCOMPS: { |
| 392 | unsigned int i; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 393 | safe_printf("WITH COMPONENTS { "); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 394 | for(i = 0; i < ct->el_count; i++) { |
| 395 | asn1p_constraint_t *cel = ct->elements[i]; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 396 | if(i) safe_printf(", "); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 397 | asn1print_constraint(cel, flags); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 398 | switch(cel->presence) { |
| 399 | case ACPRES_DEFAULT: break; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 400 | case ACPRES_PRESENT: safe_printf(" PRESENT"); break; |
| 401 | case ACPRES_ABSENT: safe_printf(" ABSENT"); break; |
| 402 | case ACPRES_OPTIONAL: safe_printf(" OPTIONAL");break; |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 405 | safe_printf(" }"); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 406 | } |
Lev Walkin | 8638f0d | 2005-03-28 07:50:06 +0000 | [diff] [blame] | 407 | break; |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 408 | case ACT_CT_CTDBY: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 409 | safe_printf("CONSTRAINED BY "); |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 410 | assert(ct->value->type == ATV_UNPARSED); |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 411 | safe_fwrite(ct->value->value.string.buf, ct->value->value.string.size); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 412 | break; |
| 413 | case ACT_CT_CTNG: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 414 | safe_printf("CONTAINING "); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 415 | asn1print_expr(ct->value->value.v_type->module->asn1p, |
| 416 | ct->value->value.v_type->module, |
| 417 | ct->value->value.v_type, |
| 418 | flags, 1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 419 | break; |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 420 | case ACT_CT_PATTERN: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 421 | safe_printf("PATTERN "); |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 422 | asn1print_value(ct->value, flags); |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 423 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 424 | case ACT_CA_SET: symno++; |
| 425 | case ACT_CA_CRC: symno++; |
| 426 | case ACT_CA_CSV: symno++; |
| 427 | case ACT_CA_UNI: symno++; |
| 428 | case ACT_CA_INT: symno++; |
| 429 | case ACT_CA_EXC: |
| 430 | { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 431 | char *symtable[] = { " EXCEPT ", " ^ ", " | ", ",", |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 432 | "", "(" }; |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 433 | unsigned int i; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 434 | for(i = 0; i < ct->el_count; i++) { |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 435 | if(i) safe_printf("%s", symtable[symno]); |
| 436 | if(ct->type == ACT_CA_CRC) safe_printf("{"); |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 437 | asn1print_constraint(ct->elements[i], flags); |
Lev Walkin | f4b711a | 2017-08-23 06:55:27 -0700 | [diff] [blame] | 438 | if(ct->type == ACT_CA_CRC) safe_printf("}"); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 439 | if(ct->type == ACT_CA_SET && i+1 < ct->el_count) |
| 440 | safe_printf(") "); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | break; |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 444 | case ACT_CA_AEX: |
| 445 | assert(ct->el_count == 1); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 446 | safe_printf("ALL EXCEPT"); |
| 447 | perhaps_subconstraints = 1; |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 448 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 449 | case ACT_INVALID: |
| 450 | assert(ct->type != ACT_INVALID); |
| 451 | break; |
| 452 | } |
| 453 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 454 | if(perhaps_subconstraints && ct->el_count) { |
| 455 | safe_printf(" "); |
| 456 | assert(ct->el_count == 1); |
| 457 | asn1print_constraint(ct->elements[0], flags); |
| 458 | } |
| 459 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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 | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 594 | int has_space = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 595 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 596 | #define HAS_SPACE() \ |
| 597 | do { \ |
| 598 | has_space = 1; \ |
| 599 | } while(0) |
| 600 | #define ENSURE_SPACE() \ |
| 601 | do { \ |
| 602 | if(!has_space) { \ |
| 603 | has_space = 1; \ |
| 604 | safe_printf(" "); \ |
| 605 | } \ |
| 606 | } while(0) |
| 607 | #define WANT_SPACE() \ |
| 608 | do { \ |
| 609 | has_space = 0; \ |
| 610 | } while(0) |
| 611 | |
| 612 | if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT)) |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 613 | INDENT("-- #line %d\n", tc->_lineno); |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 614 | |
| 615 | /* Reconstruct compiler directive information */ |
| 616 | if((tc->marker.flags & EM_INDIRECT) |
| 617 | && (tc->marker.flags & EM_OMITABLE) != EM_OMITABLE) { |
| 618 | if((flags & APF_NOINDENT)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 619 | safe_printf(" --<ASN1C.RepresentAsPointer>-- "); |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 620 | else |
| 621 | INDENT("--<ASN1C.RepresentAsPointer>--\n"); |
| 622 | } |
| 623 | |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 624 | if(tc->Identifier |
| 625 | && (!(tc->meta_type == AMT_VALUE && tc->expr_type == A1TC_REFERENCE) |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 626 | || level == 0)) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 627 | INDENT("%s", tc->Identifier); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 628 | WANT_SPACE(); |
| 629 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 630 | |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 631 | if(tc->lhs_params) { |
| 632 | asn1print_params(tc->lhs_params, flags); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | if(tc->meta_type != AMT_VALUE |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 636 | && tc->meta_type != AMT_VALUESET |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 637 | && tc->expr_type != A1TC_EXTENSIBLE) { |
| 638 | if(level) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 639 | if(tc->Identifier && !(flags & APF_NOINDENT)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 640 | safe_printf("\t"); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 641 | } else if(tc->Identifier) { |
| 642 | ENSURE_SPACE(); |
| 643 | safe_printf("::="); |
| 644 | WANT_SPACE(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
| 648 | if(tc->tag.tag_class) { |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 649 | ENSURE_SPACE(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 650 | asn1print_tag(tc, flags); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 651 | WANT_SPACE(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | switch(tc->expr_type) { |
| 655 | case A1TC_EXTENSIBLE: |
| 656 | if(tc->value) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 657 | safe_printf("!"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 658 | asn1print_value(tc->value, flags); |
| 659 | } |
| 660 | break; |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 661 | case A1TC_COMPONENTS_OF: |
| 662 | SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 663 | safe_printf(" COMPONENTS OF"); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 664 | WANT_SPACE(); |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 665 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 666 | case A1TC_REFERENCE: |
| 667 | case A1TC_UNIVERVAL: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 668 | break; |
| 669 | case A1TC_CLASSDEF: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 670 | safe_printf(" CLASS"); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 671 | WANT_SPACE(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 672 | break; |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 673 | case A1TC_CLASSFIELD_TFS ... A1TC_CLASSFIELD_OSFS: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 674 | /* Nothing to print here */ |
| 675 | break; |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 676 | case ASN_CONSTR_SET_OF: |
| 677 | case ASN_CONSTR_SEQUENCE_OF: |
| 678 | SEQ_OF = 1; |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 679 | ENSURE_SPACE(); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 680 | if(tc->expr_type == ASN_CONSTR_SET_OF) |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 681 | safe_printf("SET"); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 682 | else |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 683 | safe_printf("SEQUENCE"); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 684 | if(tc->constraints) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 685 | safe_printf(" "); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 686 | asn1print_constraint(tc->constraints, flags); |
| 687 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 688 | safe_printf(" OF"); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 689 | WANT_SPACE(); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 690 | break; |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 691 | case A1TC_VALUESET: |
| 692 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 693 | default: |
| 694 | { |
| 695 | char *p = ASN_EXPR_TYPE2STR(tc->expr_type); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 696 | ENSURE_SPACE(); |
| 697 | safe_printf("%s", p?p:"<unknown type!>"); |
| 698 | WANT_SPACE(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 699 | } |
| 700 | break; |
| 701 | } |
| 702 | |
Lev Walkin | b9d0ae3 | 2005-06-02 04:06:24 +0000 | [diff] [blame] | 703 | /* |
| 704 | * Put the name of the referred type. |
| 705 | */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 706 | if(tc->reference) { |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 707 | ENSURE_SPACE(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 708 | asn1print_ref(tc->reference, flags); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 709 | WANT_SPACE(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 712 | if(tc->meta_type == AMT_VALUESET && level == 0) { |
| 713 | ENSURE_SPACE(); |
| 714 | safe_printf("::="); |
| 715 | WANT_SPACE(); |
| 716 | } |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 717 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 718 | /* |
| 719 | * Display the descendants (children) of the current type. |
| 720 | */ |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 721 | if(TQ_FIRST(&(tc->members)) |
| 722 | || (tc->expr_type & ASN_CONSTR_MASK) |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 723 | || tc->meta_type == AMT_OBJECT |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 724 | || tc->meta_type == AMT_OBJECTCLASS |
| 725 | || tc->meta_type == AMT_OBJECTFIELD |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 726 | ) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 727 | asn1p_expr_t *se; /* SubExpression */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 728 | int put_braces = (!SEQ_OF) /* Don't need 'em, if SET OF... */ |
| 729 | && (tc->meta_type != AMT_OBJECTFIELD); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 730 | |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 731 | if(put_braces) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 732 | if(flags & APF_NOINDENT) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 733 | safe_printf("{"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 734 | if(!TQ_FIRST(&tc->members)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 735 | safe_printf("}"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 736 | } else { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 737 | safe_printf(" {"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 738 | if(TQ_FIRST(&tc->members)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 739 | safe_printf("\n"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 740 | else |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 741 | safe_printf(" }"); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 742 | } |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 743 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 744 | |
| 745 | TQ_FOR(se, &(tc->members), next) { |
| 746 | /* |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 747 | * Print the expression as it were a stand-alone type. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 748 | */ |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 749 | asn1print_expr(asn, mod, se, flags, level + 1); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 750 | if((se->marker.flags & EM_DEFAULT) == EM_DEFAULT) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 751 | safe_printf(" DEFAULT "); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 752 | asn1print_value(se->marker.default_value, flags); |
| 753 | } else if((se->marker.flags & EM_OPTIONAL) |
| 754 | == EM_OPTIONAL) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 755 | safe_printf(" OPTIONAL"); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 756 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 757 | if(TQ_NEXT(se, next)) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 758 | safe_printf(","); |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 759 | if(!(flags & APF_NOINDENT)) |
| 760 | INDENT("\n"); |
| 761 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 764 | if(put_braces && TQ_FIRST(&tc->members)) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 765 | if(!(flags & APF_NOINDENT)) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 766 | safe_printf("\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 767 | INDENT("}"); |
| 768 | } |
| 769 | } |
| 770 | |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 771 | if(tc->with_syntax) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 772 | safe_printf(" WITH SYNTAX {"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 773 | asn1print_with_syntax(tc->with_syntax, flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 774 | safe_printf("}\n"); |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 775 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 776 | |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 777 | /* Right hand specialization */ |
| 778 | if(tc->rhs_pspecs) { |
| 779 | asn1p_expr_t *se; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 780 | safe_printf("{"); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 781 | TQ_FOR(se, &(tc->rhs_pspecs->members), next) { |
| 782 | asn1print_expr(asn, mod, se, flags, level + 1); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 783 | if(TQ_NEXT(se, next)) safe_printf(", "); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 784 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 785 | safe_printf("}"); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 788 | if(!SEQ_OF && tc->constraints) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 789 | safe_printf(" "); |
Lev Walkin | 557f27d | 2006-03-21 07:46:48 +0000 | [diff] [blame] | 790 | if(tc->meta_type == AMT_VALUESET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 791 | safe_printf("{"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 792 | asn1print_constraint(tc->constraints, flags); |
Lev Walkin | 557f27d | 2006-03-21 07:46:48 +0000 | [diff] [blame] | 793 | if(tc->meta_type == AMT_VALUESET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 794 | safe_printf("}"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 795 | } |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 796 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 797 | if(tc->unique) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 798 | safe_printf(" UNIQUE"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | if(tc->meta_type == AMT_VALUE |
| 802 | && tc->expr_type != A1TC_EXTENSIBLE) { |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 803 | if(tc->expr_type == A1TC_UNIVERVAL) { |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 804 | if(tc->value) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 805 | safe_printf("("); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 806 | asn1print_value(tc->value, flags); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 807 | safe_printf(")"); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 808 | } |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 809 | } else { |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 810 | if(level == 0 && tc->Identifier) safe_printf(" ::= "); |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 811 | asn1print_value(tc->value, flags); |
| 812 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 815 | /* |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 816 | * The following section exists entirely for debugging. |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 817 | */ |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 818 | if(flags & APF_PRINT_CONSTRAINTS |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 819 | && tc->expr_type != A1TC_EXTENSIBLE) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 820 | asn1p_expr_t *top_parent; |
| 821 | |
| 822 | if(tc->combined_constraints) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 823 | safe_printf("\n-- Combined constraints: "); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 824 | asn1print_constraint(tc->combined_constraints, flags); |
| 825 | } |
| 826 | |
Lev Walkin | c0e03b9 | 2017-08-22 01:48:23 -0700 | [diff] [blame] | 827 | top_parent = WITH_MODULE_NAMESPACE( |
| 828 | tc->module, tc_ns, asn1f_find_terminal_type_ex(asn, tc_ns, tc)); |
| 829 | if(top_parent) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 830 | safe_printf("\n-- Practical constraints (%s): ", |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 831 | top_parent->Identifier); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 832 | asn1print_constraint_explain(top_parent->Identifier, |
| 833 | top_parent->expr_type, |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 834 | tc->combined_constraints, 0); |
Lev Walkin | a2abcaa | 2017-07-23 21:08:49 +0400 | [diff] [blame] | 835 | safe_printf("\n-- OER-visible constraints (%s): ", |
| 836 | top_parent->Identifier); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 837 | asn1print_constraint_explain(top_parent->Identifier, |
| 838 | top_parent->expr_type, |
Lev Walkin | a2abcaa | 2017-07-23 21:08:49 +0400 | [diff] [blame] | 839 | tc->combined_constraints, CPR_strict_OER_visibility); |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 840 | safe_printf("\n-- PER-visible constraints (%s): ", |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 841 | top_parent->Identifier); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 842 | asn1print_constraint_explain(top_parent->Identifier, |
| 843 | top_parent->expr_type, |
Lev Walkin | a2abcaa | 2017-07-23 21:08:49 +0400 | [diff] [blame] | 844 | tc->combined_constraints, CPR_strict_PER_visibility); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 845 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 846 | safe_printf("\n"); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 847 | } |
| 848 | |
Lev Walkin | d0f7b91 | 2017-08-07 18:13:04 -0700 | [diff] [blame] | 849 | if(flags & APF_PRINT_CLASS_MATRIX) do { |
Lev Walkin | 62d95d2 | 2017-08-06 23:41:11 -0700 | [diff] [blame] | 850 | size_t col, maxidlen; |
Lev Walkin | 4dcf836 | 2017-08-07 20:10:05 -0700 | [diff] [blame] | 851 | if(tc->ioc_table == NULL) { |
Lev Walkin | d0f7b91 | 2017-08-07 18:13:04 -0700 | [diff] [blame] | 852 | if(tc->expr_type == A1TC_CLASSDEF) { |
| 853 | safe_printf("\n-- Information Object Class table is empty"); |
| 854 | } |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 855 | break; |
| 856 | } |
Lev Walkin | d0f7b91 | 2017-08-07 18:13:04 -0700 | [diff] [blame] | 857 | safe_printf("\n-- Information Object Set has %d entr%s:\n", |
Lev Walkin | 4dcf836 | 2017-08-07 20:10:05 -0700 | [diff] [blame] | 858 | tc->ioc_table->rows, |
| 859 | tc->ioc_table->rows==1 ? "y" : "ies"); |
| 860 | maxidlen = asn1p_ioc_table_max_identifier_length(tc->ioc_table); |
| 861 | for(ssize_t r = -1; r < (ssize_t)tc->ioc_table->rows; r++) { |
| 862 | asn1p_ioc_row_t *row; |
| 863 | row = tc->ioc_table->row[r<0?0:r]; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 864 | if(r < 0) safe_printf("-- %s", r > 9 ? " " : ""); |
Lev Walkin | bc40726 | 2017-08-23 10:03:22 -0700 | [diff] [blame] | 865 | else |
| 866 | safe_printf("-- [%*d]", (tc->ioc_table->rows > 9) + 1, r + 1); |
| 867 | for(col = 0; col < row->columns; col++) { |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 868 | struct asn1p_ioc_cell_s *cell; |
| 869 | cell = &row->column[col]; |
| 870 | if(r < 0) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 871 | safe_printf("[%*s]", maxidlen, |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 872 | cell->field->Identifier); |
| 873 | continue; |
| 874 | } |
| 875 | if(!cell->value) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 876 | safe_printf(" %*s ", maxidlen, "<no entry>"); |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 877 | continue; |
| 878 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 879 | safe_printf(" %*s ", maxidlen, |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 880 | cell->value->Identifier); |
| 881 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 882 | safe_printf("\n"); |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 883 | } |
Lev Walkin | bc40726 | 2017-08-23 10:03:22 -0700 | [diff] [blame] | 884 | if(tc->ioc_table->extensible) { |
| 885 | safe_printf("-- [%*s] ...\n", (tc->ioc_table->rows>9)+1, ""); |
| 886 | } |
| 887 | } while(0); |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 888 | |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 889 | if(flags & APF_PRINT_CLASS_MATRIX |
| 890 | && tc->lhs_params) do { |
| 891 | int i; |
| 892 | if(tc->specializations.pspecs_count == 0) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 893 | safe_printf("\n-- No specializations found\n"); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 894 | break; |
| 895 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 896 | safe_printf("\n-- Specializations list has %d entr%s:\n", |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 897 | tc->specializations.pspecs_count, |
| 898 | tc->specializations.pspecs_count == 1 ? "y" : "ies"); |
| 899 | for(i = 0; i < tc->specializations.pspecs_count; i++) { |
| 900 | asn1p_expr_t *se; |
| 901 | struct asn1p_pspec_s *pspec; |
| 902 | pspec = &tc->specializations.pspec[i]; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 903 | safe_printf("-- "); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 904 | TQ_FOR(se, &(pspec->rhs_pspecs->members), next) { |
| 905 | asn1print_expr(asn, mod, se, flags, level+1); |
| 906 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 907 | safe_printf("\n"); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 908 | } |
| 909 | } while(0); |
| 910 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 911 | return 0; |
| 912 | } |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 913 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 914 | |
| 915 | static int |
| 916 | asn1print_expr_dtd(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, enum asn1print_flags flags, int level) { |
| 917 | asn1p_expr_t *se; |
| 918 | int expr_unordered = 0; |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 919 | int dont_involve_children = 0; |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 920 | |
| 921 | switch(expr->meta_type) { |
| 922 | case AMT_TYPE: |
| 923 | case AMT_TYPEREF: |
| 924 | break; |
| 925 | default: |
| 926 | if(expr->expr_type == A1TC_UNIVERVAL) |
| 927 | break; |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | if(!expr->Identifier) return 0; |
| 932 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 933 | if(flags & APF_LINE_COMMENTS) |
| 934 | INDENT("<!-- #line %d -->\n", expr->_lineno); |
| 935 | INDENT("<!ELEMENT %s", expr->Identifier); |
| 936 | |
| 937 | if(expr->expr_type == A1TC_REFERENCE) { |
Lev Walkin | c0e03b9 | 2017-08-22 01:48:23 -0700 | [diff] [blame] | 938 | 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] | 939 | if(!se) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 940 | safe_printf(" (ANY)"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 941 | return 0; |
| 942 | } |
| 943 | expr = se; |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 944 | dont_involve_children = 1; |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Lev Walkin | d7963aa | 2005-03-10 15:16:56 +0000 | [diff] [blame] | 947 | if(expr->expr_type == ASN_CONSTR_CHOICE |
| 948 | || expr->expr_type == ASN_CONSTR_SEQUENCE_OF |
| 949 | || expr->expr_type == ASN_CONSTR_SET_OF |
| 950 | || expr->expr_type == ASN_CONSTR_SET |
Lev Walkin | 112d69e | 2005-03-09 20:52:15 +0000 | [diff] [blame] | 951 | || expr->expr_type == ASN_BASIC_INTEGER |
| 952 | || expr->expr_type == ASN_BASIC_ENUMERATED) { |
| 953 | expr_unordered = 1; |
| 954 | } |
| 955 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 956 | if(TQ_FIRST(&expr->members)) { |
| 957 | int extensible = 0; |
Lev Walkin | fbaeb85 | 2006-11-21 10:39:52 +0000 | [diff] [blame] | 958 | if(expr->expr_type == ASN_BASIC_BIT_STRING) |
| 959 | dont_involve_children = 1; |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 960 | safe_printf(" ("); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 961 | TQ_FOR(se, &(expr->members), next) { |
| 962 | if(se->expr_type == A1TC_EXTENSIBLE) { |
| 963 | extensible = 1; |
| 964 | continue; |
| 965 | } else if(!se->Identifier |
| 966 | && se->expr_type == A1TC_REFERENCE) { |
| 967 | asn1print_ref(se->reference, flags); |
| 968 | } else if(se->Identifier) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 969 | safe_printf("%s", se->Identifier); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 970 | } else { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 971 | safe_printf("ANY"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 972 | } |
| 973 | if(expr->expr_type != ASN_CONSTR_SET |
| 974 | && expr->expr_type != ASN_CONSTR_CHOICE |
| 975 | && expr->expr_type != ASN_BASIC_INTEGER |
| 976 | && expr->expr_type != ASN_BASIC_ENUMERATED) { |
| 977 | if(expr_unordered) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 978 | safe_printf("*"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 979 | else if(se->marker.flags) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 980 | safe_printf("?"); |
Lev Walkin | fbaeb85 | 2006-11-21 10:39:52 +0000 | [diff] [blame] | 981 | else if(expr->expr_type == ASN_BASIC_BIT_STRING) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 982 | safe_printf("?"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 983 | } |
| 984 | if(TQ_NEXT(se, next) |
| 985 | && TQ_NEXT(se, next)->expr_type != A1TC_EXTENSIBLE) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 986 | safe_printf(expr_unordered?"|":", "); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | if(extensible) { |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 990 | safe_printf(expr_unordered?"|":", "); |
| 991 | safe_printf("ANY"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 992 | if(expr->expr_type != ASN_CONSTR_SET |
| 993 | && expr->expr_type != ASN_CONSTR_CHOICE |
| 994 | && expr->expr_type != ASN_BASIC_INTEGER |
| 995 | && expr->expr_type != ASN_BASIC_ENUMERATED) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 996 | safe_printf("*"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 999 | safe_printf(")"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1000 | if(expr->expr_type == ASN_CONSTR_SET) |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1001 | safe_printf("*"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1002 | |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1003 | } else switch(expr->expr_type) { |
| 1004 | case ASN_BASIC_BOOLEAN: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1005 | safe_printf(" (true|false)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1006 | break; |
| 1007 | case ASN_CONSTR_CHOICE: |
| 1008 | case ASN_CONSTR_SET: |
| 1009 | case ASN_CONSTR_SET_OF: |
| 1010 | case ASN_CONSTR_SEQUENCE: |
| 1011 | case ASN_CONSTR_SEQUENCE_OF: |
| 1012 | case ASN_BASIC_NULL: |
| 1013 | case A1TC_UNIVERVAL: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1014 | safe_printf(" EMPTY"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1015 | break; |
| 1016 | case ASN_TYPE_ANY: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1017 | safe_printf(" ANY"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1018 | break; |
| 1019 | case ASN_BASIC_BIT_STRING: |
| 1020 | case ASN_BASIC_OCTET_STRING: |
| 1021 | case ASN_BASIC_OBJECT_IDENTIFIER: |
| 1022 | case ASN_BASIC_RELATIVE_OID: |
Lev Walkin | cc11653 | 2004-10-15 06:01:54 +0000 | [diff] [blame] | 1023 | case ASN_BASIC_INTEGER: |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1024 | case ASN_BASIC_UTCTime: |
| 1025 | case ASN_BASIC_GeneralizedTime: |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1026 | case ASN_STRING_NumericString: |
| 1027 | case ASN_STRING_PrintableString: |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1028 | safe_printf(" (#PCDATA)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1029 | break; |
| 1030 | case ASN_STRING_VisibleString: |
| 1031 | case ASN_STRING_ISO646String: |
| 1032 | /* Entity references, but not XML elements may be present */ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1033 | safe_printf(" (#PCDATA)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1034 | break; |
| 1035 | case ASN_BASIC_REAL: /* e.g. <MINUS-INFINITY/> */ |
| 1036 | case ASN_BASIC_ENUMERATED: /* e.g. <enumIdentifier1/> */ |
| 1037 | default: |
| 1038 | /* |
| 1039 | * XML elements are allowed. |
| 1040 | * For example, a UTF8String may contain "<bel/>". |
| 1041 | */ |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1042 | safe_printf(" ANY"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1043 | } |
Lev Walkin | f2b2f37 | 2016-03-14 02:23:48 -0700 | [diff] [blame] | 1044 | safe_printf(">\n"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1045 | |
| 1046 | /* |
| 1047 | * Display the descendants (children) of the current type. |
| 1048 | */ |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 1049 | if(!dont_involve_children) { |
| 1050 | TQ_FOR(se, &(expr->members), next) { |
| 1051 | if(se->expr_type == A1TC_EXTENSIBLE) continue; |
| 1052 | asn1print_expr_dtd(asn, mod, se, flags, level + 1); |
| 1053 | } |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | return 0; |
| 1057 | } |