1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /** HISTORY
30*0Sstevel@tonic-gate  * 5-15-96	Jerry Yeung	replace the Integer to Integer*
31*0Sstevel@tonic-gate  * 5-20-96	Jerry Yeung	add default_sec_config_file
32*0Sstevel@tonic-gate  * 8-23-96	Jerry Yeung	change the default path
33*0Sstevel@tonic-gate  * 8-27-96      Jerry Yeung	change oid_string
34*0Sstevel@tonic-gate  * 9-06-96      Jiten Gaitonde  change cmd line usage
35*0Sstevel@tonic-gate  * 10-21-96	Jerry Yeung	fix template-code
36*0Sstevel@tonic-gate  */
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #include <stdio.h>
39*0Sstevel@tonic-gate #include <ctype.h>
40*0Sstevel@tonic-gate #include <sys/types.h>
41*0Sstevel@tonic-gate #include <sys/stat.h>
42*0Sstevel@tonic-gate #include <sys/param.h>
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #include "impl.h"
45*0Sstevel@tonic-gate #include "error.h"
46*0Sstevel@tonic-gate #include "asn1.h"
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #include "parse.h"
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #define OBJECT			1
51*0Sstevel@tonic-gate #define COLUMN			2
52*0Sstevel@tonic-gate #define NODE			3
53*0Sstevel@tonic-gate #define TABLE			4
54*0Sstevel@tonic-gate #define ENTRY			5
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate #define PRINT_OPEN_BRACKET fprintf(fp, "{\n");
58*0Sstevel@tonic-gate #define PRINT_TAG_OPEN_BRACKET fprintf(fp, "\t{\n");
59*0Sstevel@tonic-gate #define PRINT_CLOSE_BRACKET fprintf(fp, "}\n");
60*0Sstevel@tonic-gate #define PRINT_TAG_CLOSE_BRACKET fprintf(fp, "\t}\n");
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate #define SET_PRINT_ENTRY_BLOCK \
63*0Sstevel@tonic-gate 	fprintf(fp,"\tswitch(pass)\n");\
64*0Sstevel@tonic-gate 	fprintf(fp,"\t{\n");\
65*0Sstevel@tonic-gate 	fprintf(fp,"\t\tcase FIRST_PASS:\n\n");\
66*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* check the existence of the element */\n");\
67*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* which corresponds to the given index and */\n");\
68*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* check the validity of the input value */\n");\
69*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* if not valid or not exist, */\n\n");\
70*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\treturn SNMP_ERR_NOERROR;\n\n");\
71*0Sstevel@tonic-gate 	fprintf(fp,"\t\tcase SECOND_PASS:\n\n");\
72*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* change the following coding, such that */\n");\
73*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* the input value will be stored in the */\n");\
74*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* corresponding mib variable of the given */\n");\
75*0Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* index */\n");
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate #define PRINT_GET_STRING_DUMBY_BLOCK \
79*0Sstevel@tonic-gate 	fprintf(fp, "\t/* It is required to allocate memory to the pointers */\n"); \
80*0Sstevel@tonic-gate 	fprintf(fp, "\t/* inside the input argument */\n"); \
81*0Sstevel@tonic-gate 	fprintf(fp, "\t/* Here, we assume that \"hello\" is the value of the mib variable */\n"); \
82*0Sstevel@tonic-gate 	fprintf(fp, "\t/* please change it to the real one */\n\n"); \
83*0Sstevel@tonic-gate 	fprintf(fp, "\tlen = strlen(\"hello\");\n"); \
84*0Sstevel@tonic-gate 	fprintf(fp, "\tstr = (u_char*)calloc(len,sizeof(char));\n");  \
85*0Sstevel@tonic-gate 	fprintf(fp, "\tif(str==NULL){\n"); \
86*0Sstevel@tonic-gate 	fprintf(fp, "\t\treturn SNMP_ERR_GENERR;\n"); \
87*0Sstevel@tonic-gate 	fprintf(fp, "\t}\n"); \
88*0Sstevel@tonic-gate 	fprintf(fp, "\tmemcpy(str,\"hello\",len);\n\n"); \
89*0Sstevel@tonic-gate 	fprintf(fp, "\t/*fill in the contents of the argument */\n\n"); \
90*0Sstevel@tonic-gate 	fprintf(fp, "\t%s->chars = str;\n",current->label); \
91*0Sstevel@tonic-gate 	fprintf(fp, "\t%s->len = len;\n",current->label); \
92*0Sstevel@tonic-gate 	fprintf(fp, "\treturn SNMP_ERR_NOERROR;\n");
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate #define PRINT_GET_OID_DUMBY_BLOCK \
95*0Sstevel@tonic-gate 	fprintf(fp, "\t/* It is required to allocate memory to the pointers */\n");\
96*0Sstevel@tonic-gate 	fprintf(fp, "\t/* inside the input argument */\n");\
97*0Sstevel@tonic-gate 	fprintf(fp, "\t/* Here, we assume that \"1.3.6.1.4.1.42\" is the value */\n");\
98*0Sstevel@tonic-gate 	fprintf(fp, "\t/* of the mib variable */\n");\
99*0Sstevel@tonic-gate 	fprintf(fp, "\t/* please change it to the real one */\n\n");\
100*0Sstevel@tonic-gate 	fprintf(fp, "\t/* 1.3.6.1.4.1.42 has 7 number separated by \".\" */\n");\
101*0Sstevel@tonic-gate 	fprintf(fp, "\n");\
102*0Sstevel@tonic-gate 	fprintf(fp, "\tlen =7 ;\n");\
103*0Sstevel@tonic-gate 	fprintf(fp, "\tsub = (Subid*)calloc(len,sizeof(Subid));\n");\
104*0Sstevel@tonic-gate 	fprintf(fp, "\tif(sub==NULL) return SNMP_ERR_GENERR;\n");\
105*0Sstevel@tonic-gate 	fprintf(fp, "\tmemcpy(sub,fake_sub,len*sizeof(Subid));\n\n");\
106*0Sstevel@tonic-gate 	fprintf(fp, "\t/* fill in the contents of the argument */\n\n");\
107*0Sstevel@tonic-gate 	fprintf(fp, "\t%s->subids = sub;\n",current->label);\
108*0Sstevel@tonic-gate 	fprintf(fp, "\t%s->len = len;\n",current->label);\
109*0Sstevel@tonic-gate 	fprintf(fp, "\treturn SNMP_ERR_NOERROR;\n");
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate #define PRINT_SET_CASE_BLOCK \
112*0Sstevel@tonic-gate 	fprintf(fp, "\t\tcase FIRST_PASS:\n");\
113*0Sstevel@tonic-gate 	fprintf(fp, "\n");\
114*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* check the validity of the input argument */\n");\
115*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* if not valid, return SNMP_GEN_ERROR */\n\n");\
116*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n\n");\
117*0Sstevel@tonic-gate 	fprintf(fp, "\t\tcase SECOND_PASS:\n");\
118*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* change the following coding, such that */\n");\
119*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* the input value will be stored in the */\n");\
120*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* corresponding mib variable */\n\n");
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate #define PRINT_GET_CASE_BLOCK \
124*0Sstevel@tonic-gate 	fprintf(fp, "\t/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */\n");\
125*0Sstevel@tonic-gate 	fprintf(fp, "\t/* this function should modify the index argument to the */\n");\
126*0Sstevel@tonic-gate 	fprintf(fp, "\t/* appropriate value */\n");\
127*0Sstevel@tonic-gate 	fprintf(fp, "\tswitch(search_type)\n");\
128*0Sstevel@tonic-gate 	fprintf(fp, "\t{\n");\
129*0Sstevel@tonic-gate 	fprintf(fp, "\t\tcase FIRST_ENTRY:\n");\
130*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\t/* assume 1 is the first index */\n\n");\
131*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\tindex->value[0] = 1;\n");\
132*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\tindex->len = 1;\n");\
133*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\tbreak;\n\n");\
134*0Sstevel@tonic-gate 	fprintf(fp, "\t\tcase NEXT_ENTRY:\n");\
135*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\tindex->value[0]++;\n");\
136*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\tif(index->value[0]>2)\n");\
137*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\t\treturn END_OF_TABLE;\n");\
138*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\tbreak;\n\n");\
139*0Sstevel@tonic-gate 	fprintf(fp, "\t\tcase EXACT_ENTRY:\n");\
140*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\tbreak;\n");\
141*0Sstevel@tonic-gate 	fprintf(fp, "\t}\n\n");
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate /* trap support snmp oid */
144*0Sstevel@tonic-gate static Subid snmp_subids[] = { 1,3,6,1,2,1,11,(Subid)-1}; /* -1 is null(hack) */
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate static char *base_name = NULL;
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate static struct tree *root = NULL;
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate extern int    trace_level;
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate /*************************************************************************/
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate static FILE* output_file(char* filename);
155*0Sstevel@tonic-gate static void application_end();
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate static struct tree *find_node(struct tree *current, char *label);
158*0Sstevel@tonic-gate static int get_node_type(struct tree *tp);
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate static void init_tree_first_pass(struct tree *current, int *index, int *object_index, int *column_index, int *entry_index);
162*0Sstevel@tonic-gate static void init_tree_second_pass(struct tree *current);
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate static void output_tree_c(struct tree *current);
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate static void output_extern_function(FILE *fp, struct tree *current);
168*0Sstevel@tonic-gate static void output_extern_trap_function(FILE *fp);
169*0Sstevel@tonic-gate static void output_trap_function_call(FILE *fp);
170*0Sstevel@tonic-gate static void output_trap_structure(FILE *fp);
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate static void output_subid_table(FILE *fp, struct tree *current, int *subid_index);
173*0Sstevel@tonic-gate static void output_enum_table(FILE *fp, struct tree *current, int *enum_index);
174*0Sstevel@tonic-gate static void output_object_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size);
175*0Sstevel@tonic-gate static void output_entry_table(FILE *fp, struct tree *current, int *index_index, int *size);
176*0Sstevel@tonic-gate static void output_column_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size);
177*0Sstevel@tonic-gate static void output_node_table(FILE *fp, struct tree *current, int *size);
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate static void output_stub_h(struct tree *current);
181*0Sstevel@tonic-gate 
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate static void output_stub_c(struct tree *current);
184*0Sstevel@tonic-gate static void output_appl_c(struct tree *current);
185*0Sstevel@tonic-gate static void output_trap_c(struct tree *current);
186*0Sstevel@tonic-gate static void output_entry_function(FILE *fp, struct tree *current);
187*0Sstevel@tonic-gate static void output_single_obj_function(FILE *fp, struct tree *current);
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate /*************************************************************************/
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate static void application_end()
193*0Sstevel@tonic-gate {
194*0Sstevel@tonic-gate }
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate /*************************************************************************/
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate static void print_usage()
200*0Sstevel@tonic-gate {
201*0Sstevel@tonic-gate 	fprintf(stderr, "Usage: mibcodegen -b SubagentName -f mib_1.txt [mib2.txt....] [-h]\n");
202*0Sstevel@tonic-gate         exit(1);
203*0Sstevel@tonic-gate #if 0
204*0Sstevel@tonic-gate 	error_exit("Usage: mibcodegen -b SubagentName -f mib_1.txt [mib2.txt....] [-h]");
205*0Sstevel@tonic-gate #endif
206*0Sstevel@tonic-gate }
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate /*
209*0Sstevel@tonic-gate  * get the reverse-subid list from the given tree node
210*0Sstevel@tonic-gate  * len stores the number of subids
211*0Sstevel@tonic-gate  */
212*0Sstevel@tonic-gate void get_subid_of_node(struct tree *t, Subid *subids, int *len)
213*0Sstevel@tonic-gate {
214*0Sstevel@tonic-gate   struct tree *parent;
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate   *len=0 ;
217*0Sstevel@tonic-gate   parent = t;
218*0Sstevel@tonic-gate   while(parent){
219*0Sstevel@tonic-gate  	subids[(*len)++] = parent->subid;
220*0Sstevel@tonic-gate 	parent = parent->parent;
221*0Sstevel@tonic-gate   }
222*0Sstevel@tonic-gate }
223*0Sstevel@tonic-gate 
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate /*************************************************************************/
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate void main(argc, argv)
228*0Sstevel@tonic-gate 	int argc;
229*0Sstevel@tonic-gate 	char *argv[];
230*0Sstevel@tonic-gate {
231*0Sstevel@tonic-gate 	struct node *nodes = NULL;
232*0Sstevel@tonic-gate 	int i;
233*0Sstevel@tonic-gate 	int node_index;
234*0Sstevel@tonic-gate 	int object_index;
235*0Sstevel@tonic-gate 	int column_index;
236*0Sstevel@tonic-gate 	int entry_index;
237*0Sstevel@tonic-gate         char *filep[50];
238*0Sstevel@tonic-gate         int  filecount,loop=0,mibcoreflag;
239*0Sstevel@tonic-gate         int opt, doit;
240*0Sstevel@tonic-gate         extern char * optarg;
241*0Sstevel@tonic-gate         extern int    optind;
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate 	doit = 0;
245*0Sstevel@tonic-gate         trace_level=filecount=1;
246*0Sstevel@tonic-gate         mibcoreflag=0;
247*0Sstevel@tonic-gate         filep[0] = "/var/snmp/mib/mib_core.txt";
248*0Sstevel@tonic-gate 	error_init(argv[0], application_end);
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate         while((opt = getopt(argc, argv, "b:f:h")) != EOF) {
251*0Sstevel@tonic-gate           switch(opt) {
252*0Sstevel@tonic-gate             case 'b':
253*0Sstevel@tonic-gate                       base_name = (char *)strdup(optarg);
254*0Sstevel@tonic-gate                       break;
255*0Sstevel@tonic-gate             case 'f':
256*0Sstevel@tonic-gate                       filep[filecount++] = (char *)strdup(optarg);
257*0Sstevel@tonic-gate                       if (strstr(filep[filecount-1], "mib_core"))
258*0Sstevel@tonic-gate                            mibcoreflag=1;
259*0Sstevel@tonic-gate 			else
260*0Sstevel@tonic-gate 				doit=1;
261*0Sstevel@tonic-gate 
262*0Sstevel@tonic-gate                       for(;((argv[optind]!=NULL) &&
263*0Sstevel@tonic-gate                                   (argv[optind][0] != '-'));
264*0Sstevel@tonic-gate                                   optind++) {
265*0Sstevel@tonic-gate                         filep[filecount++] = (char *)strdup(argv[optind+loop]);
266*0Sstevel@tonic-gate                         if (strstr(filep[filecount-1], "mib_core"))
267*0Sstevel@tonic-gate                               mibcoreflag=1;
268*0Sstevel@tonic-gate 			else
269*0Sstevel@tonic-gate 				doit = 1;
270*0Sstevel@tonic-gate                       }
271*0Sstevel@tonic-gate                       break;
272*0Sstevel@tonic-gate             case 'h':
273*0Sstevel@tonic-gate             default:
274*0Sstevel@tonic-gate                       print_usage();
275*0Sstevel@tonic-gate 
276*0Sstevel@tonic-gate           }
277*0Sstevel@tonic-gate         } /*end of while*/
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate         if ((optind != argc) || (!base_name) || (!doit))
280*0Sstevel@tonic-gate            print_usage();
281*0Sstevel@tonic-gate 
282*0Sstevel@tonic-gate 
283*0Sstevel@tonic-gate /******
284*0Sstevel@tonic-gate 	if(argc < 3)
285*0Sstevel@tonic-gate 	{
286*0Sstevel@tonic-gate 		print_usage();
287*0Sstevel@tonic-gate 	}
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate 	base_name = (char *) malloc(strlen(argv[1]) + 1);
291*0Sstevel@tonic-gate 	strcpy(base_name, argv[1]);
292*0Sstevel@tonic-gate *******/
293*0Sstevel@tonic-gate 
294*0Sstevel@tonic-gate 	parse_init();
295*0Sstevel@tonic-gate 
296*0Sstevel@tonic-gate 	for(i = mibcoreflag; i < filecount; i++)
297*0Sstevel@tonic-gate 	{
298*0Sstevel@tonic-gate 		FILE *fp;
299*0Sstevel@tonic-gate 		struct node *n, *last;
300*0Sstevel@tonic-gate 
301*0Sstevel@tonic-gate 
302*0Sstevel@tonic-gate 		fp = fopen(filep[i], "r");
303*0Sstevel@tonic-gate 		if(fp == NULL)
304*0Sstevel@tonic-gate 		{
305*0Sstevel@tonic-gate 			error("open() failed on %s %s\n\n", filep[i], errno_string());
306*0Sstevel@tonic-gate 			print_usage();
307*0Sstevel@tonic-gate 		}
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate 		n = parse(fp);
310*0Sstevel@tonic-gate 		fclose(fp);
311*0Sstevel@tonic-gate 
312*0Sstevel@tonic-gate 		if(n == NULL)
313*0Sstevel@tonic-gate 		{
314*0Sstevel@tonic-gate 			error("WARNING : n is NULL for %s", argv[i]);
315*0Sstevel@tonic-gate 		}
316*0Sstevel@tonic-gate 		else
317*0Sstevel@tonic-gate 		{
318*0Sstevel@tonic-gate 			if(nodes == NULL)
319*0Sstevel@tonic-gate 			{
320*0Sstevel@tonic-gate 				nodes = n;
321*0Sstevel@tonic-gate 			}
322*0Sstevel@tonic-gate 			else
323*0Sstevel@tonic-gate 			{
324*0Sstevel@tonic-gate 				last = nodes;
325*0Sstevel@tonic-gate 				while(last->next)
326*0Sstevel@tonic-gate 				{
327*0Sstevel@tonic-gate 					last = last->next;
328*0Sstevel@tonic-gate 				}
329*0Sstevel@tonic-gate 				last->next = n;
330*0Sstevel@tonic-gate 			}
331*0Sstevel@tonic-gate 		}
332*0Sstevel@tonic-gate 	}
333*0Sstevel@tonic-gate 
334*0Sstevel@tonic-gate 
335*0Sstevel@tonic-gate 	root = build_tree(nodes);
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate 	node_index = 0;
338*0Sstevel@tonic-gate 	object_index = 0;
339*0Sstevel@tonic-gate 	column_index = 0;
340*0Sstevel@tonic-gate 	entry_index = 0;
341*0Sstevel@tonic-gate 	init_tree_first_pass(root, &node_index, &object_index, &column_index, &entry_index);
342*0Sstevel@tonic-gate 	init_tree_second_pass(root);
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate 	output_tree_c(root);
345*0Sstevel@tonic-gate 	output_stub_h(root);
346*0Sstevel@tonic-gate 	output_stub_c(root);
347*0Sstevel@tonic-gate 	output_appl_c(root);
348*0Sstevel@tonic-gate 	output_trap_c(root);
349*0Sstevel@tonic-gate 
350*0Sstevel@tonic-gate 	exit(0);
351*0Sstevel@tonic-gate }
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate 
354*0Sstevel@tonic-gate /*************************************************************************/
355*0Sstevel@tonic-gate 
356*0Sstevel@tonic-gate /* Possible returned values:			*/
357*0Sstevel@tonic-gate /*	NODE, TABLE, ENTRY, OBJECT, COLUMN	*/
358*0Sstevel@tonic-gate 
359*0Sstevel@tonic-gate static int get_node_type(struct tree *tp)
360*0Sstevel@tonic-gate {
361*0Sstevel@tonic-gate 	if( (tp->type == TYPE_INTEGER)
362*0Sstevel@tonic-gate 		|| (tp->type == TYPE_COUNTER)
363*0Sstevel@tonic-gate 		|| (tp->type == TYPE_GAUGE)
364*0Sstevel@tonic-gate 		|| (tp->type == TYPE_TIMETICKS)
365*0Sstevel@tonic-gate 		|| (tp->type == TYPE_OCTETSTR)
366*0Sstevel@tonic-gate 		|| (tp->type == TYPE_IPADDR)
367*0Sstevel@tonic-gate 		|| (tp->type == TYPE_OPAQUE)
368*0Sstevel@tonic-gate 		|| (tp->type == TYPE_OBJID) )
369*0Sstevel@tonic-gate 	{
370*0Sstevel@tonic-gate 		if(tp->parent->type == TYPE_ENTRY)
371*0Sstevel@tonic-gate 		{
372*0Sstevel@tonic-gate 			if(tp->parent->parent->type == TYPE_TABLE)
373*0Sstevel@tonic-gate 			{
374*0Sstevel@tonic-gate 				return COLUMN;
375*0Sstevel@tonic-gate 			}
376*0Sstevel@tonic-gate 			else
377*0Sstevel@tonic-gate 			{
378*0Sstevel@tonic-gate 				error_exit("get_node_type(): Inconsistent table definition: %s->%s->%s", tp->label, tp->parent->label, tp->parent->parent->label);
379*0Sstevel@tonic-gate 			}
380*0Sstevel@tonic-gate 		}
381*0Sstevel@tonic-gate 		else
382*0Sstevel@tonic-gate 		{
383*0Sstevel@tonic-gate 			return OBJECT;
384*0Sstevel@tonic-gate 		}
385*0Sstevel@tonic-gate 	}
386*0Sstevel@tonic-gate 	else
387*0Sstevel@tonic-gate 	{
388*0Sstevel@tonic-gate 		switch(tp->type)
389*0Sstevel@tonic-gate 		{
390*0Sstevel@tonic-gate 			case TYPE_TABLE:
391*0Sstevel@tonic-gate 				return TABLE;
392*0Sstevel@tonic-gate 
393*0Sstevel@tonic-gate 			case TYPE_ENTRY:
394*0Sstevel@tonic-gate 				return ENTRY;
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate 			default:
397*0Sstevel@tonic-gate 				return NODE;
398*0Sstevel@tonic-gate 		}
399*0Sstevel@tonic-gate 	}
400*0Sstevel@tonic-gate      	return NODE; /*lint*/
401*0Sstevel@tonic-gate }
402*0Sstevel@tonic-gate 
403*0Sstevel@tonic-gate 
404*0Sstevel@tonic-gate /*************************************************************************/
405*0Sstevel@tonic-gate 
406*0Sstevel@tonic-gate /* we suppose that the tree is ordered according to the value of subid */
407*0Sstevel@tonic-gate 
408*0Sstevel@tonic-gate static void init_tree_first_pass(struct tree *current, int *node_index, int *object_index, int *column_index, int *entry_index)
409*0Sstevel@tonic-gate {
410*0Sstevel@tonic-gate 	struct tree *tp;
411*0Sstevel@tonic-gate 	int node_type;
412*0Sstevel@tonic-gate 	struct tree *next;
413*0Sstevel@tonic-gate 
414*0Sstevel@tonic-gate 
415*0Sstevel@tonic-gate 	/* node_index */
416*0Sstevel@tonic-gate 	current->node_index = *node_index;
417*0Sstevel@tonic-gate 	(*node_index)++;
418*0Sstevel@tonic-gate 
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate 	/* node_type, object_index, column_index */
421*0Sstevel@tonic-gate 	node_type = get_node_type(current);
422*0Sstevel@tonic-gate 	current->node_type = node_type;
423*0Sstevel@tonic-gate 	switch(node_type)
424*0Sstevel@tonic-gate 	{
425*0Sstevel@tonic-gate 		case OBJECT:
426*0Sstevel@tonic-gate 			current->object_index = *object_index;
427*0Sstevel@tonic-gate 			current->column_index = -1;
428*0Sstevel@tonic-gate 			current->entry_index = -1;
429*0Sstevel@tonic-gate 			(*object_index)++;
430*0Sstevel@tonic-gate 			break;
431*0Sstevel@tonic-gate 
432*0Sstevel@tonic-gate 		case COLUMN:
433*0Sstevel@tonic-gate 			current->object_index = -1;
434*0Sstevel@tonic-gate 			current->column_index = *column_index;
435*0Sstevel@tonic-gate 			current->entry_index = -1;
436*0Sstevel@tonic-gate 			(*column_index)++;
437*0Sstevel@tonic-gate 			break;
438*0Sstevel@tonic-gate 
439*0Sstevel@tonic-gate 		case NODE:
440*0Sstevel@tonic-gate 		case TABLE:
441*0Sstevel@tonic-gate 			current->object_index = -1;
442*0Sstevel@tonic-gate 			current->column_index = -1;
443*0Sstevel@tonic-gate 			current->entry_index = -1;
444*0Sstevel@tonic-gate 			break;
445*0Sstevel@tonic-gate 
446*0Sstevel@tonic-gate 		case ENTRY:
447*0Sstevel@tonic-gate 			current->object_index = -1;
448*0Sstevel@tonic-gate 			current->column_index = -1;
449*0Sstevel@tonic-gate 			current->entry_index = *entry_index;
450*0Sstevel@tonic-gate 			(*entry_index)++;
451*0Sstevel@tonic-gate 			break;
452*0Sstevel@tonic-gate 
453*0Sstevel@tonic-gate 		default:
454*0Sstevel@tonic-gate 			error_exit("init_tree_first_pass(): Unknown node type (%d) for node %s",
455*0Sstevel@tonic-gate 				node_type, current->label);
456*0Sstevel@tonic-gate 
457*0Sstevel@tonic-gate 	}
458*0Sstevel@tonic-gate 
459*0Sstevel@tonic-gate 
460*0Sstevel@tonic-gate 	/* next FIRST PASS */
461*0Sstevel@tonic-gate 	next = current->child_list;
462*0Sstevel@tonic-gate 	if(next)
463*0Sstevel@tonic-gate 	{
464*0Sstevel@tonic-gate 		/* current is not a leaf of the tree */
465*0Sstevel@tonic-gate 
466*0Sstevel@tonic-gate 		while(next->child_list)
467*0Sstevel@tonic-gate 		{
468*0Sstevel@tonic-gate 			next = next->child_list;
469*0Sstevel@tonic-gate 		}
470*0Sstevel@tonic-gate 		current->next = next;
471*0Sstevel@tonic-gate 	}
472*0Sstevel@tonic-gate 	else
473*0Sstevel@tonic-gate 	{
474*0Sstevel@tonic-gate 		/* current is a leaf of the tree */
475*0Sstevel@tonic-gate 
476*0Sstevel@tonic-gate 		struct tree *parent;
477*0Sstevel@tonic-gate 
478*0Sstevel@tonic-gate 
479*0Sstevel@tonic-gate 		parent = current;
480*0Sstevel@tonic-gate 		while(parent)
481*0Sstevel@tonic-gate 		{
482*0Sstevel@tonic-gate 			/* the goal of this loop is to find an ancestor	*/
483*0Sstevel@tonic-gate 			/* of current for which the subtree that contains */
484*0Sstevel@tonic-gate 			/* current is not the last subtree		*/
485*0Sstevel@tonic-gate 
486*0Sstevel@tonic-gate 
487*0Sstevel@tonic-gate 			/* is parent the last child? */
488*0Sstevel@tonic-gate 			if(parent->next_peer == NULL)
489*0Sstevel@tonic-gate 			{
490*0Sstevel@tonic-gate 				/* parent is the last child in the child*/
491*0Sstevel@tonic-gate 				/* list of its parent, so go one step up*/
492*0Sstevel@tonic-gate 
493*0Sstevel@tonic-gate 				parent = parent->parent;
494*0Sstevel@tonic-gate 			}
495*0Sstevel@tonic-gate 			else
496*0Sstevel@tonic-gate 			{
497*0Sstevel@tonic-gate 				/* parent is not the last child in the	*/
498*0Sstevel@tonic-gate 				/* child list of its parent		*/
499*0Sstevel@tonic-gate 
500*0Sstevel@tonic-gate 				next = parent->next_peer;
501*0Sstevel@tonic-gate 				break;
502*0Sstevel@tonic-gate 			}
503*0Sstevel@tonic-gate 		}
504*0Sstevel@tonic-gate 
505*0Sstevel@tonic-gate 		if(parent == NULL)
506*0Sstevel@tonic-gate 		{
507*0Sstevel@tonic-gate 			/* we found the last node of the MIB */
508*0Sstevel@tonic-gate 
509*0Sstevel@tonic-gate 			current->next = NULL;
510*0Sstevel@tonic-gate 		}
511*0Sstevel@tonic-gate 		else
512*0Sstevel@tonic-gate 		{
513*0Sstevel@tonic-gate 			while(next->child_list)
514*0Sstevel@tonic-gate 			{
515*0Sstevel@tonic-gate 				next = next->child_list;
516*0Sstevel@tonic-gate 			}
517*0Sstevel@tonic-gate 			current->next = next;
518*0Sstevel@tonic-gate 		}
519*0Sstevel@tonic-gate 	}
520*0Sstevel@tonic-gate 
521*0Sstevel@tonic-gate 
522*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
523*0Sstevel@tonic-gate 	{
524*0Sstevel@tonic-gate 		init_tree_first_pass(tp, node_index, object_index, column_index, entry_index);
525*0Sstevel@tonic-gate 	}
526*0Sstevel@tonic-gate }
527*0Sstevel@tonic-gate 
528*0Sstevel@tonic-gate 
529*0Sstevel@tonic-gate /*************************************************************************/
530*0Sstevel@tonic-gate 
531*0Sstevel@tonic-gate static void init_tree_second_pass(struct tree *current)
532*0Sstevel@tonic-gate {
533*0Sstevel@tonic-gate 	struct tree *tp;
534*0Sstevel@tonic-gate 	struct tree *next;
535*0Sstevel@tonic-gate 	int node_type;
536*0Sstevel@tonic-gate 	struct index_list *indexs;
537*0Sstevel@tonic-gate 
538*0Sstevel@tonic-gate 
539*0Sstevel@tonic-gate 	/* next SECOND PASS */
540*0Sstevel@tonic-gate 	next = current->next;
541*0Sstevel@tonic-gate 	while(next)
542*0Sstevel@tonic-gate 	{
543*0Sstevel@tonic-gate 		node_type = get_node_type(next);
544*0Sstevel@tonic-gate 		if(node_type == OBJECT || node_type == COLUMN)
545*0Sstevel@tonic-gate 		{
546*0Sstevel@tonic-gate 			if(next->access & READ_FLAG)
547*0Sstevel@tonic-gate 			{
548*0Sstevel@tonic-gate 				break;
549*0Sstevel@tonic-gate 			}
550*0Sstevel@tonic-gate 		}
551*0Sstevel@tonic-gate 
552*0Sstevel@tonic-gate 		next = next->next;
553*0Sstevel@tonic-gate 	}
554*0Sstevel@tonic-gate 	current->next = next;
555*0Sstevel@tonic-gate 
556*0Sstevel@tonic-gate 
557*0Sstevel@tonic-gate 	/* consistency of node_type COLUMN, ENTRY, TABLE */
558*0Sstevel@tonic-gate 	switch(current->node_type)
559*0Sstevel@tonic-gate 	{
560*0Sstevel@tonic-gate 		case COLUMN:
561*0Sstevel@tonic-gate 			if(current->parent->node_type != ENTRY)
562*0Sstevel@tonic-gate 			{
563*0Sstevel@tonic-gate 				error_exit("The node type (%d) of %s is not ENTRY although the node type of %s is COLUMN",
564*0Sstevel@tonic-gate 					current->parent->node_type,
565*0Sstevel@tonic-gate 					current->parent->label,
566*0Sstevel@tonic-gate 					current->label);
567*0Sstevel@tonic-gate 			}
568*0Sstevel@tonic-gate 			if(current->parent->parent->node_type != TABLE)
569*0Sstevel@tonic-gate 			{
570*0Sstevel@tonic-gate 				error_exit("The node type (%d) of %s is not TABLE although the node type of %s is COLUMN",
571*0Sstevel@tonic-gate 					current->parent->parent->node_type,
572*0Sstevel@tonic-gate 					current->parent->parent->label,
573*0Sstevel@tonic-gate 					current->label);
574*0Sstevel@tonic-gate 			}
575*0Sstevel@tonic-gate 
576*0Sstevel@tonic-gate 			if( (current->n_indexs != 0) || ( current->indexs != NULL) )
577*0Sstevel@tonic-gate 			{
578*0Sstevel@tonic-gate 				error_exit("The node %s of type COLUMN has some INDEXs!",
579*0Sstevel@tonic-gate 					current->label);
580*0Sstevel@tonic-gate 			}
581*0Sstevel@tonic-gate 
582*0Sstevel@tonic-gate 			break;
583*0Sstevel@tonic-gate 
584*0Sstevel@tonic-gate 
585*0Sstevel@tonic-gate 		case ENTRY:
586*0Sstevel@tonic-gate 			if(current->parent->node_type != TABLE)
587*0Sstevel@tonic-gate 			{
588*0Sstevel@tonic-gate 				error_exit("The node type (%d) of %s is not TABLE although the node type of %s is ENTRY",
589*0Sstevel@tonic-gate 					current->parent->node_type,
590*0Sstevel@tonic-gate 					current->parent->label,
591*0Sstevel@tonic-gate 					current->label);
592*0Sstevel@tonic-gate 			}
593*0Sstevel@tonic-gate 
594*0Sstevel@tonic-gate 			/* n_indexs, indexs */
595*0Sstevel@tonic-gate 			if( (current->n_indexs == 0) || ( current->indexs == NULL) )
596*0Sstevel@tonic-gate 			{
597*0Sstevel@tonic-gate 				error_exit("The node %s of type ENTRY has no INDEX",
598*0Sstevel@tonic-gate 					current->label);
599*0Sstevel@tonic-gate 			}
600*0Sstevel@tonic-gate 
601*0Sstevel@tonic-gate 			indexs = current->indexs;
602*0Sstevel@tonic-gate 			while(indexs)
603*0Sstevel@tonic-gate 			{
604*0Sstevel@tonic-gate 				indexs->tp = find_node(root, indexs->label);
605*0Sstevel@tonic-gate 				if(indexs->tp == NULL)
606*0Sstevel@tonic-gate 				{
607*0Sstevel@tonic-gate 					error("WARNING: Can't match the INDEX %s of the entry %s",
608*0Sstevel@tonic-gate 						indexs->label,
609*0Sstevel@tonic-gate 						current->label);
610*0Sstevel@tonic-gate 				}
611*0Sstevel@tonic-gate 				else
612*0Sstevel@tonic-gate 				{
613*0Sstevel@tonic-gate 					switch(indexs->tp->type)
614*0Sstevel@tonic-gate 					{
615*0Sstevel@tonic-gate 						case TYPE_INTEGER:
616*0Sstevel@tonic-gate 						case TYPE_COUNTER:
617*0Sstevel@tonic-gate 						case TYPE_GAUGE:
618*0Sstevel@tonic-gate 						case TYPE_TIMETICKS:
619*0Sstevel@tonic-gate                                                 case TYPE_OCTETSTR:
620*0Sstevel@tonic-gate 							break;
621*0Sstevel@tonic-gate 
622*0Sstevel@tonic-gate 						default:
623*0Sstevel@tonic-gate 							error("WARNING: The agent will not support the INDEX %s whose type %d for the entry %s",
624*0Sstevel@tonic-gate 								indexs->tp->label,
625*0Sstevel@tonic-gate 								indexs->tp->type,
626*0Sstevel@tonic-gate 								current->label);
627*0Sstevel@tonic-gate 					}
628*0Sstevel@tonic-gate 				}
629*0Sstevel@tonic-gate 				indexs = indexs->next;
630*0Sstevel@tonic-gate 			}
631*0Sstevel@tonic-gate 
632*0Sstevel@tonic-gate 			break;
633*0Sstevel@tonic-gate 
634*0Sstevel@tonic-gate 
635*0Sstevel@tonic-gate 		default:
636*0Sstevel@tonic-gate 			/* n_indexs, indexs */
637*0Sstevel@tonic-gate 			if( (current->n_indexs != 0) || ( current->indexs != NULL) )
638*0Sstevel@tonic-gate 			{
639*0Sstevel@tonic-gate 				error_exit("The node %s of type %d has some INDEXs!",
640*0Sstevel@tonic-gate 					current->label,
641*0Sstevel@tonic-gate 					current->node_type);
642*0Sstevel@tonic-gate 			}
643*0Sstevel@tonic-gate 
644*0Sstevel@tonic-gate 			break;
645*0Sstevel@tonic-gate 	}
646*0Sstevel@tonic-gate 
647*0Sstevel@tonic-gate 
648*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
649*0Sstevel@tonic-gate 	{
650*0Sstevel@tonic-gate 		init_tree_second_pass(tp);
651*0Sstevel@tonic-gate 	}
652*0Sstevel@tonic-gate }
653*0Sstevel@tonic-gate 
654*0Sstevel@tonic-gate 
655*0Sstevel@tonic-gate /*************************************************************************/
656*0Sstevel@tonic-gate static void output_extern_trap_function(FILE *fp)
657*0Sstevel@tonic-gate {
658*0Sstevel@tonic-gate   struct trap_item *ip;
659*0Sstevel@tonic-gate 
660*0Sstevel@tonic-gate   fprintf(fp,"extern int SSAGetTrapPort();\n");
661*0Sstevel@tonic-gate   for(ip=trap_list;ip;ip=ip->next){
662*0Sstevel@tonic-gate 	fprintf(fp, "extern int trap_handler_%s();\n",ip->label);
663*0Sstevel@tonic-gate   }
664*0Sstevel@tonic-gate }
665*0Sstevel@tonic-gate 
666*0Sstevel@tonic-gate static void output_trap_function_call(FILE *fp)
667*0Sstevel@tonic-gate {
668*0Sstevel@tonic-gate 	struct trap_item *ip;
669*0Sstevel@tonic-gate 	struct tree *tp;
670*0Sstevel@tonic-gate 	struct index_list *variables;
671*0Sstevel@tonic-gate 	int index;
672*0Sstevel@tonic-gate 
673*0Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
674*0Sstevel@tonic-gate 		for (index = 1, variables = ip->var_list; variables;
675*0Sstevel@tonic-gate 			variables = variables->next) {
676*0Sstevel@tonic-gate 			if ((variables->tp = find_node(root,
677*0Sstevel@tonic-gate 				variables->label)) == NULL)
678*0Sstevel@tonic-gate 				error_exit("output_trap_structure(): \
679*0Sstevel@tonic-gate 				Unknown variable:%s", variables->label);
680*0Sstevel@tonic-gate 			tp = variables->tp;
681*0Sstevel@tonic-gate 			if (tp->node_type == COLUMN)
682*0Sstevel@tonic-gate 				fprintf(fp,
683*0Sstevel@tonic-gate 				"\t\tSSASetVarIndx(\"%s\",%d);\n",
684*0Sstevel@tonic-gate 				variables->label, index++);
685*0Sstevel@tonic-gate 			}
686*0Sstevel@tonic-gate 	fprintf(fp, "\t\tSSASendTrap(\"%s\");\n", ip->label);
687*0Sstevel@tonic-gate 	}
688*0Sstevel@tonic-gate }
689*0Sstevel@tonic-gate 
690*0Sstevel@tonic-gate static void output_extern_function(FILE *fp, struct tree *current)
691*0Sstevel@tonic-gate {
692*0Sstevel@tonic-gate 	struct tree *tp;
693*0Sstevel@tonic-gate 	struct index_list *indexs;
694*0Sstevel@tonic-gate 
695*0Sstevel@tonic-gate 
696*0Sstevel@tonic-gate 	switch(current->node_type)
697*0Sstevel@tonic-gate 	{
698*0Sstevel@tonic-gate 		case OBJECT:
699*0Sstevel@tonic-gate 			if(current->access & READ_FLAG)
700*0Sstevel@tonic-gate 			{
701*0Sstevel@tonic-gate 				switch(current->type)
702*0Sstevel@tonic-gate 				{
703*0Sstevel@tonic-gate 					case TYPE_INTEGER:
704*0Sstevel@tonic-gate 					case TYPE_COUNTER:
705*0Sstevel@tonic-gate 					case TYPE_GAUGE:
706*0Sstevel@tonic-gate 					case TYPE_TIMETICKS:
707*0Sstevel@tonic-gate 						fprintf(fp, "extern int get_%s(Integer *%s);\n",
708*0Sstevel@tonic-gate 							current->label,
709*0Sstevel@tonic-gate 							current->label);
710*0Sstevel@tonic-gate 						break;
711*0Sstevel@tonic-gate 
712*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
713*0Sstevel@tonic-gate 					case TYPE_IPADDR:
714*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
715*0Sstevel@tonic-gate 						fprintf(fp, "extern int get_%s(String *%s);\n",
716*0Sstevel@tonic-gate 							current->label,
717*0Sstevel@tonic-gate 							current->label);
718*0Sstevel@tonic-gate 						break;
719*0Sstevel@tonic-gate 
720*0Sstevel@tonic-gate 					case TYPE_OBJID:
721*0Sstevel@tonic-gate 						fprintf(fp, "extern int get_%s(Oid *%s);\n",
722*0Sstevel@tonic-gate 							current->label,
723*0Sstevel@tonic-gate 							current->label);
724*0Sstevel@tonic-gate 						break;
725*0Sstevel@tonic-gate 
726*0Sstevel@tonic-gate 					default:
727*0Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
728*0Sstevel@tonic-gate 							current->type,
729*0Sstevel@tonic-gate 							current->label);
730*0Sstevel@tonic-gate 				}
731*0Sstevel@tonic-gate 			}
732*0Sstevel@tonic-gate 			if(current->access & WRITE_FLAG)
733*0Sstevel@tonic-gate 			{
734*0Sstevel@tonic-gate 				switch(current->type)
735*0Sstevel@tonic-gate 				{
736*0Sstevel@tonic-gate 					case TYPE_INTEGER:
737*0Sstevel@tonic-gate 					case TYPE_COUNTER:
738*0Sstevel@tonic-gate 					case TYPE_GAUGE:
739*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-95)*/
740*0Sstevel@tonic-gate 						fprintf(fp, "extern int set_%s(int pass, Integer* %s);\n",
741*0Sstevel@tonic-gate 							current->label,
742*0Sstevel@tonic-gate 							current->label);
743*0Sstevel@tonic-gate 						break;
744*0Sstevel@tonic-gate 
745*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
746*0Sstevel@tonic-gate 					case TYPE_IPADDR:
747*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
748*0Sstevel@tonic-gate 						fprintf(fp, "extern int set_%s(int pass, String *%s);\n",
749*0Sstevel@tonic-gate 							current->label,
750*0Sstevel@tonic-gate 							current->label);
751*0Sstevel@tonic-gate 						break;
752*0Sstevel@tonic-gate 
753*0Sstevel@tonic-gate 					case TYPE_OBJID:
754*0Sstevel@tonic-gate 						fprintf(fp, "extern int set_%s(int pass, Oid *%s);\n",
755*0Sstevel@tonic-gate 							current->label,
756*0Sstevel@tonic-gate 							current->label);
757*0Sstevel@tonic-gate 						break;
758*0Sstevel@tonic-gate 
759*0Sstevel@tonic-gate 					default:
760*0Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
761*0Sstevel@tonic-gate 							current->type,
762*0Sstevel@tonic-gate 							current->label);
763*0Sstevel@tonic-gate 				}
764*0Sstevel@tonic-gate 			}
765*0Sstevel@tonic-gate 
766*0Sstevel@tonic-gate 			if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
767*0Sstevel@tonic-gate 			{
768*0Sstevel@tonic-gate 				switch(current->type)
769*0Sstevel@tonic-gate 				{
770*0Sstevel@tonic-gate 					case TYPE_INTEGER:
771*0Sstevel@tonic-gate 					case TYPE_COUNTER:
772*0Sstevel@tonic-gate 					case TYPE_GAUGE:
773*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-95)*/
774*0Sstevel@tonic-gate 						break;
775*0Sstevel@tonic-gate 
776*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
777*0Sstevel@tonic-gate 					case TYPE_IPADDR:
778*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
779*0Sstevel@tonic-gate 						fprintf(fp, "extern void free_%s(String *%s);\n",
780*0Sstevel@tonic-gate 							current->label,
781*0Sstevel@tonic-gate 							current->label);
782*0Sstevel@tonic-gate 						break;
783*0Sstevel@tonic-gate 
784*0Sstevel@tonic-gate 					case TYPE_OBJID:
785*0Sstevel@tonic-gate 						fprintf(fp, "extern void free_%s(Oid *%s);\n",
786*0Sstevel@tonic-gate 							current->label,
787*0Sstevel@tonic-gate 							current->label);
788*0Sstevel@tonic-gate 						break;
789*0Sstevel@tonic-gate 
790*0Sstevel@tonic-gate 					default:
791*0Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
792*0Sstevel@tonic-gate 							current->type,
793*0Sstevel@tonic-gate 							current->label);
794*0Sstevel@tonic-gate 				}
795*0Sstevel@tonic-gate 			}
796*0Sstevel@tonic-gate 
797*0Sstevel@tonic-gate 			break;
798*0Sstevel@tonic-gate 
799*0Sstevel@tonic-gate 
800*0Sstevel@tonic-gate 		case COLUMN:
801*0Sstevel@tonic-gate 			if(current->access & READ_FLAG)
802*0Sstevel@tonic-gate 			{
803*0Sstevel@tonic-gate 				fprintf(fp, "extern int get_%s(int search_type, ",
804*0Sstevel@tonic-gate 					current->label);
805*0Sstevel@tonic-gate 
806*0Sstevel@tonic-gate 				switch(current->type)
807*0Sstevel@tonic-gate 				{
808*0Sstevel@tonic-gate 					case TYPE_INTEGER:
809*0Sstevel@tonic-gate 					case TYPE_COUNTER:
810*0Sstevel@tonic-gate 					case TYPE_GAUGE:
811*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
812*0Sstevel@tonic-gate 						fprintf(fp, "Integer *%s, ",
813*0Sstevel@tonic-gate 							current->label);
814*0Sstevel@tonic-gate 						break;
815*0Sstevel@tonic-gate 
816*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
817*0Sstevel@tonic-gate 					case TYPE_IPADDR:
818*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
819*0Sstevel@tonic-gate 						fprintf(fp, "String *%s, ",
820*0Sstevel@tonic-gate 							current->label);
821*0Sstevel@tonic-gate 						break;
822*0Sstevel@tonic-gate 
823*0Sstevel@tonic-gate 					case TYPE_OBJID:
824*0Sstevel@tonic-gate 						fprintf(fp, "Oid *%s, ",
825*0Sstevel@tonic-gate 							current->label);
826*0Sstevel@tonic-gate 						break;
827*0Sstevel@tonic-gate 
828*0Sstevel@tonic-gate 					default:
829*0Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
830*0Sstevel@tonic-gate 						current->type,
831*0Sstevel@tonic-gate 						current->label);
832*0Sstevel@tonic-gate 				}
833*0Sstevel@tonic-gate 
834*0Sstevel@tonic-gate 				indexs = current->parent->indexs;
835*0Sstevel@tonic-gate 
836*0Sstevel@tonic-gate /* not more ind. index */
837*0Sstevel@tonic-gate 
838*0Sstevel@tonic-gate 				if(indexs)
839*0Sstevel@tonic-gate 				{
840*0Sstevel@tonic-gate 					if(indexs->tp)
841*0Sstevel@tonic-gate 					{
842*0Sstevel@tonic-gate 						switch(indexs->tp->type)
843*0Sstevel@tonic-gate 						{
844*0Sstevel@tonic-gate 							case TYPE_INTEGER:
845*0Sstevel@tonic-gate 							case TYPE_COUNTER:
846*0Sstevel@tonic-gate 							case TYPE_GAUGE:
847*0Sstevel@tonic-gate 							case TYPE_TIMETICKS:
848*0Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s);\n",
849*0Sstevel@tonic-gate 									"index");
850*0Sstevel@tonic-gate 								break;
851*0Sstevel@tonic-gate 
852*0Sstevel@tonic-gate 							case TYPE_OCTETSTR:
853*0Sstevel@tonic-gate 							case TYPE_IPADDR:
854*0Sstevel@tonic-gate 							case TYPE_OPAQUE:
855*0Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s);\n",
856*0Sstevel@tonic-gate 									"index");
857*0Sstevel@tonic-gate 								break;
858*0Sstevel@tonic-gate 
859*0Sstevel@tonic-gate 							case TYPE_OBJID:
860*0Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s);\n",
861*0Sstevel@tonic-gate 									"index");
862*0Sstevel@tonic-gate 								break;
863*0Sstevel@tonic-gate 
864*0Sstevel@tonic-gate 							default:
865*0Sstevel@tonic-gate 								error_exit("output_extern_function(): Unknown type (%d) for %s",
866*0Sstevel@tonic-gate 								indexs->tp->type,
867*0Sstevel@tonic-gate 								indexs->tp->label);
868*0Sstevel@tonic-gate 						}
869*0Sstevel@tonic-gate 					}
870*0Sstevel@tonic-gate 					else
871*0Sstevel@tonic-gate 					{
872*0Sstevel@tonic-gate 						error("WARNING: By default, the type of INDEX %s set to INTEGER",
873*0Sstevel@tonic-gate 							indexs->label);
874*0Sstevel@tonic-gate 						fprintf(fp, "IndexType *%s);\n",
875*0Sstevel@tonic-gate 								"index");
876*0Sstevel@tonic-gate 					}
877*0Sstevel@tonic-gate 
878*0Sstevel@tonic-gate 					indexs = indexs->next;
879*0Sstevel@tonic-gate 				}
880*0Sstevel@tonic-gate 
881*0Sstevel@tonic-gate 
882*0Sstevel@tonic-gate 			}
883*0Sstevel@tonic-gate 
884*0Sstevel@tonic-gate 			if(current->access & WRITE_FLAG)
885*0Sstevel@tonic-gate 			{
886*0Sstevel@tonic-gate 				fprintf(fp, "extern int set_%s(int pass, ",
887*0Sstevel@tonic-gate 					current->label);
888*0Sstevel@tonic-gate 
889*0Sstevel@tonic-gate 				indexs = current->parent->indexs;
890*0Sstevel@tonic-gate 
891*0Sstevel@tonic-gate /* not more ind. index */
892*0Sstevel@tonic-gate 
893*0Sstevel@tonic-gate 				if(indexs)
894*0Sstevel@tonic-gate 				{
895*0Sstevel@tonic-gate 					if(indexs->tp)
896*0Sstevel@tonic-gate 					{
897*0Sstevel@tonic-gate 						switch(indexs->tp->type)
898*0Sstevel@tonic-gate 						{
899*0Sstevel@tonic-gate 							case TYPE_INTEGER:
900*0Sstevel@tonic-gate 							case TYPE_COUNTER:
901*0Sstevel@tonic-gate 							case TYPE_GAUGE:
902*0Sstevel@tonic-gate 							case TYPE_TIMETICKS:
903*0Sstevel@tonic-gate 								fprintf(fp, "IndexType %s, ",
904*0Sstevel@tonic-gate 									"index");
905*0Sstevel@tonic-gate 								break;
906*0Sstevel@tonic-gate 
907*0Sstevel@tonic-gate 							case TYPE_OCTETSTR:
908*0Sstevel@tonic-gate 							case TYPE_IPADDR:
909*0Sstevel@tonic-gate 							case TYPE_OPAQUE:
910*0Sstevel@tonic-gate 								fprintf(fp, "IndexType %s, ",
911*0Sstevel@tonic-gate 									"index");
912*0Sstevel@tonic-gate 								break;
913*0Sstevel@tonic-gate 
914*0Sstevel@tonic-gate 							case TYPE_OBJID:
915*0Sstevel@tonic-gate 								fprintf(fp, "IndexType %s, ",
916*0Sstevel@tonic-gate 									"index");
917*0Sstevel@tonic-gate 								break;
918*0Sstevel@tonic-gate 
919*0Sstevel@tonic-gate 							default:
920*0Sstevel@tonic-gate 								error_exit("output_extern_function(): Unknown type (%d) for %s",
921*0Sstevel@tonic-gate 								indexs->tp->type,
922*0Sstevel@tonic-gate 								indexs->tp->label);
923*0Sstevel@tonic-gate 						}
924*0Sstevel@tonic-gate 					}
925*0Sstevel@tonic-gate 					else
926*0Sstevel@tonic-gate 					{
927*0Sstevel@tonic-gate 						error("WARNING: By default, the type of INDEX %s set to INTEGER",
928*0Sstevel@tonic-gate 							indexs->label);
929*0Sstevel@tonic-gate 						fprintf(fp, "IndexType %s, ",
930*0Sstevel@tonic-gate 								"index");
931*0Sstevel@tonic-gate 					}
932*0Sstevel@tonic-gate 
933*0Sstevel@tonic-gate 					indexs = indexs->next;
934*0Sstevel@tonic-gate 				}
935*0Sstevel@tonic-gate 
936*0Sstevel@tonic-gate 
937*0Sstevel@tonic-gate 				switch(current->type)
938*0Sstevel@tonic-gate 				{
939*0Sstevel@tonic-gate 					case TYPE_INTEGER:
940*0Sstevel@tonic-gate 					case TYPE_COUNTER:
941*0Sstevel@tonic-gate 					case TYPE_GAUGE:
942*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
943*0Sstevel@tonic-gate 						fprintf(fp, "Integer *%s);\n",
944*0Sstevel@tonic-gate 							current->label);
945*0Sstevel@tonic-gate 						break;
946*0Sstevel@tonic-gate 
947*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
948*0Sstevel@tonic-gate 					case TYPE_IPADDR:
949*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
950*0Sstevel@tonic-gate 						fprintf(fp, "String *%s);\n",
951*0Sstevel@tonic-gate 							current->label);
952*0Sstevel@tonic-gate 						break;
953*0Sstevel@tonic-gate 
954*0Sstevel@tonic-gate 					case TYPE_OBJID:
955*0Sstevel@tonic-gate 						fprintf(fp, "Oid *%s);\n",
956*0Sstevel@tonic-gate 							current->label);
957*0Sstevel@tonic-gate 						break;
958*0Sstevel@tonic-gate 
959*0Sstevel@tonic-gate 					default:
960*0Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
961*0Sstevel@tonic-gate 						current->type,
962*0Sstevel@tonic-gate 						current->label);
963*0Sstevel@tonic-gate 				}
964*0Sstevel@tonic-gate 			}
965*0Sstevel@tonic-gate 
966*0Sstevel@tonic-gate 			if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
967*0Sstevel@tonic-gate 			{
968*0Sstevel@tonic-gate 				switch(current->type)
969*0Sstevel@tonic-gate 				{
970*0Sstevel@tonic-gate 					case TYPE_INTEGER:
971*0Sstevel@tonic-gate 					case TYPE_COUNTER:
972*0Sstevel@tonic-gate 					case TYPE_GAUGE:
973*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-95)*/
974*0Sstevel@tonic-gate 						break;
975*0Sstevel@tonic-gate 
976*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
977*0Sstevel@tonic-gate 					case TYPE_IPADDR:
978*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
979*0Sstevel@tonic-gate 						fprintf(fp, "extern void free_%s(String *%s);\n",
980*0Sstevel@tonic-gate 							current->label,
981*0Sstevel@tonic-gate 							current->label);
982*0Sstevel@tonic-gate 						break;
983*0Sstevel@tonic-gate 
984*0Sstevel@tonic-gate 					case TYPE_OBJID:
985*0Sstevel@tonic-gate 						fprintf(fp, "extern void free_%s(Oid *%s);\n",
986*0Sstevel@tonic-gate 							current->label,
987*0Sstevel@tonic-gate 							current->label);
988*0Sstevel@tonic-gate 						break;
989*0Sstevel@tonic-gate 
990*0Sstevel@tonic-gate 					default:
991*0Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
992*0Sstevel@tonic-gate 							current->type,
993*0Sstevel@tonic-gate 							current->label);
994*0Sstevel@tonic-gate 				}
995*0Sstevel@tonic-gate 			}
996*0Sstevel@tonic-gate 
997*0Sstevel@tonic-gate 			break;
998*0Sstevel@tonic-gate 
999*0Sstevel@tonic-gate 
1000*0Sstevel@tonic-gate 		case ENTRY:
1001*0Sstevel@tonic-gate 			fprintf(fp, "extern int get_%s(int search_type, %c%s_t **%s_data",
1002*0Sstevel@tonic-gate 				current->label,
1003*0Sstevel@tonic-gate 				toupper(current->label[0]),
1004*0Sstevel@tonic-gate 				&(current->label[1]),
1005*0Sstevel@tonic-gate 				current->label);
1006*0Sstevel@tonic-gate 
1007*0Sstevel@tonic-gate 
1008*0Sstevel@tonic-gate 			indexs = current->indexs;
1009*0Sstevel@tonic-gate 
1010*0Sstevel@tonic-gate /* no more ind. index */
1011*0Sstevel@tonic-gate 			if(indexs)
1012*0Sstevel@tonic-gate 			{
1013*0Sstevel@tonic-gate 				if(indexs->tp)
1014*0Sstevel@tonic-gate 				{
1015*0Sstevel@tonic-gate 					switch(indexs->tp->type)
1016*0Sstevel@tonic-gate 					{
1017*0Sstevel@tonic-gate 						case TYPE_INTEGER:
1018*0Sstevel@tonic-gate 						case TYPE_COUNTER:
1019*0Sstevel@tonic-gate 						case TYPE_GAUGE:
1020*0Sstevel@tonic-gate 						case TYPE_TIMETICKS:
1021*0Sstevel@tonic-gate 							fprintf(fp, ", IndexType *%s",
1022*0Sstevel@tonic-gate 								"index");
1023*0Sstevel@tonic-gate 							break;
1024*0Sstevel@tonic-gate 
1025*0Sstevel@tonic-gate 						case TYPE_OCTETSTR:
1026*0Sstevel@tonic-gate 						case TYPE_IPADDR:
1027*0Sstevel@tonic-gate 						case TYPE_OPAQUE:
1028*0Sstevel@tonic-gate 							fprintf(fp, ", IndexType *%s",
1029*0Sstevel@tonic-gate 								"index");
1030*0Sstevel@tonic-gate 							break;
1031*0Sstevel@tonic-gate 
1032*0Sstevel@tonic-gate 						case TYPE_OBJID:
1033*0Sstevel@tonic-gate 							fprintf(fp, ", IndexType *%s",
1034*0Sstevel@tonic-gate 								"index");
1035*0Sstevel@tonic-gate 
1036*0Sstevel@tonic-gate 						default:
1037*0Sstevel@tonic-gate 							error_exit("output_extern_function(): Unknown type (%d) for %s",
1038*0Sstevel@tonic-gate 							indexs->tp->type,
1039*0Sstevel@tonic-gate 							indexs->tp->label);
1040*0Sstevel@tonic-gate 					}
1041*0Sstevel@tonic-gate 				}
1042*0Sstevel@tonic-gate 				else
1043*0Sstevel@tonic-gate 				{
1044*0Sstevel@tonic-gate 					error("WARNING: By default, the type of INDEX %s set to INTEGER",
1045*0Sstevel@tonic-gate 						indexs->label);
1046*0Sstevel@tonic-gate 					fprintf(fp, ", IndexType *%s",
1047*0Sstevel@tonic-gate 							"index");
1048*0Sstevel@tonic-gate 				}
1049*0Sstevel@tonic-gate 
1050*0Sstevel@tonic-gate 				indexs = indexs->next;
1051*0Sstevel@tonic-gate 			}
1052*0Sstevel@tonic-gate 			fprintf(fp, ");\n");
1053*0Sstevel@tonic-gate 
1054*0Sstevel@tonic-gate 			fprintf(fp, "extern void free_%s(%c%s_t *%s);\n",
1055*0Sstevel@tonic-gate 				current->label,
1056*0Sstevel@tonic-gate 				toupper(current->label[0]),
1057*0Sstevel@tonic-gate 				&(current->label[1]),
1058*0Sstevel@tonic-gate 				current->label);
1059*0Sstevel@tonic-gate 			break;
1060*0Sstevel@tonic-gate 	}
1061*0Sstevel@tonic-gate 
1062*0Sstevel@tonic-gate 
1063*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1064*0Sstevel@tonic-gate 	{
1065*0Sstevel@tonic-gate 		output_extern_function(fp, tp);
1066*0Sstevel@tonic-gate 	}
1067*0Sstevel@tonic-gate }
1068*0Sstevel@tonic-gate 
1069*0Sstevel@tonic-gate 
1070*0Sstevel@tonic-gate /*************************************************************************/
1071*0Sstevel@tonic-gate 
1072*0Sstevel@tonic-gate static void output_enum_table(FILE *fp, struct tree *current, int *enum_index)
1073*0Sstevel@tonic-gate {
1074*0Sstevel@tonic-gate 	struct tree *tp;
1075*0Sstevel@tonic-gate 	struct enum_list *enums;
1076*0Sstevel@tonic-gate 
1077*0Sstevel@tonic-gate 
1078*0Sstevel@tonic-gate 	for(enums = current->enums; enums; enums = enums->next)
1079*0Sstevel@tonic-gate 	{
1080*0Sstevel@tonic-gate 		if(enums->next == NULL)
1081*0Sstevel@tonic-gate 		{
1082*0Sstevel@tonic-gate 			fprintf(fp, "/* %6d */ { %17s, \"%s\", %d },\n",
1083*0Sstevel@tonic-gate 				*enum_index,
1084*0Sstevel@tonic-gate 				"NULL",
1085*0Sstevel@tonic-gate 				enums->label,
1086*0Sstevel@tonic-gate 				enums->value);
1087*0Sstevel@tonic-gate 		}
1088*0Sstevel@tonic-gate 		else
1089*0Sstevel@tonic-gate 		{
1090*0Sstevel@tonic-gate 			fprintf(fp, "/* %6d */ { &enum_table[%4d], \"%s\", %d },\n",
1091*0Sstevel@tonic-gate 				*enum_index,
1092*0Sstevel@tonic-gate 				(*enum_index) + 1,
1093*0Sstevel@tonic-gate 				enums->label,
1094*0Sstevel@tonic-gate 				enums->value);
1095*0Sstevel@tonic-gate 		}
1096*0Sstevel@tonic-gate 		(*enum_index)++;
1097*0Sstevel@tonic-gate 	}
1098*0Sstevel@tonic-gate 
1099*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1100*0Sstevel@tonic-gate 	{
1101*0Sstevel@tonic-gate 		output_enum_table(fp, tp, enum_index);
1102*0Sstevel@tonic-gate 	}
1103*0Sstevel@tonic-gate }
1104*0Sstevel@tonic-gate 
1105*0Sstevel@tonic-gate 
1106*0Sstevel@tonic-gate /*************************************************************************/
1107*0Sstevel@tonic-gate 
1108*0Sstevel@tonic-gate static void output_subid_table(FILE *fp, struct tree *current, int *subid_index)
1109*0Sstevel@tonic-gate {
1110*0Sstevel@tonic-gate 	struct tree *tp;
1111*0Sstevel@tonic-gate 	struct tree *parent;
1112*0Sstevel@tonic-gate 	Subid subids[MAX_OID_LEN];
1113*0Sstevel@tonic-gate 	int len = 0;
1114*0Sstevel@tonic-gate 	int i;
1115*0Sstevel@tonic-gate 
1116*0Sstevel@tonic-gate 
1117*0Sstevel@tonic-gate 	if( (current->node_type == OBJECT)
1118*0Sstevel@tonic-gate 		|| (current->node_type == COLUMN) )
1119*0Sstevel@tonic-gate 	{
1120*0Sstevel@tonic-gate 		fprintf(fp, "/* %6d */",
1121*0Sstevel@tonic-gate 			*subid_index);
1122*0Sstevel@tonic-gate 
1123*0Sstevel@tonic-gate 		parent = current;
1124*0Sstevel@tonic-gate 		while(parent)
1125*0Sstevel@tonic-gate 		{
1126*0Sstevel@tonic-gate 			subids[len++] = parent->subid;
1127*0Sstevel@tonic-gate 
1128*0Sstevel@tonic-gate 			parent = parent->parent;
1129*0Sstevel@tonic-gate 		}
1130*0Sstevel@tonic-gate 		fprintf(fp, " %d", subids[len - 1]);
1131*0Sstevel@tonic-gate 		(*subid_index)++;
1132*0Sstevel@tonic-gate 		for(i = len - 2; i >= 0; i--)
1133*0Sstevel@tonic-gate 		{
1134*0Sstevel@tonic-gate 			fprintf(fp, ", %d", subids[i]);
1135*0Sstevel@tonic-gate 			(*subid_index)++;
1136*0Sstevel@tonic-gate 		}
1137*0Sstevel@tonic-gate 		fprintf(fp, ",\n");
1138*0Sstevel@tonic-gate 	}
1139*0Sstevel@tonic-gate 
1140*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1141*0Sstevel@tonic-gate 	{
1142*0Sstevel@tonic-gate 		output_subid_table(fp, tp, subid_index);
1143*0Sstevel@tonic-gate 	}
1144*0Sstevel@tonic-gate }
1145*0Sstevel@tonic-gate 
1146*0Sstevel@tonic-gate 
1147*0Sstevel@tonic-gate /*************************************************************************/
1148*0Sstevel@tonic-gate 
1149*0Sstevel@tonic-gate static void output_object_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size)
1150*0Sstevel@tonic-gate {
1151*0Sstevel@tonic-gate 	struct tree *tp;
1152*0Sstevel@tonic-gate 	struct tree *parent;
1153*0Sstevel@tonic-gate 	struct enum_list *enums;
1154*0Sstevel@tonic-gate 	int len;
1155*0Sstevel@tonic-gate 
1156*0Sstevel@tonic-gate 
1157*0Sstevel@tonic-gate 	if(current->node_type == OBJECT)
1158*0Sstevel@tonic-gate 	{
1159*0Sstevel@tonic-gate 		fprintf(fp, "/* %6d */ {",
1160*0Sstevel@tonic-gate 			current->object_index);
1161*0Sstevel@tonic-gate 
1162*0Sstevel@tonic-gate 		/* name */
1163*0Sstevel@tonic-gate 		len = 0;
1164*0Sstevel@tonic-gate 		parent = current;
1165*0Sstevel@tonic-gate 		while(parent)
1166*0Sstevel@tonic-gate 		{
1167*0Sstevel@tonic-gate 			len++;
1168*0Sstevel@tonic-gate 
1169*0Sstevel@tonic-gate 			parent = parent->parent;
1170*0Sstevel@tonic-gate 		}
1171*0Sstevel@tonic-gate 		fprintf(fp, " { &subid_table[%d], %d }", *subid_index, len);
1172*0Sstevel@tonic-gate 
1173*0Sstevel@tonic-gate 		/* asn1_type */
1174*0Sstevel@tonic-gate 		switch(current->type)
1175*0Sstevel@tonic-gate 		{
1176*0Sstevel@tonic-gate 			case TYPE_INTEGER:
1177*0Sstevel@tonic-gate 				fprintf(fp, ", INTEGER");
1178*0Sstevel@tonic-gate 				break;
1179*0Sstevel@tonic-gate 
1180*0Sstevel@tonic-gate 			case TYPE_COUNTER:
1181*0Sstevel@tonic-gate 				fprintf(fp, ", COUNTER");
1182*0Sstevel@tonic-gate 				break;
1183*0Sstevel@tonic-gate 
1184*0Sstevel@tonic-gate 			case TYPE_GAUGE:
1185*0Sstevel@tonic-gate 				fprintf(fp, ", GAUGE");
1186*0Sstevel@tonic-gate 				break;
1187*0Sstevel@tonic-gate 
1188*0Sstevel@tonic-gate 			case TYPE_TIMETICKS:
1189*0Sstevel@tonic-gate 				fprintf(fp, ", TIMETICKS");
1190*0Sstevel@tonic-gate 				break;
1191*0Sstevel@tonic-gate 
1192*0Sstevel@tonic-gate 			case TYPE_OCTETSTR:
1193*0Sstevel@tonic-gate 				fprintf(fp, ", STRING");
1194*0Sstevel@tonic-gate 				break;
1195*0Sstevel@tonic-gate 
1196*0Sstevel@tonic-gate 			case TYPE_IPADDR:
1197*0Sstevel@tonic-gate 				fprintf(fp, ", IPADDRESS");
1198*0Sstevel@tonic-gate 				break;
1199*0Sstevel@tonic-gate 
1200*0Sstevel@tonic-gate 			case TYPE_OPAQUE:
1201*0Sstevel@tonic-gate 				fprintf(fp, ", OPAQUE");
1202*0Sstevel@tonic-gate 				break;
1203*0Sstevel@tonic-gate 
1204*0Sstevel@tonic-gate 			case TYPE_OBJID:
1205*0Sstevel@tonic-gate 				fprintf(fp, ", OBJID");
1206*0Sstevel@tonic-gate 				break;
1207*0Sstevel@tonic-gate 
1208*0Sstevel@tonic-gate 			default:
1209*0Sstevel@tonic-gate 				fprintf(fp, "ERROR!");
1210*0Sstevel@tonic-gate 				error_exit("Unknown ASN.1 type (%d) for object %s",
1211*0Sstevel@tonic-gate 					current->type,
1212*0Sstevel@tonic-gate 					current->label);
1213*0Sstevel@tonic-gate 		}
1214*0Sstevel@tonic-gate 
1215*0Sstevel@tonic-gate 		/* first_enum */
1216*0Sstevel@tonic-gate 		if(current->enums)
1217*0Sstevel@tonic-gate 		{
1218*0Sstevel@tonic-gate 			fprintf(fp, ", &enum_table[%d]", *enum_index);
1219*0Sstevel@tonic-gate 		}
1220*0Sstevel@tonic-gate 		else
1221*0Sstevel@tonic-gate 		{
1222*0Sstevel@tonic-gate 			fprintf(fp, ", NULL");
1223*0Sstevel@tonic-gate 		}
1224*0Sstevel@tonic-gate 
1225*0Sstevel@tonic-gate 		/* access */
1226*0Sstevel@tonic-gate 		if( (current->access & READ_FLAG) && (current->access & WRITE_FLAG) )
1227*0Sstevel@tonic-gate 		{
1228*0Sstevel@tonic-gate 			fprintf(fp, ", READ_FLAG | WRITE_FLAG");
1229*0Sstevel@tonic-gate 		}
1230*0Sstevel@tonic-gate 		else
1231*0Sstevel@tonic-gate 		if( (current->access & READ_FLAG) && !(current->access & WRITE_FLAG) )
1232*0Sstevel@tonic-gate 		{
1233*0Sstevel@tonic-gate 			fprintf(fp, ", READ_FLAG");
1234*0Sstevel@tonic-gate 		}
1235*0Sstevel@tonic-gate 		else
1236*0Sstevel@tonic-gate 		if( !(current->access & READ_FLAG) && (current->access & WRITE_FLAG) )
1237*0Sstevel@tonic-gate 		{
1238*0Sstevel@tonic-gate 			fprintf(fp, ", WRITE_FLAG");
1239*0Sstevel@tonic-gate 		}
1240*0Sstevel@tonic-gate 		else
1241*0Sstevel@tonic-gate 		{
1242*0Sstevel@tonic-gate 			fprintf(fp, ", 0");
1243*0Sstevel@tonic-gate 		}
1244*0Sstevel@tonic-gate                 /* type for trap fix */
1245*0Sstevel@tonic-gate 
1246*0Sstevel@tonic-gate                 fprintf(fp, ", 1");
1247*0Sstevel@tonic-gate 
1248*0Sstevel@tonic-gate 		/* get() */
1249*0Sstevel@tonic-gate 		if(current->access & READ_FLAG)
1250*0Sstevel@tonic-gate 		{
1251*0Sstevel@tonic-gate 			fprintf(fp, ", get_%s", current->label);
1252*0Sstevel@tonic-gate 		}
1253*0Sstevel@tonic-gate 		else
1254*0Sstevel@tonic-gate 		{
1255*0Sstevel@tonic-gate 			fprintf(fp, ", NULL");
1256*0Sstevel@tonic-gate 		}
1257*0Sstevel@tonic-gate 
1258*0Sstevel@tonic-gate 		/* set() */
1259*0Sstevel@tonic-gate 		if(current->access & WRITE_FLAG)
1260*0Sstevel@tonic-gate 		{
1261*0Sstevel@tonic-gate 			fprintf(fp, ", set_%s", current->label);
1262*0Sstevel@tonic-gate 		}
1263*0Sstevel@tonic-gate 		else
1264*0Sstevel@tonic-gate 		{
1265*0Sstevel@tonic-gate 			fprintf(fp, ", NULL");
1266*0Sstevel@tonic-gate 		}
1267*0Sstevel@tonic-gate 
1268*0Sstevel@tonic-gate 		/* dealloc() */
1269*0Sstevel@tonic-gate 		if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
1270*0Sstevel@tonic-gate 		{
1271*0Sstevel@tonic-gate 			switch(current->type)
1272*0Sstevel@tonic-gate 			{
1273*0Sstevel@tonic-gate 				case TYPE_INTEGER:
1274*0Sstevel@tonic-gate 				case TYPE_COUNTER:
1275*0Sstevel@tonic-gate 				case TYPE_GAUGE:
1276*0Sstevel@tonic-gate 				case TYPE_TIMETICKS:
1277*0Sstevel@tonic-gate 					fprintf(fp,",NULL");
1278*0Sstevel@tonic-gate 					break;
1279*0Sstevel@tonic-gate 				default:
1280*0Sstevel@tonic-gate 					fprintf(fp,",free_%s",current->label);
1281*0Sstevel@tonic-gate 			}
1282*0Sstevel@tonic-gate 		}
1283*0Sstevel@tonic-gate 		else
1284*0Sstevel@tonic-gate 		{
1285*0Sstevel@tonic-gate 			fprintf(fp,", NULL");
1286*0Sstevel@tonic-gate 		}
1287*0Sstevel@tonic-gate 
1288*0Sstevel@tonic-gate 
1289*0Sstevel@tonic-gate 		fprintf(fp, " },\n");
1290*0Sstevel@tonic-gate 
1291*0Sstevel@tonic-gate 
1292*0Sstevel@tonic-gate 		(*size)++;
1293*0Sstevel@tonic-gate 	}
1294*0Sstevel@tonic-gate 
1295*0Sstevel@tonic-gate 
1296*0Sstevel@tonic-gate 	if( (current->node_type == OBJECT)
1297*0Sstevel@tonic-gate 		|| (current->node_type == COLUMN) )
1298*0Sstevel@tonic-gate 	{
1299*0Sstevel@tonic-gate 		parent = current;
1300*0Sstevel@tonic-gate 		while(parent)
1301*0Sstevel@tonic-gate 		{
1302*0Sstevel@tonic-gate 			(*subid_index)++;
1303*0Sstevel@tonic-gate 
1304*0Sstevel@tonic-gate 			parent = parent->parent;
1305*0Sstevel@tonic-gate 		}
1306*0Sstevel@tonic-gate 	}
1307*0Sstevel@tonic-gate 
1308*0Sstevel@tonic-gate 
1309*0Sstevel@tonic-gate 	for(enums = current->enums; enums; enums = enums->next)
1310*0Sstevel@tonic-gate 	{
1311*0Sstevel@tonic-gate 		(*enum_index)++;
1312*0Sstevel@tonic-gate 	}
1313*0Sstevel@tonic-gate 
1314*0Sstevel@tonic-gate 
1315*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1316*0Sstevel@tonic-gate 	{
1317*0Sstevel@tonic-gate 		output_object_table(fp, tp, subid_index, enum_index, size);
1318*0Sstevel@tonic-gate 	}
1319*0Sstevel@tonic-gate }
1320*0Sstevel@tonic-gate 
1321*0Sstevel@tonic-gate 
1322*0Sstevel@tonic-gate /*************************************************************************/
1323*0Sstevel@tonic-gate 
1324*0Sstevel@tonic-gate static void output_index_table(FILE *fp, struct tree *current, int *index_index)
1325*0Sstevel@tonic-gate {
1326*0Sstevel@tonic-gate 	struct tree *tp;
1327*0Sstevel@tonic-gate 	struct index_list *indexs;
1328*0Sstevel@tonic-gate 
1329*0Sstevel@tonic-gate 
1330*0Sstevel@tonic-gate 	for(indexs = current->indexs; indexs; indexs = indexs->next)
1331*0Sstevel@tonic-gate 	{
1332*0Sstevel@tonic-gate 		if(indexs->tp)
1333*0Sstevel@tonic-gate 		{
1334*0Sstevel@tonic-gate 			if(indexs->next == NULL)
1335*0Sstevel@tonic-gate 			{
1336*0Sstevel@tonic-gate 				fprintf(fp, "/* %6d */ { %17s, \"%s\", %2d, %2d, &node_table[%d] },\n",
1337*0Sstevel@tonic-gate 					*index_index,
1338*0Sstevel@tonic-gate 					"NULL",
1339*0Sstevel@tonic-gate 					indexs->label,
1340*0Sstevel@tonic-gate                                         indexs->tp->type,
1341*0Sstevel@tonic-gate                                         indexs->tp->oct_str_len,
1342*0Sstevel@tonic-gate 					indexs->tp->node_index);
1343*0Sstevel@tonic-gate 			}
1344*0Sstevel@tonic-gate 			else
1345*0Sstevel@tonic-gate 			{
1346*0Sstevel@tonic-gate 				fprintf(fp, "/* %6d */ { &index_table[%4d], \"%s\", %2d, %2d, &node_table[%d] },\n",
1347*0Sstevel@tonic-gate 					*index_index,
1348*0Sstevel@tonic-gate 					(*index_index) + 1,
1349*0Sstevel@tonic-gate 					indexs->label,
1350*0Sstevel@tonic-gate                                         indexs->tp->type,
1351*0Sstevel@tonic-gate                                         indexs->tp->oct_str_len,
1352*0Sstevel@tonic-gate 					indexs->tp->node_index);
1353*0Sstevel@tonic-gate 			}
1354*0Sstevel@tonic-gate 		}
1355*0Sstevel@tonic-gate 		else
1356*0Sstevel@tonic-gate 		{
1357*0Sstevel@tonic-gate 			error("WARNING: node pointer for INDEX %s is NULL",
1358*0Sstevel@tonic-gate 				indexs->label);
1359*0Sstevel@tonic-gate 
1360*0Sstevel@tonic-gate 			if(indexs->next == NULL)
1361*0Sstevel@tonic-gate 			{
1362*0Sstevel@tonic-gate 				fprintf(fp, "/* %6d */ { %17s, \"%s\", %2d, %2d, NULL },\n",
1363*0Sstevel@tonic-gate 					*index_index,
1364*0Sstevel@tonic-gate 					"NULL",
1365*0Sstevel@tonic-gate 					indexs->label,
1366*0Sstevel@tonic-gate                                         indexs->tp->type,
1367*0Sstevel@tonic-gate                                         indexs->tp->oct_str_len);
1368*0Sstevel@tonic-gate 			}
1369*0Sstevel@tonic-gate 			else
1370*0Sstevel@tonic-gate 			{
1371*0Sstevel@tonic-gate 				fprintf(fp, "/* %6d */ { &index_table[%4d], \"%s\", %2d, %2d, NULL },\n",
1372*0Sstevel@tonic-gate 					*index_index,
1373*0Sstevel@tonic-gate 					(*index_index) + 1,
1374*0Sstevel@tonic-gate 					indexs->label,
1375*0Sstevel@tonic-gate                                         indexs->tp->type,
1376*0Sstevel@tonic-gate                                         indexs->tp->oct_str_len);
1377*0Sstevel@tonic-gate 			}
1378*0Sstevel@tonic-gate 		}
1379*0Sstevel@tonic-gate 
1380*0Sstevel@tonic-gate 		(*index_index)++;
1381*0Sstevel@tonic-gate 	}
1382*0Sstevel@tonic-gate 
1383*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1384*0Sstevel@tonic-gate 	{
1385*0Sstevel@tonic-gate 		output_index_table(fp, tp, index_index);
1386*0Sstevel@tonic-gate 	}
1387*0Sstevel@tonic-gate }
1388*0Sstevel@tonic-gate 
1389*0Sstevel@tonic-gate 
1390*0Sstevel@tonic-gate /*************************************************************************/
1391*0Sstevel@tonic-gate 
1392*0Sstevel@tonic-gate static void output_entry_table(FILE *fp, struct tree *current, int *index_index, int *size)
1393*0Sstevel@tonic-gate {
1394*0Sstevel@tonic-gate 	struct tree *tp;
1395*0Sstevel@tonic-gate 
1396*0Sstevel@tonic-gate 
1397*0Sstevel@tonic-gate 	if(current->node_type == ENTRY)
1398*0Sstevel@tonic-gate 	{
1399*0Sstevel@tonic-gate 		struct index_list *indexs;
1400*0Sstevel@tonic-gate 
1401*0Sstevel@tonic-gate 
1402*0Sstevel@tonic-gate 		fprintf(fp, "/* %6d */ {",
1403*0Sstevel@tonic-gate 			current->entry_index);
1404*0Sstevel@tonic-gate 
1405*0Sstevel@tonic-gate 		/* first_index, n_indexs */
1406*0Sstevel@tonic-gate 		fprintf(fp, " &index_table[%d], %d",
1407*0Sstevel@tonic-gate 			*index_index,
1408*0Sstevel@tonic-gate 			current->n_indexs);
1409*0Sstevel@tonic-gate 
1410*0Sstevel@tonic-gate 		for(indexs = current->indexs; indexs; indexs = indexs->next)
1411*0Sstevel@tonic-gate 		{
1412*0Sstevel@tonic-gate 			(*index_index)++;
1413*0Sstevel@tonic-gate 		}
1414*0Sstevel@tonic-gate 
1415*0Sstevel@tonic-gate 		/* get() */
1416*0Sstevel@tonic-gate 		fprintf(fp, ", get_%s", current->label);
1417*0Sstevel@tonic-gate 
1418*0Sstevel@tonic-gate 		/* dealloc() */
1419*0Sstevel@tonic-gate 		fprintf(fp, ", free_%s", current->label);
1420*0Sstevel@tonic-gate 
1421*0Sstevel@tonic-gate 		fprintf(fp, " },\n");
1422*0Sstevel@tonic-gate 
1423*0Sstevel@tonic-gate 
1424*0Sstevel@tonic-gate 		(*size)++;
1425*0Sstevel@tonic-gate 	}
1426*0Sstevel@tonic-gate 
1427*0Sstevel@tonic-gate 
1428*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1429*0Sstevel@tonic-gate 	{
1430*0Sstevel@tonic-gate 		output_entry_table(fp, tp, index_index, size);
1431*0Sstevel@tonic-gate 	}
1432*0Sstevel@tonic-gate }
1433*0Sstevel@tonic-gate 
1434*0Sstevel@tonic-gate 
1435*0Sstevel@tonic-gate /*************************************************************************/
1436*0Sstevel@tonic-gate 
1437*0Sstevel@tonic-gate static void output_column_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size)
1438*0Sstevel@tonic-gate {
1439*0Sstevel@tonic-gate 	struct tree *tp;
1440*0Sstevel@tonic-gate 	struct tree *parent;
1441*0Sstevel@tonic-gate 	struct enum_list *enums;
1442*0Sstevel@tonic-gate 
1443*0Sstevel@tonic-gate 
1444*0Sstevel@tonic-gate 	if(current->node_type == COLUMN)
1445*0Sstevel@tonic-gate 	{
1446*0Sstevel@tonic-gate 		int offset;
1447*0Sstevel@tonic-gate 		int len;
1448*0Sstevel@tonic-gate 		struct tree *child;
1449*0Sstevel@tonic-gate 
1450*0Sstevel@tonic-gate 
1451*0Sstevel@tonic-gate 		fprintf(fp, "/* %6d */ {",
1452*0Sstevel@tonic-gate 			current->column_index);
1453*0Sstevel@tonic-gate 
1454*0Sstevel@tonic-gate 		/* name */
1455*0Sstevel@tonic-gate 		len = 0;
1456*0Sstevel@tonic-gate 		parent = current;
1457*0Sstevel@tonic-gate 		while(parent)
1458*0Sstevel@tonic-gate 		{
1459*0Sstevel@tonic-gate 			len++;
1460*0Sstevel@tonic-gate 
1461*0Sstevel@tonic-gate 			parent = parent->parent;
1462*0Sstevel@tonic-gate 		}
1463*0Sstevel@tonic-gate 		fprintf(fp, " { &subid_table[%d], %d }", *subid_index, len);
1464*0Sstevel@tonic-gate 
1465*0Sstevel@tonic-gate 		/* asn1_type */
1466*0Sstevel@tonic-gate 		switch(current->type)
1467*0Sstevel@tonic-gate 		{
1468*0Sstevel@tonic-gate 			case TYPE_INTEGER:
1469*0Sstevel@tonic-gate 				fprintf(fp, ", INTEGER");
1470*0Sstevel@tonic-gate 				break;
1471*0Sstevel@tonic-gate 
1472*0Sstevel@tonic-gate 			case TYPE_COUNTER:
1473*0Sstevel@tonic-gate 				fprintf(fp, ", COUNTER");
1474*0Sstevel@tonic-gate 				break;
1475*0Sstevel@tonic-gate 
1476*0Sstevel@tonic-gate 			case TYPE_GAUGE:
1477*0Sstevel@tonic-gate 				fprintf(fp, ", GAUGE");
1478*0Sstevel@tonic-gate 				break;
1479*0Sstevel@tonic-gate 
1480*0Sstevel@tonic-gate 			case TYPE_TIMETICKS:
1481*0Sstevel@tonic-gate 				fprintf(fp, ", TIMETICKS");
1482*0Sstevel@tonic-gate 				break;
1483*0Sstevel@tonic-gate 
1484*0Sstevel@tonic-gate 			case TYPE_OCTETSTR:
1485*0Sstevel@tonic-gate 				fprintf(fp, ", STRING");
1486*0Sstevel@tonic-gate 				break;
1487*0Sstevel@tonic-gate 
1488*0Sstevel@tonic-gate 			case TYPE_IPADDR:
1489*0Sstevel@tonic-gate 				fprintf(fp, ", IPADDRESS");
1490*0Sstevel@tonic-gate 				break;
1491*0Sstevel@tonic-gate 
1492*0Sstevel@tonic-gate 			case TYPE_OPAQUE:
1493*0Sstevel@tonic-gate 				fprintf(fp, ", OPAQUE");
1494*0Sstevel@tonic-gate 				break;
1495*0Sstevel@tonic-gate 
1496*0Sstevel@tonic-gate 			case TYPE_OBJID:
1497*0Sstevel@tonic-gate 				fprintf(fp, ", OBJID");
1498*0Sstevel@tonic-gate 				break;
1499*0Sstevel@tonic-gate 
1500*0Sstevel@tonic-gate 			default:
1501*0Sstevel@tonic-gate 				fprintf(fp, "ERROR!");
1502*0Sstevel@tonic-gate 				error_exit("Unknown ASN.1 type (%d) for object %s",
1503*0Sstevel@tonic-gate 					current->type,
1504*0Sstevel@tonic-gate 					current->label);
1505*0Sstevel@tonic-gate 		}
1506*0Sstevel@tonic-gate 
1507*0Sstevel@tonic-gate 		/* first_enum */
1508*0Sstevel@tonic-gate 		if(current->enums)
1509*0Sstevel@tonic-gate 		{
1510*0Sstevel@tonic-gate 			fprintf(fp, ", &enum_table[%d]", *enum_index);
1511*0Sstevel@tonic-gate 		}
1512*0Sstevel@tonic-gate 		else
1513*0Sstevel@tonic-gate 		{
1514*0Sstevel@tonic-gate 			fprintf(fp, ", NULL");
1515*0Sstevel@tonic-gate 		}
1516*0Sstevel@tonic-gate 
1517*0Sstevel@tonic-gate 		/* access */
1518*0Sstevel@tonic-gate 		if( (current->access & READ_FLAG) && (current->access & WRITE_FLAG) )
1519*0Sstevel@tonic-gate 		{
1520*0Sstevel@tonic-gate 			fprintf(fp, ", READ_FLAG | WRITE_FLAG");
1521*0Sstevel@tonic-gate 		}
1522*0Sstevel@tonic-gate 		else
1523*0Sstevel@tonic-gate 		if( (current->access & READ_FLAG) && !(current->access & WRITE_FLAG) )
1524*0Sstevel@tonic-gate 		{
1525*0Sstevel@tonic-gate 			fprintf(fp, ", READ_FLAG");
1526*0Sstevel@tonic-gate 		}
1527*0Sstevel@tonic-gate 		else
1528*0Sstevel@tonic-gate 		if( !(current->access & READ_FLAG) && (current->access & WRITE_FLAG) )
1529*0Sstevel@tonic-gate 		{
1530*0Sstevel@tonic-gate 			fprintf(fp, ", WRITE_FLAG");
1531*0Sstevel@tonic-gate 		}
1532*0Sstevel@tonic-gate 		else
1533*0Sstevel@tonic-gate 		{
1534*0Sstevel@tonic-gate 			fprintf(fp, ", 0");
1535*0Sstevel@tonic-gate 		}
1536*0Sstevel@tonic-gate                 /* type  for trap fix */
1537*0Sstevel@tonic-gate 
1538*0Sstevel@tonic-gate                 fprintf(fp, ", 2");
1539*0Sstevel@tonic-gate 
1540*0Sstevel@tonic-gate                /* get() */
1541*0Sstevel@tonic-gate 
1542*0Sstevel@tonic-gate                 if(current->access & READ_FLAG)
1543*0Sstevel@tonic-gate                 {
1544*0Sstevel@tonic-gate                         fprintf(fp, ", get_%s", current->label);
1545*0Sstevel@tonic-gate                 }
1546*0Sstevel@tonic-gate                 else
1547*0Sstevel@tonic-gate                 {
1548*0Sstevel@tonic-gate                         fprintf(fp, ", NULL");
1549*0Sstevel@tonic-gate                 }
1550*0Sstevel@tonic-gate 
1551*0Sstevel@tonic-gate 		/* set() */
1552*0Sstevel@tonic-gate 		if(current->access & WRITE_FLAG)
1553*0Sstevel@tonic-gate 		{
1554*0Sstevel@tonic-gate 			fprintf(fp, ", set_%s", current->label);
1555*0Sstevel@tonic-gate 		}
1556*0Sstevel@tonic-gate 		else
1557*0Sstevel@tonic-gate 		{
1558*0Sstevel@tonic-gate 			fprintf(fp, ", NULL");
1559*0Sstevel@tonic-gate 		}
1560*0Sstevel@tonic-gate 
1561*0Sstevel@tonic-gate 		/* table */
1562*0Sstevel@tonic-gate 		fprintf(fp, ", &entry_table[%d]", current->parent->entry_index);
1563*0Sstevel@tonic-gate 
1564*0Sstevel@tonic-gate 		/* offset */
1565*0Sstevel@tonic-gate 		offset = 0;
1566*0Sstevel@tonic-gate 		for(child = current->parent->child_list; child != current; child = child->next_peer)
1567*0Sstevel@tonic-gate 		{
1568*0Sstevel@tonic-gate 			if( !(child->access & READ_FLAG) )
1569*0Sstevel@tonic-gate 			{
1570*0Sstevel@tonic-gate 				continue;
1571*0Sstevel@tonic-gate 			}
1572*0Sstevel@tonic-gate 
1573*0Sstevel@tonic-gate 			switch(child->type)
1574*0Sstevel@tonic-gate 			{
1575*0Sstevel@tonic-gate 				case TYPE_INTEGER:
1576*0Sstevel@tonic-gate 				case TYPE_COUNTER:
1577*0Sstevel@tonic-gate 				case TYPE_GAUGE:
1578*0Sstevel@tonic-gate 				case TYPE_TIMETICKS:
1579*0Sstevel@tonic-gate 					offset = offset + sizeof(Integer);
1580*0Sstevel@tonic-gate 					break;
1581*0Sstevel@tonic-gate 
1582*0Sstevel@tonic-gate 				case TYPE_OCTETSTR:
1583*0Sstevel@tonic-gate 				case TYPE_IPADDR:
1584*0Sstevel@tonic-gate 				case TYPE_OPAQUE:
1585*0Sstevel@tonic-gate 					offset = offset + sizeof(String);
1586*0Sstevel@tonic-gate 					break;
1587*0Sstevel@tonic-gate 
1588*0Sstevel@tonic-gate 				case TYPE_OBJID:
1589*0Sstevel@tonic-gate 					offset = offset + sizeof(Oid);
1590*0Sstevel@tonic-gate 					break;
1591*0Sstevel@tonic-gate 
1592*0Sstevel@tonic-gate 				default:
1593*0Sstevel@tonic-gate 					error_exit("output_column_table(): Unknown type (%d) for %s",
1594*0Sstevel@tonic-gate 						child->type,
1595*0Sstevel@tonic-gate 						child->label);
1596*0Sstevel@tonic-gate 			}
1597*0Sstevel@tonic-gate 		}
1598*0Sstevel@tonic-gate 		fprintf(fp, ", %d", offset);
1599*0Sstevel@tonic-gate 
1600*0Sstevel@tonic-gate 		fprintf(fp, " },\n");
1601*0Sstevel@tonic-gate 
1602*0Sstevel@tonic-gate 
1603*0Sstevel@tonic-gate 		(*size)++;
1604*0Sstevel@tonic-gate 	}
1605*0Sstevel@tonic-gate 
1606*0Sstevel@tonic-gate 
1607*0Sstevel@tonic-gate 	if( (current->node_type == OBJECT)
1608*0Sstevel@tonic-gate 		|| (current->node_type == COLUMN) )
1609*0Sstevel@tonic-gate 	{
1610*0Sstevel@tonic-gate 		parent = current;
1611*0Sstevel@tonic-gate 		while(parent)
1612*0Sstevel@tonic-gate 		{
1613*0Sstevel@tonic-gate 			(*subid_index)++;
1614*0Sstevel@tonic-gate 
1615*0Sstevel@tonic-gate 			parent = parent->parent;
1616*0Sstevel@tonic-gate 		}
1617*0Sstevel@tonic-gate 	}
1618*0Sstevel@tonic-gate 
1619*0Sstevel@tonic-gate 
1620*0Sstevel@tonic-gate 	for(enums = current->enums; enums; enums = enums->next)
1621*0Sstevel@tonic-gate 	{
1622*0Sstevel@tonic-gate 		(*enum_index)++;
1623*0Sstevel@tonic-gate 	}
1624*0Sstevel@tonic-gate 
1625*0Sstevel@tonic-gate 
1626*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1627*0Sstevel@tonic-gate 	{
1628*0Sstevel@tonic-gate 		output_column_table(fp, tp, subid_index, enum_index, size);
1629*0Sstevel@tonic-gate 	}
1630*0Sstevel@tonic-gate }
1631*0Sstevel@tonic-gate 
1632*0Sstevel@tonic-gate 
1633*0Sstevel@tonic-gate /*************************************************************************/
1634*0Sstevel@tonic-gate 
1635*0Sstevel@tonic-gate static void output_node_table(FILE *fp, struct tree *current, int *size)
1636*0Sstevel@tonic-gate {
1637*0Sstevel@tonic-gate 	struct tree *tp;
1638*0Sstevel@tonic-gate 
1639*0Sstevel@tonic-gate 
1640*0Sstevel@tonic-gate 	fprintf(fp, "/* %6d */ {",
1641*0Sstevel@tonic-gate 		current->node_index);
1642*0Sstevel@tonic-gate 
1643*0Sstevel@tonic-gate 	/* parent */
1644*0Sstevel@tonic-gate 	if(current->parent == NULL)
1645*0Sstevel@tonic-gate 	{
1646*0Sstevel@tonic-gate 		fprintf(fp, " %17s", "NULL");
1647*0Sstevel@tonic-gate 	}
1648*0Sstevel@tonic-gate 	else
1649*0Sstevel@tonic-gate 	{
1650*0Sstevel@tonic-gate 		fprintf(fp, " &node_table[%4d]",
1651*0Sstevel@tonic-gate 			current->parent->node_index);
1652*0Sstevel@tonic-gate 	}
1653*0Sstevel@tonic-gate 
1654*0Sstevel@tonic-gate 	/* first_child */
1655*0Sstevel@tonic-gate 	if(current->child_list == NULL)
1656*0Sstevel@tonic-gate 	{
1657*0Sstevel@tonic-gate 		fprintf(fp, ", %17s", "NULL");
1658*0Sstevel@tonic-gate 	}
1659*0Sstevel@tonic-gate 	else
1660*0Sstevel@tonic-gate 	{
1661*0Sstevel@tonic-gate 		fprintf(fp, ", &node_table[%4d]",
1662*0Sstevel@tonic-gate 			current->child_list->node_index);
1663*0Sstevel@tonic-gate 	}
1664*0Sstevel@tonic-gate 
1665*0Sstevel@tonic-gate 	/* next_peer */
1666*0Sstevel@tonic-gate 	if(current->next_peer == NULL)
1667*0Sstevel@tonic-gate 	{
1668*0Sstevel@tonic-gate 		fprintf(fp, ", %17s", "NULL");
1669*0Sstevel@tonic-gate 	}
1670*0Sstevel@tonic-gate 	else
1671*0Sstevel@tonic-gate 	{
1672*0Sstevel@tonic-gate 		fprintf(fp, ", &node_table[%4d]",
1673*0Sstevel@tonic-gate 			current->next_peer->node_index);
1674*0Sstevel@tonic-gate 	}
1675*0Sstevel@tonic-gate 
1676*0Sstevel@tonic-gate 	/* next */
1677*0Sstevel@tonic-gate 	if(current->next == NULL)
1678*0Sstevel@tonic-gate 	{
1679*0Sstevel@tonic-gate 		fprintf(fp, ", %17s", "NULL");
1680*0Sstevel@tonic-gate 	}
1681*0Sstevel@tonic-gate 	else
1682*0Sstevel@tonic-gate 	{
1683*0Sstevel@tonic-gate 		fprintf(fp, ", &node_table[%4d]",
1684*0Sstevel@tonic-gate 			current->next->node_index);
1685*0Sstevel@tonic-gate 	}
1686*0Sstevel@tonic-gate 
1687*0Sstevel@tonic-gate 	/* label, subid */
1688*0Sstevel@tonic-gate 	fprintf(fp, ", \"%s\", %d",
1689*0Sstevel@tonic-gate 		current->label, current->subid);
1690*0Sstevel@tonic-gate 
1691*0Sstevel@tonic-gate 	/* type, data */
1692*0Sstevel@tonic-gate 	switch(current->node_type)
1693*0Sstevel@tonic-gate 	{
1694*0Sstevel@tonic-gate 		case OBJECT:
1695*0Sstevel@tonic-gate 			fprintf(fp, ", OBJECT, (void *) &object_table[%d]",
1696*0Sstevel@tonic-gate 				current->object_index);
1697*0Sstevel@tonic-gate 			break;
1698*0Sstevel@tonic-gate 
1699*0Sstevel@tonic-gate 		case COLUMN:
1700*0Sstevel@tonic-gate 			fprintf(fp, ", COLUMN, (void *) &column_table[%d]",
1701*0Sstevel@tonic-gate 				current->column_index);
1702*0Sstevel@tonic-gate 			break;
1703*0Sstevel@tonic-gate 
1704*0Sstevel@tonic-gate 		case NODE:
1705*0Sstevel@tonic-gate 		case TABLE:
1706*0Sstevel@tonic-gate 		case ENTRY:
1707*0Sstevel@tonic-gate 			fprintf(fp, ", NODE, NULL");
1708*0Sstevel@tonic-gate 			break;
1709*0Sstevel@tonic-gate 
1710*0Sstevel@tonic-gate 
1711*0Sstevel@tonic-gate 		default:
1712*0Sstevel@tonic-gate 			error_exit("Unknown node type (%d) for %s",
1713*0Sstevel@tonic-gate 				current->type, current->label);
1714*0Sstevel@tonic-gate 	}
1715*0Sstevel@tonic-gate 
1716*0Sstevel@tonic-gate 	fprintf(fp, " },\n");
1717*0Sstevel@tonic-gate 
1718*0Sstevel@tonic-gate 
1719*0Sstevel@tonic-gate 	(*size)++;
1720*0Sstevel@tonic-gate 
1721*0Sstevel@tonic-gate 
1722*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1723*0Sstevel@tonic-gate 	{
1724*0Sstevel@tonic-gate 		output_node_table(fp, tp, size);
1725*0Sstevel@tonic-gate 	}
1726*0Sstevel@tonic-gate }
1727*0Sstevel@tonic-gate 
1728*0Sstevel@tonic-gate 
1729*0Sstevel@tonic-gate /*************************************************************************/
1730*0Sstevel@tonic-gate 
1731*0Sstevel@tonic-gate static void output_tree_c(struct tree *current)
1732*0Sstevel@tonic-gate {
1733*0Sstevel@tonic-gate 	char pathname[MAXPATHLEN];
1734*0Sstevel@tonic-gate 	char backup_pathname[MAXPATHLEN];
1735*0Sstevel@tonic-gate 	struct stat buf;
1736*0Sstevel@tonic-gate 	FILE *fp;
1737*0Sstevel@tonic-gate 	int subid_index;
1738*0Sstevel@tonic-gate 	int enum_index;
1739*0Sstevel@tonic-gate 	int index_index;
1740*0Sstevel@tonic-gate 	int size;
1741*0Sstevel@tonic-gate 
1742*0Sstevel@tonic-gate 
1743*0Sstevel@tonic-gate 	sprintf(pathname, "%s_tree.c", base_name);
1744*0Sstevel@tonic-gate 	sprintf(backup_pathname, "%s_tree.c.old", base_name);
1745*0Sstevel@tonic-gate 	trace("Creating %s ...\n", pathname);
1746*0Sstevel@tonic-gate 	if(stat(pathname, &buf) == 0)
1747*0Sstevel@tonic-gate 	{
1748*0Sstevel@tonic-gate                 if(rename(pathname,backup_pathname)==-1){
1749*0Sstevel@tonic-gate                   error_exit("The file %s already exists and can't be renamed!", pathname);
1750*0Sstevel@tonic-gate                 }
1751*0Sstevel@tonic-gate 	}
1752*0Sstevel@tonic-gate 
1753*0Sstevel@tonic-gate 	fp = fopen(pathname, "w");
1754*0Sstevel@tonic-gate 	if(fp == NULL)
1755*0Sstevel@tonic-gate 	{
1756*0Sstevel@tonic-gate 		error_exit("Can't open %s %s", pathname, errno_string());
1757*0Sstevel@tonic-gate 	}
1758*0Sstevel@tonic-gate 
1759*0Sstevel@tonic-gate 	fprintf(fp, "#include <sys/types.h>\n");
1760*0Sstevel@tonic-gate 	fprintf(fp, "\n");
1761*0Sstevel@tonic-gate 	fprintf(fp, "#include \"impl.h\"\n");
1762*0Sstevel@tonic-gate 	fprintf(fp, "#include \"asn1.h\"\n");
1763*0Sstevel@tonic-gate 	fprintf(fp, "#include \"node.h\"\n");
1764*0Sstevel@tonic-gate 	fprintf(fp, "\n");
1765*0Sstevel@tonic-gate 	fprintf(fp, "#include \"%s_stub.h\"\n", base_name);
1766*0Sstevel@tonic-gate 	fprintf(fp, "\n");
1767*0Sstevel@tonic-gate 	fprintf(fp, "\n");
1768*0Sstevel@tonic-gate 
1769*0Sstevel@tonic-gate 
1770*0Sstevel@tonic-gate 
1771*0Sstevel@tonic-gate 	subid_index = 0;
1772*0Sstevel@tonic-gate 	fprintf(fp, "Subid subid_table[] = {\n");
1773*0Sstevel@tonic-gate 	output_subid_table(fp, current, &subid_index);
1774*0Sstevel@tonic-gate 	fprintf(fp, "0\n");
1775*0Sstevel@tonic-gate 	fprintf(fp, "};\n");
1776*0Sstevel@tonic-gate 	fprintf(fp, "int subid_table_size = %d;\n\n", subid_index);
1777*0Sstevel@tonic-gate 
1778*0Sstevel@tonic-gate 	enum_index = 0;
1779*0Sstevel@tonic-gate 	fprintf(fp, "Enum enum_table[] = {\n");
1780*0Sstevel@tonic-gate 	output_enum_table(fp, current, &enum_index);
1781*0Sstevel@tonic-gate 	fprintf(fp, "{ NULL, NULL, 0 }\n");
1782*0Sstevel@tonic-gate 	fprintf(fp, "};\n");
1783*0Sstevel@tonic-gate 	fprintf(fp, "int enum_table_size = %d;\n\n", enum_index);
1784*0Sstevel@tonic-gate 
1785*0Sstevel@tonic-gate 	subid_index = 0;
1786*0Sstevel@tonic-gate 	enum_index = 0;
1787*0Sstevel@tonic-gate 	size = 0;
1788*0Sstevel@tonic-gate 	fprintf(fp, "Object object_table[] = {\n");
1789*0Sstevel@tonic-gate 	output_object_table(fp, current, &subid_index, &enum_index, &size);
1790*0Sstevel@tonic-gate 	fprintf(fp, "{ { NULL, 0}, 0, NULL, 0, NULL, NULL }\n");
1791*0Sstevel@tonic-gate 	fprintf(fp, "};\n");
1792*0Sstevel@tonic-gate 	fprintf(fp, "int object_table_size = %d;\n\n", size);
1793*0Sstevel@tonic-gate 
1794*0Sstevel@tonic-gate 	index_index = 0;
1795*0Sstevel@tonic-gate 	fprintf(fp, "Index index_table[] = {\n");
1796*0Sstevel@tonic-gate 	output_index_table(fp, current, &index_index);
1797*0Sstevel@tonic-gate 	fprintf(fp, "{ NULL, NULL, NULL }\n");
1798*0Sstevel@tonic-gate 	fprintf(fp, "};\n");
1799*0Sstevel@tonic-gate 	fprintf(fp, "int index_table_size = %d;\n\n", index_index);
1800*0Sstevel@tonic-gate 
1801*0Sstevel@tonic-gate 	size = 0;
1802*0Sstevel@tonic-gate 	index_index = 0;
1803*0Sstevel@tonic-gate 	fprintf(fp, "Entry entry_table[] = {\n");
1804*0Sstevel@tonic-gate 	output_entry_table(fp, current, &index_index, &size);
1805*0Sstevel@tonic-gate 	fprintf(fp, "{ NULL, 0, NULL }\n");
1806*0Sstevel@tonic-gate 	fprintf(fp, "};\n");
1807*0Sstevel@tonic-gate 	fprintf(fp, "int entry_table_size = %d;\n\n", size);
1808*0Sstevel@tonic-gate 
1809*0Sstevel@tonic-gate 	subid_index = 0;
1810*0Sstevel@tonic-gate 	enum_index = 0;
1811*0Sstevel@tonic-gate 	size = 0;
1812*0Sstevel@tonic-gate 	fprintf(fp, "Column column_table[] = {\n");
1813*0Sstevel@tonic-gate 	output_column_table(fp, current, &subid_index, &enum_index, &size);
1814*0Sstevel@tonic-gate 	fprintf(fp, "{ { NULL, 0}, 0, NULL, 0, NULL, NULL , 0 }\n");
1815*0Sstevel@tonic-gate 	fprintf(fp, "};\n");
1816*0Sstevel@tonic-gate 	fprintf(fp, "int column_table_size = %d;\n\n", size);
1817*0Sstevel@tonic-gate 
1818*0Sstevel@tonic-gate 	size = 0;
1819*0Sstevel@tonic-gate 	fprintf(fp, "Node node_table[] = {\n");
1820*0Sstevel@tonic-gate 	output_node_table(fp, current, &size);
1821*0Sstevel@tonic-gate 	fprintf(fp, "{ NULL, NULL, NULL, NULL, NULL, 0, 0, NULL }\n");
1822*0Sstevel@tonic-gate 	fprintf(fp, "};\n");
1823*0Sstevel@tonic-gate 	fprintf(fp, "int node_table_size = %d;\n\n", size);
1824*0Sstevel@tonic-gate 
1825*0Sstevel@tonic-gate 
1826*0Sstevel@tonic-gate 	fclose(fp);
1827*0Sstevel@tonic-gate }
1828*0Sstevel@tonic-gate 
1829*0Sstevel@tonic-gate 
1830*0Sstevel@tonic-gate /*************************************************************************/
1831*0Sstevel@tonic-gate 
1832*0Sstevel@tonic-gate static struct tree *find_node(struct tree *current, char *label)
1833*0Sstevel@tonic-gate {
1834*0Sstevel@tonic-gate 	struct tree *tp;
1835*0Sstevel@tonic-gate 	struct tree *t;
1836*0Sstevel@tonic-gate 
1837*0Sstevel@tonic-gate 
1838*0Sstevel@tonic-gate 	if(strcmp(current->label, label) == 0)
1839*0Sstevel@tonic-gate 	{
1840*0Sstevel@tonic-gate 		return current;
1841*0Sstevel@tonic-gate 	}
1842*0Sstevel@tonic-gate 
1843*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1844*0Sstevel@tonic-gate 	{
1845*0Sstevel@tonic-gate 		t = find_node(tp, label);
1846*0Sstevel@tonic-gate 		if(t != NULL)
1847*0Sstevel@tonic-gate 		{
1848*0Sstevel@tonic-gate 			return t;
1849*0Sstevel@tonic-gate 		}
1850*0Sstevel@tonic-gate 	}
1851*0Sstevel@tonic-gate 
1852*0Sstevel@tonic-gate 	return NULL;
1853*0Sstevel@tonic-gate }
1854*0Sstevel@tonic-gate 
1855*0Sstevel@tonic-gate 
1856*0Sstevel@tonic-gate /*************************************************************************/
1857*0Sstevel@tonic-gate 
1858*0Sstevel@tonic-gate static void output_structure(FILE *fp, struct tree *current)
1859*0Sstevel@tonic-gate {
1860*0Sstevel@tonic-gate 	struct tree *tp;
1861*0Sstevel@tonic-gate 
1862*0Sstevel@tonic-gate 
1863*0Sstevel@tonic-gate 	if(current->node_type == ENTRY)
1864*0Sstevel@tonic-gate 	{
1865*0Sstevel@tonic-gate 		struct tree *child;
1866*0Sstevel@tonic-gate 
1867*0Sstevel@tonic-gate 
1868*0Sstevel@tonic-gate 		fprintf(fp, "\n");
1869*0Sstevel@tonic-gate 		fprintf(fp, "typedef struct _%c%s_t {\n",
1870*0Sstevel@tonic-gate 			toupper(current->label[0]),
1871*0Sstevel@tonic-gate 			&(current->label[1]));
1872*0Sstevel@tonic-gate 		for(child = current->child_list; child; child = child->next_peer)
1873*0Sstevel@tonic-gate 		{
1874*0Sstevel@tonic-gate 			if( !(child->access & READ_FLAG) )
1875*0Sstevel@tonic-gate 			{
1876*0Sstevel@tonic-gate 				continue;
1877*0Sstevel@tonic-gate 			}
1878*0Sstevel@tonic-gate 
1879*0Sstevel@tonic-gate 			switch(child->type)
1880*0Sstevel@tonic-gate 			{
1881*0Sstevel@tonic-gate 				case TYPE_INTEGER:
1882*0Sstevel@tonic-gate 				case TYPE_COUNTER:
1883*0Sstevel@tonic-gate 				case TYPE_GAUGE:
1884*0Sstevel@tonic-gate 				case TYPE_TIMETICKS:
1885*0Sstevel@tonic-gate 					fprintf(fp, "\tInteger %s;\n", child->label);
1886*0Sstevel@tonic-gate 					break;
1887*0Sstevel@tonic-gate 
1888*0Sstevel@tonic-gate 				case TYPE_OCTETSTR:
1889*0Sstevel@tonic-gate 				case TYPE_IPADDR:
1890*0Sstevel@tonic-gate 				case TYPE_OPAQUE:
1891*0Sstevel@tonic-gate 					fprintf(fp, "\tString %s;\n", child->label);
1892*0Sstevel@tonic-gate 					break;
1893*0Sstevel@tonic-gate 
1894*0Sstevel@tonic-gate 				case TYPE_OBJID:
1895*0Sstevel@tonic-gate 					fprintf(fp, "\tOid %s;\n", child->label);
1896*0Sstevel@tonic-gate 					break;
1897*0Sstevel@tonic-gate 
1898*0Sstevel@tonic-gate 				default:
1899*0Sstevel@tonic-gate 					error_exit("output_structure(): Unknown type (%d) for %s",
1900*0Sstevel@tonic-gate 						child->type,
1901*0Sstevel@tonic-gate 						child->label);
1902*0Sstevel@tonic-gate 			}
1903*0Sstevel@tonic-gate 		}
1904*0Sstevel@tonic-gate 		fprintf(fp, "} %c%s_t;\n",
1905*0Sstevel@tonic-gate 			toupper(current->label[0]),
1906*0Sstevel@tonic-gate 			&(current->label[1]));
1907*0Sstevel@tonic-gate 	}
1908*0Sstevel@tonic-gate 
1909*0Sstevel@tonic-gate 
1910*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
1911*0Sstevel@tonic-gate 	{
1912*0Sstevel@tonic-gate 		output_structure(fp, tp);
1913*0Sstevel@tonic-gate 	}
1914*0Sstevel@tonic-gate }
1915*0Sstevel@tonic-gate 
1916*0Sstevel@tonic-gate 
1917*0Sstevel@tonic-gate /*************************************************************************/
1918*0Sstevel@tonic-gate 
1919*0Sstevel@tonic-gate static void output_stub_h(struct tree *current)
1920*0Sstevel@tonic-gate {
1921*0Sstevel@tonic-gate 	char pathname[MAXPATHLEN];
1922*0Sstevel@tonic-gate 	char backup_pathname[MAXPATHLEN];
1923*0Sstevel@tonic-gate 	struct stat buf;
1924*0Sstevel@tonic-gate 	FILE *fp;
1925*0Sstevel@tonic-gate 	int i;
1926*0Sstevel@tonic-gate 
1927*0Sstevel@tonic-gate 
1928*0Sstevel@tonic-gate 	sprintf(pathname, "%s_stub.h", base_name);
1929*0Sstevel@tonic-gate 	sprintf(backup_pathname, "%s_stub.h.old", base_name);
1930*0Sstevel@tonic-gate 	trace("Creating %s ...\n", pathname);
1931*0Sstevel@tonic-gate 	if(stat(pathname, &buf) == 0)
1932*0Sstevel@tonic-gate 	{
1933*0Sstevel@tonic-gate                 if(rename(pathname,backup_pathname)==-1){
1934*0Sstevel@tonic-gate                   error_exit("The file %s already exists and can't be renamed!", pathname);
1935*0Sstevel@tonic-gate                 }
1936*0Sstevel@tonic-gate 	}
1937*0Sstevel@tonic-gate 
1938*0Sstevel@tonic-gate 	fp = fopen(pathname, "w");
1939*0Sstevel@tonic-gate 	if(fp == NULL)
1940*0Sstevel@tonic-gate 	{
1941*0Sstevel@tonic-gate 		error_exit("Can't open %s %s", pathname, errno_string());
1942*0Sstevel@tonic-gate 	}
1943*0Sstevel@tonic-gate 
1944*0Sstevel@tonic-gate 	fprintf(fp, "#ifndef _");
1945*0Sstevel@tonic-gate 	for(i = 0; base_name[i] != '\0'; i++)
1946*0Sstevel@tonic-gate 	{
1947*0Sstevel@tonic-gate 		fprintf(fp, "%c", toupper(base_name[i]));
1948*0Sstevel@tonic-gate 	}
1949*0Sstevel@tonic-gate 	fprintf(fp, "_STUB_H_\n");
1950*0Sstevel@tonic-gate 	fprintf(fp, "#define _");
1951*0Sstevel@tonic-gate 	for(i = 0; base_name[i] != '\0'; i++)
1952*0Sstevel@tonic-gate 	{
1953*0Sstevel@tonic-gate 		fprintf(fp, "%c", toupper(base_name[i]));
1954*0Sstevel@tonic-gate 	}
1955*0Sstevel@tonic-gate 	fprintf(fp, "_STUB_H_\n");
1956*0Sstevel@tonic-gate 	fprintf(fp, "\n");
1957*0Sstevel@tonic-gate 
1958*0Sstevel@tonic-gate 
1959*0Sstevel@tonic-gate 	output_structure(fp, current);
1960*0Sstevel@tonic-gate 	fprintf(fp, "\n");
1961*0Sstevel@tonic-gate 
1962*0Sstevel@tonic-gate 	output_extern_function(fp, current);
1963*0Sstevel@tonic-gate 	fprintf(fp, "\n");
1964*0Sstevel@tonic-gate 
1965*0Sstevel@tonic-gate 	output_extern_trap_function(fp);
1966*0Sstevel@tonic-gate 
1967*0Sstevel@tonic-gate 	fprintf(fp, "#endif\n");
1968*0Sstevel@tonic-gate 
1969*0Sstevel@tonic-gate 	fclose(fp);
1970*0Sstevel@tonic-gate }
1971*0Sstevel@tonic-gate 
1972*0Sstevel@tonic-gate 
1973*0Sstevel@tonic-gate /*************************************************************************/
1974*0Sstevel@tonic-gate 
1975*0Sstevel@tonic-gate static void get_subids_by_name(Subid *dst,char *oid_name)
1976*0Sstevel@tonic-gate {
1977*0Sstevel@tonic-gate   struct tree *tp;
1978*0Sstevel@tonic-gate   Subid subids[MAX_OID_LEN+1];
1979*0Sstevel@tonic-gate   int i,j,len;
1980*0Sstevel@tonic-gate 
1981*0Sstevel@tonic-gate   /* find the enterprise_subids */
1982*0Sstevel@tonic-gate   if((tp = find_node(root,oid_name)) == NULL)
1983*0Sstevel@tonic-gate     fprintf (stderr, "Unknown trap enterprise variable:%s\n",oid_name);
1984*0Sstevel@tonic-gate   get_subid_of_node(tp,subids,&len);
1985*0Sstevel@tonic-gate   for(j=0,i=len-1;i>=0;i--,j++)
1986*0Sstevel@tonic-gate 	dst[j] = subids[i];
1987*0Sstevel@tonic-gate   dst[j]=(u_long)-1;
1988*0Sstevel@tonic-gate }
1989*0Sstevel@tonic-gate 
1990*0Sstevel@tonic-gate 
1991*0Sstevel@tonic-gate static void output_trap_structure(FILE *fp)
1992*0Sstevel@tonic-gate {
1993*0Sstevel@tonic-gate 	struct trap_item *ip;
1994*0Sstevel@tonic-gate 	int i, enterprise_trap;
1995*0Sstevel@tonic-gate 	struct index_list *var;
1996*0Sstevel@tonic-gate 	struct tree *tp;
1997*0Sstevel@tonic-gate 	int numCallItem = 0;
1998*0Sstevel@tonic-gate 	int numTrapElem = 0;
1999*0Sstevel@tonic-gate 	int *trapTableMap = NULL;
2000*0Sstevel@tonic-gate 	int idx, index;
2001*0Sstevel@tonic-gate 	int variableExist, columnExist = 0;
2002*0Sstevel@tonic-gate 
2003*0Sstevel@tonic-gate 
2004*0Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
2005*0Sstevel@tonic-gate 		numTrapElem++;
2006*0Sstevel@tonic-gate 		for (var = ip->var_list; var; var = var->next)
2007*0Sstevel@tonic-gate 			numCallItem++;
2008*0Sstevel@tonic-gate 	}
2009*0Sstevel@tonic-gate 
2010*0Sstevel@tonic-gate 	if (numTrapElem > 0) {
2011*0Sstevel@tonic-gate 		trapTableMap = (int *)malloc(sizeof (int) * (numTrapElem + 10));
2012*0Sstevel@tonic-gate 		if (!trapTableMap)
2013*0Sstevel@tonic-gate 			error_exit("malloc failed");
2014*0Sstevel@tonic-gate 	for (idx = 0; idx < numTrapElem+10; idx++)
2015*0Sstevel@tonic-gate 		trapTableMap[idx] = -1;
2016*0Sstevel@tonic-gate 	}
2017*0Sstevel@tonic-gate 
2018*0Sstevel@tonic-gate 	if (numCallItem > 0)
2019*0Sstevel@tonic-gate 		fprintf(fp, "struct CallbackItem genCallItem[%d] = {\n",
2020*0Sstevel@tonic-gate 			numCallItem+10);
2021*0Sstevel@tonic-gate 	else
2022*0Sstevel@tonic-gate 		fprintf(fp, "struct CallbackItem genCallItem[%d];\n",
2023*0Sstevel@tonic-gate 			numCallItem+10);
2024*0Sstevel@tonic-gate 	numCallItem = 0;
2025*0Sstevel@tonic-gate 	numTrapElem = 0;
2026*0Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
2027*0Sstevel@tonic-gate 		variableExist = 0;
2028*0Sstevel@tonic-gate 		trapTableMap[numTrapElem] = numCallItem;
2029*0Sstevel@tonic-gate 		for (var = ip->var_list; var; var = var->next) {
2030*0Sstevel@tonic-gate 			variableExist = 1;
2031*0Sstevel@tonic-gate 			if ((var->tp = find_node(root, var->label)) == NULL)
2032*0Sstevel@tonic-gate 				error_exit("output_trap_structure():Unknown \
2033*0Sstevel@tonic-gate 					variable:%s", var->label);
2034*0Sstevel@tonic-gate 				tp = var->tp;
2035*0Sstevel@tonic-gate 				if (tp->node_type == OBJECT)
2036*0Sstevel@tonic-gate 					fprintf(fp, "\t{&object_table[%d],",
2037*0Sstevel@tonic-gate 					tp->object_index);
2038*0Sstevel@tonic-gate 				else
2039*0Sstevel@tonic-gate 					if (tp->node_type == COLUMN) {
2040*0Sstevel@tonic-gate 					columnExist = 1;
2041*0Sstevel@tonic-gate 						fprintf(fp,
2042*0Sstevel@tonic-gate 					"\t{(Object *)&column_table[%d],",
2043*0Sstevel@tonic-gate 						tp->column_index);
2044*0Sstevel@tonic-gate 					} else
2045*0Sstevel@tonic-gate 						error_exit("variable: %s is not\
2046*0Sstevel@tonic-gate 						individual object", var->label);
2047*0Sstevel@tonic-gate 
2048*0Sstevel@tonic-gate 			switch (tp->type) { /* only accept object node type */
2049*0Sstevel@tonic-gate 				case TYPE_INTEGER:
2050*0Sstevel@tonic-gate 				case TYPE_COUNTER:
2051*0Sstevel@tonic-gate 				case TYPE_GAUGE:
2052*0Sstevel@tonic-gate 				case TYPE_TIMETICKS:
2053*0Sstevel@tonic-gate 					fprintf(fp, "INTEGER,");
2054*0Sstevel@tonic-gate 					break;
2055*0Sstevel@tonic-gate 				case TYPE_OCTETSTR:
2056*0Sstevel@tonic-gate 				case TYPE_IPADDR:
2057*0Sstevel@tonic-gate 				case TYPE_OPAQUE:
2058*0Sstevel@tonic-gate 					fprintf(fp, "STRING,");
2059*0Sstevel@tonic-gate 					break;
2060*0Sstevel@tonic-gate 				case TYPE_OBJID:
2061*0Sstevel@tonic-gate 					fprintf(fp, "OBJID,");
2062*0Sstevel@tonic-gate 					break;
2063*0Sstevel@tonic-gate 				default:
2064*0Sstevel@tonic-gate 					error_exit("unknown object type of \
2065*0Sstevel@tonic-gate 					variable %s", var->label);
2066*0Sstevel@tonic-gate 			}
2067*0Sstevel@tonic-gate 		numCallItem++;
2068*0Sstevel@tonic-gate 		if (var->next)
2069*0Sstevel@tonic-gate 			fprintf(fp, "%d},\n", numCallItem);
2070*0Sstevel@tonic-gate 		else
2071*0Sstevel@tonic-gate 			fprintf(fp, "-1},\n");
2072*0Sstevel@tonic-gate 		}
2073*0Sstevel@tonic-gate 		if (variableExist == 0)
2074*0Sstevel@tonic-gate 			trapTableMap[numTrapElem] = -1;
2075*0Sstevel@tonic-gate 	numTrapElem++;
2076*0Sstevel@tonic-gate 	}
2077*0Sstevel@tonic-gate 	if (numCallItem > 0) fprintf(fp, "};\n");
2078*0Sstevel@tonic-gate 	fprintf(fp, "int genNumCallItem = %d;\n", numCallItem);
2079*0Sstevel@tonic-gate 
2080*0Sstevel@tonic-gate 	/* dumby the map */
2081*0Sstevel@tonic-gate 	if (numTrapElem > 0)
2082*0Sstevel@tonic-gate 		fprintf(fp, "int genTrapTableMap[%d] = {\n", numTrapElem + 10);
2083*0Sstevel@tonic-gate 	else
2084*0Sstevel@tonic-gate 		fprintf(fp, "int genTrapTableMap[%d];\n", numTrapElem + 10);
2085*0Sstevel@tonic-gate 	for (idx = 0; idx < numTrapElem; idx++) {
2086*0Sstevel@tonic-gate 		fprintf(fp, "%d,", trapTableMap[idx]);
2087*0Sstevel@tonic-gate 	}
2088*0Sstevel@tonic-gate 	if (numTrapElem > 0) fprintf(fp, "};\n");
2089*0Sstevel@tonic-gate 
2090*0Sstevel@tonic-gate 	fprintf(fp, "int genNumTrapElem = %d;\n", numTrapElem);
2091*0Sstevel@tonic-gate 	if (numTrapElem > 0)
2092*0Sstevel@tonic-gate 		fprintf(fp, "struct TrapHndlCxt genTrapBucket[%d] = {\n",
2093*0Sstevel@tonic-gate 			numTrapElem + 10);
2094*0Sstevel@tonic-gate 	else
2095*0Sstevel@tonic-gate 		fprintf(fp, "struct TrapHndlCxt genTrapBucket[%d];\n",
2096*0Sstevel@tonic-gate 			numTrapElem+10);
2097*0Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
2098*0Sstevel@tonic-gate 		fprintf(fp, "\t{\"%s\",", ip->label);
2099*0Sstevel@tonic-gate 		if (!strcmp(ip->enterprise_label, "snmp"))
2100*0Sstevel@tonic-gate 			fprintf(fp, "0,");
2101*0Sstevel@tonic-gate 		else
2102*0Sstevel@tonic-gate 			fprintf(fp, "1,");
2103*0Sstevel@tonic-gate 		if (!strcmp(ip->enterprise_label, "snmp")) {
2104*0Sstevel@tonic-gate 			for (i = 0; i < 8; i++) {
2105*0Sstevel@tonic-gate 				ip->enterprise_subids[i] = snmp_subids[i];
2106*0Sstevel@tonic-gate 			}
2107*0Sstevel@tonic-gate 		} else {
2108*0Sstevel@tonic-gate 			get_subids_by_name(ip->enterprise_subids,
2109*0Sstevel@tonic-gate 				ip->enterprise_label);
2110*0Sstevel@tonic-gate 		}
2111*0Sstevel@tonic-gate 
2112*0Sstevel@tonic-gate 		enterprise_trap = FALSE;
2113*0Sstevel@tonic-gate 		for (i = 0; i < 7; i++) {
2114*0Sstevel@tonic-gate 			if (ip->enterprise_subids[i] != snmp_subids[i]) {
2115*0Sstevel@tonic-gate 				enterprise_trap = TRUE;
2116*0Sstevel@tonic-gate 				break;
2117*0Sstevel@tonic-gate 			}
2118*0Sstevel@tonic-gate 		}
2119*0Sstevel@tonic-gate 		if (enterprise_trap) {
2120*0Sstevel@tonic-gate 			fprintf(fp, "6,");
2121*0Sstevel@tonic-gate 			fprintf(fp, "%d},\n", ip->value);
2122*0Sstevel@tonic-gate 		} else {
2123*0Sstevel@tonic-gate 			fprintf(fp, "%d,", ip->value);
2124*0Sstevel@tonic-gate 			fprintf(fp, "0},\n");
2125*0Sstevel@tonic-gate 		}
2126*0Sstevel@tonic-gate 	}
2127*0Sstevel@tonic-gate 	if (numTrapElem > 0) fprintf(fp, "};\n");
2128*0Sstevel@tonic-gate 
2129*0Sstevel@tonic-gate /* For arbitrary length enterprise OID in traps - bug 4133978 */
2130*0Sstevel@tonic-gate /* Initializing new trap enterprise info which handles arbitrary subids */
2131*0Sstevel@tonic-gate 	if (numTrapElem > 0)
2132*0Sstevel@tonic-gate 		fprintf(fp,
2133*0Sstevel@tonic-gate 	"struct TrapAnyEnterpriseInfo genTrapAnyEnterpriseInfo[%d] = {\n",
2134*0Sstevel@tonic-gate 		numTrapElem + 10);
2135*0Sstevel@tonic-gate 	else
2136*0Sstevel@tonic-gate 		fprintf(fp, "struct TrapAnyEnterpriseInfo \
2137*0Sstevel@tonic-gate 			genTrapAnyEnterpriseInfo[%d]; \n", numTrapElem + 10);
2138*0Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
2139*0Sstevel@tonic-gate 		fprintf(fp, "\t{");
2140*0Sstevel@tonic-gate 		for (i = 0; ip->enterprise_subids[i] != -1; i++) {
2141*0Sstevel@tonic-gate 			fprintf(fp, "%d, ", ip->enterprise_subids[i]);
2142*0Sstevel@tonic-gate 		}
2143*0Sstevel@tonic-gate 		fprintf(fp, "(uint32_t)-1},\n");
2144*0Sstevel@tonic-gate 	}
2145*0Sstevel@tonic-gate 	if (numTrapElem > 0) fprintf(fp, "};\n");
2146*0Sstevel@tonic-gate 
2147*0Sstevel@tonic-gate 	if (numTrapElem == 0)
2148*0Sstevel@tonic-gate 		return;
2149*0Sstevel@tonic-gate 
2150*0Sstevel@tonic-gate 	fprintf(fp, "struct _CallTrapIndx { \n");
2151*0Sstevel@tonic-gate 	fprintf(fp, "\tchar name[256];\n");
2152*0Sstevel@tonic-gate 	fprintf(fp, "\tIndexType *pindex_obj; \n");
2153*0Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
2154*0Sstevel@tonic-gate 
2155*0Sstevel@tonic-gate 	fprintf(fp, "struct _Indx { \n");
2156*0Sstevel@tonic-gate 	fprintf(fp, "\tchar name[256]; \n");
2157*0Sstevel@tonic-gate 	fprintf(fp, "\tint index; \n");
2158*0Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
2159*0Sstevel@tonic-gate 
2160*0Sstevel@tonic-gate 	if (columnExist != 0) {
2161*0Sstevel@tonic-gate 	index = 0;
2162*0Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
2163*0Sstevel@tonic-gate 		for (var = ip->var_list; var; var = var->next) {
2164*0Sstevel@tonic-gate 			tp = var->tp;
2165*0Sstevel@tonic-gate 			if (tp->node_type == COLUMN) {
2166*0Sstevel@tonic-gate 				index++;
2167*0Sstevel@tonic-gate 			}
2168*0Sstevel@tonic-gate 		}
2169*0Sstevel@tonic-gate 	}
2170*0Sstevel@tonic-gate 
2171*0Sstevel@tonic-gate 	fprintf(fp, "int numIndxElem = %d; \n", index);
2172*0Sstevel@tonic-gate 	fprintf(fp, "struct _Indx Indx[%d] = { \n", index);
2173*0Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
2174*0Sstevel@tonic-gate 		for (var = ip->var_list; var; var = var->next) {
2175*0Sstevel@tonic-gate 			tp = var->tp;
2176*0Sstevel@tonic-gate 			if (tp->node_type == COLUMN) {
2177*0Sstevel@tonic-gate 				fprintf(fp, "\t{\"%s\", 0},\n", var->label);
2178*0Sstevel@tonic-gate 			}
2179*0Sstevel@tonic-gate 		}
2180*0Sstevel@tonic-gate 	}
2181*0Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
2182*0Sstevel@tonic-gate 	fprintf(fp, "int SSASetVarIndx(char* name, int index)\n{\n");
2183*0Sstevel@tonic-gate 	fprintf(fp, "\tint i;\n\n");
2184*0Sstevel@tonic-gate 	fprintf(fp, "\tif (!name) \n");
2185*0Sstevel@tonic-gate 	fprintf(fp, "\treturn (-1); \n\n");
2186*0Sstevel@tonic-gate 	fprintf(fp, "\tfor (i = 0; i < numIndxElem; i++) \n");
2187*0Sstevel@tonic-gate 	fprintf(fp, "\t\tif (!strcmp(name, Indx[i].name)) { \n");
2188*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\tIndx[i].index = index;\n");
2189*0Sstevel@tonic-gate 	fprintf(fp, "\t\t\treturn (0);\n");
2190*0Sstevel@tonic-gate 	fprintf(fp, "\t\t}\n");
2191*0Sstevel@tonic-gate 	fprintf(fp, "\treturn (-1);\n");
2192*0Sstevel@tonic-gate 	fprintf(fp, "}\n\n");
2193*0Sstevel@tonic-gate 	}
2194*0Sstevel@tonic-gate 
2195*0Sstevel@tonic-gate 	index = 0;
2196*0Sstevel@tonic-gate 	fprintf(fp, "IndexType TrapIndx[%d] = { \n", numCallItem);
2197*0Sstevel@tonic-gate 		for (ip = trap_list; ip; ip = ip->next) {
2198*0Sstevel@tonic-gate 			for (var = ip->var_list; var; var = var->next) {
2199*0Sstevel@tonic-gate 				tp = var->tp;
2200*0Sstevel@tonic-gate 				if (tp->node_type == OBJECT)
2201*0Sstevel@tonic-gate 					fprintf(fp, "\t{0,0,NULL},\n");
2202*0Sstevel@tonic-gate 				else if (tp->node_type == COLUMN) {
2203*0Sstevel@tonic-gate 					fprintf(fp,
2204*0Sstevel@tonic-gate 					"\t{1,1,&Indx[%d].index},\n", index++);
2205*0Sstevel@tonic-gate 				} else
2206*0Sstevel@tonic-gate 					error_exit("variable: %s is not \
2207*0Sstevel@tonic-gate 					individual object", var->label);
2208*0Sstevel@tonic-gate 			}
2209*0Sstevel@tonic-gate 		}
2210*0Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
2211*0Sstevel@tonic-gate 
2212*0Sstevel@tonic-gate 	fprintf(fp, "struct _CallTrapIndx CallTrapIndx[%d] = {\n", numTrapElem);
2213*0Sstevel@tonic-gate 		for (idx = 0, ip = trap_list; ip && idx < numTrapElem;
2214*0Sstevel@tonic-gate 			ip = ip->next, idx++) {
2215*0Sstevel@tonic-gate 			fprintf(fp, "\t{\"%s\",&TrapIndx[%d]},\n", ip->label,
2216*0Sstevel@tonic-gate 			trapTableMap[idx]);
2217*0Sstevel@tonic-gate 		}
2218*0Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
2219*0Sstevel@tonic-gate 
2220*0Sstevel@tonic-gate 
2221*0Sstevel@tonic-gate 	if (numTrapElem > 0) {
2222*0Sstevel@tonic-gate 		fprintf(fp, "int SSASendTrap(char* name)\n");
2223*0Sstevel@tonic-gate 		fprintf(fp, "{\n");
2224*0Sstevel@tonic-gate 		fprintf(fp, "\tint i;\n\n");
2225*0Sstevel@tonic-gate 		fprintf(fp, "\tif (!name) \n");
2226*0Sstevel@tonic-gate 		fprintf(fp, "\treturn (-1);\n\n");
2227*0Sstevel@tonic-gate 
2228*0Sstevel@tonic-gate 		fprintf(fp, "\tnumCallItem = genNumCallItem;\n");
2229*0Sstevel@tonic-gate 		fprintf(fp, "\tnumTrapElem = genNumTrapElem;\n");
2230*0Sstevel@tonic-gate 		fprintf(fp, "\tcallItem = genCallItem;\n");
2231*0Sstevel@tonic-gate 		fprintf(fp, "\ttrapTableMap = genTrapTableMap;\n");
2232*0Sstevel@tonic-gate 		fprintf(fp, "\ttrapBucket = genTrapBucket;\n");
2233*0Sstevel@tonic-gate 		fprintf(fp,
2234*0Sstevel@tonic-gate 		"\ttrapAnyEnterpriseInfo = genTrapAnyEnterpriseInfo;\n");
2235*0Sstevel@tonic-gate 	/* SSASendTrap4 handles tabular column elements - 4519879 */
2236*0Sstevel@tonic-gate 		fprintf(fp, "\tfor (i = 0; i < numTrapElem; i++) \n");
2237*0Sstevel@tonic-gate 	fprintf(fp, "\tif (!strcmp(name, CallTrapIndx[i].name)) \n");
2238*0Sstevel@tonic-gate 	fprintf(fp, "\t\treturn \
2239*0Sstevel@tonic-gate 	(_SSASendTrap4(name, CallTrapIndx[i].pindex_obj)); \n");
2240*0Sstevel@tonic-gate 	fprintf(fp, "\treturn (-1); \n");
2241*0Sstevel@tonic-gate 	fprintf(fp, "}\n");
2242*0Sstevel@tonic-gate 	}
2243*0Sstevel@tonic-gate }
2244*0Sstevel@tonic-gate 
2245*0Sstevel@tonic-gate 
2246*0Sstevel@tonic-gate static void output_entry_function(FILE *fp, struct tree *current)
2247*0Sstevel@tonic-gate {
2248*0Sstevel@tonic-gate 	struct tree *tp;
2249*0Sstevel@tonic-gate 	struct index_list *indexs;
2250*0Sstevel@tonic-gate 	struct tree *child;
2251*0Sstevel@tonic-gate 	int first_time_entry_print;
2252*0Sstevel@tonic-gate 
2253*0Sstevel@tonic-gate 
2254*0Sstevel@tonic-gate 	switch(current->node_type)
2255*0Sstevel@tonic-gate 	{
2256*0Sstevel@tonic-gate 		case COLUMN:
2257*0Sstevel@tonic-gate 			if( !(current->access & WRITE_FLAG) )
2258*0Sstevel@tonic-gate 			{
2259*0Sstevel@tonic-gate 				break;
2260*0Sstevel@tonic-gate 			}
2261*0Sstevel@tonic-gate 			break;
2262*0Sstevel@tonic-gate 		case ENTRY:
2263*0Sstevel@tonic-gate 			/* open a new file */
2264*0Sstevel@tonic-gate 			fclose(fp);
2265*0Sstevel@tonic-gate 		        fp = output_file(current->label);
2266*0Sstevel@tonic-gate 			fprintf(fp, "\n");
2267*0Sstevel@tonic-gate 			fprintf(fp, "/***** %-20s ********************************/\n",
2268*0Sstevel@tonic-gate 				current->label);
2269*0Sstevel@tonic-gate 			break;
2270*0Sstevel@tonic-gate 	}
2271*0Sstevel@tonic-gate 
2272*0Sstevel@tonic-gate 	switch(current->node_type)
2273*0Sstevel@tonic-gate 	{
2274*0Sstevel@tonic-gate 		case COLUMN:
2275*0Sstevel@tonic-gate 			if(current->access & READ_FLAG)
2276*0Sstevel@tonic-gate 			{
2277*0Sstevel@tonic-gate 				fprintf(fp, "\n");
2278*0Sstevel@tonic-gate 				fprintf(fp, "int get_%s(int search_type, ",
2279*0Sstevel@tonic-gate 					current->label);
2280*0Sstevel@tonic-gate 
2281*0Sstevel@tonic-gate 				switch(current->type)
2282*0Sstevel@tonic-gate 				{
2283*0Sstevel@tonic-gate 					case TYPE_INTEGER:
2284*0Sstevel@tonic-gate 					case TYPE_COUNTER:
2285*0Sstevel@tonic-gate 					case TYPE_GAUGE:
2286*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
2287*0Sstevel@tonic-gate 						fprintf(fp, "Integer *%s, ",
2288*0Sstevel@tonic-gate 							current->label);
2289*0Sstevel@tonic-gate 						break;
2290*0Sstevel@tonic-gate 
2291*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
2292*0Sstevel@tonic-gate 					case TYPE_IPADDR:
2293*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
2294*0Sstevel@tonic-gate 						fprintf(fp, "String *%s, ",
2295*0Sstevel@tonic-gate 							current->label);
2296*0Sstevel@tonic-gate 						break;
2297*0Sstevel@tonic-gate 
2298*0Sstevel@tonic-gate 					case TYPE_OBJID:
2299*0Sstevel@tonic-gate 						fprintf(fp, "Oid *%s, ",
2300*0Sstevel@tonic-gate 							current->label);
2301*0Sstevel@tonic-gate 						break;
2302*0Sstevel@tonic-gate 
2303*0Sstevel@tonic-gate 					default:
2304*0Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
2305*0Sstevel@tonic-gate 						current->type,
2306*0Sstevel@tonic-gate 						current->label);
2307*0Sstevel@tonic-gate 				}
2308*0Sstevel@tonic-gate 
2309*0Sstevel@tonic-gate 				indexs = current->parent->indexs;
2310*0Sstevel@tonic-gate 
2311*0Sstevel@tonic-gate /* not more ind. index */
2312*0Sstevel@tonic-gate 
2313*0Sstevel@tonic-gate 				if(indexs)
2314*0Sstevel@tonic-gate 				{
2315*0Sstevel@tonic-gate 					if(indexs->tp)
2316*0Sstevel@tonic-gate 					{
2317*0Sstevel@tonic-gate 						switch(indexs->tp->type)
2318*0Sstevel@tonic-gate 						{
2319*0Sstevel@tonic-gate 							case TYPE_INTEGER:
2320*0Sstevel@tonic-gate 							case TYPE_COUNTER:
2321*0Sstevel@tonic-gate 							case TYPE_GAUGE:
2322*0Sstevel@tonic-gate 							case TYPE_TIMETICKS:
2323*0Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s)\n",
2324*0Sstevel@tonic-gate 									"index");
2325*0Sstevel@tonic-gate 								break;
2326*0Sstevel@tonic-gate 
2327*0Sstevel@tonic-gate 							case TYPE_OCTETSTR:
2328*0Sstevel@tonic-gate 							case TYPE_IPADDR:
2329*0Sstevel@tonic-gate 							case TYPE_OPAQUE:
2330*0Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s)\n",
2331*0Sstevel@tonic-gate 									"index");
2332*0Sstevel@tonic-gate 								break;
2333*0Sstevel@tonic-gate 
2334*0Sstevel@tonic-gate 							case TYPE_OBJID:
2335*0Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s)\n",
2336*0Sstevel@tonic-gate 									"index");
2337*0Sstevel@tonic-gate 								break;
2338*0Sstevel@tonic-gate 
2339*0Sstevel@tonic-gate 							default:
2340*0Sstevel@tonic-gate 								error_exit("output_extern_function(): Unknown type (%d) for %s",
2341*0Sstevel@tonic-gate 								indexs->tp->type,
2342*0Sstevel@tonic-gate 								indexs->tp->label);
2343*0Sstevel@tonic-gate 						}
2344*0Sstevel@tonic-gate 					}
2345*0Sstevel@tonic-gate 					else
2346*0Sstevel@tonic-gate 					{
2347*0Sstevel@tonic-gate 						error("WARNING: By default, the type of INDEX %s set to INTEGER",
2348*0Sstevel@tonic-gate 							indexs->label);
2349*0Sstevel@tonic-gate 						fprintf(fp, "IndexType *%s)\n",
2350*0Sstevel@tonic-gate 								"index");
2351*0Sstevel@tonic-gate 					}
2352*0Sstevel@tonic-gate 
2353*0Sstevel@tonic-gate 					indexs = indexs->next;
2354*0Sstevel@tonic-gate 				}
2355*0Sstevel@tonic-gate 
2356*0Sstevel@tonic-gate 			PRINT_OPEN_BRACKET
2357*0Sstevel@tonic-gate 
2358*0Sstevel@tonic-gate 			switch(current->type)
2359*0Sstevel@tonic-gate 			{
2360*0Sstevel@tonic-gate 						case TYPE_INTEGER:
2361*0Sstevel@tonic-gate 						case TYPE_COUNTER:
2362*0Sstevel@tonic-gate 						case TYPE_TIMETICKS:
2363*0Sstevel@tonic-gate 						case TYPE_GAUGE:
2364*0Sstevel@tonic-gate 							PRINT_GET_CASE_BLOCK
2365*0Sstevel@tonic-gate 							fprintf(fp,"\t/*assume that the mib variable has a value of 1 */\n\n");
2366*0Sstevel@tonic-gate 							fprintf(fp,"\t*%s = 1;\n",current->label);
2367*0Sstevel@tonic-gate 							fprintf(fp,"\treturn SNMP_ERR_NOERROR;\n");
2368*0Sstevel@tonic-gate 							break;
2369*0Sstevel@tonic-gate 
2370*0Sstevel@tonic-gate 						case TYPE_OCTETSTR:
2371*0Sstevel@tonic-gate 						case TYPE_IPADDR:
2372*0Sstevel@tonic-gate 						case TYPE_OPAQUE:
2373*0Sstevel@tonic-gate 							fprintf(fp, "\tu_char *str;\n");
2374*0Sstevel@tonic-gate 							fprintf(fp, "\tint len;\n\n");
2375*0Sstevel@tonic-gate 							PRINT_GET_CASE_BLOCK
2376*0Sstevel@tonic-gate 							PRINT_GET_STRING_DUMBY_BLOCK
2377*0Sstevel@tonic-gate 							break;
2378*0Sstevel@tonic-gate 
2379*0Sstevel@tonic-gate 						case TYPE_OBJID:
2380*0Sstevel@tonic-gate 							fprintf(fp, "\tSubid *sub;\n");
2381*0Sstevel@tonic-gate 							fprintf(fp, "\tSubid fake_sub[] = {1,3,6,1,4,1,4,42};\n");
2382*0Sstevel@tonic-gate 							fprintf(fp, "\tint len;\n\n");
2383*0Sstevel@tonic-gate 							PRINT_GET_CASE_BLOCK
2384*0Sstevel@tonic-gate 							PRINT_GET_OID_DUMBY_BLOCK
2385*0Sstevel@tonic-gate 							break;
2386*0Sstevel@tonic-gate 
2387*0Sstevel@tonic-gate 							default:
2388*0Sstevel@tonic-gate 								error_exit("output_extern_function(): Unknown type (%d) for %s",
2389*0Sstevel@tonic-gate 								current->type,
2390*0Sstevel@tonic-gate 								current->label);
2391*0Sstevel@tonic-gate 			}
2392*0Sstevel@tonic-gate 
2393*0Sstevel@tonic-gate 				PRINT_CLOSE_BRACKET
2394*0Sstevel@tonic-gate 			}
2395*0Sstevel@tonic-gate 
2396*0Sstevel@tonic-gate 			if(current->access & WRITE_FLAG)
2397*0Sstevel@tonic-gate 			{
2398*0Sstevel@tonic-gate 				fprintf(fp, "\n");
2399*0Sstevel@tonic-gate 				fprintf(fp, "int set_%s(int pass, ",
2400*0Sstevel@tonic-gate 					current->label);
2401*0Sstevel@tonic-gate 
2402*0Sstevel@tonic-gate 				indexs = current->parent->indexs;
2403*0Sstevel@tonic-gate 
2404*0Sstevel@tonic-gate 				/* no more ind. index */
2405*0Sstevel@tonic-gate 				if(indexs)
2406*0Sstevel@tonic-gate 				{
2407*0Sstevel@tonic-gate 					if(indexs->tp)
2408*0Sstevel@tonic-gate 					{
2409*0Sstevel@tonic-gate 						switch(indexs->tp->type)
2410*0Sstevel@tonic-gate 						{
2411*0Sstevel@tonic-gate 							case TYPE_INTEGER:
2412*0Sstevel@tonic-gate 							case TYPE_COUNTER:
2413*0Sstevel@tonic-gate 							case TYPE_GAUGE:
2414*0Sstevel@tonic-gate 							case TYPE_TIMETICKS:
2415*0Sstevel@tonic-gate 							case TYPE_OCTETSTR:
2416*0Sstevel@tonic-gate 							case TYPE_IPADDR:
2417*0Sstevel@tonic-gate 							case TYPE_OPAQUE:
2418*0Sstevel@tonic-gate 							case TYPE_OBJID:
2419*0Sstevel@tonic-gate 								fprintf(fp, "IndexType %s, ",
2420*0Sstevel@tonic-gate 									"index");
2421*0Sstevel@tonic-gate 								break;
2422*0Sstevel@tonic-gate 
2423*0Sstevel@tonic-gate 							default:
2424*0Sstevel@tonic-gate 								error_exit("output_function(): Unknown type (%d) for %s",
2425*0Sstevel@tonic-gate 									indexs->tp->type,
2426*0Sstevel@tonic-gate 								indexs->tp->label);
2427*0Sstevel@tonic-gate 						}
2428*0Sstevel@tonic-gate 					}
2429*0Sstevel@tonic-gate 					else
2430*0Sstevel@tonic-gate 					{
2431*0Sstevel@tonic-gate 						error("WARNING: By default, the type of INDEX %s set to INTEGER",
2432*0Sstevel@tonic-gate 							indexs->label);
2433*0Sstevel@tonic-gate 						fprintf(fp, "Integer %s, ",
2434*0Sstevel@tonic-gate 							indexs->label);
2435*0Sstevel@tonic-gate 					}
2436*0Sstevel@tonic-gate 					indexs = indexs->next;
2437*0Sstevel@tonic-gate 				}
2438*0Sstevel@tonic-gate 
2439*0Sstevel@tonic-gate 
2440*0Sstevel@tonic-gate 				switch(current->type)
2441*0Sstevel@tonic-gate 				{
2442*0Sstevel@tonic-gate 					case TYPE_INTEGER:
2443*0Sstevel@tonic-gate 					case TYPE_COUNTER:
2444*0Sstevel@tonic-gate 					case TYPE_GAUGE:
2445*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
2446*0Sstevel@tonic-gate 						fprintf(fp, "Integer *%s)\n",
2447*0Sstevel@tonic-gate 							current->label);
2448*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2449*0Sstevel@tonic-gate 						SET_PRINT_ENTRY_BLOCK
2450*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%d\\n\",%s);\n",current->label);
2451*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
2452*0Sstevel@tonic-gate 						break;
2453*0Sstevel@tonic-gate 
2454*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
2455*0Sstevel@tonic-gate 					case TYPE_IPADDR:
2456*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
2457*0Sstevel@tonic-gate 						fprintf(fp, "String *%s)\n",
2458*0Sstevel@tonic-gate 							current->label);
2459*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2460*0Sstevel@tonic-gate 						fprintf(fp, "\tchar buf[100];\n\n");
2461*0Sstevel@tonic-gate 						SET_PRINT_ENTRY_BLOCK
2462*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tmemcpy(buf,%s->chars,%s->len);\n",current->label,current->label);
2463*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tbuf[%s->len+1] = '\\0';\n",current->label);
2464*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%s\\n\",buf);\n");
2465*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
2466*0Sstevel@tonic-gate 						break;
2467*0Sstevel@tonic-gate 
2468*0Sstevel@tonic-gate 					case TYPE_OBJID:
2469*0Sstevel@tonic-gate 						fprintf(fp, "Oid *%s)\n",
2470*0Sstevel@tonic-gate 							current->label);
2471*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2472*0Sstevel@tonic-gate 						SET_PRINT_ENTRY_BLOCK
2473*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%s\\n\",SSAOidString(%s));\n",current->label);
2474*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
2475*0Sstevel@tonic-gate 						break;
2476*0Sstevel@tonic-gate 
2477*0Sstevel@tonic-gate 					default:
2478*0Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s",
2479*0Sstevel@tonic-gate 							current->type,
2480*0Sstevel@tonic-gate 							current->label);
2481*0Sstevel@tonic-gate 				}
2482*0Sstevel@tonic-gate 				PRINT_TAG_CLOSE_BRACKET
2483*0Sstevel@tonic-gate 				PRINT_CLOSE_BRACKET
2484*0Sstevel@tonic-gate 				fprintf(fp, "\n");
2485*0Sstevel@tonic-gate 			}
2486*0Sstevel@tonic-gate 
2487*0Sstevel@tonic-gate 			if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
2488*0Sstevel@tonic-gate 			{
2489*0Sstevel@tonic-gate 				switch(current->type)
2490*0Sstevel@tonic-gate 				{
2491*0Sstevel@tonic-gate 					case TYPE_INTEGER:
2492*0Sstevel@tonic-gate 					case TYPE_COUNTER:
2493*0Sstevel@tonic-gate 					case TYPE_GAUGE:
2494*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-95)*/
2495*0Sstevel@tonic-gate 						break;
2496*0Sstevel@tonic-gate 
2497*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
2498*0Sstevel@tonic-gate 					case TYPE_IPADDR:
2499*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
2500*0Sstevel@tonic-gate 						fprintf(fp, "\n");
2501*0Sstevel@tonic-gate 						fprintf(fp, "void free_%s(String *%s)\n",
2502*0Sstevel@tonic-gate 							current->label,
2503*0Sstevel@tonic-gate 							current->label);
2504*0Sstevel@tonic-gate                                 		fprintf(fp, "{\n");
2505*0Sstevel@tonic-gate                                 		fprintf(fp, "\t if(%s->",current->label);
2506*0Sstevel@tonic-gate 						break;
2507*0Sstevel@tonic-gate 
2508*0Sstevel@tonic-gate 					case TYPE_OBJID:
2509*0Sstevel@tonic-gate 						fprintf(fp, "\n");
2510*0Sstevel@tonic-gate 						fprintf(fp, "void free_%s(Oid *%s)\n",
2511*0Sstevel@tonic-gate 							current->label,
2512*0Sstevel@tonic-gate 							current->label);
2513*0Sstevel@tonic-gate                                 		fprintf(fp, "{\n");
2514*0Sstevel@tonic-gate                                 		fprintf(fp, "\t if(%s->",current->label);
2515*0Sstevel@tonic-gate 						break;
2516*0Sstevel@tonic-gate 
2517*0Sstevel@tonic-gate 					default:
2518*0Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
2519*0Sstevel@tonic-gate 							current->type,
2520*0Sstevel@tonic-gate 							current->label);
2521*0Sstevel@tonic-gate 				}
2522*0Sstevel@tonic-gate                                 switch(current->type)
2523*0Sstevel@tonic-gate                                 {
2524*0Sstevel@tonic-gate                                         case TYPE_INTEGER:
2525*0Sstevel@tonic-gate                                         case TYPE_COUNTER:
2526*0Sstevel@tonic-gate                                         case TYPE_GAUGE:
2527*0Sstevel@tonic-gate                                         case TYPE_TIMETICKS:
2528*0Sstevel@tonic-gate                                                 break;
2529*0Sstevel@tonic-gate 
2530*0Sstevel@tonic-gate                                         case TYPE_OCTETSTR:
2531*0Sstevel@tonic-gate                                         case TYPE_IPADDR:
2532*0Sstevel@tonic-gate                                         case TYPE_OPAQUE:
2533*0Sstevel@tonic-gate                                                 fprintf(fp, "chars!=NULL && %s->len !=0)\n",current->label);
2534*0Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
2535*0Sstevel@tonic-gate                                                 fprintf(fp, "\t\tfree(%s->chars);\n",current->label);
2536*0Sstevel@tonic-gate                                                 fprintf(fp,"\t\t%s->len = 0;\n",current->label);
2537*0Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
2538*0Sstevel@tonic-gate                                 		fprintf(fp, "}\n");
2539*0Sstevel@tonic-gate                                                 break;
2540*0Sstevel@tonic-gate 
2541*0Sstevel@tonic-gate                                         case TYPE_OBJID:
2542*0Sstevel@tonic-gate                                                 fprintf(fp, "subids!=NULL && %s->len !=0)\n",current->label);
2543*0Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
2544*0Sstevel@tonic-gate                                                 fprintf(fp, "\t\tfree(%s->subids);\n",current->label);
2545*0Sstevel@tonic-gate                                                 fprintf(fp,"\t\t%s->len = 0;\n",current->label);
2546*0Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
2547*0Sstevel@tonic-gate                                 		fprintf(fp, "}\n");
2548*0Sstevel@tonic-gate                                                 break;
2549*0Sstevel@tonic-gate 
2550*0Sstevel@tonic-gate                                         default:
2551*0Sstevel@tonic-gate                                                 error_exit("output_function(): Unknown type (%d) for %s",
2552*0Sstevel@tonic-gate                                                         current->type,
2553*0Sstevel@tonic-gate                                                         current->label);
2554*0Sstevel@tonic-gate                                 }
2555*0Sstevel@tonic-gate 			}
2556*0Sstevel@tonic-gate 
2557*0Sstevel@tonic-gate 			break;
2558*0Sstevel@tonic-gate 
2559*0Sstevel@tonic-gate 
2560*0Sstevel@tonic-gate 		case ENTRY:
2561*0Sstevel@tonic-gate 			fprintf(fp, "\n");
2562*0Sstevel@tonic-gate 			fprintf(fp, "extern int get_%s(int search_type, %c%s_t **%s_data",
2563*0Sstevel@tonic-gate 				current->label,
2564*0Sstevel@tonic-gate 				toupper(current->label[0]),
2565*0Sstevel@tonic-gate 				&(current->label[1]),
2566*0Sstevel@tonic-gate 				current->label);
2567*0Sstevel@tonic-gate 
2568*0Sstevel@tonic-gate 			indexs = current->indexs;
2569*0Sstevel@tonic-gate 
2570*0Sstevel@tonic-gate /* no more ind. index */
2571*0Sstevel@tonic-gate 			if(indexs)
2572*0Sstevel@tonic-gate 			{
2573*0Sstevel@tonic-gate 				if(indexs->tp)
2574*0Sstevel@tonic-gate 				{
2575*0Sstevel@tonic-gate 					switch(indexs->tp->type)
2576*0Sstevel@tonic-gate 					{
2577*0Sstevel@tonic-gate 						case TYPE_INTEGER:
2578*0Sstevel@tonic-gate 						case TYPE_COUNTER:
2579*0Sstevel@tonic-gate 						case TYPE_GAUGE:
2580*0Sstevel@tonic-gate 						case TYPE_TIMETICKS:
2581*0Sstevel@tonic-gate 
2582*0Sstevel@tonic-gate 						case TYPE_OCTETSTR:
2583*0Sstevel@tonic-gate 						case TYPE_IPADDR:
2584*0Sstevel@tonic-gate 						case TYPE_OPAQUE:
2585*0Sstevel@tonic-gate 
2586*0Sstevel@tonic-gate 						case TYPE_OBJID:
2587*0Sstevel@tonic-gate 							fprintf(fp, ", IndexType *%s",
2588*0Sstevel@tonic-gate 								"index");
2589*0Sstevel@tonic-gate 							break;
2590*0Sstevel@tonic-gate 
2591*0Sstevel@tonic-gate 						default:
2592*0Sstevel@tonic-gate 							error_exit("output_function(): Unknown type (%d) for %s",
2593*0Sstevel@tonic-gate 								indexs->tp->type,
2594*0Sstevel@tonic-gate 								indexs->tp->label);
2595*0Sstevel@tonic-gate 					}
2596*0Sstevel@tonic-gate 				}
2597*0Sstevel@tonic-gate 				else
2598*0Sstevel@tonic-gate 				{
2599*0Sstevel@tonic-gate 					error("WARNING: By default, the type of INDEX %s set to INTEGER",
2600*0Sstevel@tonic-gate 						indexs->label);
2601*0Sstevel@tonic-gate 					fprintf(fp, ", Integer *%s",
2602*0Sstevel@tonic-gate 						indexs->label);
2603*0Sstevel@tonic-gate 				}
2604*0Sstevel@tonic-gate 
2605*0Sstevel@tonic-gate 				indexs = indexs->next;
2606*0Sstevel@tonic-gate 			}
2607*0Sstevel@tonic-gate 			fprintf(fp, ")\n");
2608*0Sstevel@tonic-gate 			fprintf(fp, "{\n");
2609*0Sstevel@tonic-gate 			fprintf(fp, "\n");
2610*0Sstevel@tonic-gate 			fprintf(fp, "\tint res;\n");
2611*0Sstevel@tonic-gate 			fprintf(fp, "\tIndexType backupIndex, useIndex;\n");
2612*0Sstevel@tonic-gate 			fprintf(fp, "\tint i;\n");
2613*0Sstevel@tonic-gate 			fprintf(fp, "\n");
2614*0Sstevel@tonic-gate 			fprintf(fp, "\t*%s_data = (%c%s_t*)calloc(1,sizeof(%c%s_t));\n",
2615*0Sstevel@tonic-gate 					current->label,
2616*0Sstevel@tonic-gate 					toupper(current->label[0]), &(current->label[1]),
2617*0Sstevel@tonic-gate 					toupper(current->label[0]), &(current->label[1]));
2618*0Sstevel@tonic-gate 			fprintf(fp,"\tif(%s_data == NULL) return SNMP_ERR_GENERR;\n",current->label);
2619*0Sstevel@tonic-gate 			fprintf(fp,"\n");
2620*0Sstevel@tonic-gate 
2621*0Sstevel@tonic-gate 				first_time_entry_print = 0;
2622*0Sstevel@tonic-gate 				for(child = current->child_list; child; child = child->next_peer)
2623*0Sstevel@tonic-gate 				{
2624*0Sstevel@tonic-gate 					if(!(child->access & READ_FLAG) )
2625*0Sstevel@tonic-gate 						continue;
2626*0Sstevel@tonic-gate 
2627*0Sstevel@tonic-gate                                 	switch(child->type)
2628*0Sstevel@tonic-gate                                 	{
2629*0Sstevel@tonic-gate                                        	 case TYPE_INTEGER:
2630*0Sstevel@tonic-gate                                        	 case TYPE_COUNTER:
2631*0Sstevel@tonic-gate                                        	 case TYPE_GAUGE:
2632*0Sstevel@tonic-gate                                        	 case TYPE_TIMETICKS:
2633*0Sstevel@tonic-gate                                        	 case TYPE_OCTETSTR:
2634*0Sstevel@tonic-gate                                        	 case TYPE_IPADDR:
2635*0Sstevel@tonic-gate                                        	 case TYPE_OPAQUE:
2636*0Sstevel@tonic-gate                                         case TYPE_OBJID:
2637*0Sstevel@tonic-gate 						first_time_entry_print++;
2638*0Sstevel@tonic-gate 						if(first_time_entry_print==1){
2639*0Sstevel@tonic-gate 			fprintf(fp, "\n");
2640*0Sstevel@tonic-gate 			fprintf(fp, "\tbackupIndex.type = index->type;\n");
2641*0Sstevel@tonic-gate 			fprintf(fp, "\tbackupIndex.len = index->len;\n");
2642*0Sstevel@tonic-gate 			fprintf(fp, "\tbackupIndex.value = (int*)calloc(index->len,sizeof(int));\n");
2643*0Sstevel@tonic-gate 			fprintf(fp, "\tfor(i=0;i<index->len;i++)\n");
2644*0Sstevel@tonic-gate 			fprintf(fp, "\t\tbackupIndex.value[i] = index->value[i];\n");
2645*0Sstevel@tonic-gate 	fprintf(fp, "\tuseIndex.type = backupIndex.type;\n");
2646*0Sstevel@tonic-gate 	fprintf(fp, "\tuseIndex.len = backupIndex.len;\n");
2647*0Sstevel@tonic-gate 	fprintf(fp, "\tuseIndex.value = (int*)calloc(backupIndex.len,sizeof(int));\n");
2648*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2649*0Sstevel@tonic-gate }else{
2650*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2651*0Sstevel@tonic-gate 	fprintf(fp, "\tfor(i=0;i<backupIndex.len;i++)\n");
2652*0Sstevel@tonic-gate 	fprintf(fp, "\t\tuseIndex.value[i] = backupIndex.value[i];\n");
2653*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2654*0Sstevel@tonic-gate }
2655*0Sstevel@tonic-gate 						fprintf(fp,"\tres = ");
2656*0Sstevel@tonic-gate 						fprintf(fp,"get_%s(\n",child->label);
2657*0Sstevel@tonic-gate 						fprintf(fp,"\t        search_type,\n");
2658*0Sstevel@tonic-gate 						fprintf(fp,"\t        &((*%s_data)->%s),\n",current->label,child->label);
2659*0Sstevel@tonic-gate 						if(first_time_entry_print==1)
2660*0Sstevel@tonic-gate 						  fprintf(fp,"\t        index);\n");
2661*0Sstevel@tonic-gate 						else
2662*0Sstevel@tonic-gate 						  fprintf(fp,"\t        &useIndex);\n");
2663*0Sstevel@tonic-gate 						fprintf(fp,"\tif(res != SNMP_ERR_NOERROR){\n");
2664*0Sstevel@tonic-gate                                                 fprintf(fp,"\t\tfree_%s(*%s_data);\n",current->label,current->label);
2665*0Sstevel@tonic-gate 						fprintf(fp, "\t\t*%s_data=NULL;\n",current->label);
2666*0Sstevel@tonic-gate                                                 fprintf(fp,"\t\tfree((char *)backupIndex.value);\n");
2667*0Sstevel@tonic-gate                                                 fprintf(fp,"\t\tfree((char *)useIndex.value);\n");
2668*0Sstevel@tonic-gate 						fprintf(fp, "\t\treturn res;\n\n");
2669*0Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
2670*0Sstevel@tonic-gate 
2671*0Sstevel@tonic-gate                                                 break;
2672*0Sstevel@tonic-gate 
2673*0Sstevel@tonic-gate                                         default:
2674*0Sstevel@tonic-gate                                                 error_exit("output_function(): Unknown type (%d) for %s",
2675*0Sstevel@tonic-gate                                                         child->type,
2676*0Sstevel@tonic-gate                                                         child->label);
2677*0Sstevel@tonic-gate                                 	}
2678*0Sstevel@tonic-gate 				}
2679*0Sstevel@tonic-gate 
2680*0Sstevel@tonic-gate 
2681*0Sstevel@tonic-gate                         fprintf(fp,"\t free((char *)backupIndex.value);\n");
2682*0Sstevel@tonic-gate                         fprintf(fp,"\t free((char *)useIndex.value);\n");
2683*0Sstevel@tonic-gate 			fprintf(fp, "\t return res;\n");
2684*0Sstevel@tonic-gate 			fprintf(fp, "}\n");
2685*0Sstevel@tonic-gate 			fprintf(fp, "\n");
2686*0Sstevel@tonic-gate 
2687*0Sstevel@tonic-gate 				fprintf(fp, "\n");
2688*0Sstevel@tonic-gate 				fprintf(fp, "void free_%s(%c%s_t *%s)\n",
2689*0Sstevel@tonic-gate 			                current->label, toupper(current->label[0]),
2690*0Sstevel@tonic-gate                                         &(current->label[1]), current->label);
2691*0Sstevel@tonic-gate                                 fprintf(fp, "{\n");
2692*0Sstevel@tonic-gate 
2693*0Sstevel@tonic-gate                                 fprintf(fp,"\tif (%s) {\n", current->label);
2694*0Sstevel@tonic-gate 
2695*0Sstevel@tonic-gate 				for(child = current->child_list; child; child = child->next_peer)
2696*0Sstevel@tonic-gate 				{
2697*0Sstevel@tonic-gate 					if(!(child->access & READ_FLAG) )
2698*0Sstevel@tonic-gate 						continue;
2699*0Sstevel@tonic-gate 
2700*0Sstevel@tonic-gate                                 	switch(child->type)
2701*0Sstevel@tonic-gate                                 	{
2702*0Sstevel@tonic-gate                                        	 case TYPE_INTEGER:
2703*0Sstevel@tonic-gate                                        	 case TYPE_COUNTER:
2704*0Sstevel@tonic-gate                                        	 case TYPE_GAUGE:
2705*0Sstevel@tonic-gate                                        	 case TYPE_TIMETICKS:
2706*0Sstevel@tonic-gate                                        	         break;
2707*0Sstevel@tonic-gate 
2708*0Sstevel@tonic-gate                                        	 case TYPE_OCTETSTR:
2709*0Sstevel@tonic-gate                                        	 case TYPE_IPADDR:
2710*0Sstevel@tonic-gate                                        	 case TYPE_OPAQUE:
2711*0Sstevel@tonic-gate                                         case TYPE_OBJID:
2712*0Sstevel@tonic-gate 						fprintf(fp, "\t\tfree_%s(&(%s->%s));\n",
2713*0Sstevel@tonic-gate 								child->label,
2714*0Sstevel@tonic-gate 								current->label,child->label);
2715*0Sstevel@tonic-gate                                                 break;
2716*0Sstevel@tonic-gate 
2717*0Sstevel@tonic-gate                                         default:
2718*0Sstevel@tonic-gate                                                 error_exit("output_function(): Unknown type (%d) for %s",
2719*0Sstevel@tonic-gate                                                         child->type,
2720*0Sstevel@tonic-gate                                                         child->label);
2721*0Sstevel@tonic-gate                                 	}
2722*0Sstevel@tonic-gate 				}
2723*0Sstevel@tonic-gate                                 fprintf(fp,"\t\tfree(%s);\n",current->label);
2724*0Sstevel@tonic-gate                                 fprintf(fp,"\t\t%s=NULL;\n",current->label);
2725*0Sstevel@tonic-gate                                 fprintf(fp,"\t}\n");
2726*0Sstevel@tonic-gate                                 fprintf(fp, "}\n");
2727*0Sstevel@tonic-gate 
2728*0Sstevel@tonic-gate 			break;
2729*0Sstevel@tonic-gate 	}
2730*0Sstevel@tonic-gate 
2731*0Sstevel@tonic-gate 
2732*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
2733*0Sstevel@tonic-gate 	{
2734*0Sstevel@tonic-gate 		output_entry_function(fp, tp);
2735*0Sstevel@tonic-gate 	}
2736*0Sstevel@tonic-gate 
2737*0Sstevel@tonic-gate }
2738*0Sstevel@tonic-gate static void output_single_obj_function(FILE *fp, struct tree *current)
2739*0Sstevel@tonic-gate {
2740*0Sstevel@tonic-gate 	struct tree *tp;
2741*0Sstevel@tonic-gate 
2742*0Sstevel@tonic-gate 
2743*0Sstevel@tonic-gate 	switch(current->node_type)
2744*0Sstevel@tonic-gate 	{
2745*0Sstevel@tonic-gate 		case OBJECT:
2746*0Sstevel@tonic-gate 			if(current->access & READ_FLAG)
2747*0Sstevel@tonic-gate 			{
2748*0Sstevel@tonic-gate 				fprintf(fp, "\n");
2749*0Sstevel@tonic-gate 				switch(current->type)
2750*0Sstevel@tonic-gate 				{
2751*0Sstevel@tonic-gate 					case TYPE_INTEGER:
2752*0Sstevel@tonic-gate 					case TYPE_COUNTER:
2753*0Sstevel@tonic-gate 					case TYPE_GAUGE:
2754*0Sstevel@tonic-gate 					case TYPE_TIMETICKS:
2755*0Sstevel@tonic-gate 						fprintf(fp, "int get_%s(Integer *%s)\n",
2756*0Sstevel@tonic-gate 							current->label,
2757*0Sstevel@tonic-gate 							current->label);
2758*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2759*0Sstevel@tonic-gate 						fprintf(fp, "\t/* assume that the mib variable has a value of 1 */\n\n");
2760*0Sstevel@tonic-gate 						fprintf(fp, "\t*%s = 1;\n",current->label);
2761*0Sstevel@tonic-gate 						fprintf(fp, "\treturn SNMP_ERR_NOERROR;\n");
2762*0Sstevel@tonic-gate 						break;
2763*0Sstevel@tonic-gate 
2764*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
2765*0Sstevel@tonic-gate 					case TYPE_IPADDR:
2766*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
2767*0Sstevel@tonic-gate 						fprintf(fp, "int get_%s(String *%s)\n",
2768*0Sstevel@tonic-gate 							current->label,
2769*0Sstevel@tonic-gate 							current->label);
2770*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2771*0Sstevel@tonic-gate 						fprintf(fp, "\tu_char *str;\n");
2772*0Sstevel@tonic-gate 						fprintf(fp, "\tint len;\n\n");
2773*0Sstevel@tonic-gate 
2774*0Sstevel@tonic-gate 						PRINT_GET_STRING_DUMBY_BLOCK
2775*0Sstevel@tonic-gate 
2776*0Sstevel@tonic-gate 						break;
2777*0Sstevel@tonic-gate 
2778*0Sstevel@tonic-gate 					case TYPE_OBJID:
2779*0Sstevel@tonic-gate 						fprintf(fp, "int get_%s(Oid *%s)\n",
2780*0Sstevel@tonic-gate 							current->label,
2781*0Sstevel@tonic-gate 							current->label);
2782*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2783*0Sstevel@tonic-gate 						fprintf(fp, "\tSubid *sub;\n");
2784*0Sstevel@tonic-gate 						fprintf(fp, "\tSubid fake_sub[] = {1,3,6,1,4,1,4,42};\n");
2785*0Sstevel@tonic-gate 						fprintf(fp, "\tint len;\n\n");
2786*0Sstevel@tonic-gate 
2787*0Sstevel@tonic-gate 						PRINT_GET_OID_DUMBY_BLOCK
2788*0Sstevel@tonic-gate 
2789*0Sstevel@tonic-gate 						break;
2790*0Sstevel@tonic-gate 
2791*0Sstevel@tonic-gate 					deafult:
2792*0Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s", current->type,
2793*0Sstevel@tonic-gate 							current->label);
2794*0Sstevel@tonic-gate 				}
2795*0Sstevel@tonic-gate 				PRINT_CLOSE_BRACKET
2796*0Sstevel@tonic-gate 			}
2797*0Sstevel@tonic-gate 
2798*0Sstevel@tonic-gate 			if(current->access & WRITE_FLAG)
2799*0Sstevel@tonic-gate 			{
2800*0Sstevel@tonic-gate 				fprintf(fp, "\n");
2801*0Sstevel@tonic-gate 				switch(current->type)
2802*0Sstevel@tonic-gate 				{
2803*0Sstevel@tonic-gate 					case TYPE_INTEGER:
2804*0Sstevel@tonic-gate 					case TYPE_COUNTER:
2805*0Sstevel@tonic-gate 					case TYPE_GAUGE:
2806*0Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
2807*0Sstevel@tonic-gate 						fprintf(fp, "int set_%s(int pass, Integer *%s)\n",
2808*0Sstevel@tonic-gate 							current->label,
2809*0Sstevel@tonic-gate 							current->label);
2810*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2811*0Sstevel@tonic-gate 						fprintf(fp, "\tswitch(pass)\n");
2812*0Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
2813*0Sstevel@tonic-gate 						PRINT_SET_CASE_BLOCK
2814*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%d\\n\",%s);\n",current->label);
2815*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
2816*0Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
2817*0Sstevel@tonic-gate 						break;
2818*0Sstevel@tonic-gate 
2819*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
2820*0Sstevel@tonic-gate 					case TYPE_IPADDR:
2821*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
2822*0Sstevel@tonic-gate 						fprintf(fp, "int set_%s(int pass, String *%s)\n",
2823*0Sstevel@tonic-gate 							current->label,
2824*0Sstevel@tonic-gate 							current->label);
2825*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2826*0Sstevel@tonic-gate 						fprintf(fp, "\tchar buf[100];\n\n");
2827*0Sstevel@tonic-gate 						fprintf(fp, "\tswitch(pass)\n");
2828*0Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
2829*0Sstevel@tonic-gate 						PRINT_SET_CASE_BLOCK
2830*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tmemcpy(buf,%s->chars,%s->len);\n",current->label,current->label);
2831*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tbuf[%s->len+1] = '\\0';\n",current->label);
2832*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%s\\n\",buf);\n");
2833*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
2834*0Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
2835*0Sstevel@tonic-gate 						break;
2836*0Sstevel@tonic-gate 
2837*0Sstevel@tonic-gate 					case TYPE_OBJID:
2838*0Sstevel@tonic-gate 						fprintf(fp, "int set_%s(int pass, Oid *%s)\n",
2839*0Sstevel@tonic-gate 							current->label,
2840*0Sstevel@tonic-gate 							current->label);
2841*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2842*0Sstevel@tonic-gate 						fprintf(fp, "\tswitch(pass)\n");
2843*0Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
2844*0Sstevel@tonic-gate 						PRINT_SET_CASE_BLOCK
2845*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%s\\n\",SSAOidString(%s));\n",current->label);
2846*0Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
2847*0Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
2848*0Sstevel@tonic-gate 						break;
2849*0Sstevel@tonic-gate 
2850*0Sstevel@tonic-gate 					default:
2851*0Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s", current->type,
2852*0Sstevel@tonic-gate 							current->label);
2853*0Sstevel@tonic-gate 				}
2854*0Sstevel@tonic-gate 
2855*0Sstevel@tonic-gate 				PRINT_CLOSE_BRACKET
2856*0Sstevel@tonic-gate 				fprintf(fp, "\n");
2857*0Sstevel@tonic-gate 			}
2858*0Sstevel@tonic-gate 
2859*0Sstevel@tonic-gate 			if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
2860*0Sstevel@tonic-gate 			{
2861*0Sstevel@tonic-gate 				switch(current->type)
2862*0Sstevel@tonic-gate 				{
2863*0Sstevel@tonic-gate 					case TYPE_INTEGER:
2864*0Sstevel@tonic-gate 					case TYPE_COUNTER:
2865*0Sstevel@tonic-gate 					case TYPE_GAUGE:
2866*0Sstevel@tonic-gate 					case TYPE_TIMETICKS:
2867*0Sstevel@tonic-gate 						break;
2868*0Sstevel@tonic-gate 
2869*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
2870*0Sstevel@tonic-gate 					case TYPE_IPADDR:
2871*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
2872*0Sstevel@tonic-gate 						fprintf(fp, "\n");
2873*0Sstevel@tonic-gate 						fprintf(fp, "void free_%s(String *%s)\n",
2874*0Sstevel@tonic-gate 							current->label,
2875*0Sstevel@tonic-gate 							current->label);
2876*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2877*0Sstevel@tonic-gate 						fprintf(fp, "\t if(%s->",current->label);
2878*0Sstevel@tonic-gate 						break;
2879*0Sstevel@tonic-gate 
2880*0Sstevel@tonic-gate 					case TYPE_OBJID:
2881*0Sstevel@tonic-gate 						fprintf(fp, "\n");
2882*0Sstevel@tonic-gate 						fprintf(fp, "void free_%s(Oid *%s)\n",
2883*0Sstevel@tonic-gate 							current->label,
2884*0Sstevel@tonic-gate 							current->label);
2885*0Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
2886*0Sstevel@tonic-gate 						fprintf(fp, "\t if(%s->",current->label);
2887*0Sstevel@tonic-gate 						break;
2888*0Sstevel@tonic-gate 
2889*0Sstevel@tonic-gate 					default:
2890*0Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s",
2891*0Sstevel@tonic-gate 							current->type,
2892*0Sstevel@tonic-gate 							current->label);
2893*0Sstevel@tonic-gate 				}
2894*0Sstevel@tonic-gate 				switch(current->type)
2895*0Sstevel@tonic-gate 				{
2896*0Sstevel@tonic-gate 					case TYPE_INTEGER:
2897*0Sstevel@tonic-gate 					case TYPE_COUNTER:
2898*0Sstevel@tonic-gate 					case TYPE_GAUGE:
2899*0Sstevel@tonic-gate 					case TYPE_TIMETICKS:
2900*0Sstevel@tonic-gate 						break;
2901*0Sstevel@tonic-gate 
2902*0Sstevel@tonic-gate 					case TYPE_OCTETSTR:
2903*0Sstevel@tonic-gate 					case TYPE_IPADDR:
2904*0Sstevel@tonic-gate 					case TYPE_OPAQUE:
2905*0Sstevel@tonic-gate 						fprintf(fp, "chars!=NULL && %s->len !=0)\n",current->label);
2906*0Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
2907*0Sstevel@tonic-gate 						fprintf(fp, "\t\tfree(%s->chars);\n",current->label);
2908*0Sstevel@tonic-gate 						fprintf(fp,"\t\t%s->len = 0;\n",current->label);
2909*0Sstevel@tonic-gate 						fprintf(fp,"\t}\n");
2910*0Sstevel@tonic-gate 						PRINT_CLOSE_BRACKET
2911*0Sstevel@tonic-gate 						break;
2912*0Sstevel@tonic-gate 
2913*0Sstevel@tonic-gate 					case TYPE_OBJID:
2914*0Sstevel@tonic-gate 						fprintf(fp, "subids!=NULL && %s->len !=0)\n",current->label);
2915*0Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
2916*0Sstevel@tonic-gate 						fprintf(fp, "\t\tfree(%s->subids);\n",current->label);
2917*0Sstevel@tonic-gate 						fprintf(fp,"\t\t%s->len = 0;\n",current->label);
2918*0Sstevel@tonic-gate 						fprintf(fp,"\t}\n");
2919*0Sstevel@tonic-gate 						PRINT_CLOSE_BRACKET
2920*0Sstevel@tonic-gate 						break;
2921*0Sstevel@tonic-gate 
2922*0Sstevel@tonic-gate 					default:
2923*0Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s",
2924*0Sstevel@tonic-gate 							current->type,
2925*0Sstevel@tonic-gate 							current->label);
2926*0Sstevel@tonic-gate 				}
2927*0Sstevel@tonic-gate 			}
2928*0Sstevel@tonic-gate 			break;
2929*0Sstevel@tonic-gate 	}
2930*0Sstevel@tonic-gate 
2931*0Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
2932*0Sstevel@tonic-gate 	{
2933*0Sstevel@tonic-gate 		output_single_obj_function(fp, tp);
2934*0Sstevel@tonic-gate 	}
2935*0Sstevel@tonic-gate 
2936*0Sstevel@tonic-gate }
2937*0Sstevel@tonic-gate 
2938*0Sstevel@tonic-gate 
2939*0Sstevel@tonic-gate /*************************************************************************/
2940*0Sstevel@tonic-gate static FILE* output_file(char* filename)
2941*0Sstevel@tonic-gate {
2942*0Sstevel@tonic-gate 	char pathname[MAXPATHLEN];
2943*0Sstevel@tonic-gate 	char backup_pathname[MAXPATHLEN];
2944*0Sstevel@tonic-gate 	FILE *fp;
2945*0Sstevel@tonic-gate 	struct stat buf;
2946*0Sstevel@tonic-gate 
2947*0Sstevel@tonic-gate 
2948*0Sstevel@tonic-gate 	sprintf(pathname, "%s_%s.c", base_name,filename);
2949*0Sstevel@tonic-gate 	sprintf(backup_pathname, "%s.%s.c.old", base_name,filename);
2950*0Sstevel@tonic-gate 	trace("Creating %s ...\n", pathname);
2951*0Sstevel@tonic-gate 	if(stat(pathname, &buf) == 0)
2952*0Sstevel@tonic-gate 	{
2953*0Sstevel@tonic-gate 		if(rename(pathname,backup_pathname)==-1){
2954*0Sstevel@tonic-gate 		  error_exit("The file %s already exists and can't be renamed!", pathname);
2955*0Sstevel@tonic-gate 		}
2956*0Sstevel@tonic-gate 	}
2957*0Sstevel@tonic-gate 
2958*0Sstevel@tonic-gate 	fp = fopen(pathname, "w");
2959*0Sstevel@tonic-gate 	if(fp == NULL)
2960*0Sstevel@tonic-gate 	{
2961*0Sstevel@tonic-gate 		error_exit("Can't open %s %s", pathname, errno_string());
2962*0Sstevel@tonic-gate 	}
2963*0Sstevel@tonic-gate 
2964*0Sstevel@tonic-gate 	fprintf(fp, "#include <sys/types.h>\n");
2965*0Sstevel@tonic-gate 	fprintf(fp, "#include <netinet/in.h>\n");
2966*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2967*0Sstevel@tonic-gate 	fprintf(fp, "#include \"impl.h\"\n");
2968*0Sstevel@tonic-gate 	fprintf(fp, "#include \"asn1.h\"\n");
2969*0Sstevel@tonic-gate 	fprintf(fp, "#include \"error.h\"\n");
2970*0Sstevel@tonic-gate 	fprintf(fp, "#include \"snmp.h\"\n");
2971*0Sstevel@tonic-gate 	fprintf(fp, "#include \"trap.h\"\n");
2972*0Sstevel@tonic-gate 	fprintf(fp, "#include \"pdu.h\"\n");
2973*0Sstevel@tonic-gate 	fprintf(fp, "#include \"node.h\"\n");
2974*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2975*0Sstevel@tonic-gate 	fprintf(fp, "#include \"%s_stub.h\"\n", base_name);
2976*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2977*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2978*0Sstevel@tonic-gate 
2979*0Sstevel@tonic-gate 	return(fp);
2980*0Sstevel@tonic-gate }
2981*0Sstevel@tonic-gate 
2982*0Sstevel@tonic-gate static void output_appl_c(struct tree *current)
2983*0Sstevel@tonic-gate {
2984*0Sstevel@tonic-gate 	FILE *fp;
2985*0Sstevel@tonic-gate 
2986*0Sstevel@tonic-gate 	fp = output_file("appl");
2987*0Sstevel@tonic-gate 	fprintf(fp, "/***** GLOBAL VARIABLES *****/\n");
2988*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2989*0Sstevel@tonic-gate 	fprintf(fp, "char default_config_file[] = \"/etc/snmp/conf/%s.reg\";\n", base_name);
2990*0Sstevel@tonic-gate 	fprintf(fp, "char default_sec_config_file[] = \"/etc/snmp/conf/%s.acl\";\n", base_name);
2991*0Sstevel@tonic-gate 	fprintf(fp, "char default_error_file[] = \"/var/snmp/%sd.log\";\n", base_name);
2992*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2993*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2994*0Sstevel@tonic-gate 
2995*0Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
2996*0Sstevel@tonic-gate 	fprintf(fp, "\n");
2997*0Sstevel@tonic-gate 	fprintf(fp, "void agent_init()\n");
2998*0Sstevel@tonic-gate 	fprintf(fp, "{\n");
2999*0Sstevel@tonic-gate 	fprintf(fp, "}\n");
3000*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3001*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3002*0Sstevel@tonic-gate 
3003*0Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
3004*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3005*0Sstevel@tonic-gate 	fprintf(fp, "void agent_end()\n");
3006*0Sstevel@tonic-gate 	fprintf(fp, "{\n");
3007*0Sstevel@tonic-gate 	fprintf(fp, "}\n");
3008*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3009*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3010*0Sstevel@tonic-gate 
3011*0Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
3012*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3013*0Sstevel@tonic-gate 	fprintf(fp, "void agent_loop()\n");
3014*0Sstevel@tonic-gate 	fprintf(fp, "{\n");
3015*0Sstevel@tonic-gate 	fprintf(fp,"\tint condition=FALSE;\n\n");
3016*0Sstevel@tonic-gate  	fprintf(fp,"\tif(condition==TRUE){\n");
3017*0Sstevel@tonic-gate 	output_trap_function_call(fp);
3018*0Sstevel@tonic-gate 	fprintf(fp, "\t}\n");
3019*0Sstevel@tonic-gate 	fprintf(fp, "}\n");
3020*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3021*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3022*0Sstevel@tonic-gate 
3023*0Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
3024*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3025*0Sstevel@tonic-gate 	fprintf(fp, "void agent_select_info(fd_set *fdset, int *numfds)\n");
3026*0Sstevel@tonic-gate 	fprintf(fp, "{\n");
3027*0Sstevel@tonic-gate 	fprintf(fp, "}\n");
3028*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3029*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3030*0Sstevel@tonic-gate 
3031*0Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
3032*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3033*0Sstevel@tonic-gate 	fprintf(fp, "void agent_select_callback(fd_set *fdset)\n");
3034*0Sstevel@tonic-gate 	fprintf(fp, "{\n");
3035*0Sstevel@tonic-gate 	fprintf(fp, "}\n");
3036*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3037*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3038*0Sstevel@tonic-gate 
3039*0Sstevel@tonic-gate 	fprintf(fp,"void main(int argc, char** argv)\n");
3040*0Sstevel@tonic-gate 	fprintf(fp,"{\n");
3041*0Sstevel@tonic-gate 	fprintf(fp,"\tSSAMain(argc,argv);\n");
3042*0Sstevel@tonic-gate 	fprintf(fp,"}\n\n");
3043*0Sstevel@tonic-gate 
3044*0Sstevel@tonic-gate 	fprintf(fp, "\n");
3045*0Sstevel@tonic-gate 	fclose(fp);
3046*0Sstevel@tonic-gate }
3047*0Sstevel@tonic-gate 
3048*0Sstevel@tonic-gate static void output_trap_c(struct tree *current)
3049*0Sstevel@tonic-gate {
3050*0Sstevel@tonic-gate 	FILE *fp;
3051*0Sstevel@tonic-gate 
3052*0Sstevel@tonic-gate 	fp = output_file("trap");
3053*0Sstevel@tonic-gate 	output_trap_structure(fp);
3054*0Sstevel@tonic-gate 	fclose(fp);
3055*0Sstevel@tonic-gate }
3056*0Sstevel@tonic-gate 
3057*0Sstevel@tonic-gate static void output_stub_c(struct tree *current)
3058*0Sstevel@tonic-gate {
3059*0Sstevel@tonic-gate 	FILE *fp;
3060*0Sstevel@tonic-gate 
3061*0Sstevel@tonic-gate 	fp = output_file("stub");
3062*0Sstevel@tonic-gate 	output_single_obj_function(fp, current);
3063*0Sstevel@tonic-gate 	output_entry_function(fp, current);
3064*0Sstevel@tonic-gate 
3065*0Sstevel@tonic-gate 	fclose(fp);
3066*0Sstevel@tonic-gate }
3067*0Sstevel@tonic-gate 
3068*0Sstevel@tonic-gate 
3069*0Sstevel@tonic-gate 
3070