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