~ubuntu-branches/ubuntu/vivid/asn1c/vivid

« back to all changes in this revision

Viewing changes to libasn1print/asn1print.c

  • Committer: Bazaar Package Importer
  • Author(s): W. Borgert
  • Date: 2006-09-23 13:50:05 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060923135005-rmay0d69e5vhunai
* New build, forgot to separate sources/diff.
* New release (closes: #327621).

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
                printf("<!-- XML DTD generated by asn1c-" VERSION " -->\n\n");
46
46
 
47
47
        TQ_FOR(mod, &(asn->modules), mod_next) {
 
48
                if(mod->_tags & MT_STANDARD_MODULE)
 
49
                        return 0; /* Ignore modules imported from skeletons */
48
50
                if(modno++) printf("\n");
49
51
                asn1print_module(asn, mod, flags);
50
52
        }
65
67
        if(flags & APF_PRINT_XML_DTD)
66
68
                printf("<!-- ASN.1 module\n");
67
69
 
68
 
        printf("%s ", mod->Identifier);
 
70
        printf("%s ", mod->ModuleName);
69
71
        if(mod->module_oid) {
70
 
                asn1print_oid(strlen(mod->Identifier), mod->module_oid, flags);
 
72
                asn1print_oid(strlen(mod->ModuleName), mod->module_oid, flags);
71
73
                printf("\n");
72
74
        }
73
75
 
104
106
 
105
107
        TQ_FOR(tc, &(mod->members), next) {
106
108
                asn1print_expr(asn, mod, tc, flags, 0);
107
 
                if(flags & APF_DEBUG_CONSTRAINTS)
 
109
                if(flags & APF_PRINT_CONSTRAINTS)
108
110
                        printf("\n");
109
111
                else
110
112
                        printf("\n\n");
168
170
 
169
171
        (void)flags;    /* Unused argument */
170
172
 
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
 
        }
185
 
        printf("%" PRIdASN "]", tag->tag_value);
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
 
        }
 
173
        printf("%s", asn1p_tag2string(tag, 0));
192
174
 
193
175
        return 0;
194
176
}
208
190
        case ATV_REAL:
209
191
                printf("%f", val->value.v_double);
210
192
                return 0;
 
193
        case ATV_TYPE:
 
194
                asn1print_expr(val->value.v_type->module->asn1p,
 
195
                        val->value.v_type->module,
 
196
                        val->value.v_type, flags, 0);
 
197
                return 0;
211
198
        case ATV_INTEGER:
212
199
                printf("%" PRIdASN, val->value.v_integer);
213
200
                return 0;
230
217
                return 0;
231
218
        case ATV_STRING:
232
219
                {
233
 
                        char *p = val->value.string.buf;
 
220
                        char *p = (char *)val->value.string.buf;
234
221
                        putchar('"');
235
222
                        if(strchr(p, '"')) {
236
223
                                /* Mask quotes */
246
233
                }
247
234
                return 0;
248
235
        case ATV_UNPARSED:
249
 
                fputs(val->value.string.buf, stdout);
 
236
                fputs((char *)val->value.string.buf, stdout);
250
237
                return 0;
251
238
        case ATV_BITVECTOR:
252
239
                {
277
264
                }
278
265
        case ATV_REFERENCED:
279
266
                return asn1print_ref(val->value.reference, flags);
 
267
        case ATV_VALUESET:
 
268
                return asn1print_constraint(val->value.constraint, flags);
280
269
        case ATV_CHOICE_IDENTIFIER:
281
270
                printf("%s: ", val->value.choice_identifier.identifier);
282
271
                return asn1print_value(val->value.choice_identifier.value, flags);
298
287
 
299
288
        switch(ct->type) {
300
289
        case ACT_EL_TYPE:
301
 
                asn1print_value(ct->value, flags);
 
290
                asn1print_value(ct->containedSubtype, flags);
302
291
                break;
303
292
        case ACT_EL_VALUE:
304
293
                asn1print_value(ct->value, flags);
365
354
                }
366
355
                break;
367
356
        case ACT_CT_CTDBY:
368
 
                printf("CONSTRAINED BY ");
 
357
                printf("(CONSTRAINED BY ");
369
358
                assert(ct->value->type == ATV_UNPARSED);
370
359
                fwrite(ct->value->value.string.buf,
371
360
                        1, ct->value->value.string.size, stdout);
 
361
                printf(")");
 
362
                break;
 
363
        case ACT_CT_CTNG:
 
364
                printf("(CONTAINING ");
 
365
                asn1print_expr(ct->value->value.v_type->module->asn1p,
 
366
                        ct->value->value.v_type->module,
 
367
                        ct->value->value.v_type,
 
368
                        flags, 1);
 
369
                printf(")");
372
370
                break;
373
371
        case ACT_CA_SET: symno++;
374
372
        case ACT_CA_CRC: symno++;
380
378
                        char *symtable[] = { " EXCEPT ", " ^ ", " | ", ",",
381
379
                                        "", "(" };
382
380
                        unsigned int i;
 
381
                        if(ct->type == ACT_CA_CRC) fputs("(", stdout);
383
382
                        for(i = 0; i < ct->el_count; i++) {
384
383
                                if(i) fputs(symtable[symno], stdout);
385
384
                                if(ct->type == ACT_CA_CRC) fputs("{", stdout);
389
388
                                && ct->type == ACT_CA_SET)
390
389
                                        fputs(")", stdout);
391
390
                        }
 
391
                        if(ct->type == ACT_CA_CRC) fputs(")", stdout);
392
392
                }
393
393
                break;
394
394
        case ACT_CA_AEX:
430
430
asn1print_with_syntax(asn1p_wsyntx_t *wx, enum asn1print_flags flags) {
431
431
        if(wx) {
432
432
                asn1p_wsyntx_chunk_t *wc;
433
 
                printf(" WITH SYNTAX {");
434
433
                TQ_FOR(wc, &(wx->chunks), next) {
435
 
                        if(wc->ref) {
436
 
                                asn1print_ref(wc->ref, flags);
437
 
                        } else {
438
 
                                fwrite(wc->buf, 1, wc->len, stdout);
439
 
                        }
 
434
                  switch(wc->type) {
 
435
                  case WC_LITERAL:
 
436
                  case WC_WHITESPACE:
 
437
                  case WC_FIELD:
 
438
                        printf("%s", wc->content.token);
 
439
                        break;
 
440
                  case WC_OPTIONALGROUP:
 
441
                        printf("[");
 
442
                        asn1print_with_syntax(wc->content.syntax,flags);
 
443
                        printf("]");
 
444
                        break;
 
445
                  }
440
446
                }
441
 
                printf("}\n");
442
447
        }
443
448
 
444
449
        return 0;
465
470
        int as_char = (type==ACT_CT_FROM);
466
471
        int i;
467
472
 
468
 
        range = asn1constraint_compute_PER_range(expr_type, ct, type,
469
 
                        0, 0, strict_PER_visible);
 
473
        range = asn1constraint_compute_PER_range(expr_type, ct, type, 0, 0,
 
474
                        strict_PER_visible ? CPR_strict_PER_visibility : 0);
470
475
        if(!range) return -1;
471
476
 
472
477
        if(range->incompatible
528
533
 
529
534
        if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT))
530
535
                INDENT("-- #line %d\n", tc->_lineno);
531
 
        if(tc->Identifier)
 
536
 
 
537
        /* Reconstruct compiler directive information */
 
538
        if((tc->marker.flags & EM_INDIRECT)
 
539
        && (tc->marker.flags & EM_OMITABLE) != EM_OMITABLE) {
 
540
                if((flags & APF_NOINDENT))
 
541
                        printf(" --<ASN1C.RepresentAsPointer>-- ");
 
542
                else
 
543
                        INDENT("--<ASN1C.RepresentAsPointer>--\n");
 
544
        }
 
545
 
 
546
        if(tc->Identifier
 
547
        && (!(tc->meta_type == AMT_VALUE && tc->expr_type == A1TC_REFERENCE)
 
548
         || level == 0))
532
549
                INDENT("%s", tc->Identifier);
533
550
 
534
 
        if(tc->params) {
535
 
                asn1print_params(tc->params, flags);
 
551
        if(tc->lhs_params) {
 
552
                asn1print_params(tc->lhs_params, flags);
536
553
        }
537
554
 
538
555
        if(tc->meta_type != AMT_VALUE
562
579
                SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */
563
580
                printf("    COMPONENTS OF");
564
581
                break;
565
 
        case A1TC_PARAMETRIZED:
566
 
                flags |= APF_NOINDENT;
567
582
        case A1TC_REFERENCE:
568
583
        case A1TC_UNIVERVAL:
569
584
                break;
570
585
        case A1TC_CLASSDEF:
571
586
                printf(" CLASS");
572
587
                break;
573
 
        case A1TC_CLASSFIELD:
 
588
        case A1TC_CLASSFIELD_TFS ... A1TC_CLASSFIELD_OSFS:
574
589
                /* Nothing to print here */
575
590
                break;
576
591
        case ASN_CONSTR_SET_OF:
586
601
                }
587
602
                printf(" OF");
588
603
                break;
 
604
        case A1TC_VALUESET:
 
605
                break;
589
606
        default:
590
607
                {
591
608
                        char *p = ASN_EXPR_TYPE2STR(tc->expr_type);
594
611
                break;
595
612
        }
596
613
 
 
614
        /*
 
615
         * Put the name of the referred type.
 
616
         */
597
617
        if(tc->reference) {
598
 
                if(!(flags & APF_NOINDENT))
599
 
                        printf(" ");
 
618
                printf(" ");
600
619
                asn1print_ref(tc->reference, flags);
601
620
        }
602
621
 
603
 
        if(tc->meta_type == AMT_VALUESET)
 
622
        if(tc->meta_type == AMT_VALUESET && level == 0)
604
623
                printf(" ::=");
605
624
 
606
625
        /*
608
627
         */
609
628
        if(TQ_FIRST(&(tc->members))
610
629
        || (tc->expr_type & ASN_CONSTR_MASK)
611
 
        || tc->meta_type == AMT_VALUESET
612
630
        || tc->meta_type == AMT_OBJECT
613
 
        || tc->meta_type == AMT_OBJECTSET
 
631
        || tc->meta_type == AMT_OBJECTCLASS
 
632
        || tc->meta_type == AMT_OBJECTFIELD
614
633
        ) {
615
634
                asn1p_expr_t *se;       /* SubExpression */
616
 
                int put_braces = !SEQ_OF; /* Don't need 'em, if SET OF... */
 
635
                int put_braces = (!SEQ_OF) /* Don't need 'em, if SET OF... */
 
636
                        && (tc->meta_type != AMT_OBJECTFIELD);
617
637
 
618
638
                if(put_braces) {
619
639
                        if(flags & APF_NOINDENT) {
655
675
                }
656
676
        }
657
677
 
658
 
        if(tc->with_syntax)
 
678
        if(tc->with_syntax) {
 
679
                printf(" WITH SYNTAX {");
659
680
                asn1print_with_syntax(tc->with_syntax, flags);
 
681
                printf("}\n");
 
682
        }
 
683
 
 
684
        /* Right hand specialization */
 
685
        if(tc->rhs_pspecs) {
 
686
                asn1p_expr_t *se;
 
687
                printf("{");
 
688
                TQ_FOR(se, &(tc->rhs_pspecs->members), next) {
 
689
                        asn1print_expr(asn, mod, se, flags, level + 1);
 
690
                        if(TQ_NEXT(se, next)) printf(", ");
 
691
                }
 
692
                printf("}");
 
693
        }
660
694
 
661
695
        if(!SEQ_OF && tc->constraints) {
662
696
                printf(" ");
 
697
                if(tc->meta_type == AMT_VALUESET)
 
698
                        printf("{");
663
699
                asn1print_constraint(tc->constraints, flags);
 
700
                if(tc->meta_type == AMT_VALUESET)
 
701
                        printf("}");
664
702
        }
665
703
 
666
704
        if(tc->unique) {
676
714
                                printf(")");
677
715
                        }
678
716
                } else {
679
 
                        printf(" ::= ");
 
717
                        if(level == 0) printf(" ::= ");
680
718
                        asn1print_value(tc->value, flags);
681
719
                }
682
720
        }
684
722
        /*
685
723
         * The following section exists entirely for debugging.
686
724
         */
687
 
        if(flags & APF_DEBUG_CONSTRAINTS
 
725
        if(flags & APF_PRINT_CONSTRAINTS
688
726
        && tc->expr_type != A1TC_EXTENSIBLE) {
689
727
                asn1p_expr_t *top_parent;
690
728
 
707
745
                printf("\n");
708
746
        }
709
747
 
 
748
        if(flags & APF_PRINT_CLASS_MATRIX
 
749
        && tc->expr_type == A1TC_CLASSDEF) do {
 
750
                int r, col, maxidlen;
 
751
                if(tc->object_class_matrix.rows == 0) {
 
752
                        printf("\n-- Class matrix is empty");
 
753
                        break;
 
754
                }
 
755
                printf("\n-- Class matrix has %d entr%s:\n",
 
756
                                tc->object_class_matrix.rows,
 
757
                                tc->object_class_matrix.rows==1 ? "y" : "ies");
 
758
                maxidlen = tc->object_class_matrix.max_identifier_length;
 
759
                for(r = -1; r < tc->object_class_matrix.rows; r++) {
 
760
                        struct asn1p_ioc_row_s *row;
 
761
                        row = tc->object_class_matrix.row[r<0?0:r];
 
762
                        if(r < 0) printf("--    %s", r > 9 ? " " : "");
 
763
                        else printf("-- [%*d]", r > 9 ? 2 : 1, r+1);
 
764
                        for(col = 0; col < row->columns; col++) {
 
765
                                struct asn1p_ioc_cell_s *cell;
 
766
                                cell = &row->column[col];
 
767
                                if(r < 0) {
 
768
                                        printf("[%*s]", maxidlen,
 
769
                                                cell->field->Identifier);
 
770
                                        continue;
 
771
                                }
 
772
                                if(!cell->value) {
 
773
                                        printf(" %*s ", maxidlen, "<no entry>");
 
774
                                        continue;
 
775
                                }
 
776
                                printf(" %*s ", maxidlen,
 
777
                                        cell->value->Identifier);
 
778
                        }
 
779
                        printf("\n");
 
780
                }
 
781
        } while(0);
 
782
 
 
783
        if(flags & APF_PRINT_CLASS_MATRIX
 
784
        && tc->lhs_params) do {
 
785
                int i;
 
786
                if(tc->specializations.pspecs_count == 0) {
 
787
                        printf("\n-- No specializations found\n");
 
788
                        break;
 
789
                }
 
790
                printf("\n-- Specializations list has %d entr%s:\n",
 
791
                        tc->specializations.pspecs_count,
 
792
                        tc->specializations.pspecs_count == 1 ? "y" : "ies");
 
793
                for(i = 0; i < tc->specializations.pspecs_count; i++) {
 
794
                        asn1p_expr_t *se;
 
795
                        struct asn1p_pspec_s *pspec;
 
796
                        pspec = &tc->specializations.pspec[i];
 
797
                        printf("-- ");
 
798
                        TQ_FOR(se, &(pspec->rhs_pspecs->members), next) {
 
799
                                asn1print_expr(asn, mod, se, flags, level+1);
 
800
                        }
 
801
                        printf("\n");
 
802
                }
 
803
        } while(0);
 
804
 
710
805
        return 0;
711
806
}
712
807