Debian Codegraph @

tbl-tools/mkchdr/tbl-gen-c-hdr.c

raw symbols SCIP
1 /*
2 * file: .../tbl-tools/mkchdr/tbl_gen_c_hdr.c - prints C type defs for
3 * vals tbl decoder will return for the given type table.
4 *
5 *
6 * Mike Sample
7 *
8 * Copyright (C) 1993 Michael Sample
9 * and the University of British Columbia
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program and the associated libraries are distributed in the hope
17 * that they will be useful, but WITHOUT ANY WARRANTY; without even the
18 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License and GNU Library General
20 * Public License for more details.
21 *
22 * $Header: /baseline/SNACC/tbl-tools/mkchdr/tbl-gen-c-hdr.c,v 1.2 2003/12/17 19:05:04 gronej Exp $
23 * $Log: tbl-gen-c-hdr.c,v $
24 * Revision 1.2 2003/12/17 19:05:04 gronej
25 * SNACC baseline merged with PER v1_7 tag
26 *
27 * Revision 1.1.2.1 2003/11/05 14:59:00 gronej
28 * working PER code merged with esnacc_1_6
29 *
30 * Revision 1.1.1.1 2000/08/21 20:35:48 leonberp
31 * First CVS Version of SNACC.
32 *
33 * Revision 1.1 1997/02/15 19:05:31 rj
34 * first check-in
35 *
36 */
37
38
39 #include "tbl-incl.h"
40
41 static int indentIncrG = 4;
42
43
44
45 void TblPrintCType PROTO ((TBLTypeDef *tblTd, TBLType *tblT, FILE *f, unsigned short int indent));
46
47 static char *genericFieldNameG = "field";
48
49 /*
50 * Print C type info for the values that the tbl decode will return (and
51 * tbl encoder will expect) for the given tbl
52 */
53 void
54 TblPrintCHdr PARAMS ((tbl, f),
55 TBL *tbl _AND_
56 FILE *f)
57 {
58 TBLTypeDef *tblTd;
59 TBLModule *tblMod;
60
61 /* print file comment */
62 fprintf (f,"/*\n");
63 fprintf (f," * type definitions for the values that the snacc table\n");
64 fprintf (f," * decoder will return and snacc table encoder expects\n");
65 fprintf (f," * for the type table that contains the following modules:\n");
66 fprintf (f," * \n");
67 FOR_EACH_LIST_ELMT (tblMod, tbl->modules)
68 {
69 if (!tblMod->isUseful)
70 {
71 if (tblMod->name.octs != NULL)
72 fprintf (f," * %s\n",tblMod->name.octs);
73 else
74 {
75 fprintf (f," <no name> id = ");
76 PrintAsnOid (f, &tblMod->id, 0);
77 fprintf (f,"\n");
78 }
79 }
80 }
81 fprintf (f," *\n");
82 fprintf (f," * UBC snacc written by Mike Sample\n");
83 fprintf (f," * NOTE: This is a machine generated file \n");
84 fprintf (f," * NOTE2: Table routines don't use this so feel free to make changes\n");
85 fprintf (f," * that do not affect the structure. Changing field \n");
86 fprintf (f," * and type names is fine.\n");
87 fprintf (f," */\n\n\n");
88
89 /* print C type defs */
90 FOR_EACH_LIST_ELMT (tblMod, tbl->modules)
91 {
92 if (!tblMod->isUseful) /* don't print useful types */
93 {
94 fprintf (f,"/* start of module %s's definitions */\n\n", tblMod->name.octs);
95 FOR_EACH_LIST_ELMT (tblTd, tblMod->typeDefs)
96 {
97 fprintf (f,"typedef ");
98 TblPrintCType (tblTd, tblTd->type, f, 0);
99 fprintf (f," %s;\n\n", tblTd->typeName.octs);
100 }
101 }
102 }
103 } /* TblPrintCHdr */
104
105
106 /*
107 * simple routine to print the C version of the type
108 * This routine only indents directly after printing a newline
109 * (ie no indent is done for the first text written)
110 */
111 void
112 TblPrintCType PARAMS ((tblTd, tblT, f, indent),
113 TBLTypeDef *tblTd _AND_
114 TBLType *tblT _AND_
115 FILE *f _AND_
116 unsigned short int indent)
117 {
118 TBLType *structElmtType;
119 TBLType *choiceElmtType;
120 void *tmp;
121 int currElmt;
122 int currFieldNo;
123
124
125 switch (tblT->typeId)
126 {
127 case TBL_TYPEREF:
128 fprintf (f, "%s",tblT->content->a.typeRef->typeDefPtr->typeName.octs);
129 break;
130
131 case TBL_SEQUENCE:
132 case TBL_SET:
133 fprintf (f,"struct %s\n", tblTd->typeName.octs);
134 Indent (f, indent);
135 fprintf (f,"{\n");
136 currFieldNo = 0;
137 tmp = CURR_LIST_NODE (tblT->content->a.elmts);
138 FOR_EACH_LIST_ELMT (structElmtType, tblT->content->a.elmts)
139 {
140 Indent (f, indent+indentIncrG);
141 TblPrintCType (tblTd, structElmtType, f, indent+indentIncrG);
142 if (structElmtType->fieldName.octs != NULL)
143 fprintf (f," %s;", structElmtType->fieldName.octs);
144 else
145 fprintf (f," %s%d;", genericFieldNameG, currFieldNo++);
146
147 fprintf (f,"\n");
148 }
149
150 SET_CURR_LIST_NODE (tblT->content->a.elmts, tmp);
151 fprintf (f,"}");
152 break;
153
154 case TBL_SEQUENCEOF:
155 case TBL_SETOF:
156 fprintf (f,"AsnList");
157 break;
158
159 case TBL_CHOICE:
160 fprintf (f,"struct %s\n", tblTd->typeName.octs);
161 Indent (f, indent);
162 fprintf (f,"{\n");
163 /* print enum */
164 Indent (f, indent+indentIncrG);
165 fprintf (f,"enum\n");
166 Indent (f, indent+indentIncrG);
167 fprintf (f,"{\n");
168 currElmt = 0;
169 currFieldNo = 0;
170 tmp = CURR_LIST_NODE (tblT->content->a.elmts);
171 FOR_EACH_LIST_ELMT (choiceElmtType, tblT->content->a.elmts)
172 {
173 Indent (f, indent+indentIncrG+indentIncrG);
174 if (choiceElmtType->fieldName.octs != NULL)
175 fprintf (f,"%s", choiceElmtType->fieldName.octs);
176 else
177 fprintf (f," %s%d", genericFieldNameG, currFieldNo++);
178 fprintf (f,"_ID = %d", currElmt++);
179 if (choiceElmtType != LAST_LIST_ELMT (tblT->content->a.elmts))
180 fprintf (f,",");
181 fprintf (f,"\n");
182 }
183 Indent (f, indent);
184 fprintf (f," } choiceId;\n");
185
186 /* print elmt union */
187 Indent (f, indent+indentIncrG);
188 fprintf (f,"union\n");
189 Indent (f, indent+indentIncrG);
190 fprintf (f,"{\n");
191 currFieldNo = 0;
192 FOR_EACH_LIST_ELMT (choiceElmtType, tblT->content->a.elmts)
193 {
194 Indent (f, indent+indentIncrG+indentIncrG);
195 TblPrintCType (tblTd, choiceElmtType, f, indent+indentIncrG+indentIncrG);
196 if (choiceElmtType->fieldName.octs != NULL)
197 fprintf (f," %s;\n", choiceElmtType->fieldName.octs);
198 else
199 fprintf (f," %s%d;", genericFieldNameG, currFieldNo++);
200 }
201 SET_CURR_LIST_NODE (tblT->content->a.elmts, tmp);
202 Indent (f, indent+indentIncrG);
203 fprintf (f,"} a;\n");
204 Indent (f, indent);
205 fprintf (f,"}");
206 break;
207
208 case TBL_BOOLEAN:
209 fprintf (f,"AsnBool");
210 break;
211
212 case TBL_INTEGER:
213 case TBL_ENUMERATED:
214 fprintf (f,"AsnInt");
215 break;
216
217 case TBL_BITSTRING:
218 fprintf (f,"AsnBits");
219 break;
220
221 case TBL_OCTETSTRING:
222 fprintf (f,"AsnOcts");
223 break;
224
225 case TBL_NULL:
226 fprintf (f,"AsnNull");
227 break;
228
229 case TBL_OID:
230 fprintf (f,"AsnOid");
231 break;
232
233 case TBL_REAL:
234 fprintf (f,"AsnReal");
235 break;
236
237 default:
238 fprintf (f, "<ERROR - unknown type!>");
239 }
240
241 /*
242 * types defined directly from another typedef are
243 * the same type as the other typedef (so not a pointer).
244 * All other type refs are done by pointer
245 */
246 if (tblT != tblTd->type)
247 fprintf (f,"*");
248
249
250 } /* TblPrintCType */