]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/src/tbl-print.c
Security-54.1.3.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c-lib / src / tbl-print.c
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 #ifdef TTBL
20
21 /*
22 * tbl_print.c - type table value printer
23 *
24 *
25 * Mike Sample
26 *
27 * Copyright (C) 1993 Michael Sample
28 * and the University of British Columbia
29 * This library is free software; you can redistribute it and/or
30 * modify it provided that this copyright/license information is retained
31 * in original form.
32 *
33 * If you modify this file, you must clearly indicate your changes.
34 *
35 * This source code is distributed in the hope that it will be
36 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
37 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38 */
39
40
41 #include <stdio.h>
42 #include "tbl-incl.h"
43
44 static int indentIncrG = 2;
45
46 /*
47 * Print value v to file f as though it is of type modName.typeName in
48 * table tbl.
49 */
50 void
51 TblPrintValue PARAMS ((tbl, modName, typeName, f, v),
52 TBL *tbl _AND_
53 char *modName _AND_
54 char *typeName _AND_
55 FILE *f _AND_
56 AVal *v)
57 {
58 TBLTypeDef *tblTd;
59 TBLModule *tblMod;
60
61 tblTd = TblFindTypeDef (tbl, modName, typeName, &tblMod);
62
63 if (tblTd == NULL)
64 {
65 TblError ("TblEncode: Could not find a type definition with the given module and name");
66 }
67 else
68 {
69 fprintf (f, "value %s.%s ::= \n", tblMod->name.octs, typeName);
70 TblPrintTypeValue (tblTd->type, f, v, 0);
71 }
72
73 } /* TblPrint */
74
75 /*
76 * starts using indent after first newline printed by this routine
77 */
78 void
79 TblPrintTypeValue PARAMS ((tblT, f, v, indent),
80 TBLType *tblT _AND_
81 FILE *f _AND_
82 AVal *v _AND_
83 unsigned short int indent)
84 {
85 AVal *elmtV;
86 AsnList *lVal;
87 unsigned int currElmt;
88 TBLType *listElmtType;
89 TBLType *structElmtType;
90 TBLType *choiceElmtType;
91 AChoiceVal *cVal;
92 AStructVal *sVal;
93 void *tmp;
94
95 switch (tblT->typeId)
96 {
97 case TBL_TYPEREF:
98 TblPrintTypeValue (tblT->content->a.typeRef->typeDefPtr->type, f, v, indent);
99 break;
100
101 case TBL_SEQUENCE:
102 case TBL_SET:
103 fprintf (f,"{\n");
104 currElmt = 0;
105 sVal = (AStructVal*)v;
106 tmp = CURR_LIST_NODE (tblT->content->a.elmts);
107 FOR_EACH_LIST_ELMT (structElmtType, tblT->content->a.elmts)
108 {
109 Indent (f, indent+indentIncrG);
110 elmtV = sVal[currElmt++];
111 if (!(structElmtType->optional && (elmtV == NULL)))
112 {
113 if (structElmtType->fieldName.octs != NULL)
114 fprintf (f,"%s ", structElmtType->fieldName.octs);
115
116 TblPrintTypeValue (structElmtType, f, elmtV, indent+indentIncrG);
117
118 if (structElmtType != LAST_LIST_ELMT (tblT->content->a.elmts))
119 fprintf (f,",\n");
120 else
121 fprintf (f,"\n");
122 }
123 }
124 /* restore list curr in case recursive type */
125 SET_CURR_LIST_NODE (tblT->content->a.elmts, tmp);
126 Indent (f,indent);
127 fprintf (f,"}");
128 break;
129
130 case TBL_SEQUENCEOF:
131 case TBL_SETOF:
132 fprintf (f,"{\n");
133 lVal = (AsnList*)v;
134 listElmtType = FIRST_LIST_ELMT (tblT->content->a.elmts);
135 tmp = CURR_LIST_NODE (tblT->content->a.elmts);
136 FOR_EACH_LIST_ELMT (elmtV, lVal)
137 {
138 Indent (f, indent+indentIncrG);
139 TblPrintTypeValue (listElmtType, f, elmtV, indent+indentIncrG);
140 if (elmtV != LAST_LIST_ELMT (lVal))
141 fprintf (f,",\n");
142 else
143 fprintf (f,"\n");
144 }
145 /* restore old list curr ptr */
146 SET_CURR_LIST_NODE (tblT->content->a.elmts, tmp);
147 Indent (f,indent);
148 fprintf (f,"}");
149 break;
150
151 case TBL_CHOICE:
152 cVal = (AChoiceVal*) v;
153 choiceElmtType = (TBLType*)GetAsnListElmt (tblT->content->a.elmts, cVal->choiceId);
154 if (choiceElmtType->fieldName.octs != NULL)
155 fprintf (f,"%s ", choiceElmtType->fieldName.octs);
156 TblPrintTypeValue (choiceElmtType, f, cVal->val, indent+indentIncrG);
157 break;
158
159 case TBL_BOOLEAN:
160 PrintAsnBool (f, (AsnBool*)v,indent);
161 break;
162
163 case TBL_INTEGER:
164 case TBL_ENUMERATED:
165 PrintAsnInt (f, (AsnInt*)v, indent);
166 break;
167
168 case TBL_BITSTRING:
169 PrintAsnBits (f, (AsnBits*)v, indent);
170 break;
171
172 case TBL_OCTETSTRING:
173 PrintAsnOcts (f, (AsnOcts*)v, indent);
174 break;
175
176 case TBL_NULL:
177 PrintAsnNull (f, (AsnNull*)v, indent);
178 break;
179
180 case TBL_OID:
181 PrintAsnOid (f, (AsnOid*)v, indent);
182 break;
183
184 case TBL_REAL:
185 PrintAsnReal (f, (AsnReal*)v, indent);
186 break;
187
188 default:
189 fprintf (f, "<ERROR - unknown type!>");
190 }
191
192 } /* TblPrintTypeValue */
193
194 #endif /* TTBL */