]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-vals.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/Darwin/src/live/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-vals.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
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
37 * Revision 1.2 2001/05/05 00:59:28 rmurphy
38 * Adding darwin license headers
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.
43 * Revision 1.1.1.1 1999/03/16 18:06:43 aram
44 * Originals from SMIME Free Library.
46 * Revision 1.4 1997/05/07 14:59:31 wan
47 * Fixed bug in C value string generation.
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.
52 * changed `_' to `-' in file names.
54 * Revision 1.2 1994/09/01 00:24:18 rj
55 * snacc_config.h removed.
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.
66 #include "asn1module.h"
69 #include "lib-types.h"
71 #include "type-info.h"
73 #include "snacc-util.h"
78 /* non-exported routines' prototypes */
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
));
88 PrintCValueDef
PARAMS ((src
, r
, v
),
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
))
100 * put instantiation in src file
102 PrintValueDefsType (src
, r
, v
);
104 PrintValueDefsName (src
, r
, v
);
106 PrintValueInstatiation (src
, r
, v
);
107 fprintf (src
,";\n\n");
109 } /* PrintCValueDef */
112 PrintCValueExtern
PARAMS ((hdr
, r
, v
),
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
))
124 * put extern declaration in hdr file
126 fprintf (hdr
,"extern ");
127 PrintValueDefsType (hdr
, r
, v
);
129 PrintValueDefsName (hdr
, r
, v
);
132 } /* PrintCValueExtern */
136 PrintValueDefsName
PARAMS ((f
, r
, v
),
142 cName
= Asn1ValueName2CValueName (v
->definedName
);
143 fprintf (f
, "%s", cName
);
148 PrintValueDefsType
PARAMS ((f
, r
, v
),
153 /* needs work - just do ints bools and oid's for now */
154 switch (v
->value
->basicValue
->choiceId
)
157 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_OID
].cTypeName
);
160 case BASICVALUE_INTEGER
:
161 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_INTEGER
].cTypeName
);
164 case BASICVALUE_BOOLEAN
:
165 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_BOOLEAN
].cTypeName
);
175 PrintValueInstatiation
PARAMS ((f
, r
, v
),
180 /* needs work - just do ints, bools and oids for now */
181 switch (v
->value
->basicValue
->choiceId
)
184 PrintCOidValue (f
, r
, v
->value
->basicValue
->a
.oid
);
187 case BASICVALUE_INTEGER
:
188 fprintf (f
, "%d", v
->value
->basicValue
->a
.integer
);
191 case BASICVALUE_BOOLEAN
:
192 if (v
->value
->basicValue
->a
.boolean
)
195 fprintf (f
, "FALSE");
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.
212 * eg for the oid { 0 1 2 } (in AOID format)
221 PrintCOidValue
PARAMS ((f
, r
, oid
),
229 fprintf (f
, "%d, ",oid
->octetLen
);
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
]);
238 } /* PrintCOidValue */