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