]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-vals2.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.
20 * compiler/back-ends/c-gen/gen-vals.c - prints ASN.1 values in C format
24 * Copyright (C) 1991, 1992 Michael Sample
25 * and the University of British Columbia
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.
32 * $Header: /cvs/root/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/Attic/gen-vals2.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
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
37 * Revision 1.2 2001/05/05 00:59:28 rmurphy
38 * Adding darwin license headers
40 * Revision 1.1.1.1 1999/03/16 18:06:43 aram
41 * Originals from SMIME Free Library.
43 * Revision 1.4 1997/05/07 14:59:31 wan
44 * Fixed bug in C value string generation.
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.
49 * changed `_' to `-' in file names.
51 * Revision 1.2 1994/09/01 00:24:18 rj
52 * snacc_config.h removed.
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.
63 #include "asn1module.h"
66 #include "lib-types.h"
68 #include "type-info.h"
70 #include "snacc-util.h"
75 /* non-exported routines' prototypes */
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
));
85 PrintCValueDef
PARAMS ((src
, r
, v
),
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
))
97 * put instantiation in src file
99 PrintValueDefsType (src
, r
, v
);
101 PrintValueDefsName (src
, r
, v
);
103 PrintValueInstatiation (src
, r
, v
);
104 fprintf (src
,";\n\n");
106 } /* PrintCValueDef */
109 PrintCValueExtern
PARAMS ((hdr
, r
, v
),
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
))
121 * put extern declaration in hdr file
123 fprintf (hdr
,"extern ");
124 PrintValueDefsType (hdr
, r
, v
);
126 PrintValueDefsName (hdr
, r
, v
);
129 } /* PrintCValueExtern */
133 PrintValueDefsName
PARAMS ((f
, r
, v
),
139 cName
= Asn1ValueName2CValueName (v
->definedName
);
140 fprintf (f
, "%s", cName
);
145 PrintValueDefsType
PARAMS ((f
, r
, v
),
150 /* needs work - just do ints bools and oid's for now */
151 switch (v
->value
->basicValue
->choiceId
)
154 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_OID
].cTypeName
);
157 case BASICVALUE_INTEGER
:
158 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_INTEGER
].cTypeName
);
161 case BASICVALUE_BOOLEAN
:
162 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_BOOLEAN
].cTypeName
);
172 PrintValueInstatiation
PARAMS ((f
, r
, v
),
177 /* needs work - just do ints, bools and oids for now */
178 switch (v
->value
->basicValue
->choiceId
)
181 PrintCOidValue (f
, r
, v
->value
->basicValue
->a
.oid
);
184 case BASICVALUE_INTEGER
:
185 fprintf (f
, "%d", v
->value
->basicValue
->a
.integer
);
188 case BASICVALUE_BOOLEAN
:
189 if (v
->value
->basicValue
->a
.boolean
)
192 fprintf (f
, "FALSE");
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.
209 * eg for the oid { 0 1 2 } (in AOID format)
218 PrintCOidValue
PARAMS ((f
, r
, oid
),
226 fprintf (f
, "%d, ",oid
->octetLen
);
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
]);
235 } /* PrintCOidValue */