]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/src/tbl-print.c
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
22 * tbl_print.c - type table value printer
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
33 * If you modify this file, you must clearly indicate your changes.
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.
44 static int indentIncrG
= 2;
47 * Print value v to file f as though it is of type modName.typeName in
51 TblPrintValue
PARAMS ((tbl
, modName
, typeName
, f
, v
),
61 tblTd
= TblFindTypeDef (tbl
, modName
, typeName
, &tblMod
);
65 TblError ("TblEncode: Could not find a type definition with the given module and name");
69 fprintf (f
, "value %s.%s ::= \n", tblMod
->name
.octs
, typeName
);
70 TblPrintTypeValue (tblTd
->type
, f
, v
, 0);
76 * starts using indent after first newline printed by this routine
79 TblPrintTypeValue
PARAMS ((tblT
, f
, v
, indent
),
83 unsigned short int indent
)
87 unsigned int currElmt
;
88 TBLType
*listElmtType
;
89 TBLType
*structElmtType
;
90 TBLType
*choiceElmtType
;
98 TblPrintTypeValue (tblT
->content
->a
.typeRef
->typeDefPtr
->type
, f
, v
, indent
);
105 sVal
= (AStructVal
*)v
;
106 tmp
= CURR_LIST_NODE (tblT
->content
->a
.elmts
);
107 FOR_EACH_LIST_ELMT (structElmtType
, tblT
->content
->a
.elmts
)
109 Indent (f
, indent
+indentIncrG
);
110 elmtV
= sVal
[currElmt
++];
111 if (!(structElmtType
->optional
&& (elmtV
== NULL
)))
113 if (structElmtType
->fieldName
.octs
!= NULL
)
114 fprintf (f
,"%s ", structElmtType
->fieldName
.octs
);
116 TblPrintTypeValue (structElmtType
, f
, elmtV
, indent
+indentIncrG
);
118 if (structElmtType
!= LAST_LIST_ELMT (tblT
->content
->a
.elmts
))
124 /* restore list curr in case recursive type */
125 SET_CURR_LIST_NODE (tblT
->content
->a
.elmts
, tmp
);
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
)
138 Indent (f
, indent
+indentIncrG
);
139 TblPrintTypeValue (listElmtType
, f
, elmtV
, indent
+indentIncrG
);
140 if (elmtV
!= LAST_LIST_ELMT (lVal
))
145 /* restore old list curr ptr */
146 SET_CURR_LIST_NODE (tblT
->content
->a
.elmts
, tmp
);
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
);
160 PrintAsnBool (f
, (AsnBool
*)v
,indent
);
165 PrintAsnInt (f
, (AsnInt
*)v
, indent
);
169 PrintAsnBits (f
, (AsnBits
*)v
, indent
);
172 case TBL_OCTETSTRING
:
173 PrintAsnOcts (f
, (AsnOcts
*)v
, indent
);
177 PrintAsnNull (f
, (AsnNull
*)v
, indent
);
181 PrintAsnOid (f
, (AsnOid
*)v
, indent
);
185 PrintAsnReal (f
, (AsnReal
*)v
, indent
);
189 fprintf (f
, "<ERROR - unknown type!>");
192 } /* TblPrintTypeValue */