]>
Commit | Line | Data |
---|---|---|
bac41a7b A |
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 | /* | |
20 | * compiler/back-ends/c-gen/gen-vals.c - prints ASN.1 values in C format | |
21 | * | |
22 | * | |
23 | * MS Feb 92 | |
24 | * Copyright (C) 1991, 1992 Michael Sample | |
25 | * and the University of British Columbia | |
26 | * | |
27 | * This program is free software; you can redistribute it and/or modify | |
28 | * it under the terms of the GNU General Public License as published by | |
29 | * the Free Software Foundation; either version 2 of the License, or | |
30 | * (at your option) any later version. | |
31 | * | |
a66d0d4a | 32 | * $Header: /cvs/root/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/Attic/gen-vals.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $ |
bac41a7b A |
33 | * $Log: gen-vals.c,v $ |
34 | * Revision 1.1.1.1 2001/05/18 23:14:09 mb | |
35 | * Move from private repository to open source repository | |
36 | * | |
37 | * Revision 1.2 2001/05/05 00:59:28 rmurphy | |
38 | * Adding darwin license headers | |
39 | * | |
40 | * Revision 1.1 2000/05/10 21:35:01 rmurphy | |
41 | * Adding back in base code files which had been moved to "2" versions. | |
42 | * | |
43 | * Revision 1.1.1.1 1999/03/16 18:06:43 aram | |
44 | * Originals from SMIME Free Library. | |
45 | * | |
46 | * Revision 1.4 1997/05/07 14:59:31 wan | |
47 | * Fixed bug in C value string generation. | |
48 | * | |
49 | * Revision 1.3 1995/07/25 18:44:12 rj | |
50 | * file name has been shortened for redundant part: c-gen/gen-c-vals -> c-gen/gen-vals. | |
51 | * | |
52 | * changed `_' to `-' in file names. | |
53 | * | |
54 | * Revision 1.2 1994/09/01 00:24:18 rj | |
55 | * snacc_config.h removed. | |
56 | * | |
57 | * Revision 1.1 1994/08/28 09:48:33 rj | |
58 | * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. | |
59 | * | |
60 | */ | |
61 | ||
62 | #include <stdio.h> | |
63 | ||
64 | #include "asn-incl.h" | |
65 | #include "oid.h" | |
66 | #include "asn1module.h" | |
67 | #include "mem.h" | |
68 | #include "define.h" | |
69 | #include "lib-types.h" | |
70 | #include "rules.h" | |
71 | #include "type-info.h" | |
72 | #include "str-util.h" | |
73 | #include "snacc-util.h" | |
74 | #include "util.h" | |
75 | #include "kwd.h" | |
76 | #include "gen-vals.h" | |
77 | ||
78 | /* non-exported routines' prototypes */ | |
79 | ||
80 | static void PrintValueDefsName PROTO ((FILE *f, CRules *r, ValueDef *v)); | |
81 | static void PrintValueDefsType PROTO ((FILE *f, CRules *r, ValueDef *v)); | |
82 | static void PrintValueInstatiation PROTO ((FILE *f, CRules *r, ValueDef *v)); | |
83 | ||
84 | ||
85 | ||
86 | ||
87 | void | |
88 | PrintCValueDef PARAMS ((src, r, v), | |
89 | FILE *src _AND_ | |
90 | CRules *r _AND_ | |
91 | ValueDef *v) | |
92 | { | |
93 | /* just do oid's, ints and bools for now */ | |
94 | if ((v->value->basicValue->choiceId != BASICVALUE_OID) && | |
95 | (v->value->basicValue->choiceId != BASICVALUE_INTEGER) && | |
96 | (v->value->basicValue->choiceId != BASICVALUE_BOOLEAN)) | |
97 | return; | |
98 | ||
99 | /* | |
100 | * put instantiation in src file | |
101 | */ | |
102 | PrintValueDefsType (src, r, v); | |
103 | fprintf (src," "); | |
104 | PrintValueDefsName (src, r, v); | |
105 | fprintf (src," = "); | |
106 | PrintValueInstatiation (src, r, v); | |
107 | fprintf (src,";\n\n"); | |
108 | ||
109 | } /* PrintCValueDef */ | |
110 | ||
111 | void | |
112 | PrintCValueExtern PARAMS ((hdr, r, v), | |
113 | FILE *hdr _AND_ | |
114 | CRules *r _AND_ | |
115 | ValueDef *v) | |
116 | { | |
117 | /* just do oid's, ints and bools for now */ | |
118 | if ((v->value->basicValue->choiceId != BASICVALUE_OID) && | |
119 | (v->value->basicValue->choiceId != BASICVALUE_INTEGER) && | |
120 | (v->value->basicValue->choiceId != BASICVALUE_BOOLEAN)) | |
121 | return; | |
122 | ||
123 | /* | |
124 | * put extern declaration in hdr file | |
125 | */ | |
126 | fprintf (hdr,"extern "); | |
127 | PrintValueDefsType (hdr, r, v); | |
128 | fprintf (hdr," "); | |
129 | PrintValueDefsName (hdr, r, v); | |
130 | fprintf (hdr,";\n"); | |
131 | ||
132 | } /* PrintCValueExtern */ | |
133 | ||
134 | ||
135 | static void | |
136 | PrintValueDefsName PARAMS ((f, r, v), | |
137 | FILE *f _AND_ | |
138 | CRules *r _AND_ | |
139 | ValueDef *v) | |
140 | { | |
141 | char *cName; | |
142 | cName = Asn1ValueName2CValueName (v->definedName); | |
143 | fprintf (f, "%s", cName); | |
144 | Free (cName); | |
145 | } | |
146 | ||
147 | static void | |
148 | PrintValueDefsType PARAMS ((f, r, v), | |
149 | FILE *f _AND_ | |
150 | CRules *r _AND_ | |
151 | ValueDef *v) | |
152 | { | |
153 | /* needs work - just do ints bools and oid's for now */ | |
154 | switch (v->value->basicValue->choiceId) | |
155 | { | |
156 | case BASICVALUE_OID: | |
157 | fprintf (f, "%s", r->typeConvTbl[BASICTYPE_OID].cTypeName); | |
158 | break; | |
159 | ||
160 | case BASICVALUE_INTEGER: | |
161 | fprintf (f, "%s", r->typeConvTbl[BASICTYPE_INTEGER].cTypeName); | |
162 | break; | |
163 | ||
164 | case BASICVALUE_BOOLEAN: | |
165 | fprintf (f, "%s", r->typeConvTbl[BASICTYPE_BOOLEAN].cTypeName); | |
166 | break; | |
167 | ||
168 | default: | |
169 | break; | |
170 | } | |
171 | } | |
172 | ||
173 | ||
174 | static void | |
175 | PrintValueInstatiation PARAMS ((f, r, v), | |
176 | FILE *f _AND_ | |
177 | CRules *r _AND_ | |
178 | ValueDef *v) | |
179 | { | |
180 | /* needs work - just do ints, bools and oids for now */ | |
181 | switch (v->value->basicValue->choiceId) | |
182 | { | |
183 | case BASICVALUE_OID: | |
184 | PrintCOidValue (f, r, v->value->basicValue->a.oid); | |
185 | break; | |
186 | ||
187 | case BASICVALUE_INTEGER: | |
188 | fprintf (f, "%d", v->value->basicValue->a.integer); | |
189 | break; | |
190 | ||
191 | case BASICVALUE_BOOLEAN: | |
192 | if (v->value->basicValue->a.boolean) | |
193 | fprintf (f, "TRUE"); | |
194 | else | |
195 | fprintf (f, "FALSE"); | |
196 | break; | |
197 | ||
198 | default: | |
199 | break; | |
200 | } | |
201 | ||
202 | ||
203 | } | |
204 | ||
205 | ||
206 | ||
207 | /* | |
208 | * given an AOID, a c value is produced. | |
209 | * This is used for turning ASN.1 OBJECT ID values | |
210 | * into usable c values. | |
211 | * | |
212 | * eg for the oid { 0 1 2 } (in AOID format) | |
213 | * | |
214 | * { | |
215 | * 2, | |
216 | * "\1\2" | |
217 | * } | |
218 | * is produced. | |
219 | */ | |
220 | void | |
221 | PrintCOidValue PARAMS ((f, r, oid), | |
222 | FILE *f _AND_ | |
223 | CRules *r _AND_ | |
224 | AsnOid *oid) | |
225 | { | |
226 | int i; | |
227 | ||
228 | fprintf (f, "{ "); | |
229 | fprintf (f, "%d, ",oid->octetLen); | |
230 | fprintf (f, "\""); | |
231 | ||
232 | /* print encoded oid string in C's 'octal' escape format */ | |
233 | for (i = 0; i < oid->octetLen; i++) | |
234 | fprintf (f, "\\%o", (unsigned char) oid->octs[i]); | |
235 | fprintf (f, "\""); | |
236 | fprintf (f, " }"); | |
237 | ||
238 | } /* PrintCOidValue */ |