Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <errno.h> |
| 4 | #include <assert.h> |
| 5 | |
| 6 | #include <asn1parser.h> |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 7 | #include <asn1fix_export.h> |
Lev Walkin | 9095ada | 2004-08-18 05:41:05 +0000 | [diff] [blame] | 8 | #include <asn1fix_crange.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | |
| 10 | #include "asn1print.h" |
| 11 | |
| 12 | #define INDENT(fmt, args...) do { \ |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 13 | if(!(flags & APF_NOINDENT)) { \ |
| 14 | int __i = level; \ |
| 15 | while(__i--) printf(" "); \ |
| 16 | } \ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | printf(fmt, ##args); \ |
| 18 | } while(0) |
| 19 | |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 20 | 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] | 21 | static int asn1print_oid(int prior_len, asn1p_oid_t *oid, enum asn1print_flags flags); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 22 | static int asn1print_ref(asn1p_ref_t *ref, enum asn1print_flags flags); |
| 23 | static int asn1print_tag(asn1p_expr_t *tc, enum asn1print_flags flags); |
| 24 | static int asn1print_params(asn1p_paramlist_t *pl,enum asn1print_flags flags); |
| 25 | static int asn1print_with_syntax(asn1p_wsyntx_t *wx, enum asn1print_flags flags); |
| 26 | static int asn1print_constraint(asn1p_constraint_t *, enum asn1print_flags); |
| 27 | static int asn1print_value(asn1p_value_t *val, enum asn1print_flags flags); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 28 | static int asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level); |
| 29 | 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] | 30 | |
| 31 | /* |
| 32 | * Print the contents of the parsed ASN tree. |
| 33 | */ |
| 34 | int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 35 | asn1print(asn1p_t *asn, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 36 | asn1p_module_t *mod; |
Lev Walkin | c70c2ef | 2004-09-30 06:38:21 +0000 | [diff] [blame] | 37 | int modno = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 38 | |
| 39 | if(asn == NULL) { |
| 40 | errno = EINVAL; |
| 41 | return -1; |
| 42 | } |
| 43 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 44 | if(flags & APF_PRINT_XML_DTD) |
| 45 | printf("<!-- XML DTD generated by asn1c-" VERSION " -->\n\n"); |
| 46 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 47 | TQ_FOR(mod, &(asn->modules), mod_next) { |
Lev Walkin | c70c2ef | 2004-09-30 06:38:21 +0000 | [diff] [blame] | 48 | if(modno++) printf("\n"); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 49 | asn1print_module(asn, mod, flags); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Lev Walkin | 112d69e | 2005-03-09 20:52:15 +0000 | [diff] [blame] | 52 | if(flags & APF_PRINT_XML_DTD) { |
| 53 | /* Values for BOOLEAN */ |
| 54 | printf("<!ELEMENT true EMPTY>\n"); |
| 55 | printf("<!ELEMENT false EMPTY>\n"); |
| 56 | } |
| 57 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 62 | 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] | 63 | asn1p_expr_t *tc; |
| 64 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 65 | if(flags & APF_PRINT_XML_DTD) |
| 66 | printf("<!-- ASN.1 module\n"); |
| 67 | |
Lev Walkin | c70c2ef | 2004-09-30 06:38:21 +0000 | [diff] [blame] | 68 | printf("%s ", mod->Identifier); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 69 | if(mod->module_oid) { |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 70 | asn1print_oid(strlen(mod->Identifier), mod->module_oid, flags); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 71 | printf("\n"); |
| 72 | } |
| 73 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 74 | if(flags & APF_PRINT_XML_DTD) { |
| 75 | if(mod->source_file_name |
| 76 | && strcmp(mod->source_file_name, "-")) |
| 77 | printf("found in %s", mod->source_file_name); |
| 78 | printf(" -->\n\n"); |
| 79 | |
| 80 | TQ_FOR(tc, &(mod->members), next) { |
| 81 | asn1print_expr_dtd(asn, mod, tc, flags, 0); |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 87 | printf("DEFINITIONS"); |
| 88 | |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 89 | if(mod->module_flags & MSF_TAG_INSTRUCTIONS) |
| 90 | printf(" TAG INSTRUCTIONS"); |
| 91 | if(mod->module_flags & MSF_XER_INSTRUCTIONS) |
| 92 | printf(" XER INSTRUCTIONS"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 93 | if(mod->module_flags & MSF_EXPLICIT_TAGS) |
| 94 | printf(" EXPLICIT TAGS"); |
| 95 | if(mod->module_flags & MSF_IMPLICIT_TAGS) |
| 96 | printf(" IMPLICIT TAGS"); |
| 97 | if(mod->module_flags & MSF_AUTOMATIC_TAGS) |
| 98 | printf(" AUTOMATIC TAGS"); |
| 99 | if(mod->module_flags & MSF_EXTENSIBILITY_IMPLIED) |
| 100 | printf(" EXTENSIBILITY IMPLIED"); |
| 101 | |
| 102 | printf(" ::=\n"); |
| 103 | printf("BEGIN\n\n"); |
| 104 | |
| 105 | TQ_FOR(tc, &(mod->members), next) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 106 | asn1print_expr(asn, mod, tc, flags, 0); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 107 | if(flags & APF_DEBUG_CONSTRAINTS) |
| 108 | printf("\n"); |
| 109 | else |
| 110 | printf("\n\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | printf("END\n"); |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static int |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 119 | asn1print_oid(int prior_len, asn1p_oid_t *oid, enum asn1print_flags flags) { |
| 120 | size_t accum = prior_len; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 121 | int ac; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 122 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 123 | (void)flags; /* Unused argument */ |
| 124 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 125 | printf("{"); |
| 126 | for(ac = 0; ac < oid->arcs_count; ac++) { |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 127 | const char *arcname = oid->arcs[ac].name; |
| 128 | |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 129 | if(accum + strlen(arcname ? arcname : "") > 75) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 130 | printf("\n\t"); |
| 131 | accum = 0; |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 132 | } else { |
| 133 | accum += printf(" "); |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 134 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 135 | |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 136 | if(arcname) { |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 137 | accum += printf("%s", arcname); |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 138 | if(oid->arcs[ac].number >= 0) { |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 139 | accum += printf("(%" PRIdASN ")", |
| 140 | oid->arcs[ac].number); |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 141 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 142 | } else { |
Lev Walkin | d6db802 | 2005-03-18 03:53:05 +0000 | [diff] [blame] | 143 | accum += printf("%" PRIdASN, oid->arcs[ac].number); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 144 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 145 | } |
| 146 | printf(" }"); |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 152 | asn1print_ref(asn1p_ref_t *ref, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 153 | int cc; |
| 154 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 155 | (void)flags; /* Unused argument */ |
| 156 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 157 | for(cc = 0; cc < ref->comp_count; cc++) { |
| 158 | if(cc) printf("."); |
| 159 | printf("%s", ref->components[cc].name); |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 166 | asn1print_tag(asn1p_expr_t *tc, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 167 | struct asn1p_type_tag_s *tag = &tc->tag; |
| 168 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 169 | (void)flags; /* Unused argument */ |
| 170 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 171 | if(tag->tag_class == TC_NOCLASS) |
| 172 | return 0; |
| 173 | |
| 174 | printf("["); |
| 175 | switch(tag->tag_class) { |
| 176 | case TC_NOCLASS: |
| 177 | assert(tag->tag_class != TC_NOCLASS); |
| 178 | break; |
| 179 | case TC_UNIVERSAL: printf("UNIVERSAL "); break; |
| 180 | case TC_PRIVATE: printf("PRIVATE "); break; |
| 181 | case TC_APPLICATION: printf("APPLICATION "); break; |
| 182 | case TC_CONTEXT_SPECIFIC: |
| 183 | break; |
| 184 | } |
Lev Walkin | 33c16ba | 2004-09-24 21:01:43 +0000 | [diff] [blame] | 185 | printf("%" PRIdASN "]", tag->tag_value); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 186 | |
| 187 | switch(tag->tag_mode) { |
| 188 | case TM_DEFAULT: break; |
| 189 | case TM_IMPLICIT: printf(" IMPLICIT"); break; |
| 190 | case TM_EXPLICIT: printf(" EXPLICIT"); break; |
| 191 | } |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 197 | asn1print_value(asn1p_value_t *val, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 198 | |
| 199 | if(val == NULL) |
| 200 | return 0; |
| 201 | |
| 202 | switch(val->type) { |
| 203 | case ATV_NOVALUE: |
| 204 | break; |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 205 | case ATV_NULL: |
| 206 | printf("NULL"); |
| 207 | return 0; |
| 208 | case ATV_REAL: |
| 209 | printf("%f", val->value.v_double); |
| 210 | return 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 211 | case ATV_INTEGER: |
Lev Walkin | 33c16ba | 2004-09-24 21:01:43 +0000 | [diff] [blame] | 212 | printf("%" PRIdASN, val->value.v_integer); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 213 | return 0; |
| 214 | case ATV_MIN: printf("MIN"); return 0; |
| 215 | case ATV_MAX: printf("MAX"); return 0; |
| 216 | case ATV_FALSE: printf("FALSE"); return 0; |
| 217 | case ATV_TRUE: printf("TRUE"); return 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 218 | case ATV_STRING: |
| 219 | { |
| 220 | char *p = val->value.string.buf; |
| 221 | putchar('"'); |
| 222 | if(strchr(p, '"')) { |
| 223 | /* Mask quotes */ |
| 224 | for(; *p; p++) { |
| 225 | if(*p == '"') |
| 226 | putchar(*p); |
| 227 | putchar(*p); |
| 228 | } |
| 229 | } else { |
| 230 | fputs(p, stdout); |
| 231 | } |
| 232 | putchar('"'); |
| 233 | } |
| 234 | return 0; |
| 235 | case ATV_UNPARSED: |
| 236 | fputs(val->value.string.buf, stdout); |
| 237 | return 0; |
| 238 | case ATV_BITVECTOR: |
| 239 | { |
| 240 | uint8_t *bitvector; |
| 241 | int bits; |
| 242 | int i; |
| 243 | |
| 244 | bitvector = val->value.binary_vector.bits; |
| 245 | bits = val->value.binary_vector.size_in_bits; |
| 246 | |
| 247 | printf("'"); |
| 248 | if(bits%8) { |
| 249 | for(i = 0; i < bits; i++) { |
| 250 | uint8_t uc; |
| 251 | uc = bitvector[i>>3]; |
| 252 | putchar(((uc >> (7-(i%8)))&1)?'1':'0'); |
| 253 | } |
| 254 | printf("'B"); |
| 255 | } else { |
| 256 | char hextable[16] = "0123456789ABCDEF"; |
| 257 | for(i = 0; i < (bits>>3); i++) { |
| 258 | putchar(hextable[bitvector[i] >> 4]); |
| 259 | putchar(hextable[bitvector[i] & 0x0f]); |
| 260 | } |
| 261 | printf("'H"); |
| 262 | } |
Lev Walkin | 043af0d | 2005-02-24 21:07:35 +0000 | [diff] [blame] | 263 | return 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 264 | } |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 265 | case ATV_REFERENCED: |
| 266 | return asn1print_ref(val->value.reference, flags); |
| 267 | case ATV_CHOICE_IDENTIFIER: |
| 268 | printf("%s: ", val->value.choice_identifier.identifier); |
| 269 | return asn1print_value(val->value.choice_identifier.value, flags); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | assert(val->type || !"Unknown"); |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 278 | asn1print_constraint(asn1p_constraint_t *ct, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 279 | int symno = 0; |
| 280 | |
| 281 | if(ct == 0) return 0; |
| 282 | |
| 283 | if(ct->type == ACT_CA_SET) |
| 284 | printf("("); |
| 285 | |
| 286 | switch(ct->type) { |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame^] | 287 | case ACT_EL_TYPE: |
| 288 | asn1print_value(ct->value, flags); |
| 289 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 290 | case ACT_EL_VALUE: |
| 291 | asn1print_value(ct->value, flags); |
| 292 | break; |
| 293 | case ACT_EL_RANGE: |
| 294 | case ACT_EL_LLRANGE: |
| 295 | case ACT_EL_RLRANGE: |
| 296 | case ACT_EL_ULRANGE: |
| 297 | asn1print_value(ct->range_start, flags); |
| 298 | switch(ct->type) { |
| 299 | case ACT_EL_RANGE: printf(".."); break; |
| 300 | case ACT_EL_LLRANGE: printf("<.."); break; |
| 301 | case ACT_EL_RLRANGE: printf("..<"); break; |
| 302 | case ACT_EL_ULRANGE: printf("<..<"); break; |
| 303 | default: printf("?..?"); break; |
| 304 | } |
| 305 | asn1print_value(ct->range_stop, flags); |
| 306 | break; |
| 307 | case ACT_EL_EXT: |
| 308 | printf("..."); |
| 309 | break; |
| 310 | case ACT_CT_SIZE: |
| 311 | case ACT_CT_FROM: |
| 312 | switch(ct->type) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 313 | case ACT_CT_SIZE: printf("SIZE("); break; |
| 314 | case ACT_CT_FROM: printf("FROM("); break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 315 | default: printf("??? ("); break; |
| 316 | } |
| 317 | assert(ct->el_count != 0); |
| 318 | assert(ct->el_count == 1); |
| 319 | asn1print_constraint(ct->elements[0], flags); |
| 320 | printf(")"); |
| 321 | break; |
| 322 | case ACT_CT_WCOMP: |
| 323 | case ACT_CT_WCOMPS: |
| 324 | printf("???"); |
| 325 | break; |
| 326 | case ACT_CA_SET: symno++; |
| 327 | case ACT_CA_CRC: symno++; |
| 328 | case ACT_CA_CSV: symno++; |
| 329 | case ACT_CA_UNI: symno++; |
| 330 | case ACT_CA_INT: symno++; |
| 331 | case ACT_CA_EXC: |
| 332 | { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 333 | char *symtable[] = { " EXCEPT ", " ^ ", " | ", ",", |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 334 | "", "(" }; |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 335 | unsigned int i; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 336 | for(i = 0; i < ct->el_count; i++) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 337 | enum asn1print_flags nflags = flags; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 338 | if(i) fputs(symtable[symno], stdout); |
| 339 | if(ct->type == ACT_CA_CRC) fputs("{", stdout); |
| 340 | asn1print_constraint(ct->elements[i], nflags); |
| 341 | if(ct->type == ACT_CA_CRC) fputs("}", stdout); |
| 342 | if(i+1 < ct->el_count |
| 343 | && ct->type == ACT_CA_SET) |
| 344 | fputs(")", stdout); |
| 345 | } |
| 346 | } |
| 347 | break; |
| 348 | case ACT_INVALID: |
| 349 | assert(ct->type != ACT_INVALID); |
| 350 | break; |
| 351 | } |
| 352 | |
| 353 | if(ct->type == ACT_CA_SET) |
| 354 | printf(")"); |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 360 | asn1print_params(asn1p_paramlist_t *pl, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 361 | if(pl) { |
| 362 | int i; |
| 363 | printf("{"); |
| 364 | for(i = 0; i < pl->params_count; i++) { |
| 365 | if(i) printf(", "); |
| 366 | if(pl->params[i].governor) { |
| 367 | asn1print_ref(pl->params[i].governor, flags); |
| 368 | printf(":"); |
| 369 | } |
| 370 | printf("%s", pl->params[i].argument); |
| 371 | } |
| 372 | printf("}"); |
| 373 | } |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 379 | asn1print_with_syntax(asn1p_wsyntx_t *wx, enum asn1print_flags flags) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 380 | if(wx) { |
| 381 | asn1p_wsyntx_chunk_t *wc; |
| 382 | printf(" WITH SYNTAX {"); |
| 383 | TQ_FOR(wc, &(wx->chunks), next) { |
| 384 | if(wc->ref) { |
| 385 | asn1print_ref(wc->ref, flags); |
| 386 | } else { |
| 387 | fwrite(wc->buf, 1, wc->len, stdout); |
| 388 | } |
| 389 | } |
| 390 | printf("}\n"); |
| 391 | } |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static int |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 397 | asn1print_crange_value(asn1cnst_edge_t *edge, int as_char) { |
| 398 | switch(edge->type) { |
| 399 | case ARE_MIN: printf("MIN"); break; |
| 400 | case ARE_MAX: printf("MAX"); break; |
| 401 | case ARE_VALUE: |
| 402 | if(as_char) { |
| 403 | printf("\"%c\"", (unsigned char)edge->value); |
| 404 | } else { |
Lev Walkin | 33c16ba | 2004-09-24 21:01:43 +0000 | [diff] [blame] | 405 | printf("%" PRIdASN, edge->value); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | static int |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 412 | asn1print_constraint_explain_type(asn1p_expr_type_e expr_type, asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, int strict_PER_visible) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 413 | asn1cnst_range_t *range; |
| 414 | int as_char = (type==ACT_CT_FROM); |
| 415 | int i; |
| 416 | |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 417 | range = asn1constraint_compute_PER_range(expr_type, ct, type, |
| 418 | 0, 0, strict_PER_visible); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 419 | if(!range) return -1; |
| 420 | |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 421 | if(range->incompatible |
| 422 | || (strict_PER_visible && range->not_PER_visible)) { |
| 423 | asn1constraint_range_free(range); |
| 424 | return 0; |
| 425 | } |
| 426 | |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 427 | switch(type) { |
| 428 | case ACT_CT_FROM: printf("(FROM("); break; |
| 429 | case ACT_CT_SIZE: printf("(SIZE("); break; |
| 430 | default: printf("("); break; |
| 431 | } |
| 432 | for(i = -1; i < range->el_count; i++) { |
| 433 | asn1cnst_range_t *r; |
| 434 | if(i == -1) { |
| 435 | if(range->el_count) continue; |
| 436 | r = range; |
| 437 | } else { |
| 438 | r = range->elements[i]; |
| 439 | } |
| 440 | if(i > 0) { |
| 441 | printf(" | "); |
| 442 | } |
| 443 | asn1print_crange_value(&r->left, as_char); |
| 444 | if(r->left.type != r->right.type |
| 445 | || r->left.value != r->right.value) { |
| 446 | printf(".."); |
| 447 | asn1print_crange_value(&r->right, as_char); |
| 448 | } |
| 449 | } |
| 450 | if(range->extensible) |
| 451 | printf(",..."); |
| 452 | printf(type==ACT_EL_RANGE?")":"))"); |
| 453 | |
| 454 | if(range->empty_constraint) |
| 455 | printf(":Empty!"); |
| 456 | |
| 457 | asn1constraint_range_free(range); |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int |
| 462 | asn1print_constraint_explain(asn1p_expr_type_e expr_type, |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 463 | asn1p_constraint_t *ct, int s_PV) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 464 | |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 465 | asn1print_constraint_explain_type(expr_type, ct, ACT_EL_RANGE, s_PV); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 466 | printf(" "); |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 467 | asn1print_constraint_explain_type(expr_type, ct, ACT_CT_SIZE, s_PV); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 468 | printf(" "); |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 469 | asn1print_constraint_explain_type(expr_type, ct, ACT_CT_FROM, s_PV); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | static int |
| 475 | 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] | 476 | int SEQ_OF = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 477 | |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 478 | if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT)) |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 479 | INDENT("-- #line %d\n", tc->_lineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 480 | if(tc->Identifier) |
| 481 | INDENT("%s", tc->Identifier); |
| 482 | |
| 483 | if(tc->params) { |
| 484 | asn1print_params(tc->params, flags); |
| 485 | } |
| 486 | |
| 487 | if(tc->meta_type != AMT_VALUE |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 488 | && tc->meta_type != AMT_VALUESET |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 489 | && tc->expr_type != A1TC_EXTENSIBLE) { |
| 490 | if(level) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 491 | if(tc->Identifier && !(flags & APF_NOINDENT)) |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 492 | printf("\t"); |
| 493 | } else { |
| 494 | printf(" ::="); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if(tc->tag.tag_class) { |
| 499 | printf(" "); |
| 500 | asn1print_tag(tc, flags); |
| 501 | } |
| 502 | |
| 503 | switch(tc->expr_type) { |
| 504 | case A1TC_EXTENSIBLE: |
| 505 | if(tc->value) { |
| 506 | printf("!"); |
| 507 | asn1print_value(tc->value, flags); |
| 508 | } |
| 509 | break; |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 510 | case A1TC_COMPONENTS_OF: |
| 511 | SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */ |
| 512 | printf(" COMPONENTS OF"); |
| 513 | break; |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 514 | case A1TC_PARAMETRIZED: |
| 515 | flags |= APF_NOINDENT; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 516 | case A1TC_REFERENCE: |
| 517 | case A1TC_UNIVERVAL: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 518 | break; |
| 519 | case A1TC_CLASSDEF: |
| 520 | printf(" CLASS"); |
| 521 | break; |
| 522 | case A1TC_CLASSFIELD: |
| 523 | /* Nothing to print here */ |
| 524 | break; |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 525 | case ASN_CONSTR_SET_OF: |
| 526 | case ASN_CONSTR_SEQUENCE_OF: |
| 527 | SEQ_OF = 1; |
| 528 | if(tc->expr_type == ASN_CONSTR_SET_OF) |
| 529 | printf(" SET"); |
| 530 | else |
| 531 | printf(" SEQUENCE"); |
| 532 | if(tc->constraints) { |
| 533 | printf(" "); |
| 534 | asn1print_constraint(tc->constraints, flags); |
| 535 | } |
| 536 | printf(" OF"); |
| 537 | break; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 538 | default: |
| 539 | { |
| 540 | char *p = ASN_EXPR_TYPE2STR(tc->expr_type); |
| 541 | printf(" %s", p?p:"<unknown type!>"); |
| 542 | } |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | if(tc->reference) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 547 | if(!(flags & APF_NOINDENT)) |
| 548 | printf(" "); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 549 | asn1print_ref(tc->reference, flags); |
| 550 | } |
| 551 | |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 552 | if(tc->meta_type == AMT_VALUESET) |
| 553 | printf(" ::="); |
| 554 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 555 | /* |
| 556 | * Display the descendants (children) of the current type. |
| 557 | */ |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 558 | if(TQ_FIRST(&(tc->members)) |
| 559 | || (tc->expr_type & ASN_CONSTR_MASK) |
| 560 | || tc->meta_type == AMT_VALUESET |
| 561 | || tc->meta_type == AMT_OBJECT |
| 562 | || tc->meta_type == AMT_OBJECTSET |
| 563 | ) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 564 | asn1p_expr_t *se; /* SubExpression */ |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 565 | int put_braces = !SEQ_OF; /* Don't need 'em, if SET OF... */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 566 | |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 567 | if(put_braces) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 568 | if(flags & APF_NOINDENT) { |
| 569 | printf("{"); |
| 570 | if(!TQ_FIRST(&tc->members)) |
| 571 | printf("}"); |
| 572 | } else { |
| 573 | printf(" {"); |
| 574 | if(TQ_FIRST(&tc->members)) |
| 575 | printf("\n"); |
| 576 | else |
| 577 | printf(" }"); |
| 578 | } |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 579 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 580 | |
| 581 | TQ_FOR(se, &(tc->members), next) { |
| 582 | /* |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 583 | * Print the expression as it were a stand-alone type. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 584 | */ |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 585 | asn1print_expr(asn, mod, se, flags, level + 1); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 586 | if((se->marker.flags & EM_DEFAULT) == EM_DEFAULT) { |
| 587 | printf(" DEFAULT "); |
| 588 | asn1print_value(se->marker.default_value, flags); |
| 589 | } else if((se->marker.flags & EM_OPTIONAL) |
| 590 | == EM_OPTIONAL) { |
Lev Walkin | 6e8da2b | 2004-09-10 08:21:27 +0000 | [diff] [blame] | 591 | printf(" OPTIONAL"); |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 592 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 593 | if(TQ_NEXT(se, next)) { |
| 594 | printf(","); |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 595 | if(!(flags & APF_NOINDENT)) |
| 596 | INDENT("\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Lev Walkin | c74ea22 | 2004-08-25 02:27:47 +0000 | [diff] [blame] | 600 | if(put_braces && TQ_FIRST(&tc->members)) { |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 601 | if(!(flags & APF_NOINDENT)) |
| 602 | printf("\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 603 | INDENT("}"); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | if(tc->with_syntax) |
| 608 | asn1print_with_syntax(tc->with_syntax, flags); |
| 609 | |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 610 | if(!SEQ_OF && tc->constraints) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 611 | printf(" "); |
| 612 | asn1print_constraint(tc->constraints, flags); |
| 613 | } |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 614 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 615 | if(tc->unique) { |
| 616 | printf(" UNIQUE"); |
| 617 | } |
| 618 | |
| 619 | if(tc->meta_type == AMT_VALUE |
| 620 | && tc->expr_type != A1TC_EXTENSIBLE) { |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 621 | if(tc->expr_type == A1TC_UNIVERVAL) { |
Lev Walkin | b1e0708 | 2004-09-15 11:44:55 +0000 | [diff] [blame] | 622 | if(tc->value) { |
| 623 | printf("("); |
| 624 | asn1print_value(tc->value, flags); |
| 625 | printf(")"); |
| 626 | } |
Lev Walkin | 0056aec | 2004-09-05 10:38:50 +0000 | [diff] [blame] | 627 | } else { |
| 628 | printf(" ::= "); |
| 629 | asn1print_value(tc->value, flags); |
| 630 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 633 | /* |
Lev Walkin | f4069d2 | 2005-02-15 07:06:05 +0000 | [diff] [blame] | 634 | * The following section exists entirely for debugging. |
Lev Walkin | fd151ce | 2004-08-22 03:08:51 +0000 | [diff] [blame] | 635 | */ |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 636 | if(flags & APF_DEBUG_CONSTRAINTS |
| 637 | && tc->expr_type != A1TC_EXTENSIBLE) { |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 638 | asn1p_expr_t *top_parent; |
| 639 | |
| 640 | if(tc->combined_constraints) { |
| 641 | printf("\n-- Combined constraints: "); |
| 642 | asn1print_constraint(tc->combined_constraints, flags); |
| 643 | } |
| 644 | |
Lev Walkin | e4d6ab8 | 2004-09-22 16:05:13 +0000 | [diff] [blame] | 645 | top_parent = asn1f_find_terminal_type_ex(asn, tc); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 646 | if(top_parent) { |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 647 | printf("\n-- Practical constraints (%s): ", |
| 648 | top_parent->Identifier); |
| 649 | asn1print_constraint_explain(top_parent->expr_type, |
| 650 | tc->combined_constraints, 0); |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 651 | printf("\n-- PER-visible constraints (%s): ", |
| 652 | top_parent->Identifier); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 653 | asn1print_constraint_explain(top_parent->expr_type, |
Lev Walkin | e8e87f1 | 2004-08-25 02:00:03 +0000 | [diff] [blame] | 654 | tc->combined_constraints, 1); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 655 | } |
Lev Walkin | b1ef396 | 2004-08-20 13:24:28 +0000 | [diff] [blame] | 656 | printf("\n"); |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 659 | return 0; |
| 660 | } |
Lev Walkin | 3140e0e | 2004-08-18 04:50:37 +0000 | [diff] [blame] | 661 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 662 | |
| 663 | static int |
| 664 | asn1print_expr_dtd(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, enum asn1print_flags flags, int level) { |
| 665 | asn1p_expr_t *se; |
| 666 | int expr_unordered = 0; |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 667 | int dont_involve_children = 0; |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 668 | |
| 669 | switch(expr->meta_type) { |
| 670 | case AMT_TYPE: |
| 671 | case AMT_TYPEREF: |
| 672 | break; |
| 673 | default: |
| 674 | if(expr->expr_type == A1TC_UNIVERVAL) |
| 675 | break; |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | if(!expr->Identifier) return 0; |
| 680 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 681 | if(flags & APF_LINE_COMMENTS) |
| 682 | INDENT("<!-- #line %d -->\n", expr->_lineno); |
| 683 | INDENT("<!ELEMENT %s", expr->Identifier); |
| 684 | |
| 685 | if(expr->expr_type == A1TC_REFERENCE) { |
| 686 | se = asn1f_find_terminal_type_ex(asn, expr); |
| 687 | if(!se) { |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 688 | printf(" (ANY)"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 689 | return 0; |
| 690 | } |
| 691 | expr = se; |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 692 | dont_involve_children = 1; |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Lev Walkin | d7963aa | 2005-03-10 15:16:56 +0000 | [diff] [blame] | 695 | if(expr->expr_type == ASN_CONSTR_CHOICE |
| 696 | || expr->expr_type == ASN_CONSTR_SEQUENCE_OF |
| 697 | || expr->expr_type == ASN_CONSTR_SET_OF |
| 698 | || expr->expr_type == ASN_CONSTR_SET |
Lev Walkin | 112d69e | 2005-03-09 20:52:15 +0000 | [diff] [blame] | 699 | || expr->expr_type == ASN_BASIC_INTEGER |
| 700 | || expr->expr_type == ASN_BASIC_ENUMERATED) { |
| 701 | expr_unordered = 1; |
| 702 | } |
| 703 | |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 704 | if(TQ_FIRST(&expr->members)) { |
| 705 | int extensible = 0; |
| 706 | printf(" ("); |
| 707 | TQ_FOR(se, &(expr->members), next) { |
| 708 | if(se->expr_type == A1TC_EXTENSIBLE) { |
| 709 | extensible = 1; |
| 710 | continue; |
| 711 | } else if(!se->Identifier |
| 712 | && se->expr_type == A1TC_REFERENCE) { |
| 713 | asn1print_ref(se->reference, flags); |
| 714 | } else if(se->Identifier) { |
| 715 | printf("%s", se->Identifier); |
| 716 | } else { |
| 717 | printf("ANY"); |
| 718 | } |
| 719 | if(expr->expr_type != ASN_CONSTR_SET |
| 720 | && expr->expr_type != ASN_CONSTR_CHOICE |
| 721 | && expr->expr_type != ASN_BASIC_INTEGER |
| 722 | && expr->expr_type != ASN_BASIC_ENUMERATED) { |
| 723 | if(expr_unordered) |
| 724 | printf("*"); |
| 725 | else if(se->marker.flags) |
| 726 | printf("?"); |
| 727 | } |
| 728 | if(TQ_NEXT(se, next) |
| 729 | && TQ_NEXT(se, next)->expr_type != A1TC_EXTENSIBLE) { |
| 730 | printf(expr_unordered?"|":", "); |
| 731 | } |
| 732 | } |
| 733 | if(extensible) { |
| 734 | printf(expr_unordered?"|":", "); |
| 735 | printf("ANY"); |
| 736 | if(expr->expr_type != ASN_CONSTR_SET |
| 737 | && expr->expr_type != ASN_CONSTR_CHOICE |
| 738 | && expr->expr_type != ASN_BASIC_INTEGER |
| 739 | && expr->expr_type != ASN_BASIC_ENUMERATED) |
| 740 | printf("*"); |
| 741 | } |
| 742 | |
| 743 | printf(")"); |
| 744 | if(expr->expr_type == ASN_CONSTR_SET) |
| 745 | printf("*"); |
| 746 | |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 747 | } else switch(expr->expr_type) { |
| 748 | case ASN_BASIC_BOOLEAN: |
Lev Walkin | 112d69e | 2005-03-09 20:52:15 +0000 | [diff] [blame] | 749 | printf(" (true|false)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 750 | break; |
| 751 | case ASN_CONSTR_CHOICE: |
| 752 | case ASN_CONSTR_SET: |
| 753 | case ASN_CONSTR_SET_OF: |
| 754 | case ASN_CONSTR_SEQUENCE: |
| 755 | case ASN_CONSTR_SEQUENCE_OF: |
| 756 | case ASN_BASIC_NULL: |
| 757 | case A1TC_UNIVERVAL: |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 758 | printf(" EMPTY"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 759 | break; |
| 760 | case ASN_TYPE_ANY: |
| 761 | printf(" ANY"); |
| 762 | break; |
| 763 | case ASN_BASIC_BIT_STRING: |
| 764 | case ASN_BASIC_OCTET_STRING: |
| 765 | case ASN_BASIC_OBJECT_IDENTIFIER: |
| 766 | case ASN_BASIC_RELATIVE_OID: |
Lev Walkin | cc11653 | 2004-10-15 06:01:54 +0000 | [diff] [blame] | 767 | case ASN_BASIC_INTEGER: |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 768 | case ASN_BASIC_UTCTime: |
| 769 | case ASN_BASIC_GeneralizedTime: |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 770 | case ASN_STRING_NumericString: |
| 771 | case ASN_STRING_PrintableString: |
Lev Walkin | cc11653 | 2004-10-15 06:01:54 +0000 | [diff] [blame] | 772 | printf(" (#PCDATA)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 773 | break; |
| 774 | case ASN_STRING_VisibleString: |
| 775 | case ASN_STRING_ISO646String: |
| 776 | /* Entity references, but not XML elements may be present */ |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 777 | printf(" (#PCDATA)"); |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 778 | break; |
| 779 | case ASN_BASIC_REAL: /* e.g. <MINUS-INFINITY/> */ |
| 780 | case ASN_BASIC_ENUMERATED: /* e.g. <enumIdentifier1/> */ |
| 781 | default: |
| 782 | /* |
| 783 | * XML elements are allowed. |
| 784 | * For example, a UTF8String may contain "<bel/>". |
| 785 | */ |
| 786 | printf(" ANY"); |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 787 | } |
| 788 | printf(">\n"); |
| 789 | |
| 790 | /* |
| 791 | * Display the descendants (children) of the current type. |
| 792 | */ |
Lev Walkin | ef39f7e | 2004-10-14 05:11:25 +0000 | [diff] [blame] | 793 | if(!dont_involve_children) { |
| 794 | TQ_FOR(se, &(expr->members), next) { |
| 795 | if(se->expr_type == A1TC_EXTENSIBLE) continue; |
| 796 | asn1print_expr_dtd(asn, mod, se, flags, level + 1); |
| 797 | } |
Lev Walkin | f748451 | 2004-10-13 09:13:56 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | return 0; |
| 801 | } |