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/idl_gen/gen_vals.c - prints ASN.1 values in IDL format
23 * Copyright (C) 1991, 1992 Michael Sample
24 * and the University of British Columbia
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/compiler/back-ends/idl-gen/gen-vals.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
32 * $Log: gen-vals.c,v $
33 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
34 * Move from private repository to open source repository
36 * Revision 1.2 2001/05/05 00:59:29 rmurphy
37 * Adding darwin license headers
39 * Revision 1.1.1.1 1999/03/16 18:06:45 aram
40 * Originals from SMIME Free Library.
42 * Revision 1.1 1997/01/01 20:25:36 rj
50 #include "asn1module.h"
54 #include "lib-types.h"
56 #include "snacc-util.h"
60 /* non-exported routines' prototypes */
62 static void PrintIDLValueDefsName
PROTO ((FILE *f
, IDLRules
*r
, ValueDef
*v
));
68 PrintIDLValueDef
PARAMS ((idl
, r
, v
),
73 /* just do oid's, ints and bools for now */
74 if ((v
->value
->basicValue
->choiceId
!= BASICVALUE_OID
) &&
75 (v
->value
->basicValue
->choiceId
!= BASICVALUE_INTEGER
) &&
76 (v
->value
->basicValue
->choiceId
!= BASICVALUE_BOOLEAN
))
80 * put instantiation in idl file
82 fprintf (idl
, " const ");
83 PrintIDLValuesClass (idl
, r
, v
->value
);
85 PrintIDLValueDefsName (idl
, r
, v
);
87 PrintIDLValueInstatiation (idl
, r
, v
->value
);
88 fprintf (idl
, ";\n\n");
90 } /* PrintIDLValueDef */
94 PrintIDLValueDefsName
PARAMS ((f
, r
, v
),
100 cName
= Asn1ValueName2CValueName (v
->definedName
);
101 fprintf (f
, "%s", cName
);
106 PrintIDLValuesClass
PARAMS ((f
, r
, v
),
111 /* needs work - just do ints bools and oid's for now */
112 switch (v
->basicValue
->choiceId
)
115 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_OID
].typeName
);
118 case BASICVALUE_INTEGER
:
119 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_INTEGER
].typeName
);
122 case BASICVALUE_BOOLEAN
:
123 fprintf (f
, "%s", r
->typeConvTbl
[BASICTYPE_BOOLEAN
].typeName
);
133 PrintIDLValueInstatiation
PARAMS ((f
, r
, v
),
138 /* needs work - just do oids, ints and bools for now */
139 switch (v
->basicValue
->choiceId
)
142 PrintIDLOidValue (f
, r
, v
->basicValue
->a
.oid
);
145 case BASICVALUE_INTEGER
:
146 PrintIDLIntValue (f
, r
, v
->basicValue
->a
.integer
);
149 case BASICVALUE_BOOLEAN
:
150 fprintf (f
, v
->basicValue
->a
.boolean
? "TRUE" : "FALSE");
161 * given an AOID, c++ AOID constructors params are produced.
162 * This is used for turning ASN.1 OBJECT ID values
163 * into usable c++ values.
165 * eg for the oid { 0 1 2 } (in AOID format)
170 PrintIDLOidValue
PARAMS ((f
, r
, v
),
175 unsigned short int firstArcNum
;
176 unsigned long int arcNum
;
181 /* un-munge first two arc numbers */
182 for (arcNum
= 0, i
=0; (i
< v
->octetLen
) && (v
->octs
[i
] & 0x80);i
++)
183 arcNum
= (arcNum
<< 7) + (v
->octs
[i
] & 0x7f);
185 arcNum
= (arcNum
<< 7) + (v
->octs
[i
] & 0x7f);
187 firstArcNum
= arcNum
/40;
191 fprintf (f
, "%u, %u", firstArcNum
, arcNum
- (firstArcNum
* 40));
193 for (; i
< v
->octetLen
; )
195 for (arcNum
= 0; (i
< v
->octetLen
) && (v
->octs
[i
] & 0x80);i
++)
196 arcNum
= (arcNum
<< 7) + (v
->octs
[i
] & 0x7f);
198 arcNum
= (arcNum
<< 7) + (v
->octs
[i
] & 0x7f);
201 fprintf (f
, ", %u", arcNum
);
205 } /* PrintIDLOidValue */
210 PrintIDLIntValue
PARAMS ((f
, r
, v
),
215 fprintf (f
, "%d", v
);
217 } /* PrintIDLIntValue */