xref: /onnv-gate/usr/src/cmd/agents/snmp/parser/backend.c (revision 1706:0e053bac3f94)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1706Swesolows  * Common Development and Distribution License (the "License").
6*1706Swesolows  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*1706Swesolows 
220Sstevel@tonic-gate /*
23*1706Swesolows  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /** HISTORY
300Sstevel@tonic-gate  * 5-15-96	Jerry Yeung	replace the Integer to Integer*
310Sstevel@tonic-gate  * 5-20-96	Jerry Yeung	add default_sec_config_file
320Sstevel@tonic-gate  * 8-23-96	Jerry Yeung	change the default path
330Sstevel@tonic-gate  * 8-27-96      Jerry Yeung	change oid_string
340Sstevel@tonic-gate  * 9-06-96      Jiten Gaitonde  change cmd line usage
350Sstevel@tonic-gate  * 10-21-96	Jerry Yeung	fix template-code
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #include <stdio.h>
390Sstevel@tonic-gate #include <ctype.h>
400Sstevel@tonic-gate #include <sys/types.h>
410Sstevel@tonic-gate #include <sys/stat.h>
420Sstevel@tonic-gate #include <sys/param.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #include "impl.h"
450Sstevel@tonic-gate #include "error.h"
460Sstevel@tonic-gate #include "asn1.h"
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #include "parse.h"
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #define OBJECT			1
510Sstevel@tonic-gate #define COLUMN			2
520Sstevel@tonic-gate #define NODE			3
530Sstevel@tonic-gate #define TABLE			4
540Sstevel@tonic-gate #define ENTRY			5
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #define PRINT_OPEN_BRACKET fprintf(fp, "{\n");
580Sstevel@tonic-gate #define PRINT_TAG_OPEN_BRACKET fprintf(fp, "\t{\n");
590Sstevel@tonic-gate #define PRINT_CLOSE_BRACKET fprintf(fp, "}\n");
600Sstevel@tonic-gate #define PRINT_TAG_CLOSE_BRACKET fprintf(fp, "\t}\n");
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #define SET_PRINT_ENTRY_BLOCK \
630Sstevel@tonic-gate 	fprintf(fp,"\tswitch(pass)\n");\
640Sstevel@tonic-gate 	fprintf(fp,"\t{\n");\
650Sstevel@tonic-gate 	fprintf(fp,"\t\tcase FIRST_PASS:\n\n");\
660Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* check the existence of the element */\n");\
670Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* which corresponds to the given index and */\n");\
680Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* check the validity of the input value */\n");\
690Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* if not valid or not exist, */\n\n");\
700Sstevel@tonic-gate 	fprintf(fp,"\t\t\treturn SNMP_ERR_NOERROR;\n\n");\
710Sstevel@tonic-gate 	fprintf(fp,"\t\tcase SECOND_PASS:\n\n");\
720Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* change the following coding, such that */\n");\
730Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* the input value will be stored in the */\n");\
740Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* corresponding mib variable of the given */\n");\
750Sstevel@tonic-gate 	fprintf(fp,"\t\t\t/* index */\n");
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 
780Sstevel@tonic-gate #define PRINT_GET_STRING_DUMBY_BLOCK \
790Sstevel@tonic-gate 	fprintf(fp, "\t/* It is required to allocate memory to the pointers */\n"); \
800Sstevel@tonic-gate 	fprintf(fp, "\t/* inside the input argument */\n"); \
810Sstevel@tonic-gate 	fprintf(fp, "\t/* Here, we assume that \"hello\" is the value of the mib variable */\n"); \
820Sstevel@tonic-gate 	fprintf(fp, "\t/* please change it to the real one */\n\n"); \
830Sstevel@tonic-gate 	fprintf(fp, "\tlen = strlen(\"hello\");\n"); \
840Sstevel@tonic-gate 	fprintf(fp, "\tstr = (u_char*)calloc(len,sizeof(char));\n");  \
850Sstevel@tonic-gate 	fprintf(fp, "\tif(str==NULL){\n"); \
860Sstevel@tonic-gate 	fprintf(fp, "\t\treturn SNMP_ERR_GENERR;\n"); \
870Sstevel@tonic-gate 	fprintf(fp, "\t}\n"); \
880Sstevel@tonic-gate 	fprintf(fp, "\tmemcpy(str,\"hello\",len);\n\n"); \
890Sstevel@tonic-gate 	fprintf(fp, "\t/*fill in the contents of the argument */\n\n"); \
900Sstevel@tonic-gate 	fprintf(fp, "\t%s->chars = str;\n",current->label); \
910Sstevel@tonic-gate 	fprintf(fp, "\t%s->len = len;\n",current->label); \
920Sstevel@tonic-gate 	fprintf(fp, "\treturn SNMP_ERR_NOERROR;\n");
930Sstevel@tonic-gate 
940Sstevel@tonic-gate #define PRINT_GET_OID_DUMBY_BLOCK \
950Sstevel@tonic-gate 	fprintf(fp, "\t/* It is required to allocate memory to the pointers */\n");\
960Sstevel@tonic-gate 	fprintf(fp, "\t/* inside the input argument */\n");\
970Sstevel@tonic-gate 	fprintf(fp, "\t/* Here, we assume that \"1.3.6.1.4.1.42\" is the value */\n");\
980Sstevel@tonic-gate 	fprintf(fp, "\t/* of the mib variable */\n");\
990Sstevel@tonic-gate 	fprintf(fp, "\t/* please change it to the real one */\n\n");\
1000Sstevel@tonic-gate 	fprintf(fp, "\t/* 1.3.6.1.4.1.42 has 7 number separated by \".\" */\n");\
1010Sstevel@tonic-gate 	fprintf(fp, "\n");\
1020Sstevel@tonic-gate 	fprintf(fp, "\tlen =7 ;\n");\
1030Sstevel@tonic-gate 	fprintf(fp, "\tsub = (Subid*)calloc(len,sizeof(Subid));\n");\
1040Sstevel@tonic-gate 	fprintf(fp, "\tif(sub==NULL) return SNMP_ERR_GENERR;\n");\
1050Sstevel@tonic-gate 	fprintf(fp, "\tmemcpy(sub,fake_sub,len*sizeof(Subid));\n\n");\
1060Sstevel@tonic-gate 	fprintf(fp, "\t/* fill in the contents of the argument */\n\n");\
1070Sstevel@tonic-gate 	fprintf(fp, "\t%s->subids = sub;\n",current->label);\
1080Sstevel@tonic-gate 	fprintf(fp, "\t%s->len = len;\n",current->label);\
1090Sstevel@tonic-gate 	fprintf(fp, "\treturn SNMP_ERR_NOERROR;\n");
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate #define PRINT_SET_CASE_BLOCK \
1120Sstevel@tonic-gate 	fprintf(fp, "\t\tcase FIRST_PASS:\n");\
1130Sstevel@tonic-gate 	fprintf(fp, "\n");\
1140Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* check the validity of the input argument */\n");\
1150Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* if not valid, return SNMP_GEN_ERROR */\n\n");\
1160Sstevel@tonic-gate 	fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n\n");\
1170Sstevel@tonic-gate 	fprintf(fp, "\t\tcase SECOND_PASS:\n");\
1180Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* change the following coding, such that */\n");\
1190Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* the input value will be stored in the */\n");\
1200Sstevel@tonic-gate 	fprintf(fp, "\t\t\t/* corresponding mib variable */\n\n");
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate #define PRINT_GET_CASE_BLOCK \
1240Sstevel@tonic-gate 	fprintf(fp, "\t/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */\n");\
1250Sstevel@tonic-gate 	fprintf(fp, "\t/* this function should modify the index argument to the */\n");\
1260Sstevel@tonic-gate 	fprintf(fp, "\t/* appropriate value */\n");\
1270Sstevel@tonic-gate 	fprintf(fp, "\tswitch(search_type)\n");\
1280Sstevel@tonic-gate 	fprintf(fp, "\t{\n");\
1290Sstevel@tonic-gate 	fprintf(fp, "\t\tcase FIRST_ENTRY:\n");\
1300Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\t/* assume 1 is the first index */\n\n");\
1310Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\tindex->value[0] = 1;\n");\
1320Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\tindex->len = 1;\n");\
1330Sstevel@tonic-gate 	fprintf(fp, "\t\t\tbreak;\n\n");\
1340Sstevel@tonic-gate 	fprintf(fp, "\t\tcase NEXT_ENTRY:\n");\
1350Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\tindex->value[0]++;\n");\
1360Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\tif(index->value[0]>2)\n");\
1370Sstevel@tonic-gate 	fprintf(fp, "\t\t\t\t\treturn END_OF_TABLE;\n");\
1380Sstevel@tonic-gate 	fprintf(fp, "\t\t\tbreak;\n\n");\
1390Sstevel@tonic-gate 	fprintf(fp, "\t\tcase EXACT_ENTRY:\n");\
1400Sstevel@tonic-gate 	fprintf(fp, "\t\t\tbreak;\n");\
1410Sstevel@tonic-gate 	fprintf(fp, "\t}\n\n");
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate /* trap support snmp oid */
1440Sstevel@tonic-gate static Subid snmp_subids[] = { 1,3,6,1,2,1,11,(Subid)-1}; /* -1 is null(hack) */
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate static char *base_name = NULL;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate static struct tree *root = NULL;
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate extern int    trace_level;
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate /*************************************************************************/
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate static FILE* output_file(char* filename);
1550Sstevel@tonic-gate static void application_end();
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate static struct tree *find_node(struct tree *current, char *label);
1580Sstevel@tonic-gate static int get_node_type(struct tree *tp);
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate static void init_tree_first_pass(struct tree *current, int *index, int *object_index, int *column_index, int *entry_index);
1620Sstevel@tonic-gate static void init_tree_second_pass(struct tree *current);
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate static void output_tree_c(struct tree *current);
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate static void output_extern_function(FILE *fp, struct tree *current);
1680Sstevel@tonic-gate static void output_extern_trap_function(FILE *fp);
1690Sstevel@tonic-gate static void output_trap_function_call(FILE *fp);
1700Sstevel@tonic-gate static void output_trap_structure(FILE *fp);
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate static void output_subid_table(FILE *fp, struct tree *current, int *subid_index);
1730Sstevel@tonic-gate static void output_enum_table(FILE *fp, struct tree *current, int *enum_index);
1740Sstevel@tonic-gate static void output_object_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size);
1750Sstevel@tonic-gate static void output_entry_table(FILE *fp, struct tree *current, int *index_index, int *size);
1760Sstevel@tonic-gate static void output_column_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size);
1770Sstevel@tonic-gate static void output_node_table(FILE *fp, struct tree *current, int *size);
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate static void output_stub_h(struct tree *current);
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate static void output_stub_c(struct tree *current);
1840Sstevel@tonic-gate static void output_appl_c(struct tree *current);
1850Sstevel@tonic-gate static void output_trap_c(struct tree *current);
1860Sstevel@tonic-gate static void output_entry_function(FILE *fp, struct tree *current);
1870Sstevel@tonic-gate static void output_single_obj_function(FILE *fp, struct tree *current);
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate /*************************************************************************/
1910Sstevel@tonic-gate 
application_end()1920Sstevel@tonic-gate static void application_end()
1930Sstevel@tonic-gate {
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate /*************************************************************************/
1980Sstevel@tonic-gate 
print_usage()1990Sstevel@tonic-gate static void print_usage()
2000Sstevel@tonic-gate {
2010Sstevel@tonic-gate 	fprintf(stderr, "Usage: mibcodegen -b SubagentName -f mib_1.txt [mib2.txt....] [-h]\n");
2020Sstevel@tonic-gate         exit(1);
2030Sstevel@tonic-gate #if 0
2040Sstevel@tonic-gate 	error_exit("Usage: mibcodegen -b SubagentName -f mib_1.txt [mib2.txt....] [-h]");
2050Sstevel@tonic-gate #endif
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate /*
2090Sstevel@tonic-gate  * get the reverse-subid list from the given tree node
2100Sstevel@tonic-gate  * len stores the number of subids
2110Sstevel@tonic-gate  */
get_subid_of_node(struct tree * t,Subid * subids,int * len)2120Sstevel@tonic-gate void get_subid_of_node(struct tree *t, Subid *subids, int *len)
2130Sstevel@tonic-gate {
2140Sstevel@tonic-gate   struct tree *parent;
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate   *len=0 ;
2170Sstevel@tonic-gate   parent = t;
2180Sstevel@tonic-gate   while(parent){
2190Sstevel@tonic-gate  	subids[(*len)++] = parent->subid;
2200Sstevel@tonic-gate 	parent = parent->parent;
2210Sstevel@tonic-gate   }
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate /*************************************************************************/
2260Sstevel@tonic-gate 
227*1706Swesolows int
main(int argc,char * argv[])228*1706Swesolows main(int argc, char *argv[])
2290Sstevel@tonic-gate {
2300Sstevel@tonic-gate 	struct node *nodes = NULL;
2310Sstevel@tonic-gate 	int i;
2320Sstevel@tonic-gate 	int node_index;
2330Sstevel@tonic-gate 	int object_index;
2340Sstevel@tonic-gate 	int column_index;
2350Sstevel@tonic-gate 	int entry_index;
2360Sstevel@tonic-gate         char *filep[50];
2370Sstevel@tonic-gate         int  filecount,loop=0,mibcoreflag;
2380Sstevel@tonic-gate         int opt, doit;
2390Sstevel@tonic-gate         extern char * optarg;
2400Sstevel@tonic-gate         extern int    optind;
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	doit = 0;
2440Sstevel@tonic-gate         trace_level=filecount=1;
2450Sstevel@tonic-gate         mibcoreflag=0;
2460Sstevel@tonic-gate         filep[0] = "/var/snmp/mib/mib_core.txt";
2470Sstevel@tonic-gate 	error_init(argv[0], application_end);
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate         while((opt = getopt(argc, argv, "b:f:h")) != EOF) {
2500Sstevel@tonic-gate           switch(opt) {
2510Sstevel@tonic-gate             case 'b':
2520Sstevel@tonic-gate                       base_name = (char *)strdup(optarg);
2530Sstevel@tonic-gate                       break;
2540Sstevel@tonic-gate             case 'f':
2550Sstevel@tonic-gate                       filep[filecount++] = (char *)strdup(optarg);
2560Sstevel@tonic-gate                       if (strstr(filep[filecount-1], "mib_core"))
2570Sstevel@tonic-gate                            mibcoreflag=1;
2580Sstevel@tonic-gate 			else
2590Sstevel@tonic-gate 				doit=1;
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate                       for(;((argv[optind]!=NULL) &&
2620Sstevel@tonic-gate                                   (argv[optind][0] != '-'));
2630Sstevel@tonic-gate                                   optind++) {
2640Sstevel@tonic-gate                         filep[filecount++] = (char *)strdup(argv[optind+loop]);
2650Sstevel@tonic-gate                         if (strstr(filep[filecount-1], "mib_core"))
2660Sstevel@tonic-gate                               mibcoreflag=1;
2670Sstevel@tonic-gate 			else
2680Sstevel@tonic-gate 				doit = 1;
2690Sstevel@tonic-gate                       }
2700Sstevel@tonic-gate                       break;
2710Sstevel@tonic-gate             case 'h':
2720Sstevel@tonic-gate             default:
2730Sstevel@tonic-gate                       print_usage();
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate           }
2760Sstevel@tonic-gate         } /*end of while*/
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate         if ((optind != argc) || (!base_name) || (!doit))
2790Sstevel@tonic-gate            print_usage();
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate /******
2830Sstevel@tonic-gate 	if(argc < 3)
2840Sstevel@tonic-gate 	{
2850Sstevel@tonic-gate 		print_usage();
2860Sstevel@tonic-gate 	}
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	base_name = (char *) malloc(strlen(argv[1]) + 1);
2900Sstevel@tonic-gate 	strcpy(base_name, argv[1]);
2910Sstevel@tonic-gate *******/
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate 	parse_init();
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	for(i = mibcoreflag; i < filecount; i++)
2960Sstevel@tonic-gate 	{
2970Sstevel@tonic-gate 		FILE *fp;
2980Sstevel@tonic-gate 		struct node *n, *last;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 		fp = fopen(filep[i], "r");
3020Sstevel@tonic-gate 		if(fp == NULL)
3030Sstevel@tonic-gate 		{
3040Sstevel@tonic-gate 			error("open() failed on %s %s\n\n", filep[i], errno_string());
3050Sstevel@tonic-gate 			print_usage();
3060Sstevel@tonic-gate 		}
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 		n = parse(fp);
3090Sstevel@tonic-gate 		fclose(fp);
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 		if(n == NULL)
3120Sstevel@tonic-gate 		{
3130Sstevel@tonic-gate 			error("WARNING : n is NULL for %s", argv[i]);
3140Sstevel@tonic-gate 		}
3150Sstevel@tonic-gate 		else
3160Sstevel@tonic-gate 		{
3170Sstevel@tonic-gate 			if(nodes == NULL)
3180Sstevel@tonic-gate 			{
3190Sstevel@tonic-gate 				nodes = n;
3200Sstevel@tonic-gate 			}
3210Sstevel@tonic-gate 			else
3220Sstevel@tonic-gate 			{
3230Sstevel@tonic-gate 				last = nodes;
3240Sstevel@tonic-gate 				while(last->next)
3250Sstevel@tonic-gate 				{
3260Sstevel@tonic-gate 					last = last->next;
3270Sstevel@tonic-gate 				}
3280Sstevel@tonic-gate 				last->next = n;
3290Sstevel@tonic-gate 			}
3300Sstevel@tonic-gate 		}
3310Sstevel@tonic-gate 	}
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 	root = build_tree(nodes);
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	node_index = 0;
3370Sstevel@tonic-gate 	object_index = 0;
3380Sstevel@tonic-gate 	column_index = 0;
3390Sstevel@tonic-gate 	entry_index = 0;
3400Sstevel@tonic-gate 	init_tree_first_pass(root, &node_index, &object_index, &column_index, &entry_index);
3410Sstevel@tonic-gate 	init_tree_second_pass(root);
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	output_tree_c(root);
3440Sstevel@tonic-gate 	output_stub_h(root);
3450Sstevel@tonic-gate 	output_stub_c(root);
3460Sstevel@tonic-gate 	output_appl_c(root);
3470Sstevel@tonic-gate 	output_trap_c(root);
3480Sstevel@tonic-gate 
349*1706Swesolows 	return (0);
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate /*************************************************************************/
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate /* Possible returned values:			*/
3560Sstevel@tonic-gate /*	NODE, TABLE, ENTRY, OBJECT, COLUMN	*/
3570Sstevel@tonic-gate 
get_node_type(struct tree * tp)3580Sstevel@tonic-gate static int get_node_type(struct tree *tp)
3590Sstevel@tonic-gate {
3600Sstevel@tonic-gate 	if( (tp->type == TYPE_INTEGER)
3610Sstevel@tonic-gate 		|| (tp->type == TYPE_COUNTER)
3620Sstevel@tonic-gate 		|| (tp->type == TYPE_GAUGE)
3630Sstevel@tonic-gate 		|| (tp->type == TYPE_TIMETICKS)
3640Sstevel@tonic-gate 		|| (tp->type == TYPE_OCTETSTR)
3650Sstevel@tonic-gate 		|| (tp->type == TYPE_IPADDR)
3660Sstevel@tonic-gate 		|| (tp->type == TYPE_OPAQUE)
3670Sstevel@tonic-gate 		|| (tp->type == TYPE_OBJID) )
3680Sstevel@tonic-gate 	{
3690Sstevel@tonic-gate 		if(tp->parent->type == TYPE_ENTRY)
3700Sstevel@tonic-gate 		{
3710Sstevel@tonic-gate 			if(tp->parent->parent->type == TYPE_TABLE)
3720Sstevel@tonic-gate 			{
3730Sstevel@tonic-gate 				return COLUMN;
3740Sstevel@tonic-gate 			}
3750Sstevel@tonic-gate 			else
3760Sstevel@tonic-gate 			{
3770Sstevel@tonic-gate 				error_exit("get_node_type(): Inconsistent table definition: %s->%s->%s", tp->label, tp->parent->label, tp->parent->parent->label);
3780Sstevel@tonic-gate 			}
3790Sstevel@tonic-gate 		}
3800Sstevel@tonic-gate 		else
3810Sstevel@tonic-gate 		{
3820Sstevel@tonic-gate 			return OBJECT;
3830Sstevel@tonic-gate 		}
3840Sstevel@tonic-gate 	}
3850Sstevel@tonic-gate 	else
3860Sstevel@tonic-gate 	{
3870Sstevel@tonic-gate 		switch(tp->type)
3880Sstevel@tonic-gate 		{
3890Sstevel@tonic-gate 			case TYPE_TABLE:
3900Sstevel@tonic-gate 				return TABLE;
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate 			case TYPE_ENTRY:
3930Sstevel@tonic-gate 				return ENTRY;
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate 			default:
3960Sstevel@tonic-gate 				return NODE;
3970Sstevel@tonic-gate 		}
3980Sstevel@tonic-gate 	}
3990Sstevel@tonic-gate      	return NODE; /*lint*/
4000Sstevel@tonic-gate }
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate /*************************************************************************/
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate /* we suppose that the tree is ordered according to the value of subid */
4060Sstevel@tonic-gate 
init_tree_first_pass(struct tree * current,int * node_index,int * object_index,int * column_index,int * entry_index)4070Sstevel@tonic-gate static void init_tree_first_pass(struct tree *current, int *node_index, int *object_index, int *column_index, int *entry_index)
4080Sstevel@tonic-gate {
4090Sstevel@tonic-gate 	struct tree *tp;
4100Sstevel@tonic-gate 	int node_type;
4110Sstevel@tonic-gate 	struct tree *next;
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate 	/* node_index */
4150Sstevel@tonic-gate 	current->node_index = *node_index;
4160Sstevel@tonic-gate 	(*node_index)++;
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate 
4190Sstevel@tonic-gate 	/* node_type, object_index, column_index */
4200Sstevel@tonic-gate 	node_type = get_node_type(current);
4210Sstevel@tonic-gate 	current->node_type = node_type;
4220Sstevel@tonic-gate 	switch(node_type)
4230Sstevel@tonic-gate 	{
4240Sstevel@tonic-gate 		case OBJECT:
4250Sstevel@tonic-gate 			current->object_index = *object_index;
4260Sstevel@tonic-gate 			current->column_index = -1;
4270Sstevel@tonic-gate 			current->entry_index = -1;
4280Sstevel@tonic-gate 			(*object_index)++;
4290Sstevel@tonic-gate 			break;
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 		case COLUMN:
4320Sstevel@tonic-gate 			current->object_index = -1;
4330Sstevel@tonic-gate 			current->column_index = *column_index;
4340Sstevel@tonic-gate 			current->entry_index = -1;
4350Sstevel@tonic-gate 			(*column_index)++;
4360Sstevel@tonic-gate 			break;
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate 		case NODE:
4390Sstevel@tonic-gate 		case TABLE:
4400Sstevel@tonic-gate 			current->object_index = -1;
4410Sstevel@tonic-gate 			current->column_index = -1;
4420Sstevel@tonic-gate 			current->entry_index = -1;
4430Sstevel@tonic-gate 			break;
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 		case ENTRY:
4460Sstevel@tonic-gate 			current->object_index = -1;
4470Sstevel@tonic-gate 			current->column_index = -1;
4480Sstevel@tonic-gate 			current->entry_index = *entry_index;
4490Sstevel@tonic-gate 			(*entry_index)++;
4500Sstevel@tonic-gate 			break;
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate 		default:
4530Sstevel@tonic-gate 			error_exit("init_tree_first_pass(): Unknown node type (%d) for node %s",
4540Sstevel@tonic-gate 				node_type, current->label);
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate 	}
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate 	/* next FIRST PASS */
4600Sstevel@tonic-gate 	next = current->child_list;
4610Sstevel@tonic-gate 	if(next)
4620Sstevel@tonic-gate 	{
4630Sstevel@tonic-gate 		/* current is not a leaf of the tree */
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 		while(next->child_list)
4660Sstevel@tonic-gate 		{
4670Sstevel@tonic-gate 			next = next->child_list;
4680Sstevel@tonic-gate 		}
4690Sstevel@tonic-gate 		current->next = next;
4700Sstevel@tonic-gate 	}
4710Sstevel@tonic-gate 	else
4720Sstevel@tonic-gate 	{
4730Sstevel@tonic-gate 		/* current is a leaf of the tree */
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate 		struct tree *parent;
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 		parent = current;
4790Sstevel@tonic-gate 		while(parent)
4800Sstevel@tonic-gate 		{
4810Sstevel@tonic-gate 			/* the goal of this loop is to find an ancestor	*/
4820Sstevel@tonic-gate 			/* of current for which the subtree that contains */
4830Sstevel@tonic-gate 			/* current is not the last subtree		*/
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate 			/* is parent the last child? */
4870Sstevel@tonic-gate 			if(parent->next_peer == NULL)
4880Sstevel@tonic-gate 			{
4890Sstevel@tonic-gate 				/* parent is the last child in the child*/
4900Sstevel@tonic-gate 				/* list of its parent, so go one step up*/
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 				parent = parent->parent;
4930Sstevel@tonic-gate 			}
4940Sstevel@tonic-gate 			else
4950Sstevel@tonic-gate 			{
4960Sstevel@tonic-gate 				/* parent is not the last child in the	*/
4970Sstevel@tonic-gate 				/* child list of its parent		*/
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate 				next = parent->next_peer;
5000Sstevel@tonic-gate 				break;
5010Sstevel@tonic-gate 			}
5020Sstevel@tonic-gate 		}
5030Sstevel@tonic-gate 
5040Sstevel@tonic-gate 		if(parent == NULL)
5050Sstevel@tonic-gate 		{
5060Sstevel@tonic-gate 			/* we found the last node of the MIB */
5070Sstevel@tonic-gate 
5080Sstevel@tonic-gate 			current->next = NULL;
5090Sstevel@tonic-gate 		}
5100Sstevel@tonic-gate 		else
5110Sstevel@tonic-gate 		{
5120Sstevel@tonic-gate 			while(next->child_list)
5130Sstevel@tonic-gate 			{
5140Sstevel@tonic-gate 				next = next->child_list;
5150Sstevel@tonic-gate 			}
5160Sstevel@tonic-gate 			current->next = next;
5170Sstevel@tonic-gate 		}
5180Sstevel@tonic-gate 	}
5190Sstevel@tonic-gate 
5200Sstevel@tonic-gate 
5210Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
5220Sstevel@tonic-gate 	{
5230Sstevel@tonic-gate 		init_tree_first_pass(tp, node_index, object_index, column_index, entry_index);
5240Sstevel@tonic-gate 	}
5250Sstevel@tonic-gate }
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate /*************************************************************************/
5290Sstevel@tonic-gate 
init_tree_second_pass(struct tree * current)5300Sstevel@tonic-gate static void init_tree_second_pass(struct tree *current)
5310Sstevel@tonic-gate {
5320Sstevel@tonic-gate 	struct tree *tp;
5330Sstevel@tonic-gate 	struct tree *next;
5340Sstevel@tonic-gate 	int node_type;
5350Sstevel@tonic-gate 	struct index_list *indexs;
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate 	/* next SECOND PASS */
5390Sstevel@tonic-gate 	next = current->next;
5400Sstevel@tonic-gate 	while(next)
5410Sstevel@tonic-gate 	{
5420Sstevel@tonic-gate 		node_type = get_node_type(next);
5430Sstevel@tonic-gate 		if(node_type == OBJECT || node_type == COLUMN)
5440Sstevel@tonic-gate 		{
5450Sstevel@tonic-gate 			if(next->access & READ_FLAG)
5460Sstevel@tonic-gate 			{
5470Sstevel@tonic-gate 				break;
5480Sstevel@tonic-gate 			}
5490Sstevel@tonic-gate 		}
5500Sstevel@tonic-gate 
5510Sstevel@tonic-gate 		next = next->next;
5520Sstevel@tonic-gate 	}
5530Sstevel@tonic-gate 	current->next = next;
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate 
5560Sstevel@tonic-gate 	/* consistency of node_type COLUMN, ENTRY, TABLE */
5570Sstevel@tonic-gate 	switch(current->node_type)
5580Sstevel@tonic-gate 	{
5590Sstevel@tonic-gate 		case COLUMN:
5600Sstevel@tonic-gate 			if(current->parent->node_type != ENTRY)
5610Sstevel@tonic-gate 			{
5620Sstevel@tonic-gate 				error_exit("The node type (%d) of %s is not ENTRY although the node type of %s is COLUMN",
5630Sstevel@tonic-gate 					current->parent->node_type,
5640Sstevel@tonic-gate 					current->parent->label,
5650Sstevel@tonic-gate 					current->label);
5660Sstevel@tonic-gate 			}
5670Sstevel@tonic-gate 			if(current->parent->parent->node_type != TABLE)
5680Sstevel@tonic-gate 			{
5690Sstevel@tonic-gate 				error_exit("The node type (%d) of %s is not TABLE although the node type of %s is COLUMN",
5700Sstevel@tonic-gate 					current->parent->parent->node_type,
5710Sstevel@tonic-gate 					current->parent->parent->label,
5720Sstevel@tonic-gate 					current->label);
5730Sstevel@tonic-gate 			}
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate 			if( (current->n_indexs != 0) || ( current->indexs != NULL) )
5760Sstevel@tonic-gate 			{
5770Sstevel@tonic-gate 				error_exit("The node %s of type COLUMN has some INDEXs!",
5780Sstevel@tonic-gate 					current->label);
5790Sstevel@tonic-gate 			}
5800Sstevel@tonic-gate 
5810Sstevel@tonic-gate 			break;
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate 		case ENTRY:
5850Sstevel@tonic-gate 			if(current->parent->node_type != TABLE)
5860Sstevel@tonic-gate 			{
5870Sstevel@tonic-gate 				error_exit("The node type (%d) of %s is not TABLE although the node type of %s is ENTRY",
5880Sstevel@tonic-gate 					current->parent->node_type,
5890Sstevel@tonic-gate 					current->parent->label,
5900Sstevel@tonic-gate 					current->label);
5910Sstevel@tonic-gate 			}
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate 			/* n_indexs, indexs */
5940Sstevel@tonic-gate 			if( (current->n_indexs == 0) || ( current->indexs == NULL) )
5950Sstevel@tonic-gate 			{
5960Sstevel@tonic-gate 				error_exit("The node %s of type ENTRY has no INDEX",
5970Sstevel@tonic-gate 					current->label);
5980Sstevel@tonic-gate 			}
5990Sstevel@tonic-gate 
6000Sstevel@tonic-gate 			indexs = current->indexs;
6010Sstevel@tonic-gate 			while(indexs)
6020Sstevel@tonic-gate 			{
6030Sstevel@tonic-gate 				indexs->tp = find_node(root, indexs->label);
6040Sstevel@tonic-gate 				if(indexs->tp == NULL)
6050Sstevel@tonic-gate 				{
6060Sstevel@tonic-gate 					error("WARNING: Can't match the INDEX %s of the entry %s",
6070Sstevel@tonic-gate 						indexs->label,
6080Sstevel@tonic-gate 						current->label);
6090Sstevel@tonic-gate 				}
6100Sstevel@tonic-gate 				else
6110Sstevel@tonic-gate 				{
6120Sstevel@tonic-gate 					switch(indexs->tp->type)
6130Sstevel@tonic-gate 					{
6140Sstevel@tonic-gate 						case TYPE_INTEGER:
6150Sstevel@tonic-gate 						case TYPE_COUNTER:
6160Sstevel@tonic-gate 						case TYPE_GAUGE:
6170Sstevel@tonic-gate 						case TYPE_TIMETICKS:
6180Sstevel@tonic-gate                                                 case TYPE_OCTETSTR:
6190Sstevel@tonic-gate 							break;
6200Sstevel@tonic-gate 
6210Sstevel@tonic-gate 						default:
6220Sstevel@tonic-gate 							error("WARNING: The agent will not support the INDEX %s whose type %d for the entry %s",
6230Sstevel@tonic-gate 								indexs->tp->label,
6240Sstevel@tonic-gate 								indexs->tp->type,
6250Sstevel@tonic-gate 								current->label);
6260Sstevel@tonic-gate 					}
6270Sstevel@tonic-gate 				}
6280Sstevel@tonic-gate 				indexs = indexs->next;
6290Sstevel@tonic-gate 			}
6300Sstevel@tonic-gate 
6310Sstevel@tonic-gate 			break;
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate 		default:
6350Sstevel@tonic-gate 			/* n_indexs, indexs */
6360Sstevel@tonic-gate 			if( (current->n_indexs != 0) || ( current->indexs != NULL) )
6370Sstevel@tonic-gate 			{
6380Sstevel@tonic-gate 				error_exit("The node %s of type %d has some INDEXs!",
6390Sstevel@tonic-gate 					current->label,
6400Sstevel@tonic-gate 					current->node_type);
6410Sstevel@tonic-gate 			}
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 			break;
6440Sstevel@tonic-gate 	}
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
6480Sstevel@tonic-gate 	{
6490Sstevel@tonic-gate 		init_tree_second_pass(tp);
6500Sstevel@tonic-gate 	}
6510Sstevel@tonic-gate }
6520Sstevel@tonic-gate 
6530Sstevel@tonic-gate 
6540Sstevel@tonic-gate /*************************************************************************/
output_extern_trap_function(FILE * fp)6550Sstevel@tonic-gate static void output_extern_trap_function(FILE *fp)
6560Sstevel@tonic-gate {
6570Sstevel@tonic-gate   struct trap_item *ip;
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate   fprintf(fp,"extern int SSAGetTrapPort();\n");
6600Sstevel@tonic-gate   for(ip=trap_list;ip;ip=ip->next){
6610Sstevel@tonic-gate 	fprintf(fp, "extern int trap_handler_%s();\n",ip->label);
6620Sstevel@tonic-gate   }
6630Sstevel@tonic-gate }
6640Sstevel@tonic-gate 
output_trap_function_call(FILE * fp)6650Sstevel@tonic-gate static void output_trap_function_call(FILE *fp)
6660Sstevel@tonic-gate {
6670Sstevel@tonic-gate 	struct trap_item *ip;
6680Sstevel@tonic-gate 	struct tree *tp;
6690Sstevel@tonic-gate 	struct index_list *variables;
6700Sstevel@tonic-gate 	int index;
6710Sstevel@tonic-gate 
6720Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
6730Sstevel@tonic-gate 		for (index = 1, variables = ip->var_list; variables;
6740Sstevel@tonic-gate 			variables = variables->next) {
6750Sstevel@tonic-gate 			if ((variables->tp = find_node(root,
6760Sstevel@tonic-gate 				variables->label)) == NULL)
6770Sstevel@tonic-gate 				error_exit("output_trap_structure(): \
6780Sstevel@tonic-gate 				Unknown variable:%s", variables->label);
6790Sstevel@tonic-gate 			tp = variables->tp;
6800Sstevel@tonic-gate 			if (tp->node_type == COLUMN)
6810Sstevel@tonic-gate 				fprintf(fp,
6820Sstevel@tonic-gate 				"\t\tSSASetVarIndx(\"%s\",%d);\n",
6830Sstevel@tonic-gate 				variables->label, index++);
6840Sstevel@tonic-gate 			}
6850Sstevel@tonic-gate 	fprintf(fp, "\t\tSSASendTrap(\"%s\");\n", ip->label);
6860Sstevel@tonic-gate 	}
6870Sstevel@tonic-gate }
6880Sstevel@tonic-gate 
output_extern_function(FILE * fp,struct tree * current)6890Sstevel@tonic-gate static void output_extern_function(FILE *fp, struct tree *current)
6900Sstevel@tonic-gate {
6910Sstevel@tonic-gate 	struct tree *tp;
6920Sstevel@tonic-gate 	struct index_list *indexs;
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate 
6950Sstevel@tonic-gate 	switch(current->node_type)
6960Sstevel@tonic-gate 	{
6970Sstevel@tonic-gate 		case OBJECT:
6980Sstevel@tonic-gate 			if(current->access & READ_FLAG)
6990Sstevel@tonic-gate 			{
7000Sstevel@tonic-gate 				switch(current->type)
7010Sstevel@tonic-gate 				{
7020Sstevel@tonic-gate 					case TYPE_INTEGER:
7030Sstevel@tonic-gate 					case TYPE_COUNTER:
7040Sstevel@tonic-gate 					case TYPE_GAUGE:
7050Sstevel@tonic-gate 					case TYPE_TIMETICKS:
7060Sstevel@tonic-gate 						fprintf(fp, "extern int get_%s(Integer *%s);\n",
7070Sstevel@tonic-gate 							current->label,
7080Sstevel@tonic-gate 							current->label);
7090Sstevel@tonic-gate 						break;
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate 					case TYPE_OCTETSTR:
7120Sstevel@tonic-gate 					case TYPE_IPADDR:
7130Sstevel@tonic-gate 					case TYPE_OPAQUE:
7140Sstevel@tonic-gate 						fprintf(fp, "extern int get_%s(String *%s);\n",
7150Sstevel@tonic-gate 							current->label,
7160Sstevel@tonic-gate 							current->label);
7170Sstevel@tonic-gate 						break;
7180Sstevel@tonic-gate 
7190Sstevel@tonic-gate 					case TYPE_OBJID:
7200Sstevel@tonic-gate 						fprintf(fp, "extern int get_%s(Oid *%s);\n",
7210Sstevel@tonic-gate 							current->label,
7220Sstevel@tonic-gate 							current->label);
7230Sstevel@tonic-gate 						break;
7240Sstevel@tonic-gate 
7250Sstevel@tonic-gate 					default:
7260Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
7270Sstevel@tonic-gate 							current->type,
7280Sstevel@tonic-gate 							current->label);
7290Sstevel@tonic-gate 				}
7300Sstevel@tonic-gate 			}
7310Sstevel@tonic-gate 			if(current->access & WRITE_FLAG)
7320Sstevel@tonic-gate 			{
7330Sstevel@tonic-gate 				switch(current->type)
7340Sstevel@tonic-gate 				{
7350Sstevel@tonic-gate 					case TYPE_INTEGER:
7360Sstevel@tonic-gate 					case TYPE_COUNTER:
7370Sstevel@tonic-gate 					case TYPE_GAUGE:
7380Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-95)*/
7390Sstevel@tonic-gate 						fprintf(fp, "extern int set_%s(int pass, Integer* %s);\n",
7400Sstevel@tonic-gate 							current->label,
7410Sstevel@tonic-gate 							current->label);
7420Sstevel@tonic-gate 						break;
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate 					case TYPE_OCTETSTR:
7450Sstevel@tonic-gate 					case TYPE_IPADDR:
7460Sstevel@tonic-gate 					case TYPE_OPAQUE:
7470Sstevel@tonic-gate 						fprintf(fp, "extern int set_%s(int pass, String *%s);\n",
7480Sstevel@tonic-gate 							current->label,
7490Sstevel@tonic-gate 							current->label);
7500Sstevel@tonic-gate 						break;
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate 					case TYPE_OBJID:
7530Sstevel@tonic-gate 						fprintf(fp, "extern int set_%s(int pass, Oid *%s);\n",
7540Sstevel@tonic-gate 							current->label,
7550Sstevel@tonic-gate 							current->label);
7560Sstevel@tonic-gate 						break;
7570Sstevel@tonic-gate 
7580Sstevel@tonic-gate 					default:
7590Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
7600Sstevel@tonic-gate 							current->type,
7610Sstevel@tonic-gate 							current->label);
7620Sstevel@tonic-gate 				}
7630Sstevel@tonic-gate 			}
7640Sstevel@tonic-gate 
7650Sstevel@tonic-gate 			if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
7660Sstevel@tonic-gate 			{
7670Sstevel@tonic-gate 				switch(current->type)
7680Sstevel@tonic-gate 				{
7690Sstevel@tonic-gate 					case TYPE_INTEGER:
7700Sstevel@tonic-gate 					case TYPE_COUNTER:
7710Sstevel@tonic-gate 					case TYPE_GAUGE:
7720Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-95)*/
7730Sstevel@tonic-gate 						break;
7740Sstevel@tonic-gate 
7750Sstevel@tonic-gate 					case TYPE_OCTETSTR:
7760Sstevel@tonic-gate 					case TYPE_IPADDR:
7770Sstevel@tonic-gate 					case TYPE_OPAQUE:
7780Sstevel@tonic-gate 						fprintf(fp, "extern void free_%s(String *%s);\n",
7790Sstevel@tonic-gate 							current->label,
7800Sstevel@tonic-gate 							current->label);
7810Sstevel@tonic-gate 						break;
7820Sstevel@tonic-gate 
7830Sstevel@tonic-gate 					case TYPE_OBJID:
7840Sstevel@tonic-gate 						fprintf(fp, "extern void free_%s(Oid *%s);\n",
7850Sstevel@tonic-gate 							current->label,
7860Sstevel@tonic-gate 							current->label);
7870Sstevel@tonic-gate 						break;
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate 					default:
7900Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
7910Sstevel@tonic-gate 							current->type,
7920Sstevel@tonic-gate 							current->label);
7930Sstevel@tonic-gate 				}
7940Sstevel@tonic-gate 			}
7950Sstevel@tonic-gate 
7960Sstevel@tonic-gate 			break;
7970Sstevel@tonic-gate 
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 		case COLUMN:
8000Sstevel@tonic-gate 			if(current->access & READ_FLAG)
8010Sstevel@tonic-gate 			{
8020Sstevel@tonic-gate 				fprintf(fp, "extern int get_%s(int search_type, ",
8030Sstevel@tonic-gate 					current->label);
8040Sstevel@tonic-gate 
8050Sstevel@tonic-gate 				switch(current->type)
8060Sstevel@tonic-gate 				{
8070Sstevel@tonic-gate 					case TYPE_INTEGER:
8080Sstevel@tonic-gate 					case TYPE_COUNTER:
8090Sstevel@tonic-gate 					case TYPE_GAUGE:
8100Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
8110Sstevel@tonic-gate 						fprintf(fp, "Integer *%s, ",
8120Sstevel@tonic-gate 							current->label);
8130Sstevel@tonic-gate 						break;
8140Sstevel@tonic-gate 
8150Sstevel@tonic-gate 					case TYPE_OCTETSTR:
8160Sstevel@tonic-gate 					case TYPE_IPADDR:
8170Sstevel@tonic-gate 					case TYPE_OPAQUE:
8180Sstevel@tonic-gate 						fprintf(fp, "String *%s, ",
8190Sstevel@tonic-gate 							current->label);
8200Sstevel@tonic-gate 						break;
8210Sstevel@tonic-gate 
8220Sstevel@tonic-gate 					case TYPE_OBJID:
8230Sstevel@tonic-gate 						fprintf(fp, "Oid *%s, ",
8240Sstevel@tonic-gate 							current->label);
8250Sstevel@tonic-gate 						break;
8260Sstevel@tonic-gate 
8270Sstevel@tonic-gate 					default:
8280Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
8290Sstevel@tonic-gate 						current->type,
8300Sstevel@tonic-gate 						current->label);
8310Sstevel@tonic-gate 				}
8320Sstevel@tonic-gate 
8330Sstevel@tonic-gate 				indexs = current->parent->indexs;
8340Sstevel@tonic-gate 
8350Sstevel@tonic-gate /* not more ind. index */
8360Sstevel@tonic-gate 
8370Sstevel@tonic-gate 				if(indexs)
8380Sstevel@tonic-gate 				{
8390Sstevel@tonic-gate 					if(indexs->tp)
8400Sstevel@tonic-gate 					{
8410Sstevel@tonic-gate 						switch(indexs->tp->type)
8420Sstevel@tonic-gate 						{
8430Sstevel@tonic-gate 							case TYPE_INTEGER:
8440Sstevel@tonic-gate 							case TYPE_COUNTER:
8450Sstevel@tonic-gate 							case TYPE_GAUGE:
8460Sstevel@tonic-gate 							case TYPE_TIMETICKS:
8470Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s);\n",
8480Sstevel@tonic-gate 									"index");
8490Sstevel@tonic-gate 								break;
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate 							case TYPE_OCTETSTR:
8520Sstevel@tonic-gate 							case TYPE_IPADDR:
8530Sstevel@tonic-gate 							case TYPE_OPAQUE:
8540Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s);\n",
8550Sstevel@tonic-gate 									"index");
8560Sstevel@tonic-gate 								break;
8570Sstevel@tonic-gate 
8580Sstevel@tonic-gate 							case TYPE_OBJID:
8590Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s);\n",
8600Sstevel@tonic-gate 									"index");
8610Sstevel@tonic-gate 								break;
8620Sstevel@tonic-gate 
8630Sstevel@tonic-gate 							default:
8640Sstevel@tonic-gate 								error_exit("output_extern_function(): Unknown type (%d) for %s",
8650Sstevel@tonic-gate 								indexs->tp->type,
8660Sstevel@tonic-gate 								indexs->tp->label);
8670Sstevel@tonic-gate 						}
8680Sstevel@tonic-gate 					}
8690Sstevel@tonic-gate 					else
8700Sstevel@tonic-gate 					{
8710Sstevel@tonic-gate 						error("WARNING: By default, the type of INDEX %s set to INTEGER",
8720Sstevel@tonic-gate 							indexs->label);
8730Sstevel@tonic-gate 						fprintf(fp, "IndexType *%s);\n",
8740Sstevel@tonic-gate 								"index");
8750Sstevel@tonic-gate 					}
8760Sstevel@tonic-gate 
8770Sstevel@tonic-gate 					indexs = indexs->next;
8780Sstevel@tonic-gate 				}
8790Sstevel@tonic-gate 
8800Sstevel@tonic-gate 
8810Sstevel@tonic-gate 			}
8820Sstevel@tonic-gate 
8830Sstevel@tonic-gate 			if(current->access & WRITE_FLAG)
8840Sstevel@tonic-gate 			{
8850Sstevel@tonic-gate 				fprintf(fp, "extern int set_%s(int pass, ",
8860Sstevel@tonic-gate 					current->label);
8870Sstevel@tonic-gate 
8880Sstevel@tonic-gate 				indexs = current->parent->indexs;
8890Sstevel@tonic-gate 
8900Sstevel@tonic-gate /* not more ind. index */
8910Sstevel@tonic-gate 
8920Sstevel@tonic-gate 				if(indexs)
8930Sstevel@tonic-gate 				{
8940Sstevel@tonic-gate 					if(indexs->tp)
8950Sstevel@tonic-gate 					{
8960Sstevel@tonic-gate 						switch(indexs->tp->type)
8970Sstevel@tonic-gate 						{
8980Sstevel@tonic-gate 							case TYPE_INTEGER:
8990Sstevel@tonic-gate 							case TYPE_COUNTER:
9000Sstevel@tonic-gate 							case TYPE_GAUGE:
9010Sstevel@tonic-gate 							case TYPE_TIMETICKS:
9020Sstevel@tonic-gate 								fprintf(fp, "IndexType %s, ",
9030Sstevel@tonic-gate 									"index");
9040Sstevel@tonic-gate 								break;
9050Sstevel@tonic-gate 
9060Sstevel@tonic-gate 							case TYPE_OCTETSTR:
9070Sstevel@tonic-gate 							case TYPE_IPADDR:
9080Sstevel@tonic-gate 							case TYPE_OPAQUE:
9090Sstevel@tonic-gate 								fprintf(fp, "IndexType %s, ",
9100Sstevel@tonic-gate 									"index");
9110Sstevel@tonic-gate 								break;
9120Sstevel@tonic-gate 
9130Sstevel@tonic-gate 							case TYPE_OBJID:
9140Sstevel@tonic-gate 								fprintf(fp, "IndexType %s, ",
9150Sstevel@tonic-gate 									"index");
9160Sstevel@tonic-gate 								break;
9170Sstevel@tonic-gate 
9180Sstevel@tonic-gate 							default:
9190Sstevel@tonic-gate 								error_exit("output_extern_function(): Unknown type (%d) for %s",
9200Sstevel@tonic-gate 								indexs->tp->type,
9210Sstevel@tonic-gate 								indexs->tp->label);
9220Sstevel@tonic-gate 						}
9230Sstevel@tonic-gate 					}
9240Sstevel@tonic-gate 					else
9250Sstevel@tonic-gate 					{
9260Sstevel@tonic-gate 						error("WARNING: By default, the type of INDEX %s set to INTEGER",
9270Sstevel@tonic-gate 							indexs->label);
9280Sstevel@tonic-gate 						fprintf(fp, "IndexType %s, ",
9290Sstevel@tonic-gate 								"index");
9300Sstevel@tonic-gate 					}
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate 					indexs = indexs->next;
9330Sstevel@tonic-gate 				}
9340Sstevel@tonic-gate 
9350Sstevel@tonic-gate 
9360Sstevel@tonic-gate 				switch(current->type)
9370Sstevel@tonic-gate 				{
9380Sstevel@tonic-gate 					case TYPE_INTEGER:
9390Sstevel@tonic-gate 					case TYPE_COUNTER:
9400Sstevel@tonic-gate 					case TYPE_GAUGE:
9410Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
9420Sstevel@tonic-gate 						fprintf(fp, "Integer *%s);\n",
9430Sstevel@tonic-gate 							current->label);
9440Sstevel@tonic-gate 						break;
9450Sstevel@tonic-gate 
9460Sstevel@tonic-gate 					case TYPE_OCTETSTR:
9470Sstevel@tonic-gate 					case TYPE_IPADDR:
9480Sstevel@tonic-gate 					case TYPE_OPAQUE:
9490Sstevel@tonic-gate 						fprintf(fp, "String *%s);\n",
9500Sstevel@tonic-gate 							current->label);
9510Sstevel@tonic-gate 						break;
9520Sstevel@tonic-gate 
9530Sstevel@tonic-gate 					case TYPE_OBJID:
9540Sstevel@tonic-gate 						fprintf(fp, "Oid *%s);\n",
9550Sstevel@tonic-gate 							current->label);
9560Sstevel@tonic-gate 						break;
9570Sstevel@tonic-gate 
9580Sstevel@tonic-gate 					default:
9590Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
9600Sstevel@tonic-gate 						current->type,
9610Sstevel@tonic-gate 						current->label);
9620Sstevel@tonic-gate 				}
9630Sstevel@tonic-gate 			}
9640Sstevel@tonic-gate 
9650Sstevel@tonic-gate 			if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
9660Sstevel@tonic-gate 			{
9670Sstevel@tonic-gate 				switch(current->type)
9680Sstevel@tonic-gate 				{
9690Sstevel@tonic-gate 					case TYPE_INTEGER:
9700Sstevel@tonic-gate 					case TYPE_COUNTER:
9710Sstevel@tonic-gate 					case TYPE_GAUGE:
9720Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-95)*/
9730Sstevel@tonic-gate 						break;
9740Sstevel@tonic-gate 
9750Sstevel@tonic-gate 					case TYPE_OCTETSTR:
9760Sstevel@tonic-gate 					case TYPE_IPADDR:
9770Sstevel@tonic-gate 					case TYPE_OPAQUE:
9780Sstevel@tonic-gate 						fprintf(fp, "extern void free_%s(String *%s);\n",
9790Sstevel@tonic-gate 							current->label,
9800Sstevel@tonic-gate 							current->label);
9810Sstevel@tonic-gate 						break;
9820Sstevel@tonic-gate 
9830Sstevel@tonic-gate 					case TYPE_OBJID:
9840Sstevel@tonic-gate 						fprintf(fp, "extern void free_%s(Oid *%s);\n",
9850Sstevel@tonic-gate 							current->label,
9860Sstevel@tonic-gate 							current->label);
9870Sstevel@tonic-gate 						break;
9880Sstevel@tonic-gate 
9890Sstevel@tonic-gate 					default:
9900Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
9910Sstevel@tonic-gate 							current->type,
9920Sstevel@tonic-gate 							current->label);
9930Sstevel@tonic-gate 				}
9940Sstevel@tonic-gate 			}
9950Sstevel@tonic-gate 
9960Sstevel@tonic-gate 			break;
9970Sstevel@tonic-gate 
9980Sstevel@tonic-gate 
9990Sstevel@tonic-gate 		case ENTRY:
10000Sstevel@tonic-gate 			fprintf(fp, "extern int get_%s(int search_type, %c%s_t **%s_data",
10010Sstevel@tonic-gate 				current->label,
10020Sstevel@tonic-gate 				toupper(current->label[0]),
10030Sstevel@tonic-gate 				&(current->label[1]),
10040Sstevel@tonic-gate 				current->label);
10050Sstevel@tonic-gate 
10060Sstevel@tonic-gate 
10070Sstevel@tonic-gate 			indexs = current->indexs;
10080Sstevel@tonic-gate 
10090Sstevel@tonic-gate /* no more ind. index */
10100Sstevel@tonic-gate 			if(indexs)
10110Sstevel@tonic-gate 			{
10120Sstevel@tonic-gate 				if(indexs->tp)
10130Sstevel@tonic-gate 				{
10140Sstevel@tonic-gate 					switch(indexs->tp->type)
10150Sstevel@tonic-gate 					{
10160Sstevel@tonic-gate 						case TYPE_INTEGER:
10170Sstevel@tonic-gate 						case TYPE_COUNTER:
10180Sstevel@tonic-gate 						case TYPE_GAUGE:
10190Sstevel@tonic-gate 						case TYPE_TIMETICKS:
10200Sstevel@tonic-gate 							fprintf(fp, ", IndexType *%s",
10210Sstevel@tonic-gate 								"index");
10220Sstevel@tonic-gate 							break;
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate 						case TYPE_OCTETSTR:
10250Sstevel@tonic-gate 						case TYPE_IPADDR:
10260Sstevel@tonic-gate 						case TYPE_OPAQUE:
10270Sstevel@tonic-gate 							fprintf(fp, ", IndexType *%s",
10280Sstevel@tonic-gate 								"index");
10290Sstevel@tonic-gate 							break;
10300Sstevel@tonic-gate 
10310Sstevel@tonic-gate 						case TYPE_OBJID:
10320Sstevel@tonic-gate 							fprintf(fp, ", IndexType *%s",
10330Sstevel@tonic-gate 								"index");
10340Sstevel@tonic-gate 
10350Sstevel@tonic-gate 						default:
10360Sstevel@tonic-gate 							error_exit("output_extern_function(): Unknown type (%d) for %s",
10370Sstevel@tonic-gate 							indexs->tp->type,
10380Sstevel@tonic-gate 							indexs->tp->label);
10390Sstevel@tonic-gate 					}
10400Sstevel@tonic-gate 				}
10410Sstevel@tonic-gate 				else
10420Sstevel@tonic-gate 				{
10430Sstevel@tonic-gate 					error("WARNING: By default, the type of INDEX %s set to INTEGER",
10440Sstevel@tonic-gate 						indexs->label);
10450Sstevel@tonic-gate 					fprintf(fp, ", IndexType *%s",
10460Sstevel@tonic-gate 							"index");
10470Sstevel@tonic-gate 				}
10480Sstevel@tonic-gate 
10490Sstevel@tonic-gate 				indexs = indexs->next;
10500Sstevel@tonic-gate 			}
10510Sstevel@tonic-gate 			fprintf(fp, ");\n");
10520Sstevel@tonic-gate 
10530Sstevel@tonic-gate 			fprintf(fp, "extern void free_%s(%c%s_t *%s);\n",
10540Sstevel@tonic-gate 				current->label,
10550Sstevel@tonic-gate 				toupper(current->label[0]),
10560Sstevel@tonic-gate 				&(current->label[1]),
10570Sstevel@tonic-gate 				current->label);
10580Sstevel@tonic-gate 			break;
10590Sstevel@tonic-gate 	}
10600Sstevel@tonic-gate 
10610Sstevel@tonic-gate 
10620Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
10630Sstevel@tonic-gate 	{
10640Sstevel@tonic-gate 		output_extern_function(fp, tp);
10650Sstevel@tonic-gate 	}
10660Sstevel@tonic-gate }
10670Sstevel@tonic-gate 
10680Sstevel@tonic-gate 
10690Sstevel@tonic-gate /*************************************************************************/
10700Sstevel@tonic-gate 
output_enum_table(FILE * fp,struct tree * current,int * enum_index)10710Sstevel@tonic-gate static void output_enum_table(FILE *fp, struct tree *current, int *enum_index)
10720Sstevel@tonic-gate {
10730Sstevel@tonic-gate 	struct tree *tp;
10740Sstevel@tonic-gate 	struct enum_list *enums;
10750Sstevel@tonic-gate 
10760Sstevel@tonic-gate 
10770Sstevel@tonic-gate 	for(enums = current->enums; enums; enums = enums->next)
10780Sstevel@tonic-gate 	{
10790Sstevel@tonic-gate 		if(enums->next == NULL)
10800Sstevel@tonic-gate 		{
10810Sstevel@tonic-gate 			fprintf(fp, "/* %6d */ { %17s, \"%s\", %d },\n",
10820Sstevel@tonic-gate 				*enum_index,
10830Sstevel@tonic-gate 				"NULL",
10840Sstevel@tonic-gate 				enums->label,
10850Sstevel@tonic-gate 				enums->value);
10860Sstevel@tonic-gate 		}
10870Sstevel@tonic-gate 		else
10880Sstevel@tonic-gate 		{
10890Sstevel@tonic-gate 			fprintf(fp, "/* %6d */ { &enum_table[%4d], \"%s\", %d },\n",
10900Sstevel@tonic-gate 				*enum_index,
10910Sstevel@tonic-gate 				(*enum_index) + 1,
10920Sstevel@tonic-gate 				enums->label,
10930Sstevel@tonic-gate 				enums->value);
10940Sstevel@tonic-gate 		}
10950Sstevel@tonic-gate 		(*enum_index)++;
10960Sstevel@tonic-gate 	}
10970Sstevel@tonic-gate 
10980Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
10990Sstevel@tonic-gate 	{
11000Sstevel@tonic-gate 		output_enum_table(fp, tp, enum_index);
11010Sstevel@tonic-gate 	}
11020Sstevel@tonic-gate }
11030Sstevel@tonic-gate 
11040Sstevel@tonic-gate 
11050Sstevel@tonic-gate /*************************************************************************/
11060Sstevel@tonic-gate 
output_subid_table(FILE * fp,struct tree * current,int * subid_index)11070Sstevel@tonic-gate static void output_subid_table(FILE *fp, struct tree *current, int *subid_index)
11080Sstevel@tonic-gate {
11090Sstevel@tonic-gate 	struct tree *tp;
11100Sstevel@tonic-gate 	struct tree *parent;
11110Sstevel@tonic-gate 	Subid subids[MAX_OID_LEN];
11120Sstevel@tonic-gate 	int len = 0;
11130Sstevel@tonic-gate 	int i;
11140Sstevel@tonic-gate 
11150Sstevel@tonic-gate 
11160Sstevel@tonic-gate 	if( (current->node_type == OBJECT)
11170Sstevel@tonic-gate 		|| (current->node_type == COLUMN) )
11180Sstevel@tonic-gate 	{
11190Sstevel@tonic-gate 		fprintf(fp, "/* %6d */",
11200Sstevel@tonic-gate 			*subid_index);
11210Sstevel@tonic-gate 
11220Sstevel@tonic-gate 		parent = current;
11230Sstevel@tonic-gate 		while(parent)
11240Sstevel@tonic-gate 		{
11250Sstevel@tonic-gate 			subids[len++] = parent->subid;
11260Sstevel@tonic-gate 
11270Sstevel@tonic-gate 			parent = parent->parent;
11280Sstevel@tonic-gate 		}
11290Sstevel@tonic-gate 		fprintf(fp, " %d", subids[len - 1]);
11300Sstevel@tonic-gate 		(*subid_index)++;
11310Sstevel@tonic-gate 		for(i = len - 2; i >= 0; i--)
11320Sstevel@tonic-gate 		{
11330Sstevel@tonic-gate 			fprintf(fp, ", %d", subids[i]);
11340Sstevel@tonic-gate 			(*subid_index)++;
11350Sstevel@tonic-gate 		}
11360Sstevel@tonic-gate 		fprintf(fp, ",\n");
11370Sstevel@tonic-gate 	}
11380Sstevel@tonic-gate 
11390Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
11400Sstevel@tonic-gate 	{
11410Sstevel@tonic-gate 		output_subid_table(fp, tp, subid_index);
11420Sstevel@tonic-gate 	}
11430Sstevel@tonic-gate }
11440Sstevel@tonic-gate 
11450Sstevel@tonic-gate 
11460Sstevel@tonic-gate /*************************************************************************/
11470Sstevel@tonic-gate 
output_object_table(FILE * fp,struct tree * current,int * subid_index,int * enum_index,int * size)11480Sstevel@tonic-gate static void output_object_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size)
11490Sstevel@tonic-gate {
11500Sstevel@tonic-gate 	struct tree *tp;
11510Sstevel@tonic-gate 	struct tree *parent;
11520Sstevel@tonic-gate 	struct enum_list *enums;
11530Sstevel@tonic-gate 	int len;
11540Sstevel@tonic-gate 
11550Sstevel@tonic-gate 
11560Sstevel@tonic-gate 	if(current->node_type == OBJECT)
11570Sstevel@tonic-gate 	{
11580Sstevel@tonic-gate 		fprintf(fp, "/* %6d */ {",
11590Sstevel@tonic-gate 			current->object_index);
11600Sstevel@tonic-gate 
11610Sstevel@tonic-gate 		/* name */
11620Sstevel@tonic-gate 		len = 0;
11630Sstevel@tonic-gate 		parent = current;
11640Sstevel@tonic-gate 		while(parent)
11650Sstevel@tonic-gate 		{
11660Sstevel@tonic-gate 			len++;
11670Sstevel@tonic-gate 
11680Sstevel@tonic-gate 			parent = parent->parent;
11690Sstevel@tonic-gate 		}
11700Sstevel@tonic-gate 		fprintf(fp, " { &subid_table[%d], %d }", *subid_index, len);
11710Sstevel@tonic-gate 
11720Sstevel@tonic-gate 		/* asn1_type */
11730Sstevel@tonic-gate 		switch(current->type)
11740Sstevel@tonic-gate 		{
11750Sstevel@tonic-gate 			case TYPE_INTEGER:
11760Sstevel@tonic-gate 				fprintf(fp, ", INTEGER");
11770Sstevel@tonic-gate 				break;
11780Sstevel@tonic-gate 
11790Sstevel@tonic-gate 			case TYPE_COUNTER:
11800Sstevel@tonic-gate 				fprintf(fp, ", COUNTER");
11810Sstevel@tonic-gate 				break;
11820Sstevel@tonic-gate 
11830Sstevel@tonic-gate 			case TYPE_GAUGE:
11840Sstevel@tonic-gate 				fprintf(fp, ", GAUGE");
11850Sstevel@tonic-gate 				break;
11860Sstevel@tonic-gate 
11870Sstevel@tonic-gate 			case TYPE_TIMETICKS:
11880Sstevel@tonic-gate 				fprintf(fp, ", TIMETICKS");
11890Sstevel@tonic-gate 				break;
11900Sstevel@tonic-gate 
11910Sstevel@tonic-gate 			case TYPE_OCTETSTR:
11920Sstevel@tonic-gate 				fprintf(fp, ", STRING");
11930Sstevel@tonic-gate 				break;
11940Sstevel@tonic-gate 
11950Sstevel@tonic-gate 			case TYPE_IPADDR:
11960Sstevel@tonic-gate 				fprintf(fp, ", IPADDRESS");
11970Sstevel@tonic-gate 				break;
11980Sstevel@tonic-gate 
11990Sstevel@tonic-gate 			case TYPE_OPAQUE:
12000Sstevel@tonic-gate 				fprintf(fp, ", OPAQUE");
12010Sstevel@tonic-gate 				break;
12020Sstevel@tonic-gate 
12030Sstevel@tonic-gate 			case TYPE_OBJID:
12040Sstevel@tonic-gate 				fprintf(fp, ", OBJID");
12050Sstevel@tonic-gate 				break;
12060Sstevel@tonic-gate 
12070Sstevel@tonic-gate 			default:
12080Sstevel@tonic-gate 				fprintf(fp, "ERROR!");
12090Sstevel@tonic-gate 				error_exit("Unknown ASN.1 type (%d) for object %s",
12100Sstevel@tonic-gate 					current->type,
12110Sstevel@tonic-gate 					current->label);
12120Sstevel@tonic-gate 		}
12130Sstevel@tonic-gate 
12140Sstevel@tonic-gate 		/* first_enum */
12150Sstevel@tonic-gate 		if(current->enums)
12160Sstevel@tonic-gate 		{
12170Sstevel@tonic-gate 			fprintf(fp, ", &enum_table[%d]", *enum_index);
12180Sstevel@tonic-gate 		}
12190Sstevel@tonic-gate 		else
12200Sstevel@tonic-gate 		{
12210Sstevel@tonic-gate 			fprintf(fp, ", NULL");
12220Sstevel@tonic-gate 		}
12230Sstevel@tonic-gate 
12240Sstevel@tonic-gate 		/* access */
12250Sstevel@tonic-gate 		if( (current->access & READ_FLAG) && (current->access & WRITE_FLAG) )
12260Sstevel@tonic-gate 		{
12270Sstevel@tonic-gate 			fprintf(fp, ", READ_FLAG | WRITE_FLAG");
12280Sstevel@tonic-gate 		}
12290Sstevel@tonic-gate 		else
12300Sstevel@tonic-gate 		if( (current->access & READ_FLAG) && !(current->access & WRITE_FLAG) )
12310Sstevel@tonic-gate 		{
12320Sstevel@tonic-gate 			fprintf(fp, ", READ_FLAG");
12330Sstevel@tonic-gate 		}
12340Sstevel@tonic-gate 		else
12350Sstevel@tonic-gate 		if( !(current->access & READ_FLAG) && (current->access & WRITE_FLAG) )
12360Sstevel@tonic-gate 		{
12370Sstevel@tonic-gate 			fprintf(fp, ", WRITE_FLAG");
12380Sstevel@tonic-gate 		}
12390Sstevel@tonic-gate 		else
12400Sstevel@tonic-gate 		{
12410Sstevel@tonic-gate 			fprintf(fp, ", 0");
12420Sstevel@tonic-gate 		}
12430Sstevel@tonic-gate                 /* type for trap fix */
12440Sstevel@tonic-gate 
12450Sstevel@tonic-gate                 fprintf(fp, ", 1");
12460Sstevel@tonic-gate 
12470Sstevel@tonic-gate 		/* get() */
12480Sstevel@tonic-gate 		if(current->access & READ_FLAG)
12490Sstevel@tonic-gate 		{
12500Sstevel@tonic-gate 			fprintf(fp, ", get_%s", current->label);
12510Sstevel@tonic-gate 		}
12520Sstevel@tonic-gate 		else
12530Sstevel@tonic-gate 		{
12540Sstevel@tonic-gate 			fprintf(fp, ", NULL");
12550Sstevel@tonic-gate 		}
12560Sstevel@tonic-gate 
12570Sstevel@tonic-gate 		/* set() */
12580Sstevel@tonic-gate 		if(current->access & WRITE_FLAG)
12590Sstevel@tonic-gate 		{
12600Sstevel@tonic-gate 			fprintf(fp, ", set_%s", current->label);
12610Sstevel@tonic-gate 		}
12620Sstevel@tonic-gate 		else
12630Sstevel@tonic-gate 		{
12640Sstevel@tonic-gate 			fprintf(fp, ", NULL");
12650Sstevel@tonic-gate 		}
12660Sstevel@tonic-gate 
12670Sstevel@tonic-gate 		/* dealloc() */
12680Sstevel@tonic-gate 		if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
12690Sstevel@tonic-gate 		{
12700Sstevel@tonic-gate 			switch(current->type)
12710Sstevel@tonic-gate 			{
12720Sstevel@tonic-gate 				case TYPE_INTEGER:
12730Sstevel@tonic-gate 				case TYPE_COUNTER:
12740Sstevel@tonic-gate 				case TYPE_GAUGE:
12750Sstevel@tonic-gate 				case TYPE_TIMETICKS:
12760Sstevel@tonic-gate 					fprintf(fp,",NULL");
12770Sstevel@tonic-gate 					break;
12780Sstevel@tonic-gate 				default:
12790Sstevel@tonic-gate 					fprintf(fp,",free_%s",current->label);
12800Sstevel@tonic-gate 			}
12810Sstevel@tonic-gate 		}
12820Sstevel@tonic-gate 		else
12830Sstevel@tonic-gate 		{
12840Sstevel@tonic-gate 			fprintf(fp,", NULL");
12850Sstevel@tonic-gate 		}
12860Sstevel@tonic-gate 
12870Sstevel@tonic-gate 
12880Sstevel@tonic-gate 		fprintf(fp, " },\n");
12890Sstevel@tonic-gate 
12900Sstevel@tonic-gate 
12910Sstevel@tonic-gate 		(*size)++;
12920Sstevel@tonic-gate 	}
12930Sstevel@tonic-gate 
12940Sstevel@tonic-gate 
12950Sstevel@tonic-gate 	if( (current->node_type == OBJECT)
12960Sstevel@tonic-gate 		|| (current->node_type == COLUMN) )
12970Sstevel@tonic-gate 	{
12980Sstevel@tonic-gate 		parent = current;
12990Sstevel@tonic-gate 		while(parent)
13000Sstevel@tonic-gate 		{
13010Sstevel@tonic-gate 			(*subid_index)++;
13020Sstevel@tonic-gate 
13030Sstevel@tonic-gate 			parent = parent->parent;
13040Sstevel@tonic-gate 		}
13050Sstevel@tonic-gate 	}
13060Sstevel@tonic-gate 
13070Sstevel@tonic-gate 
13080Sstevel@tonic-gate 	for(enums = current->enums; enums; enums = enums->next)
13090Sstevel@tonic-gate 	{
13100Sstevel@tonic-gate 		(*enum_index)++;
13110Sstevel@tonic-gate 	}
13120Sstevel@tonic-gate 
13130Sstevel@tonic-gate 
13140Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
13150Sstevel@tonic-gate 	{
13160Sstevel@tonic-gate 		output_object_table(fp, tp, subid_index, enum_index, size);
13170Sstevel@tonic-gate 	}
13180Sstevel@tonic-gate }
13190Sstevel@tonic-gate 
13200Sstevel@tonic-gate 
13210Sstevel@tonic-gate /*************************************************************************/
13220Sstevel@tonic-gate 
output_index_table(FILE * fp,struct tree * current,int * index_index)13230Sstevel@tonic-gate static void output_index_table(FILE *fp, struct tree *current, int *index_index)
13240Sstevel@tonic-gate {
13250Sstevel@tonic-gate 	struct tree *tp;
13260Sstevel@tonic-gate 	struct index_list *indexs;
13270Sstevel@tonic-gate 
13280Sstevel@tonic-gate 
13290Sstevel@tonic-gate 	for(indexs = current->indexs; indexs; indexs = indexs->next)
13300Sstevel@tonic-gate 	{
13310Sstevel@tonic-gate 		if(indexs->tp)
13320Sstevel@tonic-gate 		{
13330Sstevel@tonic-gate 			if(indexs->next == NULL)
13340Sstevel@tonic-gate 			{
13350Sstevel@tonic-gate 				fprintf(fp, "/* %6d */ { %17s, \"%s\", %2d, %2d, &node_table[%d] },\n",
13360Sstevel@tonic-gate 					*index_index,
13370Sstevel@tonic-gate 					"NULL",
13380Sstevel@tonic-gate 					indexs->label,
13390Sstevel@tonic-gate                                         indexs->tp->type,
13400Sstevel@tonic-gate                                         indexs->tp->oct_str_len,
13410Sstevel@tonic-gate 					indexs->tp->node_index);
13420Sstevel@tonic-gate 			}
13430Sstevel@tonic-gate 			else
13440Sstevel@tonic-gate 			{
13450Sstevel@tonic-gate 				fprintf(fp, "/* %6d */ { &index_table[%4d], \"%s\", %2d, %2d, &node_table[%d] },\n",
13460Sstevel@tonic-gate 					*index_index,
13470Sstevel@tonic-gate 					(*index_index) + 1,
13480Sstevel@tonic-gate 					indexs->label,
13490Sstevel@tonic-gate                                         indexs->tp->type,
13500Sstevel@tonic-gate                                         indexs->tp->oct_str_len,
13510Sstevel@tonic-gate 					indexs->tp->node_index);
13520Sstevel@tonic-gate 			}
13530Sstevel@tonic-gate 		}
13540Sstevel@tonic-gate 		else
13550Sstevel@tonic-gate 		{
13560Sstevel@tonic-gate 			error("WARNING: node pointer for INDEX %s is NULL",
13570Sstevel@tonic-gate 				indexs->label);
13580Sstevel@tonic-gate 
13590Sstevel@tonic-gate 			if(indexs->next == NULL)
13600Sstevel@tonic-gate 			{
13610Sstevel@tonic-gate 				fprintf(fp, "/* %6d */ { %17s, \"%s\", %2d, %2d, NULL },\n",
13620Sstevel@tonic-gate 					*index_index,
13630Sstevel@tonic-gate 					"NULL",
13640Sstevel@tonic-gate 					indexs->label,
13650Sstevel@tonic-gate                                         indexs->tp->type,
13660Sstevel@tonic-gate                                         indexs->tp->oct_str_len);
13670Sstevel@tonic-gate 			}
13680Sstevel@tonic-gate 			else
13690Sstevel@tonic-gate 			{
13700Sstevel@tonic-gate 				fprintf(fp, "/* %6d */ { &index_table[%4d], \"%s\", %2d, %2d, NULL },\n",
13710Sstevel@tonic-gate 					*index_index,
13720Sstevel@tonic-gate 					(*index_index) + 1,
13730Sstevel@tonic-gate 					indexs->label,
13740Sstevel@tonic-gate                                         indexs->tp->type,
13750Sstevel@tonic-gate                                         indexs->tp->oct_str_len);
13760Sstevel@tonic-gate 			}
13770Sstevel@tonic-gate 		}
13780Sstevel@tonic-gate 
13790Sstevel@tonic-gate 		(*index_index)++;
13800Sstevel@tonic-gate 	}
13810Sstevel@tonic-gate 
13820Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
13830Sstevel@tonic-gate 	{
13840Sstevel@tonic-gate 		output_index_table(fp, tp, index_index);
13850Sstevel@tonic-gate 	}
13860Sstevel@tonic-gate }
13870Sstevel@tonic-gate 
13880Sstevel@tonic-gate 
13890Sstevel@tonic-gate /*************************************************************************/
13900Sstevel@tonic-gate 
output_entry_table(FILE * fp,struct tree * current,int * index_index,int * size)13910Sstevel@tonic-gate static void output_entry_table(FILE *fp, struct tree *current, int *index_index, int *size)
13920Sstevel@tonic-gate {
13930Sstevel@tonic-gate 	struct tree *tp;
13940Sstevel@tonic-gate 
13950Sstevel@tonic-gate 
13960Sstevel@tonic-gate 	if(current->node_type == ENTRY)
13970Sstevel@tonic-gate 	{
13980Sstevel@tonic-gate 		struct index_list *indexs;
13990Sstevel@tonic-gate 
14000Sstevel@tonic-gate 
14010Sstevel@tonic-gate 		fprintf(fp, "/* %6d */ {",
14020Sstevel@tonic-gate 			current->entry_index);
14030Sstevel@tonic-gate 
14040Sstevel@tonic-gate 		/* first_index, n_indexs */
14050Sstevel@tonic-gate 		fprintf(fp, " &index_table[%d], %d",
14060Sstevel@tonic-gate 			*index_index,
14070Sstevel@tonic-gate 			current->n_indexs);
14080Sstevel@tonic-gate 
14090Sstevel@tonic-gate 		for(indexs = current->indexs; indexs; indexs = indexs->next)
14100Sstevel@tonic-gate 		{
14110Sstevel@tonic-gate 			(*index_index)++;
14120Sstevel@tonic-gate 		}
14130Sstevel@tonic-gate 
14140Sstevel@tonic-gate 		/* get() */
14150Sstevel@tonic-gate 		fprintf(fp, ", get_%s", current->label);
14160Sstevel@tonic-gate 
14170Sstevel@tonic-gate 		/* dealloc() */
14180Sstevel@tonic-gate 		fprintf(fp, ", free_%s", current->label);
14190Sstevel@tonic-gate 
14200Sstevel@tonic-gate 		fprintf(fp, " },\n");
14210Sstevel@tonic-gate 
14220Sstevel@tonic-gate 
14230Sstevel@tonic-gate 		(*size)++;
14240Sstevel@tonic-gate 	}
14250Sstevel@tonic-gate 
14260Sstevel@tonic-gate 
14270Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
14280Sstevel@tonic-gate 	{
14290Sstevel@tonic-gate 		output_entry_table(fp, tp, index_index, size);
14300Sstevel@tonic-gate 	}
14310Sstevel@tonic-gate }
14320Sstevel@tonic-gate 
14330Sstevel@tonic-gate 
14340Sstevel@tonic-gate /*************************************************************************/
14350Sstevel@tonic-gate 
output_column_table(FILE * fp,struct tree * current,int * subid_index,int * enum_index,int * size)14360Sstevel@tonic-gate static void output_column_table(FILE *fp, struct tree *current, int *subid_index, int *enum_index, int *size)
14370Sstevel@tonic-gate {
14380Sstevel@tonic-gate 	struct tree *tp;
14390Sstevel@tonic-gate 	struct tree *parent;
14400Sstevel@tonic-gate 	struct enum_list *enums;
14410Sstevel@tonic-gate 
14420Sstevel@tonic-gate 
14430Sstevel@tonic-gate 	if(current->node_type == COLUMN)
14440Sstevel@tonic-gate 	{
14450Sstevel@tonic-gate 		int offset;
14460Sstevel@tonic-gate 		int len;
14470Sstevel@tonic-gate 		struct tree *child;
14480Sstevel@tonic-gate 
14490Sstevel@tonic-gate 
14500Sstevel@tonic-gate 		fprintf(fp, "/* %6d */ {",
14510Sstevel@tonic-gate 			current->column_index);
14520Sstevel@tonic-gate 
14530Sstevel@tonic-gate 		/* name */
14540Sstevel@tonic-gate 		len = 0;
14550Sstevel@tonic-gate 		parent = current;
14560Sstevel@tonic-gate 		while(parent)
14570Sstevel@tonic-gate 		{
14580Sstevel@tonic-gate 			len++;
14590Sstevel@tonic-gate 
14600Sstevel@tonic-gate 			parent = parent->parent;
14610Sstevel@tonic-gate 		}
14620Sstevel@tonic-gate 		fprintf(fp, " { &subid_table[%d], %d }", *subid_index, len);
14630Sstevel@tonic-gate 
14640Sstevel@tonic-gate 		/* asn1_type */
14650Sstevel@tonic-gate 		switch(current->type)
14660Sstevel@tonic-gate 		{
14670Sstevel@tonic-gate 			case TYPE_INTEGER:
14680Sstevel@tonic-gate 				fprintf(fp, ", INTEGER");
14690Sstevel@tonic-gate 				break;
14700Sstevel@tonic-gate 
14710Sstevel@tonic-gate 			case TYPE_COUNTER:
14720Sstevel@tonic-gate 				fprintf(fp, ", COUNTER");
14730Sstevel@tonic-gate 				break;
14740Sstevel@tonic-gate 
14750Sstevel@tonic-gate 			case TYPE_GAUGE:
14760Sstevel@tonic-gate 				fprintf(fp, ", GAUGE");
14770Sstevel@tonic-gate 				break;
14780Sstevel@tonic-gate 
14790Sstevel@tonic-gate 			case TYPE_TIMETICKS:
14800Sstevel@tonic-gate 				fprintf(fp, ", TIMETICKS");
14810Sstevel@tonic-gate 				break;
14820Sstevel@tonic-gate 
14830Sstevel@tonic-gate 			case TYPE_OCTETSTR:
14840Sstevel@tonic-gate 				fprintf(fp, ", STRING");
14850Sstevel@tonic-gate 				break;
14860Sstevel@tonic-gate 
14870Sstevel@tonic-gate 			case TYPE_IPADDR:
14880Sstevel@tonic-gate 				fprintf(fp, ", IPADDRESS");
14890Sstevel@tonic-gate 				break;
14900Sstevel@tonic-gate 
14910Sstevel@tonic-gate 			case TYPE_OPAQUE:
14920Sstevel@tonic-gate 				fprintf(fp, ", OPAQUE");
14930Sstevel@tonic-gate 				break;
14940Sstevel@tonic-gate 
14950Sstevel@tonic-gate 			case TYPE_OBJID:
14960Sstevel@tonic-gate 				fprintf(fp, ", OBJID");
14970Sstevel@tonic-gate 				break;
14980Sstevel@tonic-gate 
14990Sstevel@tonic-gate 			default:
15000Sstevel@tonic-gate 				fprintf(fp, "ERROR!");
15010Sstevel@tonic-gate 				error_exit("Unknown ASN.1 type (%d) for object %s",
15020Sstevel@tonic-gate 					current->type,
15030Sstevel@tonic-gate 					current->label);
15040Sstevel@tonic-gate 		}
15050Sstevel@tonic-gate 
15060Sstevel@tonic-gate 		/* first_enum */
15070Sstevel@tonic-gate 		if(current->enums)
15080Sstevel@tonic-gate 		{
15090Sstevel@tonic-gate 			fprintf(fp, ", &enum_table[%d]", *enum_index);
15100Sstevel@tonic-gate 		}
15110Sstevel@tonic-gate 		else
15120Sstevel@tonic-gate 		{
15130Sstevel@tonic-gate 			fprintf(fp, ", NULL");
15140Sstevel@tonic-gate 		}
15150Sstevel@tonic-gate 
15160Sstevel@tonic-gate 		/* access */
15170Sstevel@tonic-gate 		if( (current->access & READ_FLAG) && (current->access & WRITE_FLAG) )
15180Sstevel@tonic-gate 		{
15190Sstevel@tonic-gate 			fprintf(fp, ", READ_FLAG | WRITE_FLAG");
15200Sstevel@tonic-gate 		}
15210Sstevel@tonic-gate 		else
15220Sstevel@tonic-gate 		if( (current->access & READ_FLAG) && !(current->access & WRITE_FLAG) )
15230Sstevel@tonic-gate 		{
15240Sstevel@tonic-gate 			fprintf(fp, ", READ_FLAG");
15250Sstevel@tonic-gate 		}
15260Sstevel@tonic-gate 		else
15270Sstevel@tonic-gate 		if( !(current->access & READ_FLAG) && (current->access & WRITE_FLAG) )
15280Sstevel@tonic-gate 		{
15290Sstevel@tonic-gate 			fprintf(fp, ", WRITE_FLAG");
15300Sstevel@tonic-gate 		}
15310Sstevel@tonic-gate 		else
15320Sstevel@tonic-gate 		{
15330Sstevel@tonic-gate 			fprintf(fp, ", 0");
15340Sstevel@tonic-gate 		}
15350Sstevel@tonic-gate                 /* type  for trap fix */
15360Sstevel@tonic-gate 
15370Sstevel@tonic-gate                 fprintf(fp, ", 2");
15380Sstevel@tonic-gate 
15390Sstevel@tonic-gate                /* get() */
15400Sstevel@tonic-gate 
15410Sstevel@tonic-gate                 if(current->access & READ_FLAG)
15420Sstevel@tonic-gate                 {
15430Sstevel@tonic-gate                         fprintf(fp, ", get_%s", current->label);
15440Sstevel@tonic-gate                 }
15450Sstevel@tonic-gate                 else
15460Sstevel@tonic-gate                 {
15470Sstevel@tonic-gate                         fprintf(fp, ", NULL");
15480Sstevel@tonic-gate                 }
15490Sstevel@tonic-gate 
15500Sstevel@tonic-gate 		/* set() */
15510Sstevel@tonic-gate 		if(current->access & WRITE_FLAG)
15520Sstevel@tonic-gate 		{
15530Sstevel@tonic-gate 			fprintf(fp, ", set_%s", current->label);
15540Sstevel@tonic-gate 		}
15550Sstevel@tonic-gate 		else
15560Sstevel@tonic-gate 		{
15570Sstevel@tonic-gate 			fprintf(fp, ", NULL");
15580Sstevel@tonic-gate 		}
15590Sstevel@tonic-gate 
15600Sstevel@tonic-gate 		/* table */
15610Sstevel@tonic-gate 		fprintf(fp, ", &entry_table[%d]", current->parent->entry_index);
15620Sstevel@tonic-gate 
15630Sstevel@tonic-gate 		/* offset */
15640Sstevel@tonic-gate 		offset = 0;
15650Sstevel@tonic-gate 		for(child = current->parent->child_list; child != current; child = child->next_peer)
15660Sstevel@tonic-gate 		{
15670Sstevel@tonic-gate 			if( !(child->access & READ_FLAG) )
15680Sstevel@tonic-gate 			{
15690Sstevel@tonic-gate 				continue;
15700Sstevel@tonic-gate 			}
15710Sstevel@tonic-gate 
15720Sstevel@tonic-gate 			switch(child->type)
15730Sstevel@tonic-gate 			{
15740Sstevel@tonic-gate 				case TYPE_INTEGER:
15750Sstevel@tonic-gate 				case TYPE_COUNTER:
15760Sstevel@tonic-gate 				case TYPE_GAUGE:
15770Sstevel@tonic-gate 				case TYPE_TIMETICKS:
15780Sstevel@tonic-gate 					offset = offset + sizeof(Integer);
15790Sstevel@tonic-gate 					break;
15800Sstevel@tonic-gate 
15810Sstevel@tonic-gate 				case TYPE_OCTETSTR:
15820Sstevel@tonic-gate 				case TYPE_IPADDR:
15830Sstevel@tonic-gate 				case TYPE_OPAQUE:
15840Sstevel@tonic-gate 					offset = offset + sizeof(String);
15850Sstevel@tonic-gate 					break;
15860Sstevel@tonic-gate 
15870Sstevel@tonic-gate 				case TYPE_OBJID:
15880Sstevel@tonic-gate 					offset = offset + sizeof(Oid);
15890Sstevel@tonic-gate 					break;
15900Sstevel@tonic-gate 
15910Sstevel@tonic-gate 				default:
15920Sstevel@tonic-gate 					error_exit("output_column_table(): Unknown type (%d) for %s",
15930Sstevel@tonic-gate 						child->type,
15940Sstevel@tonic-gate 						child->label);
15950Sstevel@tonic-gate 			}
15960Sstevel@tonic-gate 		}
15970Sstevel@tonic-gate 		fprintf(fp, ", %d", offset);
15980Sstevel@tonic-gate 
15990Sstevel@tonic-gate 		fprintf(fp, " },\n");
16000Sstevel@tonic-gate 
16010Sstevel@tonic-gate 
16020Sstevel@tonic-gate 		(*size)++;
16030Sstevel@tonic-gate 	}
16040Sstevel@tonic-gate 
16050Sstevel@tonic-gate 
16060Sstevel@tonic-gate 	if( (current->node_type == OBJECT)
16070Sstevel@tonic-gate 		|| (current->node_type == COLUMN) )
16080Sstevel@tonic-gate 	{
16090Sstevel@tonic-gate 		parent = current;
16100Sstevel@tonic-gate 		while(parent)
16110Sstevel@tonic-gate 		{
16120Sstevel@tonic-gate 			(*subid_index)++;
16130Sstevel@tonic-gate 
16140Sstevel@tonic-gate 			parent = parent->parent;
16150Sstevel@tonic-gate 		}
16160Sstevel@tonic-gate 	}
16170Sstevel@tonic-gate 
16180Sstevel@tonic-gate 
16190Sstevel@tonic-gate 	for(enums = current->enums; enums; enums = enums->next)
16200Sstevel@tonic-gate 	{
16210Sstevel@tonic-gate 		(*enum_index)++;
16220Sstevel@tonic-gate 	}
16230Sstevel@tonic-gate 
16240Sstevel@tonic-gate 
16250Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
16260Sstevel@tonic-gate 	{
16270Sstevel@tonic-gate 		output_column_table(fp, tp, subid_index, enum_index, size);
16280Sstevel@tonic-gate 	}
16290Sstevel@tonic-gate }
16300Sstevel@tonic-gate 
16310Sstevel@tonic-gate 
16320Sstevel@tonic-gate /*************************************************************************/
16330Sstevel@tonic-gate 
output_node_table(FILE * fp,struct tree * current,int * size)16340Sstevel@tonic-gate static void output_node_table(FILE *fp, struct tree *current, int *size)
16350Sstevel@tonic-gate {
16360Sstevel@tonic-gate 	struct tree *tp;
16370Sstevel@tonic-gate 
16380Sstevel@tonic-gate 
16390Sstevel@tonic-gate 	fprintf(fp, "/* %6d */ {",
16400Sstevel@tonic-gate 		current->node_index);
16410Sstevel@tonic-gate 
16420Sstevel@tonic-gate 	/* parent */
16430Sstevel@tonic-gate 	if(current->parent == NULL)
16440Sstevel@tonic-gate 	{
16450Sstevel@tonic-gate 		fprintf(fp, " %17s", "NULL");
16460Sstevel@tonic-gate 	}
16470Sstevel@tonic-gate 	else
16480Sstevel@tonic-gate 	{
16490Sstevel@tonic-gate 		fprintf(fp, " &node_table[%4d]",
16500Sstevel@tonic-gate 			current->parent->node_index);
16510Sstevel@tonic-gate 	}
16520Sstevel@tonic-gate 
16530Sstevel@tonic-gate 	/* first_child */
16540Sstevel@tonic-gate 	if(current->child_list == NULL)
16550Sstevel@tonic-gate 	{
16560Sstevel@tonic-gate 		fprintf(fp, ", %17s", "NULL");
16570Sstevel@tonic-gate 	}
16580Sstevel@tonic-gate 	else
16590Sstevel@tonic-gate 	{
16600Sstevel@tonic-gate 		fprintf(fp, ", &node_table[%4d]",
16610Sstevel@tonic-gate 			current->child_list->node_index);
16620Sstevel@tonic-gate 	}
16630Sstevel@tonic-gate 
16640Sstevel@tonic-gate 	/* next_peer */
16650Sstevel@tonic-gate 	if(current->next_peer == NULL)
16660Sstevel@tonic-gate 	{
16670Sstevel@tonic-gate 		fprintf(fp, ", %17s", "NULL");
16680Sstevel@tonic-gate 	}
16690Sstevel@tonic-gate 	else
16700Sstevel@tonic-gate 	{
16710Sstevel@tonic-gate 		fprintf(fp, ", &node_table[%4d]",
16720Sstevel@tonic-gate 			current->next_peer->node_index);
16730Sstevel@tonic-gate 	}
16740Sstevel@tonic-gate 
16750Sstevel@tonic-gate 	/* next */
16760Sstevel@tonic-gate 	if(current->next == NULL)
16770Sstevel@tonic-gate 	{
16780Sstevel@tonic-gate 		fprintf(fp, ", %17s", "NULL");
16790Sstevel@tonic-gate 	}
16800Sstevel@tonic-gate 	else
16810Sstevel@tonic-gate 	{
16820Sstevel@tonic-gate 		fprintf(fp, ", &node_table[%4d]",
16830Sstevel@tonic-gate 			current->next->node_index);
16840Sstevel@tonic-gate 	}
16850Sstevel@tonic-gate 
16860Sstevel@tonic-gate 	/* label, subid */
16870Sstevel@tonic-gate 	fprintf(fp, ", \"%s\", %d",
16880Sstevel@tonic-gate 		current->label, current->subid);
16890Sstevel@tonic-gate 
16900Sstevel@tonic-gate 	/* type, data */
16910Sstevel@tonic-gate 	switch(current->node_type)
16920Sstevel@tonic-gate 	{
16930Sstevel@tonic-gate 		case OBJECT:
16940Sstevel@tonic-gate 			fprintf(fp, ", OBJECT, (void *) &object_table[%d]",
16950Sstevel@tonic-gate 				current->object_index);
16960Sstevel@tonic-gate 			break;
16970Sstevel@tonic-gate 
16980Sstevel@tonic-gate 		case COLUMN:
16990Sstevel@tonic-gate 			fprintf(fp, ", COLUMN, (void *) &column_table[%d]",
17000Sstevel@tonic-gate 				current->column_index);
17010Sstevel@tonic-gate 			break;
17020Sstevel@tonic-gate 
17030Sstevel@tonic-gate 		case NODE:
17040Sstevel@tonic-gate 		case TABLE:
17050Sstevel@tonic-gate 		case ENTRY:
17060Sstevel@tonic-gate 			fprintf(fp, ", NODE, NULL");
17070Sstevel@tonic-gate 			break;
17080Sstevel@tonic-gate 
17090Sstevel@tonic-gate 
17100Sstevel@tonic-gate 		default:
17110Sstevel@tonic-gate 			error_exit("Unknown node type (%d) for %s",
17120Sstevel@tonic-gate 				current->type, current->label);
17130Sstevel@tonic-gate 	}
17140Sstevel@tonic-gate 
17150Sstevel@tonic-gate 	fprintf(fp, " },\n");
17160Sstevel@tonic-gate 
17170Sstevel@tonic-gate 
17180Sstevel@tonic-gate 	(*size)++;
17190Sstevel@tonic-gate 
17200Sstevel@tonic-gate 
17210Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
17220Sstevel@tonic-gate 	{
17230Sstevel@tonic-gate 		output_node_table(fp, tp, size);
17240Sstevel@tonic-gate 	}
17250Sstevel@tonic-gate }
17260Sstevel@tonic-gate 
17270Sstevel@tonic-gate 
17280Sstevel@tonic-gate /*************************************************************************/
17290Sstevel@tonic-gate 
output_tree_c(struct tree * current)17300Sstevel@tonic-gate static void output_tree_c(struct tree *current)
17310Sstevel@tonic-gate {
17320Sstevel@tonic-gate 	char pathname[MAXPATHLEN];
17330Sstevel@tonic-gate 	char backup_pathname[MAXPATHLEN];
17340Sstevel@tonic-gate 	struct stat buf;
17350Sstevel@tonic-gate 	FILE *fp;
17360Sstevel@tonic-gate 	int subid_index;
17370Sstevel@tonic-gate 	int enum_index;
17380Sstevel@tonic-gate 	int index_index;
17390Sstevel@tonic-gate 	int size;
17400Sstevel@tonic-gate 
17410Sstevel@tonic-gate 
17420Sstevel@tonic-gate 	sprintf(pathname, "%s_tree.c", base_name);
17430Sstevel@tonic-gate 	sprintf(backup_pathname, "%s_tree.c.old", base_name);
17440Sstevel@tonic-gate 	trace("Creating %s ...\n", pathname);
17450Sstevel@tonic-gate 	if(stat(pathname, &buf) == 0)
17460Sstevel@tonic-gate 	{
17470Sstevel@tonic-gate                 if(rename(pathname,backup_pathname)==-1){
17480Sstevel@tonic-gate                   error_exit("The file %s already exists and can't be renamed!", pathname);
17490Sstevel@tonic-gate                 }
17500Sstevel@tonic-gate 	}
17510Sstevel@tonic-gate 
17520Sstevel@tonic-gate 	fp = fopen(pathname, "w");
17530Sstevel@tonic-gate 	if(fp == NULL)
17540Sstevel@tonic-gate 	{
17550Sstevel@tonic-gate 		error_exit("Can't open %s %s", pathname, errno_string());
17560Sstevel@tonic-gate 	}
17570Sstevel@tonic-gate 
17580Sstevel@tonic-gate 	fprintf(fp, "#include <sys/types.h>\n");
17590Sstevel@tonic-gate 	fprintf(fp, "\n");
17600Sstevel@tonic-gate 	fprintf(fp, "#include \"impl.h\"\n");
17610Sstevel@tonic-gate 	fprintf(fp, "#include \"asn1.h\"\n");
17620Sstevel@tonic-gate 	fprintf(fp, "#include \"node.h\"\n");
17630Sstevel@tonic-gate 	fprintf(fp, "\n");
17640Sstevel@tonic-gate 	fprintf(fp, "#include \"%s_stub.h\"\n", base_name);
17650Sstevel@tonic-gate 	fprintf(fp, "\n");
17660Sstevel@tonic-gate 	fprintf(fp, "\n");
17670Sstevel@tonic-gate 
17680Sstevel@tonic-gate 
17690Sstevel@tonic-gate 
17700Sstevel@tonic-gate 	subid_index = 0;
17710Sstevel@tonic-gate 	fprintf(fp, "Subid subid_table[] = {\n");
17720Sstevel@tonic-gate 	output_subid_table(fp, current, &subid_index);
17730Sstevel@tonic-gate 	fprintf(fp, "0\n");
17740Sstevel@tonic-gate 	fprintf(fp, "};\n");
17750Sstevel@tonic-gate 	fprintf(fp, "int subid_table_size = %d;\n\n", subid_index);
17760Sstevel@tonic-gate 
17770Sstevel@tonic-gate 	enum_index = 0;
17780Sstevel@tonic-gate 	fprintf(fp, "Enum enum_table[] = {\n");
17790Sstevel@tonic-gate 	output_enum_table(fp, current, &enum_index);
17800Sstevel@tonic-gate 	fprintf(fp, "{ NULL, NULL, 0 }\n");
17810Sstevel@tonic-gate 	fprintf(fp, "};\n");
17820Sstevel@tonic-gate 	fprintf(fp, "int enum_table_size = %d;\n\n", enum_index);
17830Sstevel@tonic-gate 
17840Sstevel@tonic-gate 	subid_index = 0;
17850Sstevel@tonic-gate 	enum_index = 0;
17860Sstevel@tonic-gate 	size = 0;
17870Sstevel@tonic-gate 	fprintf(fp, "Object object_table[] = {\n");
17880Sstevel@tonic-gate 	output_object_table(fp, current, &subid_index, &enum_index, &size);
17890Sstevel@tonic-gate 	fprintf(fp, "{ { NULL, 0}, 0, NULL, 0, NULL, NULL }\n");
17900Sstevel@tonic-gate 	fprintf(fp, "};\n");
17910Sstevel@tonic-gate 	fprintf(fp, "int object_table_size = %d;\n\n", size);
17920Sstevel@tonic-gate 
17930Sstevel@tonic-gate 	index_index = 0;
17940Sstevel@tonic-gate 	fprintf(fp, "Index index_table[] = {\n");
17950Sstevel@tonic-gate 	output_index_table(fp, current, &index_index);
17960Sstevel@tonic-gate 	fprintf(fp, "{ NULL, NULL, NULL }\n");
17970Sstevel@tonic-gate 	fprintf(fp, "};\n");
17980Sstevel@tonic-gate 	fprintf(fp, "int index_table_size = %d;\n\n", index_index);
17990Sstevel@tonic-gate 
18000Sstevel@tonic-gate 	size = 0;
18010Sstevel@tonic-gate 	index_index = 0;
18020Sstevel@tonic-gate 	fprintf(fp, "Entry entry_table[] = {\n");
18030Sstevel@tonic-gate 	output_entry_table(fp, current, &index_index, &size);
18040Sstevel@tonic-gate 	fprintf(fp, "{ NULL, 0, NULL }\n");
18050Sstevel@tonic-gate 	fprintf(fp, "};\n");
18060Sstevel@tonic-gate 	fprintf(fp, "int entry_table_size = %d;\n\n", size);
18070Sstevel@tonic-gate 
18080Sstevel@tonic-gate 	subid_index = 0;
18090Sstevel@tonic-gate 	enum_index = 0;
18100Sstevel@tonic-gate 	size = 0;
18110Sstevel@tonic-gate 	fprintf(fp, "Column column_table[] = {\n");
18120Sstevel@tonic-gate 	output_column_table(fp, current, &subid_index, &enum_index, &size);
18130Sstevel@tonic-gate 	fprintf(fp, "{ { NULL, 0}, 0, NULL, 0, NULL, NULL , 0 }\n");
18140Sstevel@tonic-gate 	fprintf(fp, "};\n");
18150Sstevel@tonic-gate 	fprintf(fp, "int column_table_size = %d;\n\n", size);
18160Sstevel@tonic-gate 
18170Sstevel@tonic-gate 	size = 0;
18180Sstevel@tonic-gate 	fprintf(fp, "Node node_table[] = {\n");
18190Sstevel@tonic-gate 	output_node_table(fp, current, &size);
18200Sstevel@tonic-gate 	fprintf(fp, "{ NULL, NULL, NULL, NULL, NULL, 0, 0, NULL }\n");
18210Sstevel@tonic-gate 	fprintf(fp, "};\n");
18220Sstevel@tonic-gate 	fprintf(fp, "int node_table_size = %d;\n\n", size);
18230Sstevel@tonic-gate 
18240Sstevel@tonic-gate 
18250Sstevel@tonic-gate 	fclose(fp);
18260Sstevel@tonic-gate }
18270Sstevel@tonic-gate 
18280Sstevel@tonic-gate 
18290Sstevel@tonic-gate /*************************************************************************/
18300Sstevel@tonic-gate 
find_node(struct tree * current,char * label)18310Sstevel@tonic-gate static struct tree *find_node(struct tree *current, char *label)
18320Sstevel@tonic-gate {
18330Sstevel@tonic-gate 	struct tree *tp;
18340Sstevel@tonic-gate 	struct tree *t;
18350Sstevel@tonic-gate 
18360Sstevel@tonic-gate 
18370Sstevel@tonic-gate 	if(strcmp(current->label, label) == 0)
18380Sstevel@tonic-gate 	{
18390Sstevel@tonic-gate 		return current;
18400Sstevel@tonic-gate 	}
18410Sstevel@tonic-gate 
18420Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
18430Sstevel@tonic-gate 	{
18440Sstevel@tonic-gate 		t = find_node(tp, label);
18450Sstevel@tonic-gate 		if(t != NULL)
18460Sstevel@tonic-gate 		{
18470Sstevel@tonic-gate 			return t;
18480Sstevel@tonic-gate 		}
18490Sstevel@tonic-gate 	}
18500Sstevel@tonic-gate 
18510Sstevel@tonic-gate 	return NULL;
18520Sstevel@tonic-gate }
18530Sstevel@tonic-gate 
18540Sstevel@tonic-gate 
18550Sstevel@tonic-gate /*************************************************************************/
18560Sstevel@tonic-gate 
output_structure(FILE * fp,struct tree * current)18570Sstevel@tonic-gate static void output_structure(FILE *fp, struct tree *current)
18580Sstevel@tonic-gate {
18590Sstevel@tonic-gate 	struct tree *tp;
18600Sstevel@tonic-gate 
18610Sstevel@tonic-gate 
18620Sstevel@tonic-gate 	if(current->node_type == ENTRY)
18630Sstevel@tonic-gate 	{
18640Sstevel@tonic-gate 		struct tree *child;
18650Sstevel@tonic-gate 
18660Sstevel@tonic-gate 
18670Sstevel@tonic-gate 		fprintf(fp, "\n");
18680Sstevel@tonic-gate 		fprintf(fp, "typedef struct _%c%s_t {\n",
18690Sstevel@tonic-gate 			toupper(current->label[0]),
18700Sstevel@tonic-gate 			&(current->label[1]));
18710Sstevel@tonic-gate 		for(child = current->child_list; child; child = child->next_peer)
18720Sstevel@tonic-gate 		{
18730Sstevel@tonic-gate 			if( !(child->access & READ_FLAG) )
18740Sstevel@tonic-gate 			{
18750Sstevel@tonic-gate 				continue;
18760Sstevel@tonic-gate 			}
18770Sstevel@tonic-gate 
18780Sstevel@tonic-gate 			switch(child->type)
18790Sstevel@tonic-gate 			{
18800Sstevel@tonic-gate 				case TYPE_INTEGER:
18810Sstevel@tonic-gate 				case TYPE_COUNTER:
18820Sstevel@tonic-gate 				case TYPE_GAUGE:
18830Sstevel@tonic-gate 				case TYPE_TIMETICKS:
18840Sstevel@tonic-gate 					fprintf(fp, "\tInteger %s;\n", child->label);
18850Sstevel@tonic-gate 					break;
18860Sstevel@tonic-gate 
18870Sstevel@tonic-gate 				case TYPE_OCTETSTR:
18880Sstevel@tonic-gate 				case TYPE_IPADDR:
18890Sstevel@tonic-gate 				case TYPE_OPAQUE:
18900Sstevel@tonic-gate 					fprintf(fp, "\tString %s;\n", child->label);
18910Sstevel@tonic-gate 					break;
18920Sstevel@tonic-gate 
18930Sstevel@tonic-gate 				case TYPE_OBJID:
18940Sstevel@tonic-gate 					fprintf(fp, "\tOid %s;\n", child->label);
18950Sstevel@tonic-gate 					break;
18960Sstevel@tonic-gate 
18970Sstevel@tonic-gate 				default:
18980Sstevel@tonic-gate 					error_exit("output_structure(): Unknown type (%d) for %s",
18990Sstevel@tonic-gate 						child->type,
19000Sstevel@tonic-gate 						child->label);
19010Sstevel@tonic-gate 			}
19020Sstevel@tonic-gate 		}
19030Sstevel@tonic-gate 		fprintf(fp, "} %c%s_t;\n",
19040Sstevel@tonic-gate 			toupper(current->label[0]),
19050Sstevel@tonic-gate 			&(current->label[1]));
19060Sstevel@tonic-gate 	}
19070Sstevel@tonic-gate 
19080Sstevel@tonic-gate 
19090Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
19100Sstevel@tonic-gate 	{
19110Sstevel@tonic-gate 		output_structure(fp, tp);
19120Sstevel@tonic-gate 	}
19130Sstevel@tonic-gate }
19140Sstevel@tonic-gate 
19150Sstevel@tonic-gate 
19160Sstevel@tonic-gate /*************************************************************************/
19170Sstevel@tonic-gate 
output_stub_h(struct tree * current)19180Sstevel@tonic-gate static void output_stub_h(struct tree *current)
19190Sstevel@tonic-gate {
19200Sstevel@tonic-gate 	char pathname[MAXPATHLEN];
19210Sstevel@tonic-gate 	char backup_pathname[MAXPATHLEN];
19220Sstevel@tonic-gate 	struct stat buf;
19230Sstevel@tonic-gate 	FILE *fp;
19240Sstevel@tonic-gate 	int i;
19250Sstevel@tonic-gate 
19260Sstevel@tonic-gate 
19270Sstevel@tonic-gate 	sprintf(pathname, "%s_stub.h", base_name);
19280Sstevel@tonic-gate 	sprintf(backup_pathname, "%s_stub.h.old", base_name);
19290Sstevel@tonic-gate 	trace("Creating %s ...\n", pathname);
19300Sstevel@tonic-gate 	if(stat(pathname, &buf) == 0)
19310Sstevel@tonic-gate 	{
19320Sstevel@tonic-gate                 if(rename(pathname,backup_pathname)==-1){
19330Sstevel@tonic-gate                   error_exit("The file %s already exists and can't be renamed!", pathname);
19340Sstevel@tonic-gate                 }
19350Sstevel@tonic-gate 	}
19360Sstevel@tonic-gate 
19370Sstevel@tonic-gate 	fp = fopen(pathname, "w");
19380Sstevel@tonic-gate 	if(fp == NULL)
19390Sstevel@tonic-gate 	{
19400Sstevel@tonic-gate 		error_exit("Can't open %s %s", pathname, errno_string());
19410Sstevel@tonic-gate 	}
19420Sstevel@tonic-gate 
19430Sstevel@tonic-gate 	fprintf(fp, "#ifndef _");
19440Sstevel@tonic-gate 	for(i = 0; base_name[i] != '\0'; i++)
19450Sstevel@tonic-gate 	{
19460Sstevel@tonic-gate 		fprintf(fp, "%c", toupper(base_name[i]));
19470Sstevel@tonic-gate 	}
19480Sstevel@tonic-gate 	fprintf(fp, "_STUB_H_\n");
19490Sstevel@tonic-gate 	fprintf(fp, "#define _");
19500Sstevel@tonic-gate 	for(i = 0; base_name[i] != '\0'; i++)
19510Sstevel@tonic-gate 	{
19520Sstevel@tonic-gate 		fprintf(fp, "%c", toupper(base_name[i]));
19530Sstevel@tonic-gate 	}
19540Sstevel@tonic-gate 	fprintf(fp, "_STUB_H_\n");
19550Sstevel@tonic-gate 	fprintf(fp, "\n");
19560Sstevel@tonic-gate 
19570Sstevel@tonic-gate 
19580Sstevel@tonic-gate 	output_structure(fp, current);
19590Sstevel@tonic-gate 	fprintf(fp, "\n");
19600Sstevel@tonic-gate 
19610Sstevel@tonic-gate 	output_extern_function(fp, current);
19620Sstevel@tonic-gate 	fprintf(fp, "\n");
19630Sstevel@tonic-gate 
19640Sstevel@tonic-gate 	output_extern_trap_function(fp);
19650Sstevel@tonic-gate 
19660Sstevel@tonic-gate 	fprintf(fp, "#endif\n");
19670Sstevel@tonic-gate 
19680Sstevel@tonic-gate 	fclose(fp);
19690Sstevel@tonic-gate }
19700Sstevel@tonic-gate 
19710Sstevel@tonic-gate 
19720Sstevel@tonic-gate /*************************************************************************/
19730Sstevel@tonic-gate 
get_subids_by_name(Subid * dst,char * oid_name)19740Sstevel@tonic-gate static void get_subids_by_name(Subid *dst,char *oid_name)
19750Sstevel@tonic-gate {
19760Sstevel@tonic-gate   struct tree *tp;
19770Sstevel@tonic-gate   Subid subids[MAX_OID_LEN+1];
19780Sstevel@tonic-gate   int i,j,len;
19790Sstevel@tonic-gate 
19800Sstevel@tonic-gate   /* find the enterprise_subids */
19810Sstevel@tonic-gate   if((tp = find_node(root,oid_name)) == NULL)
19820Sstevel@tonic-gate     fprintf (stderr, "Unknown trap enterprise variable:%s\n",oid_name);
19830Sstevel@tonic-gate   get_subid_of_node(tp,subids,&len);
19840Sstevel@tonic-gate   for(j=0,i=len-1;i>=0;i--,j++)
19850Sstevel@tonic-gate 	dst[j] = subids[i];
19860Sstevel@tonic-gate   dst[j]=(u_long)-1;
19870Sstevel@tonic-gate }
19880Sstevel@tonic-gate 
19890Sstevel@tonic-gate 
output_trap_structure(FILE * fp)19900Sstevel@tonic-gate static void output_trap_structure(FILE *fp)
19910Sstevel@tonic-gate {
19920Sstevel@tonic-gate 	struct trap_item *ip;
19930Sstevel@tonic-gate 	int i, enterprise_trap;
19940Sstevel@tonic-gate 	struct index_list *var;
19950Sstevel@tonic-gate 	struct tree *tp;
19960Sstevel@tonic-gate 	int numCallItem = 0;
19970Sstevel@tonic-gate 	int numTrapElem = 0;
19980Sstevel@tonic-gate 	int *trapTableMap = NULL;
19990Sstevel@tonic-gate 	int idx, index;
20000Sstevel@tonic-gate 	int variableExist, columnExist = 0;
20010Sstevel@tonic-gate 
20020Sstevel@tonic-gate 
20030Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
20040Sstevel@tonic-gate 		numTrapElem++;
20050Sstevel@tonic-gate 		for (var = ip->var_list; var; var = var->next)
20060Sstevel@tonic-gate 			numCallItem++;
20070Sstevel@tonic-gate 	}
20080Sstevel@tonic-gate 
20090Sstevel@tonic-gate 	if (numTrapElem > 0) {
20100Sstevel@tonic-gate 		trapTableMap = (int *)malloc(sizeof (int) * (numTrapElem + 10));
20110Sstevel@tonic-gate 		if (!trapTableMap)
20120Sstevel@tonic-gate 			error_exit("malloc failed");
20130Sstevel@tonic-gate 	for (idx = 0; idx < numTrapElem+10; idx++)
20140Sstevel@tonic-gate 		trapTableMap[idx] = -1;
20150Sstevel@tonic-gate 	}
20160Sstevel@tonic-gate 
20170Sstevel@tonic-gate 	if (numCallItem > 0)
20180Sstevel@tonic-gate 		fprintf(fp, "struct CallbackItem genCallItem[%d] = {\n",
20190Sstevel@tonic-gate 			numCallItem+10);
20200Sstevel@tonic-gate 	else
20210Sstevel@tonic-gate 		fprintf(fp, "struct CallbackItem genCallItem[%d];\n",
20220Sstevel@tonic-gate 			numCallItem+10);
20230Sstevel@tonic-gate 	numCallItem = 0;
20240Sstevel@tonic-gate 	numTrapElem = 0;
20250Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
20260Sstevel@tonic-gate 		variableExist = 0;
20270Sstevel@tonic-gate 		trapTableMap[numTrapElem] = numCallItem;
20280Sstevel@tonic-gate 		for (var = ip->var_list; var; var = var->next) {
20290Sstevel@tonic-gate 			variableExist = 1;
20300Sstevel@tonic-gate 			if ((var->tp = find_node(root, var->label)) == NULL)
20310Sstevel@tonic-gate 				error_exit("output_trap_structure():Unknown \
20320Sstevel@tonic-gate 					variable:%s", var->label);
20330Sstevel@tonic-gate 				tp = var->tp;
20340Sstevel@tonic-gate 				if (tp->node_type == OBJECT)
20350Sstevel@tonic-gate 					fprintf(fp, "\t{&object_table[%d],",
20360Sstevel@tonic-gate 					tp->object_index);
20370Sstevel@tonic-gate 				else
20380Sstevel@tonic-gate 					if (tp->node_type == COLUMN) {
20390Sstevel@tonic-gate 					columnExist = 1;
20400Sstevel@tonic-gate 						fprintf(fp,
20410Sstevel@tonic-gate 					"\t{(Object *)&column_table[%d],",
20420Sstevel@tonic-gate 						tp->column_index);
20430Sstevel@tonic-gate 					} else
20440Sstevel@tonic-gate 						error_exit("variable: %s is not\
20450Sstevel@tonic-gate 						individual object", var->label);
20460Sstevel@tonic-gate 
20470Sstevel@tonic-gate 			switch (tp->type) { /* only accept object node type */
20480Sstevel@tonic-gate 				case TYPE_INTEGER:
20490Sstevel@tonic-gate 				case TYPE_COUNTER:
20500Sstevel@tonic-gate 				case TYPE_GAUGE:
20510Sstevel@tonic-gate 				case TYPE_TIMETICKS:
20520Sstevel@tonic-gate 					fprintf(fp, "INTEGER,");
20530Sstevel@tonic-gate 					break;
20540Sstevel@tonic-gate 				case TYPE_OCTETSTR:
20550Sstevel@tonic-gate 				case TYPE_IPADDR:
20560Sstevel@tonic-gate 				case TYPE_OPAQUE:
20570Sstevel@tonic-gate 					fprintf(fp, "STRING,");
20580Sstevel@tonic-gate 					break;
20590Sstevel@tonic-gate 				case TYPE_OBJID:
20600Sstevel@tonic-gate 					fprintf(fp, "OBJID,");
20610Sstevel@tonic-gate 					break;
20620Sstevel@tonic-gate 				default:
20630Sstevel@tonic-gate 					error_exit("unknown object type of \
20640Sstevel@tonic-gate 					variable %s", var->label);
20650Sstevel@tonic-gate 			}
20660Sstevel@tonic-gate 		numCallItem++;
20670Sstevel@tonic-gate 		if (var->next)
20680Sstevel@tonic-gate 			fprintf(fp, "%d},\n", numCallItem);
20690Sstevel@tonic-gate 		else
20700Sstevel@tonic-gate 			fprintf(fp, "-1},\n");
20710Sstevel@tonic-gate 		}
20720Sstevel@tonic-gate 		if (variableExist == 0)
20730Sstevel@tonic-gate 			trapTableMap[numTrapElem] = -1;
20740Sstevel@tonic-gate 	numTrapElem++;
20750Sstevel@tonic-gate 	}
20760Sstevel@tonic-gate 	if (numCallItem > 0) fprintf(fp, "};\n");
20770Sstevel@tonic-gate 	fprintf(fp, "int genNumCallItem = %d;\n", numCallItem);
20780Sstevel@tonic-gate 
20790Sstevel@tonic-gate 	/* dumby the map */
20800Sstevel@tonic-gate 	if (numTrapElem > 0)
20810Sstevel@tonic-gate 		fprintf(fp, "int genTrapTableMap[%d] = {\n", numTrapElem + 10);
20820Sstevel@tonic-gate 	else
20830Sstevel@tonic-gate 		fprintf(fp, "int genTrapTableMap[%d];\n", numTrapElem + 10);
20840Sstevel@tonic-gate 	for (idx = 0; idx < numTrapElem; idx++) {
20850Sstevel@tonic-gate 		fprintf(fp, "%d,", trapTableMap[idx]);
20860Sstevel@tonic-gate 	}
20870Sstevel@tonic-gate 	if (numTrapElem > 0) fprintf(fp, "};\n");
20880Sstevel@tonic-gate 
20890Sstevel@tonic-gate 	fprintf(fp, "int genNumTrapElem = %d;\n", numTrapElem);
20900Sstevel@tonic-gate 	if (numTrapElem > 0)
20910Sstevel@tonic-gate 		fprintf(fp, "struct TrapHndlCxt genTrapBucket[%d] = {\n",
20920Sstevel@tonic-gate 			numTrapElem + 10);
20930Sstevel@tonic-gate 	else
20940Sstevel@tonic-gate 		fprintf(fp, "struct TrapHndlCxt genTrapBucket[%d];\n",
20950Sstevel@tonic-gate 			numTrapElem+10);
20960Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
20970Sstevel@tonic-gate 		fprintf(fp, "\t{\"%s\",", ip->label);
20980Sstevel@tonic-gate 		if (!strcmp(ip->enterprise_label, "snmp"))
20990Sstevel@tonic-gate 			fprintf(fp, "0,");
21000Sstevel@tonic-gate 		else
21010Sstevel@tonic-gate 			fprintf(fp, "1,");
21020Sstevel@tonic-gate 		if (!strcmp(ip->enterprise_label, "snmp")) {
21030Sstevel@tonic-gate 			for (i = 0; i < 8; i++) {
21040Sstevel@tonic-gate 				ip->enterprise_subids[i] = snmp_subids[i];
21050Sstevel@tonic-gate 			}
21060Sstevel@tonic-gate 		} else {
21070Sstevel@tonic-gate 			get_subids_by_name(ip->enterprise_subids,
21080Sstevel@tonic-gate 				ip->enterprise_label);
21090Sstevel@tonic-gate 		}
21100Sstevel@tonic-gate 
21110Sstevel@tonic-gate 		enterprise_trap = FALSE;
21120Sstevel@tonic-gate 		for (i = 0; i < 7; i++) {
21130Sstevel@tonic-gate 			if (ip->enterprise_subids[i] != snmp_subids[i]) {
21140Sstevel@tonic-gate 				enterprise_trap = TRUE;
21150Sstevel@tonic-gate 				break;
21160Sstevel@tonic-gate 			}
21170Sstevel@tonic-gate 		}
21180Sstevel@tonic-gate 		if (enterprise_trap) {
21190Sstevel@tonic-gate 			fprintf(fp, "6,");
21200Sstevel@tonic-gate 			fprintf(fp, "%d},\n", ip->value);
21210Sstevel@tonic-gate 		} else {
21220Sstevel@tonic-gate 			fprintf(fp, "%d,", ip->value);
21230Sstevel@tonic-gate 			fprintf(fp, "0},\n");
21240Sstevel@tonic-gate 		}
21250Sstevel@tonic-gate 	}
21260Sstevel@tonic-gate 	if (numTrapElem > 0) fprintf(fp, "};\n");
21270Sstevel@tonic-gate 
21280Sstevel@tonic-gate /* For arbitrary length enterprise OID in traps - bug 4133978 */
21290Sstevel@tonic-gate /* Initializing new trap enterprise info which handles arbitrary subids */
21300Sstevel@tonic-gate 	if (numTrapElem > 0)
21310Sstevel@tonic-gate 		fprintf(fp,
21320Sstevel@tonic-gate 	"struct TrapAnyEnterpriseInfo genTrapAnyEnterpriseInfo[%d] = {\n",
21330Sstevel@tonic-gate 		numTrapElem + 10);
21340Sstevel@tonic-gate 	else
21350Sstevel@tonic-gate 		fprintf(fp, "struct TrapAnyEnterpriseInfo \
21360Sstevel@tonic-gate 			genTrapAnyEnterpriseInfo[%d]; \n", numTrapElem + 10);
21370Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
21380Sstevel@tonic-gate 		fprintf(fp, "\t{");
21390Sstevel@tonic-gate 		for (i = 0; ip->enterprise_subids[i] != -1; i++) {
21400Sstevel@tonic-gate 			fprintf(fp, "%d, ", ip->enterprise_subids[i]);
21410Sstevel@tonic-gate 		}
21420Sstevel@tonic-gate 		fprintf(fp, "(uint32_t)-1},\n");
21430Sstevel@tonic-gate 	}
21440Sstevel@tonic-gate 	if (numTrapElem > 0) fprintf(fp, "};\n");
21450Sstevel@tonic-gate 
21460Sstevel@tonic-gate 	if (numTrapElem == 0)
21470Sstevel@tonic-gate 		return;
21480Sstevel@tonic-gate 
21490Sstevel@tonic-gate 	fprintf(fp, "struct _CallTrapIndx { \n");
21500Sstevel@tonic-gate 	fprintf(fp, "\tchar name[256];\n");
21510Sstevel@tonic-gate 	fprintf(fp, "\tIndexType *pindex_obj; \n");
21520Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
21530Sstevel@tonic-gate 
21540Sstevel@tonic-gate 	fprintf(fp, "struct _Indx { \n");
21550Sstevel@tonic-gate 	fprintf(fp, "\tchar name[256]; \n");
21560Sstevel@tonic-gate 	fprintf(fp, "\tint index; \n");
21570Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
21580Sstevel@tonic-gate 
21590Sstevel@tonic-gate 	if (columnExist != 0) {
21600Sstevel@tonic-gate 	index = 0;
21610Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
21620Sstevel@tonic-gate 		for (var = ip->var_list; var; var = var->next) {
21630Sstevel@tonic-gate 			tp = var->tp;
21640Sstevel@tonic-gate 			if (tp->node_type == COLUMN) {
21650Sstevel@tonic-gate 				index++;
21660Sstevel@tonic-gate 			}
21670Sstevel@tonic-gate 		}
21680Sstevel@tonic-gate 	}
21690Sstevel@tonic-gate 
21700Sstevel@tonic-gate 	fprintf(fp, "int numIndxElem = %d; \n", index);
21710Sstevel@tonic-gate 	fprintf(fp, "struct _Indx Indx[%d] = { \n", index);
21720Sstevel@tonic-gate 	for (ip = trap_list; ip; ip = ip->next) {
21730Sstevel@tonic-gate 		for (var = ip->var_list; var; var = var->next) {
21740Sstevel@tonic-gate 			tp = var->tp;
21750Sstevel@tonic-gate 			if (tp->node_type == COLUMN) {
21760Sstevel@tonic-gate 				fprintf(fp, "\t{\"%s\", 0},\n", var->label);
21770Sstevel@tonic-gate 			}
21780Sstevel@tonic-gate 		}
21790Sstevel@tonic-gate 	}
21800Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
21810Sstevel@tonic-gate 	fprintf(fp, "int SSASetVarIndx(char* name, int index)\n{\n");
21820Sstevel@tonic-gate 	fprintf(fp, "\tint i;\n\n");
21830Sstevel@tonic-gate 	fprintf(fp, "\tif (!name) \n");
21840Sstevel@tonic-gate 	fprintf(fp, "\treturn (-1); \n\n");
21850Sstevel@tonic-gate 	fprintf(fp, "\tfor (i = 0; i < numIndxElem; i++) \n");
21860Sstevel@tonic-gate 	fprintf(fp, "\t\tif (!strcmp(name, Indx[i].name)) { \n");
21870Sstevel@tonic-gate 	fprintf(fp, "\t\t\tIndx[i].index = index;\n");
21880Sstevel@tonic-gate 	fprintf(fp, "\t\t\treturn (0);\n");
21890Sstevel@tonic-gate 	fprintf(fp, "\t\t}\n");
21900Sstevel@tonic-gate 	fprintf(fp, "\treturn (-1);\n");
21910Sstevel@tonic-gate 	fprintf(fp, "}\n\n");
21920Sstevel@tonic-gate 	}
21930Sstevel@tonic-gate 
21940Sstevel@tonic-gate 	index = 0;
21950Sstevel@tonic-gate 	fprintf(fp, "IndexType TrapIndx[%d] = { \n", numCallItem);
21960Sstevel@tonic-gate 		for (ip = trap_list; ip; ip = ip->next) {
21970Sstevel@tonic-gate 			for (var = ip->var_list; var; var = var->next) {
21980Sstevel@tonic-gate 				tp = var->tp;
21990Sstevel@tonic-gate 				if (tp->node_type == OBJECT)
22000Sstevel@tonic-gate 					fprintf(fp, "\t{0,0,NULL},\n");
22010Sstevel@tonic-gate 				else if (tp->node_type == COLUMN) {
22020Sstevel@tonic-gate 					fprintf(fp,
22030Sstevel@tonic-gate 					"\t{1,1,&Indx[%d].index},\n", index++);
22040Sstevel@tonic-gate 				} else
22050Sstevel@tonic-gate 					error_exit("variable: %s is not \
22060Sstevel@tonic-gate 					individual object", var->label);
22070Sstevel@tonic-gate 			}
22080Sstevel@tonic-gate 		}
22090Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
22100Sstevel@tonic-gate 
22110Sstevel@tonic-gate 	fprintf(fp, "struct _CallTrapIndx CallTrapIndx[%d] = {\n", numTrapElem);
22120Sstevel@tonic-gate 		for (idx = 0, ip = trap_list; ip && idx < numTrapElem;
22130Sstevel@tonic-gate 			ip = ip->next, idx++) {
22140Sstevel@tonic-gate 			fprintf(fp, "\t{\"%s\",&TrapIndx[%d]},\n", ip->label,
22150Sstevel@tonic-gate 			trapTableMap[idx]);
22160Sstevel@tonic-gate 		}
22170Sstevel@tonic-gate 	fprintf(fp, "};\n\n");
22180Sstevel@tonic-gate 
22190Sstevel@tonic-gate 
22200Sstevel@tonic-gate 	if (numTrapElem > 0) {
22210Sstevel@tonic-gate 		fprintf(fp, "int SSASendTrap(char* name)\n");
22220Sstevel@tonic-gate 		fprintf(fp, "{\n");
22230Sstevel@tonic-gate 		fprintf(fp, "\tint i;\n\n");
22240Sstevel@tonic-gate 		fprintf(fp, "\tif (!name) \n");
22250Sstevel@tonic-gate 		fprintf(fp, "\treturn (-1);\n\n");
22260Sstevel@tonic-gate 
22270Sstevel@tonic-gate 		fprintf(fp, "\tnumCallItem = genNumCallItem;\n");
22280Sstevel@tonic-gate 		fprintf(fp, "\tnumTrapElem = genNumTrapElem;\n");
22290Sstevel@tonic-gate 		fprintf(fp, "\tcallItem = genCallItem;\n");
22300Sstevel@tonic-gate 		fprintf(fp, "\ttrapTableMap = genTrapTableMap;\n");
22310Sstevel@tonic-gate 		fprintf(fp, "\ttrapBucket = genTrapBucket;\n");
22320Sstevel@tonic-gate 		fprintf(fp,
22330Sstevel@tonic-gate 		"\ttrapAnyEnterpriseInfo = genTrapAnyEnterpriseInfo;\n");
22340Sstevel@tonic-gate 	/* SSASendTrap4 handles tabular column elements - 4519879 */
22350Sstevel@tonic-gate 		fprintf(fp, "\tfor (i = 0; i < numTrapElem; i++) \n");
22360Sstevel@tonic-gate 	fprintf(fp, "\tif (!strcmp(name, CallTrapIndx[i].name)) \n");
22370Sstevel@tonic-gate 	fprintf(fp, "\t\treturn \
22380Sstevel@tonic-gate 	(_SSASendTrap4(name, CallTrapIndx[i].pindex_obj)); \n");
22390Sstevel@tonic-gate 	fprintf(fp, "\treturn (-1); \n");
22400Sstevel@tonic-gate 	fprintf(fp, "}\n");
22410Sstevel@tonic-gate 	}
22420Sstevel@tonic-gate }
22430Sstevel@tonic-gate 
22440Sstevel@tonic-gate 
output_entry_function(FILE * fp,struct tree * current)22450Sstevel@tonic-gate static void output_entry_function(FILE *fp, struct tree *current)
22460Sstevel@tonic-gate {
22470Sstevel@tonic-gate 	struct tree *tp;
22480Sstevel@tonic-gate 	struct index_list *indexs;
22490Sstevel@tonic-gate 	struct tree *child;
22500Sstevel@tonic-gate 	int first_time_entry_print;
22510Sstevel@tonic-gate 
22520Sstevel@tonic-gate 
22530Sstevel@tonic-gate 	switch(current->node_type)
22540Sstevel@tonic-gate 	{
22550Sstevel@tonic-gate 		case COLUMN:
22560Sstevel@tonic-gate 			if( !(current->access & WRITE_FLAG) )
22570Sstevel@tonic-gate 			{
22580Sstevel@tonic-gate 				break;
22590Sstevel@tonic-gate 			}
22600Sstevel@tonic-gate 			break;
22610Sstevel@tonic-gate 		case ENTRY:
22620Sstevel@tonic-gate 			/* open a new file */
22630Sstevel@tonic-gate 			fclose(fp);
22640Sstevel@tonic-gate 		        fp = output_file(current->label);
22650Sstevel@tonic-gate 			fprintf(fp, "\n");
22660Sstevel@tonic-gate 			fprintf(fp, "/***** %-20s ********************************/\n",
22670Sstevel@tonic-gate 				current->label);
22680Sstevel@tonic-gate 			break;
22690Sstevel@tonic-gate 	}
22700Sstevel@tonic-gate 
22710Sstevel@tonic-gate 	switch(current->node_type)
22720Sstevel@tonic-gate 	{
22730Sstevel@tonic-gate 		case COLUMN:
22740Sstevel@tonic-gate 			if(current->access & READ_FLAG)
22750Sstevel@tonic-gate 			{
22760Sstevel@tonic-gate 				fprintf(fp, "\n");
22770Sstevel@tonic-gate 				fprintf(fp, "int get_%s(int search_type, ",
22780Sstevel@tonic-gate 					current->label);
22790Sstevel@tonic-gate 
22800Sstevel@tonic-gate 				switch(current->type)
22810Sstevel@tonic-gate 				{
22820Sstevel@tonic-gate 					case TYPE_INTEGER:
22830Sstevel@tonic-gate 					case TYPE_COUNTER:
22840Sstevel@tonic-gate 					case TYPE_GAUGE:
22850Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
22860Sstevel@tonic-gate 						fprintf(fp, "Integer *%s, ",
22870Sstevel@tonic-gate 							current->label);
22880Sstevel@tonic-gate 						break;
22890Sstevel@tonic-gate 
22900Sstevel@tonic-gate 					case TYPE_OCTETSTR:
22910Sstevel@tonic-gate 					case TYPE_IPADDR:
22920Sstevel@tonic-gate 					case TYPE_OPAQUE:
22930Sstevel@tonic-gate 						fprintf(fp, "String *%s, ",
22940Sstevel@tonic-gate 							current->label);
22950Sstevel@tonic-gate 						break;
22960Sstevel@tonic-gate 
22970Sstevel@tonic-gate 					case TYPE_OBJID:
22980Sstevel@tonic-gate 						fprintf(fp, "Oid *%s, ",
22990Sstevel@tonic-gate 							current->label);
23000Sstevel@tonic-gate 						break;
23010Sstevel@tonic-gate 
23020Sstevel@tonic-gate 					default:
23030Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
23040Sstevel@tonic-gate 						current->type,
23050Sstevel@tonic-gate 						current->label);
23060Sstevel@tonic-gate 				}
23070Sstevel@tonic-gate 
23080Sstevel@tonic-gate 				indexs = current->parent->indexs;
23090Sstevel@tonic-gate 
23100Sstevel@tonic-gate /* not more ind. index */
23110Sstevel@tonic-gate 
23120Sstevel@tonic-gate 				if(indexs)
23130Sstevel@tonic-gate 				{
23140Sstevel@tonic-gate 					if(indexs->tp)
23150Sstevel@tonic-gate 					{
23160Sstevel@tonic-gate 						switch(indexs->tp->type)
23170Sstevel@tonic-gate 						{
23180Sstevel@tonic-gate 							case TYPE_INTEGER:
23190Sstevel@tonic-gate 							case TYPE_COUNTER:
23200Sstevel@tonic-gate 							case TYPE_GAUGE:
23210Sstevel@tonic-gate 							case TYPE_TIMETICKS:
23220Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s)\n",
23230Sstevel@tonic-gate 									"index");
23240Sstevel@tonic-gate 								break;
23250Sstevel@tonic-gate 
23260Sstevel@tonic-gate 							case TYPE_OCTETSTR:
23270Sstevel@tonic-gate 							case TYPE_IPADDR:
23280Sstevel@tonic-gate 							case TYPE_OPAQUE:
23290Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s)\n",
23300Sstevel@tonic-gate 									"index");
23310Sstevel@tonic-gate 								break;
23320Sstevel@tonic-gate 
23330Sstevel@tonic-gate 							case TYPE_OBJID:
23340Sstevel@tonic-gate 								fprintf(fp, "IndexType *%s)\n",
23350Sstevel@tonic-gate 									"index");
23360Sstevel@tonic-gate 								break;
23370Sstevel@tonic-gate 
23380Sstevel@tonic-gate 							default:
23390Sstevel@tonic-gate 								error_exit("output_extern_function(): Unknown type (%d) for %s",
23400Sstevel@tonic-gate 								indexs->tp->type,
23410Sstevel@tonic-gate 								indexs->tp->label);
23420Sstevel@tonic-gate 						}
23430Sstevel@tonic-gate 					}
23440Sstevel@tonic-gate 					else
23450Sstevel@tonic-gate 					{
23460Sstevel@tonic-gate 						error("WARNING: By default, the type of INDEX %s set to INTEGER",
23470Sstevel@tonic-gate 							indexs->label);
23480Sstevel@tonic-gate 						fprintf(fp, "IndexType *%s)\n",
23490Sstevel@tonic-gate 								"index");
23500Sstevel@tonic-gate 					}
23510Sstevel@tonic-gate 
23520Sstevel@tonic-gate 					indexs = indexs->next;
23530Sstevel@tonic-gate 				}
23540Sstevel@tonic-gate 
23550Sstevel@tonic-gate 			PRINT_OPEN_BRACKET
23560Sstevel@tonic-gate 
23570Sstevel@tonic-gate 			switch(current->type)
23580Sstevel@tonic-gate 			{
23590Sstevel@tonic-gate 						case TYPE_INTEGER:
23600Sstevel@tonic-gate 						case TYPE_COUNTER:
23610Sstevel@tonic-gate 						case TYPE_TIMETICKS:
23620Sstevel@tonic-gate 						case TYPE_GAUGE:
23630Sstevel@tonic-gate 							PRINT_GET_CASE_BLOCK
23640Sstevel@tonic-gate 							fprintf(fp,"\t/*assume that the mib variable has a value of 1 */\n\n");
23650Sstevel@tonic-gate 							fprintf(fp,"\t*%s = 1;\n",current->label);
23660Sstevel@tonic-gate 							fprintf(fp,"\treturn SNMP_ERR_NOERROR;\n");
23670Sstevel@tonic-gate 							break;
23680Sstevel@tonic-gate 
23690Sstevel@tonic-gate 						case TYPE_OCTETSTR:
23700Sstevel@tonic-gate 						case TYPE_IPADDR:
23710Sstevel@tonic-gate 						case TYPE_OPAQUE:
23720Sstevel@tonic-gate 							fprintf(fp, "\tu_char *str;\n");
23730Sstevel@tonic-gate 							fprintf(fp, "\tint len;\n\n");
23740Sstevel@tonic-gate 							PRINT_GET_CASE_BLOCK
23750Sstevel@tonic-gate 							PRINT_GET_STRING_DUMBY_BLOCK
23760Sstevel@tonic-gate 							break;
23770Sstevel@tonic-gate 
23780Sstevel@tonic-gate 						case TYPE_OBJID:
23790Sstevel@tonic-gate 							fprintf(fp, "\tSubid *sub;\n");
23800Sstevel@tonic-gate 							fprintf(fp, "\tSubid fake_sub[] = {1,3,6,1,4,1,4,42};\n");
23810Sstevel@tonic-gate 							fprintf(fp, "\tint len;\n\n");
23820Sstevel@tonic-gate 							PRINT_GET_CASE_BLOCK
23830Sstevel@tonic-gate 							PRINT_GET_OID_DUMBY_BLOCK
23840Sstevel@tonic-gate 							break;
23850Sstevel@tonic-gate 
23860Sstevel@tonic-gate 							default:
23870Sstevel@tonic-gate 								error_exit("output_extern_function(): Unknown type (%d) for %s",
23880Sstevel@tonic-gate 								current->type,
23890Sstevel@tonic-gate 								current->label);
23900Sstevel@tonic-gate 			}
23910Sstevel@tonic-gate 
23920Sstevel@tonic-gate 				PRINT_CLOSE_BRACKET
23930Sstevel@tonic-gate 			}
23940Sstevel@tonic-gate 
23950Sstevel@tonic-gate 			if(current->access & WRITE_FLAG)
23960Sstevel@tonic-gate 			{
23970Sstevel@tonic-gate 				fprintf(fp, "\n");
23980Sstevel@tonic-gate 				fprintf(fp, "int set_%s(int pass, ",
23990Sstevel@tonic-gate 					current->label);
24000Sstevel@tonic-gate 
24010Sstevel@tonic-gate 				indexs = current->parent->indexs;
24020Sstevel@tonic-gate 
24030Sstevel@tonic-gate 				/* no more ind. index */
24040Sstevel@tonic-gate 				if(indexs)
24050Sstevel@tonic-gate 				{
24060Sstevel@tonic-gate 					if(indexs->tp)
24070Sstevel@tonic-gate 					{
24080Sstevel@tonic-gate 						switch(indexs->tp->type)
24090Sstevel@tonic-gate 						{
24100Sstevel@tonic-gate 							case TYPE_INTEGER:
24110Sstevel@tonic-gate 							case TYPE_COUNTER:
24120Sstevel@tonic-gate 							case TYPE_GAUGE:
24130Sstevel@tonic-gate 							case TYPE_TIMETICKS:
24140Sstevel@tonic-gate 							case TYPE_OCTETSTR:
24150Sstevel@tonic-gate 							case TYPE_IPADDR:
24160Sstevel@tonic-gate 							case TYPE_OPAQUE:
24170Sstevel@tonic-gate 							case TYPE_OBJID:
24180Sstevel@tonic-gate 								fprintf(fp, "IndexType %s, ",
24190Sstevel@tonic-gate 									"index");
24200Sstevel@tonic-gate 								break;
24210Sstevel@tonic-gate 
24220Sstevel@tonic-gate 							default:
24230Sstevel@tonic-gate 								error_exit("output_function(): Unknown type (%d) for %s",
24240Sstevel@tonic-gate 									indexs->tp->type,
24250Sstevel@tonic-gate 								indexs->tp->label);
24260Sstevel@tonic-gate 						}
24270Sstevel@tonic-gate 					}
24280Sstevel@tonic-gate 					else
24290Sstevel@tonic-gate 					{
24300Sstevel@tonic-gate 						error("WARNING: By default, the type of INDEX %s set to INTEGER",
24310Sstevel@tonic-gate 							indexs->label);
24320Sstevel@tonic-gate 						fprintf(fp, "Integer %s, ",
24330Sstevel@tonic-gate 							indexs->label);
24340Sstevel@tonic-gate 					}
24350Sstevel@tonic-gate 					indexs = indexs->next;
24360Sstevel@tonic-gate 				}
24370Sstevel@tonic-gate 
24380Sstevel@tonic-gate 
24390Sstevel@tonic-gate 				switch(current->type)
24400Sstevel@tonic-gate 				{
24410Sstevel@tonic-gate 					case TYPE_INTEGER:
24420Sstevel@tonic-gate 					case TYPE_COUNTER:
24430Sstevel@tonic-gate 					case TYPE_GAUGE:
24440Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
24450Sstevel@tonic-gate 						fprintf(fp, "Integer *%s)\n",
24460Sstevel@tonic-gate 							current->label);
24470Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
24480Sstevel@tonic-gate 						SET_PRINT_ENTRY_BLOCK
24490Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%d\\n\",%s);\n",current->label);
24500Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
24510Sstevel@tonic-gate 						break;
24520Sstevel@tonic-gate 
24530Sstevel@tonic-gate 					case TYPE_OCTETSTR:
24540Sstevel@tonic-gate 					case TYPE_IPADDR:
24550Sstevel@tonic-gate 					case TYPE_OPAQUE:
24560Sstevel@tonic-gate 						fprintf(fp, "String *%s)\n",
24570Sstevel@tonic-gate 							current->label);
24580Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
24590Sstevel@tonic-gate 						fprintf(fp, "\tchar buf[100];\n\n");
24600Sstevel@tonic-gate 						SET_PRINT_ENTRY_BLOCK
24610Sstevel@tonic-gate 						fprintf(fp, "\t\t\tmemcpy(buf,%s->chars,%s->len);\n",current->label,current->label);
24620Sstevel@tonic-gate 						fprintf(fp, "\t\t\tbuf[%s->len+1] = '\\0';\n",current->label);
24630Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%s\\n\",buf);\n");
24640Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
24650Sstevel@tonic-gate 						break;
24660Sstevel@tonic-gate 
24670Sstevel@tonic-gate 					case TYPE_OBJID:
24680Sstevel@tonic-gate 						fprintf(fp, "Oid *%s)\n",
24690Sstevel@tonic-gate 							current->label);
24700Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
24710Sstevel@tonic-gate 						SET_PRINT_ENTRY_BLOCK
24720Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%s\\n\",SSAOidString(%s));\n",current->label);
24730Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
24740Sstevel@tonic-gate 						break;
24750Sstevel@tonic-gate 
24760Sstevel@tonic-gate 					default:
24770Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s",
24780Sstevel@tonic-gate 							current->type,
24790Sstevel@tonic-gate 							current->label);
24800Sstevel@tonic-gate 				}
24810Sstevel@tonic-gate 				PRINT_TAG_CLOSE_BRACKET
24820Sstevel@tonic-gate 				PRINT_CLOSE_BRACKET
24830Sstevel@tonic-gate 				fprintf(fp, "\n");
24840Sstevel@tonic-gate 			}
24850Sstevel@tonic-gate 
24860Sstevel@tonic-gate 			if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
24870Sstevel@tonic-gate 			{
24880Sstevel@tonic-gate 				switch(current->type)
24890Sstevel@tonic-gate 				{
24900Sstevel@tonic-gate 					case TYPE_INTEGER:
24910Sstevel@tonic-gate 					case TYPE_COUNTER:
24920Sstevel@tonic-gate 					case TYPE_GAUGE:
24930Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-95)*/
24940Sstevel@tonic-gate 						break;
24950Sstevel@tonic-gate 
24960Sstevel@tonic-gate 					case TYPE_OCTETSTR:
24970Sstevel@tonic-gate 					case TYPE_IPADDR:
24980Sstevel@tonic-gate 					case TYPE_OPAQUE:
24990Sstevel@tonic-gate 						fprintf(fp, "\n");
25000Sstevel@tonic-gate 						fprintf(fp, "void free_%s(String *%s)\n",
25010Sstevel@tonic-gate 							current->label,
25020Sstevel@tonic-gate 							current->label);
25030Sstevel@tonic-gate                                 		fprintf(fp, "{\n");
25040Sstevel@tonic-gate                                 		fprintf(fp, "\t if(%s->",current->label);
25050Sstevel@tonic-gate 						break;
25060Sstevel@tonic-gate 
25070Sstevel@tonic-gate 					case TYPE_OBJID:
25080Sstevel@tonic-gate 						fprintf(fp, "\n");
25090Sstevel@tonic-gate 						fprintf(fp, "void free_%s(Oid *%s)\n",
25100Sstevel@tonic-gate 							current->label,
25110Sstevel@tonic-gate 							current->label);
25120Sstevel@tonic-gate                                 		fprintf(fp, "{\n");
25130Sstevel@tonic-gate                                 		fprintf(fp, "\t if(%s->",current->label);
25140Sstevel@tonic-gate 						break;
25150Sstevel@tonic-gate 
25160Sstevel@tonic-gate 					default:
25170Sstevel@tonic-gate 						error_exit("output_extern_function(): Unknown type (%d) for %s",
25180Sstevel@tonic-gate 							current->type,
25190Sstevel@tonic-gate 							current->label);
25200Sstevel@tonic-gate 				}
25210Sstevel@tonic-gate                                 switch(current->type)
25220Sstevel@tonic-gate                                 {
25230Sstevel@tonic-gate                                         case TYPE_INTEGER:
25240Sstevel@tonic-gate                                         case TYPE_COUNTER:
25250Sstevel@tonic-gate                                         case TYPE_GAUGE:
25260Sstevel@tonic-gate                                         case TYPE_TIMETICKS:
25270Sstevel@tonic-gate                                                 break;
25280Sstevel@tonic-gate 
25290Sstevel@tonic-gate                                         case TYPE_OCTETSTR:
25300Sstevel@tonic-gate                                         case TYPE_IPADDR:
25310Sstevel@tonic-gate                                         case TYPE_OPAQUE:
25320Sstevel@tonic-gate                                                 fprintf(fp, "chars!=NULL && %s->len !=0)\n",current->label);
25330Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
25340Sstevel@tonic-gate                                                 fprintf(fp, "\t\tfree(%s->chars);\n",current->label);
25350Sstevel@tonic-gate                                                 fprintf(fp,"\t\t%s->len = 0;\n",current->label);
25360Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
25370Sstevel@tonic-gate                                 		fprintf(fp, "}\n");
25380Sstevel@tonic-gate                                                 break;
25390Sstevel@tonic-gate 
25400Sstevel@tonic-gate                                         case TYPE_OBJID:
25410Sstevel@tonic-gate                                                 fprintf(fp, "subids!=NULL && %s->len !=0)\n",current->label);
25420Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
25430Sstevel@tonic-gate                                                 fprintf(fp, "\t\tfree(%s->subids);\n",current->label);
25440Sstevel@tonic-gate                                                 fprintf(fp,"\t\t%s->len = 0;\n",current->label);
25450Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
25460Sstevel@tonic-gate                                 		fprintf(fp, "}\n");
25470Sstevel@tonic-gate                                                 break;
25480Sstevel@tonic-gate 
25490Sstevel@tonic-gate                                         default:
25500Sstevel@tonic-gate                                                 error_exit("output_function(): Unknown type (%d) for %s",
25510Sstevel@tonic-gate                                                         current->type,
25520Sstevel@tonic-gate                                                         current->label);
25530Sstevel@tonic-gate                                 }
25540Sstevel@tonic-gate 			}
25550Sstevel@tonic-gate 
25560Sstevel@tonic-gate 			break;
25570Sstevel@tonic-gate 
25580Sstevel@tonic-gate 
25590Sstevel@tonic-gate 		case ENTRY:
25600Sstevel@tonic-gate 			fprintf(fp, "\n");
25610Sstevel@tonic-gate 			fprintf(fp, "extern int get_%s(int search_type, %c%s_t **%s_data",
25620Sstevel@tonic-gate 				current->label,
25630Sstevel@tonic-gate 				toupper(current->label[0]),
25640Sstevel@tonic-gate 				&(current->label[1]),
25650Sstevel@tonic-gate 				current->label);
25660Sstevel@tonic-gate 
25670Sstevel@tonic-gate 			indexs = current->indexs;
25680Sstevel@tonic-gate 
25690Sstevel@tonic-gate /* no more ind. index */
25700Sstevel@tonic-gate 			if(indexs)
25710Sstevel@tonic-gate 			{
25720Sstevel@tonic-gate 				if(indexs->tp)
25730Sstevel@tonic-gate 				{
25740Sstevel@tonic-gate 					switch(indexs->tp->type)
25750Sstevel@tonic-gate 					{
25760Sstevel@tonic-gate 						case TYPE_INTEGER:
25770Sstevel@tonic-gate 						case TYPE_COUNTER:
25780Sstevel@tonic-gate 						case TYPE_GAUGE:
25790Sstevel@tonic-gate 						case TYPE_TIMETICKS:
25800Sstevel@tonic-gate 
25810Sstevel@tonic-gate 						case TYPE_OCTETSTR:
25820Sstevel@tonic-gate 						case TYPE_IPADDR:
25830Sstevel@tonic-gate 						case TYPE_OPAQUE:
25840Sstevel@tonic-gate 
25850Sstevel@tonic-gate 						case TYPE_OBJID:
25860Sstevel@tonic-gate 							fprintf(fp, ", IndexType *%s",
25870Sstevel@tonic-gate 								"index");
25880Sstevel@tonic-gate 							break;
25890Sstevel@tonic-gate 
25900Sstevel@tonic-gate 						default:
25910Sstevel@tonic-gate 							error_exit("output_function(): Unknown type (%d) for %s",
25920Sstevel@tonic-gate 								indexs->tp->type,
25930Sstevel@tonic-gate 								indexs->tp->label);
25940Sstevel@tonic-gate 					}
25950Sstevel@tonic-gate 				}
25960Sstevel@tonic-gate 				else
25970Sstevel@tonic-gate 				{
25980Sstevel@tonic-gate 					error("WARNING: By default, the type of INDEX %s set to INTEGER",
25990Sstevel@tonic-gate 						indexs->label);
26000Sstevel@tonic-gate 					fprintf(fp, ", Integer *%s",
26010Sstevel@tonic-gate 						indexs->label);
26020Sstevel@tonic-gate 				}
26030Sstevel@tonic-gate 
26040Sstevel@tonic-gate 				indexs = indexs->next;
26050Sstevel@tonic-gate 			}
26060Sstevel@tonic-gate 			fprintf(fp, ")\n");
26070Sstevel@tonic-gate 			fprintf(fp, "{\n");
26080Sstevel@tonic-gate 			fprintf(fp, "\n");
26090Sstevel@tonic-gate 			fprintf(fp, "\tint res;\n");
26100Sstevel@tonic-gate 			fprintf(fp, "\tIndexType backupIndex, useIndex;\n");
26110Sstevel@tonic-gate 			fprintf(fp, "\tint i;\n");
26120Sstevel@tonic-gate 			fprintf(fp, "\n");
26130Sstevel@tonic-gate 			fprintf(fp, "\t*%s_data = (%c%s_t*)calloc(1,sizeof(%c%s_t));\n",
26140Sstevel@tonic-gate 					current->label,
26150Sstevel@tonic-gate 					toupper(current->label[0]), &(current->label[1]),
26160Sstevel@tonic-gate 					toupper(current->label[0]), &(current->label[1]));
26170Sstevel@tonic-gate 			fprintf(fp,"\tif(%s_data == NULL) return SNMP_ERR_GENERR;\n",current->label);
26180Sstevel@tonic-gate 			fprintf(fp,"\n");
26190Sstevel@tonic-gate 
26200Sstevel@tonic-gate 				first_time_entry_print = 0;
26210Sstevel@tonic-gate 				for(child = current->child_list; child; child = child->next_peer)
26220Sstevel@tonic-gate 				{
26230Sstevel@tonic-gate 					if(!(child->access & READ_FLAG) )
26240Sstevel@tonic-gate 						continue;
26250Sstevel@tonic-gate 
26260Sstevel@tonic-gate                                 	switch(child->type)
26270Sstevel@tonic-gate                                 	{
26280Sstevel@tonic-gate                                        	 case TYPE_INTEGER:
26290Sstevel@tonic-gate                                        	 case TYPE_COUNTER:
26300Sstevel@tonic-gate                                        	 case TYPE_GAUGE:
26310Sstevel@tonic-gate                                        	 case TYPE_TIMETICKS:
26320Sstevel@tonic-gate                                        	 case TYPE_OCTETSTR:
26330Sstevel@tonic-gate                                        	 case TYPE_IPADDR:
26340Sstevel@tonic-gate                                        	 case TYPE_OPAQUE:
26350Sstevel@tonic-gate                                         case TYPE_OBJID:
26360Sstevel@tonic-gate 						first_time_entry_print++;
26370Sstevel@tonic-gate 						if(first_time_entry_print==1){
26380Sstevel@tonic-gate 			fprintf(fp, "\n");
26390Sstevel@tonic-gate 			fprintf(fp, "\tbackupIndex.type = index->type;\n");
26400Sstevel@tonic-gate 			fprintf(fp, "\tbackupIndex.len = index->len;\n");
26410Sstevel@tonic-gate 			fprintf(fp, "\tbackupIndex.value = (int*)calloc(index->len,sizeof(int));\n");
26420Sstevel@tonic-gate 			fprintf(fp, "\tfor(i=0;i<index->len;i++)\n");
26430Sstevel@tonic-gate 			fprintf(fp, "\t\tbackupIndex.value[i] = index->value[i];\n");
26440Sstevel@tonic-gate 	fprintf(fp, "\tuseIndex.type = backupIndex.type;\n");
26450Sstevel@tonic-gate 	fprintf(fp, "\tuseIndex.len = backupIndex.len;\n");
26460Sstevel@tonic-gate 	fprintf(fp, "\tuseIndex.value = (int*)calloc(backupIndex.len,sizeof(int));\n");
26470Sstevel@tonic-gate 	fprintf(fp, "\n");
26480Sstevel@tonic-gate }else{
26490Sstevel@tonic-gate 	fprintf(fp, "\n");
26500Sstevel@tonic-gate 	fprintf(fp, "\tfor(i=0;i<backupIndex.len;i++)\n");
26510Sstevel@tonic-gate 	fprintf(fp, "\t\tuseIndex.value[i] = backupIndex.value[i];\n");
26520Sstevel@tonic-gate 	fprintf(fp, "\n");
26530Sstevel@tonic-gate }
26540Sstevel@tonic-gate 						fprintf(fp,"\tres = ");
26550Sstevel@tonic-gate 						fprintf(fp,"get_%s(\n",child->label);
26560Sstevel@tonic-gate 						fprintf(fp,"\t        search_type,\n");
26570Sstevel@tonic-gate 						fprintf(fp,"\t        &((*%s_data)->%s),\n",current->label,child->label);
26580Sstevel@tonic-gate 						if(first_time_entry_print==1)
26590Sstevel@tonic-gate 						  fprintf(fp,"\t        index);\n");
26600Sstevel@tonic-gate 						else
26610Sstevel@tonic-gate 						  fprintf(fp,"\t        &useIndex);\n");
26620Sstevel@tonic-gate 						fprintf(fp,"\tif(res != SNMP_ERR_NOERROR){\n");
26630Sstevel@tonic-gate                                                 fprintf(fp,"\t\tfree_%s(*%s_data);\n",current->label,current->label);
26640Sstevel@tonic-gate 						fprintf(fp, "\t\t*%s_data=NULL;\n",current->label);
26650Sstevel@tonic-gate                                                 fprintf(fp,"\t\tfree((char *)backupIndex.value);\n");
26660Sstevel@tonic-gate                                                 fprintf(fp,"\t\tfree((char *)useIndex.value);\n");
26670Sstevel@tonic-gate 						fprintf(fp, "\t\treturn res;\n\n");
26680Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
26690Sstevel@tonic-gate 
26700Sstevel@tonic-gate                                                 break;
26710Sstevel@tonic-gate 
26720Sstevel@tonic-gate                                         default:
26730Sstevel@tonic-gate                                                 error_exit("output_function(): Unknown type (%d) for %s",
26740Sstevel@tonic-gate                                                         child->type,
26750Sstevel@tonic-gate                                                         child->label);
26760Sstevel@tonic-gate                                 	}
26770Sstevel@tonic-gate 				}
26780Sstevel@tonic-gate 
26790Sstevel@tonic-gate 
26800Sstevel@tonic-gate                         fprintf(fp,"\t free((char *)backupIndex.value);\n");
26810Sstevel@tonic-gate                         fprintf(fp,"\t free((char *)useIndex.value);\n");
26820Sstevel@tonic-gate 			fprintf(fp, "\t return res;\n");
26830Sstevel@tonic-gate 			fprintf(fp, "}\n");
26840Sstevel@tonic-gate 			fprintf(fp, "\n");
26850Sstevel@tonic-gate 
26860Sstevel@tonic-gate 				fprintf(fp, "\n");
26870Sstevel@tonic-gate 				fprintf(fp, "void free_%s(%c%s_t *%s)\n",
26880Sstevel@tonic-gate 			                current->label, toupper(current->label[0]),
26890Sstevel@tonic-gate                                         &(current->label[1]), current->label);
26900Sstevel@tonic-gate                                 fprintf(fp, "{\n");
26910Sstevel@tonic-gate 
26920Sstevel@tonic-gate                                 fprintf(fp,"\tif (%s) {\n", current->label);
26930Sstevel@tonic-gate 
26940Sstevel@tonic-gate 				for(child = current->child_list; child; child = child->next_peer)
26950Sstevel@tonic-gate 				{
26960Sstevel@tonic-gate 					if(!(child->access & READ_FLAG) )
26970Sstevel@tonic-gate 						continue;
26980Sstevel@tonic-gate 
26990Sstevel@tonic-gate                                 	switch(child->type)
27000Sstevel@tonic-gate                                 	{
27010Sstevel@tonic-gate                                        	 case TYPE_INTEGER:
27020Sstevel@tonic-gate                                        	 case TYPE_COUNTER:
27030Sstevel@tonic-gate                                        	 case TYPE_GAUGE:
27040Sstevel@tonic-gate                                        	 case TYPE_TIMETICKS:
27050Sstevel@tonic-gate                                        	         break;
27060Sstevel@tonic-gate 
27070Sstevel@tonic-gate                                        	 case TYPE_OCTETSTR:
27080Sstevel@tonic-gate                                        	 case TYPE_IPADDR:
27090Sstevel@tonic-gate                                        	 case TYPE_OPAQUE:
27100Sstevel@tonic-gate                                         case TYPE_OBJID:
27110Sstevel@tonic-gate 						fprintf(fp, "\t\tfree_%s(&(%s->%s));\n",
27120Sstevel@tonic-gate 								child->label,
27130Sstevel@tonic-gate 								current->label,child->label);
27140Sstevel@tonic-gate                                                 break;
27150Sstevel@tonic-gate 
27160Sstevel@tonic-gate                                         default:
27170Sstevel@tonic-gate                                                 error_exit("output_function(): Unknown type (%d) for %s",
27180Sstevel@tonic-gate                                                         child->type,
27190Sstevel@tonic-gate                                                         child->label);
27200Sstevel@tonic-gate                                 	}
27210Sstevel@tonic-gate 				}
27220Sstevel@tonic-gate                                 fprintf(fp,"\t\tfree(%s);\n",current->label);
27230Sstevel@tonic-gate                                 fprintf(fp,"\t\t%s=NULL;\n",current->label);
27240Sstevel@tonic-gate                                 fprintf(fp,"\t}\n");
27250Sstevel@tonic-gate                                 fprintf(fp, "}\n");
27260Sstevel@tonic-gate 
27270Sstevel@tonic-gate 			break;
27280Sstevel@tonic-gate 	}
27290Sstevel@tonic-gate 
27300Sstevel@tonic-gate 
27310Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
27320Sstevel@tonic-gate 	{
27330Sstevel@tonic-gate 		output_entry_function(fp, tp);
27340Sstevel@tonic-gate 	}
27350Sstevel@tonic-gate 
27360Sstevel@tonic-gate }
output_single_obj_function(FILE * fp,struct tree * current)27370Sstevel@tonic-gate static void output_single_obj_function(FILE *fp, struct tree *current)
27380Sstevel@tonic-gate {
27390Sstevel@tonic-gate 	struct tree *tp;
27400Sstevel@tonic-gate 
27410Sstevel@tonic-gate 
27420Sstevel@tonic-gate 	switch(current->node_type)
27430Sstevel@tonic-gate 	{
27440Sstevel@tonic-gate 		case OBJECT:
27450Sstevel@tonic-gate 			if(current->access & READ_FLAG)
27460Sstevel@tonic-gate 			{
27470Sstevel@tonic-gate 				fprintf(fp, "\n");
27480Sstevel@tonic-gate 				switch(current->type)
27490Sstevel@tonic-gate 				{
27500Sstevel@tonic-gate 					case TYPE_INTEGER:
27510Sstevel@tonic-gate 					case TYPE_COUNTER:
27520Sstevel@tonic-gate 					case TYPE_GAUGE:
27530Sstevel@tonic-gate 					case TYPE_TIMETICKS:
27540Sstevel@tonic-gate 						fprintf(fp, "int get_%s(Integer *%s)\n",
27550Sstevel@tonic-gate 							current->label,
27560Sstevel@tonic-gate 							current->label);
27570Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
27580Sstevel@tonic-gate 						fprintf(fp, "\t/* assume that the mib variable has a value of 1 */\n\n");
27590Sstevel@tonic-gate 						fprintf(fp, "\t*%s = 1;\n",current->label);
27600Sstevel@tonic-gate 						fprintf(fp, "\treturn SNMP_ERR_NOERROR;\n");
27610Sstevel@tonic-gate 						break;
27620Sstevel@tonic-gate 
27630Sstevel@tonic-gate 					case TYPE_OCTETSTR:
27640Sstevel@tonic-gate 					case TYPE_IPADDR:
27650Sstevel@tonic-gate 					case TYPE_OPAQUE:
27660Sstevel@tonic-gate 						fprintf(fp, "int get_%s(String *%s)\n",
27670Sstevel@tonic-gate 							current->label,
27680Sstevel@tonic-gate 							current->label);
27690Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
27700Sstevel@tonic-gate 						fprintf(fp, "\tu_char *str;\n");
27710Sstevel@tonic-gate 						fprintf(fp, "\tint len;\n\n");
27720Sstevel@tonic-gate 
27730Sstevel@tonic-gate 						PRINT_GET_STRING_DUMBY_BLOCK
27740Sstevel@tonic-gate 
27750Sstevel@tonic-gate 						break;
27760Sstevel@tonic-gate 
27770Sstevel@tonic-gate 					case TYPE_OBJID:
27780Sstevel@tonic-gate 						fprintf(fp, "int get_%s(Oid *%s)\n",
27790Sstevel@tonic-gate 							current->label,
27800Sstevel@tonic-gate 							current->label);
27810Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
27820Sstevel@tonic-gate 						fprintf(fp, "\tSubid *sub;\n");
27830Sstevel@tonic-gate 						fprintf(fp, "\tSubid fake_sub[] = {1,3,6,1,4,1,4,42};\n");
27840Sstevel@tonic-gate 						fprintf(fp, "\tint len;\n\n");
27850Sstevel@tonic-gate 
27860Sstevel@tonic-gate 						PRINT_GET_OID_DUMBY_BLOCK
27870Sstevel@tonic-gate 
27880Sstevel@tonic-gate 						break;
27890Sstevel@tonic-gate 
27900Sstevel@tonic-gate 					deafult:
27910Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s", current->type,
27920Sstevel@tonic-gate 							current->label);
27930Sstevel@tonic-gate 				}
27940Sstevel@tonic-gate 				PRINT_CLOSE_BRACKET
27950Sstevel@tonic-gate 			}
27960Sstevel@tonic-gate 
27970Sstevel@tonic-gate 			if(current->access & WRITE_FLAG)
27980Sstevel@tonic-gate 			{
27990Sstevel@tonic-gate 				fprintf(fp, "\n");
28000Sstevel@tonic-gate 				switch(current->type)
28010Sstevel@tonic-gate 				{
28020Sstevel@tonic-gate 					case TYPE_INTEGER:
28030Sstevel@tonic-gate 					case TYPE_COUNTER:
28040Sstevel@tonic-gate 					case TYPE_GAUGE:
28050Sstevel@tonic-gate 					case TYPE_TIMETICKS: /*(5-15-96)*/
28060Sstevel@tonic-gate 						fprintf(fp, "int set_%s(int pass, Integer *%s)\n",
28070Sstevel@tonic-gate 							current->label,
28080Sstevel@tonic-gate 							current->label);
28090Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
28100Sstevel@tonic-gate 						fprintf(fp, "\tswitch(pass)\n");
28110Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
28120Sstevel@tonic-gate 						PRINT_SET_CASE_BLOCK
28130Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%d\\n\",%s);\n",current->label);
28140Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
28150Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
28160Sstevel@tonic-gate 						break;
28170Sstevel@tonic-gate 
28180Sstevel@tonic-gate 					case TYPE_OCTETSTR:
28190Sstevel@tonic-gate 					case TYPE_IPADDR:
28200Sstevel@tonic-gate 					case TYPE_OPAQUE:
28210Sstevel@tonic-gate 						fprintf(fp, "int set_%s(int pass, String *%s)\n",
28220Sstevel@tonic-gate 							current->label,
28230Sstevel@tonic-gate 							current->label);
28240Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
28250Sstevel@tonic-gate 						fprintf(fp, "\tchar buf[100];\n\n");
28260Sstevel@tonic-gate 						fprintf(fp, "\tswitch(pass)\n");
28270Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
28280Sstevel@tonic-gate 						PRINT_SET_CASE_BLOCK
28290Sstevel@tonic-gate 						fprintf(fp, "\t\t\tmemcpy(buf,%s->chars,%s->len);\n",current->label,current->label);
28300Sstevel@tonic-gate 						fprintf(fp, "\t\t\tbuf[%s->len+1] = '\\0';\n",current->label);
28310Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%s\\n\",buf);\n");
28320Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
28330Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
28340Sstevel@tonic-gate 						break;
28350Sstevel@tonic-gate 
28360Sstevel@tonic-gate 					case TYPE_OBJID:
28370Sstevel@tonic-gate 						fprintf(fp, "int set_%s(int pass, Oid *%s)\n",
28380Sstevel@tonic-gate 							current->label,
28390Sstevel@tonic-gate 							current->label);
28400Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
28410Sstevel@tonic-gate 						fprintf(fp, "\tswitch(pass)\n");
28420Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
28430Sstevel@tonic-gate 						PRINT_SET_CASE_BLOCK
28440Sstevel@tonic-gate 						fprintf(fp, "\t\t\tprintf(\"The new value is %%s\\n\",SSAOidString(%s));\n",current->label);
28450Sstevel@tonic-gate 						fprintf(fp, "\t\t\treturn SNMP_ERR_NOERROR;\n");
28460Sstevel@tonic-gate 						fprintf(fp, "\t}\n");
28470Sstevel@tonic-gate 						break;
28480Sstevel@tonic-gate 
28490Sstevel@tonic-gate 					default:
28500Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s", current->type,
28510Sstevel@tonic-gate 							current->label);
28520Sstevel@tonic-gate 				}
28530Sstevel@tonic-gate 
28540Sstevel@tonic-gate 				PRINT_CLOSE_BRACKET
28550Sstevel@tonic-gate 				fprintf(fp, "\n");
28560Sstevel@tonic-gate 			}
28570Sstevel@tonic-gate 
28580Sstevel@tonic-gate 			if( (current->access & READ_FLAG) || (current->access & WRITE_FLAG) )
28590Sstevel@tonic-gate 			{
28600Sstevel@tonic-gate 				switch(current->type)
28610Sstevel@tonic-gate 				{
28620Sstevel@tonic-gate 					case TYPE_INTEGER:
28630Sstevel@tonic-gate 					case TYPE_COUNTER:
28640Sstevel@tonic-gate 					case TYPE_GAUGE:
28650Sstevel@tonic-gate 					case TYPE_TIMETICKS:
28660Sstevel@tonic-gate 						break;
28670Sstevel@tonic-gate 
28680Sstevel@tonic-gate 					case TYPE_OCTETSTR:
28690Sstevel@tonic-gate 					case TYPE_IPADDR:
28700Sstevel@tonic-gate 					case TYPE_OPAQUE:
28710Sstevel@tonic-gate 						fprintf(fp, "\n");
28720Sstevel@tonic-gate 						fprintf(fp, "void free_%s(String *%s)\n",
28730Sstevel@tonic-gate 							current->label,
28740Sstevel@tonic-gate 							current->label);
28750Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
28760Sstevel@tonic-gate 						fprintf(fp, "\t if(%s->",current->label);
28770Sstevel@tonic-gate 						break;
28780Sstevel@tonic-gate 
28790Sstevel@tonic-gate 					case TYPE_OBJID:
28800Sstevel@tonic-gate 						fprintf(fp, "\n");
28810Sstevel@tonic-gate 						fprintf(fp, "void free_%s(Oid *%s)\n",
28820Sstevel@tonic-gate 							current->label,
28830Sstevel@tonic-gate 							current->label);
28840Sstevel@tonic-gate 						PRINT_OPEN_BRACKET
28850Sstevel@tonic-gate 						fprintf(fp, "\t if(%s->",current->label);
28860Sstevel@tonic-gate 						break;
28870Sstevel@tonic-gate 
28880Sstevel@tonic-gate 					default:
28890Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s",
28900Sstevel@tonic-gate 							current->type,
28910Sstevel@tonic-gate 							current->label);
28920Sstevel@tonic-gate 				}
28930Sstevel@tonic-gate 				switch(current->type)
28940Sstevel@tonic-gate 				{
28950Sstevel@tonic-gate 					case TYPE_INTEGER:
28960Sstevel@tonic-gate 					case TYPE_COUNTER:
28970Sstevel@tonic-gate 					case TYPE_GAUGE:
28980Sstevel@tonic-gate 					case TYPE_TIMETICKS:
28990Sstevel@tonic-gate 						break;
29000Sstevel@tonic-gate 
29010Sstevel@tonic-gate 					case TYPE_OCTETSTR:
29020Sstevel@tonic-gate 					case TYPE_IPADDR:
29030Sstevel@tonic-gate 					case TYPE_OPAQUE:
29040Sstevel@tonic-gate 						fprintf(fp, "chars!=NULL && %s->len !=0)\n",current->label);
29050Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
29060Sstevel@tonic-gate 						fprintf(fp, "\t\tfree(%s->chars);\n",current->label);
29070Sstevel@tonic-gate 						fprintf(fp,"\t\t%s->len = 0;\n",current->label);
29080Sstevel@tonic-gate 						fprintf(fp,"\t}\n");
29090Sstevel@tonic-gate 						PRINT_CLOSE_BRACKET
29100Sstevel@tonic-gate 						break;
29110Sstevel@tonic-gate 
29120Sstevel@tonic-gate 					case TYPE_OBJID:
29130Sstevel@tonic-gate 						fprintf(fp, "subids!=NULL && %s->len !=0)\n",current->label);
29140Sstevel@tonic-gate 						fprintf(fp, "\t{\n");
29150Sstevel@tonic-gate 						fprintf(fp, "\t\tfree(%s->subids);\n",current->label);
29160Sstevel@tonic-gate 						fprintf(fp,"\t\t%s->len = 0;\n",current->label);
29170Sstevel@tonic-gate 						fprintf(fp,"\t}\n");
29180Sstevel@tonic-gate 						PRINT_CLOSE_BRACKET
29190Sstevel@tonic-gate 						break;
29200Sstevel@tonic-gate 
29210Sstevel@tonic-gate 					default:
29220Sstevel@tonic-gate 						error_exit("output_function(): Unknown type (%d) for %s",
29230Sstevel@tonic-gate 							current->type,
29240Sstevel@tonic-gate 							current->label);
29250Sstevel@tonic-gate 				}
29260Sstevel@tonic-gate 			}
29270Sstevel@tonic-gate 			break;
29280Sstevel@tonic-gate 	}
29290Sstevel@tonic-gate 
29300Sstevel@tonic-gate 	for(tp = current->child_list; tp; tp = tp->next_peer)
29310Sstevel@tonic-gate 	{
29320Sstevel@tonic-gate 		output_single_obj_function(fp, tp);
29330Sstevel@tonic-gate 	}
29340Sstevel@tonic-gate 
29350Sstevel@tonic-gate }
29360Sstevel@tonic-gate 
29370Sstevel@tonic-gate 
29380Sstevel@tonic-gate /*************************************************************************/
output_file(char * filename)29390Sstevel@tonic-gate static FILE* output_file(char* filename)
29400Sstevel@tonic-gate {
29410Sstevel@tonic-gate 	char pathname[MAXPATHLEN];
29420Sstevel@tonic-gate 	char backup_pathname[MAXPATHLEN];
29430Sstevel@tonic-gate 	FILE *fp;
29440Sstevel@tonic-gate 	struct stat buf;
29450Sstevel@tonic-gate 
29460Sstevel@tonic-gate 
29470Sstevel@tonic-gate 	sprintf(pathname, "%s_%s.c", base_name,filename);
29480Sstevel@tonic-gate 	sprintf(backup_pathname, "%s.%s.c.old", base_name,filename);
29490Sstevel@tonic-gate 	trace("Creating %s ...\n", pathname);
29500Sstevel@tonic-gate 	if(stat(pathname, &buf) == 0)
29510Sstevel@tonic-gate 	{
29520Sstevel@tonic-gate 		if(rename(pathname,backup_pathname)==-1){
29530Sstevel@tonic-gate 		  error_exit("The file %s already exists and can't be renamed!", pathname);
29540Sstevel@tonic-gate 		}
29550Sstevel@tonic-gate 	}
29560Sstevel@tonic-gate 
29570Sstevel@tonic-gate 	fp = fopen(pathname, "w");
29580Sstevel@tonic-gate 	if(fp == NULL)
29590Sstevel@tonic-gate 	{
29600Sstevel@tonic-gate 		error_exit("Can't open %s %s", pathname, errno_string());
29610Sstevel@tonic-gate 	}
29620Sstevel@tonic-gate 
29630Sstevel@tonic-gate 	fprintf(fp, "#include <sys/types.h>\n");
29640Sstevel@tonic-gate 	fprintf(fp, "#include <netinet/in.h>\n");
29650Sstevel@tonic-gate 	fprintf(fp, "\n");
29660Sstevel@tonic-gate 	fprintf(fp, "#include \"impl.h\"\n");
29670Sstevel@tonic-gate 	fprintf(fp, "#include \"asn1.h\"\n");
29680Sstevel@tonic-gate 	fprintf(fp, "#include \"error.h\"\n");
29690Sstevel@tonic-gate 	fprintf(fp, "#include \"snmp.h\"\n");
29700Sstevel@tonic-gate 	fprintf(fp, "#include \"trap.h\"\n");
29710Sstevel@tonic-gate 	fprintf(fp, "#include \"pdu.h\"\n");
29720Sstevel@tonic-gate 	fprintf(fp, "#include \"node.h\"\n");
29730Sstevel@tonic-gate 	fprintf(fp, "\n");
29740Sstevel@tonic-gate 	fprintf(fp, "#include \"%s_stub.h\"\n", base_name);
29750Sstevel@tonic-gate 	fprintf(fp, "\n");
29760Sstevel@tonic-gate 	fprintf(fp, "\n");
29770Sstevel@tonic-gate 
29780Sstevel@tonic-gate 	return(fp);
29790Sstevel@tonic-gate }
29800Sstevel@tonic-gate 
output_appl_c(struct tree * current)29810Sstevel@tonic-gate static void output_appl_c(struct tree *current)
29820Sstevel@tonic-gate {
29830Sstevel@tonic-gate 	FILE *fp;
29840Sstevel@tonic-gate 
29850Sstevel@tonic-gate 	fp = output_file("appl");
29860Sstevel@tonic-gate 	fprintf(fp, "/***** GLOBAL VARIABLES *****/\n");
29870Sstevel@tonic-gate 	fprintf(fp, "\n");
29880Sstevel@tonic-gate 	fprintf(fp, "char default_config_file[] = \"/etc/snmp/conf/%s.reg\";\n", base_name);
29890Sstevel@tonic-gate 	fprintf(fp, "char default_sec_config_file[] = \"/etc/snmp/conf/%s.acl\";\n", base_name);
29900Sstevel@tonic-gate 	fprintf(fp, "char default_error_file[] = \"/var/snmp/%sd.log\";\n", base_name);
29910Sstevel@tonic-gate 	fprintf(fp, "\n");
29920Sstevel@tonic-gate 	fprintf(fp, "\n");
29930Sstevel@tonic-gate 
29940Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
29950Sstevel@tonic-gate 	fprintf(fp, "\n");
29960Sstevel@tonic-gate 	fprintf(fp, "void agent_init()\n");
29970Sstevel@tonic-gate 	fprintf(fp, "{\n");
29980Sstevel@tonic-gate 	fprintf(fp, "}\n");
29990Sstevel@tonic-gate 	fprintf(fp, "\n");
30000Sstevel@tonic-gate 	fprintf(fp, "\n");
30010Sstevel@tonic-gate 
30020Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
30030Sstevel@tonic-gate 	fprintf(fp, "\n");
30040Sstevel@tonic-gate 	fprintf(fp, "void agent_end()\n");
30050Sstevel@tonic-gate 	fprintf(fp, "{\n");
30060Sstevel@tonic-gate 	fprintf(fp, "}\n");
30070Sstevel@tonic-gate 	fprintf(fp, "\n");
30080Sstevel@tonic-gate 	fprintf(fp, "\n");
30090Sstevel@tonic-gate 
30100Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
30110Sstevel@tonic-gate 	fprintf(fp, "\n");
30120Sstevel@tonic-gate 	fprintf(fp, "void agent_loop()\n");
30130Sstevel@tonic-gate 	fprintf(fp, "{\n");
30140Sstevel@tonic-gate 	fprintf(fp,"\tint condition=FALSE;\n\n");
30150Sstevel@tonic-gate  	fprintf(fp,"\tif(condition==TRUE){\n");
30160Sstevel@tonic-gate 	output_trap_function_call(fp);
30170Sstevel@tonic-gate 	fprintf(fp, "\t}\n");
30180Sstevel@tonic-gate 	fprintf(fp, "}\n");
30190Sstevel@tonic-gate 	fprintf(fp, "\n");
30200Sstevel@tonic-gate 	fprintf(fp, "\n");
30210Sstevel@tonic-gate 
30220Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
30230Sstevel@tonic-gate 	fprintf(fp, "\n");
30240Sstevel@tonic-gate 	fprintf(fp, "void agent_select_info(fd_set *fdset, int *numfds)\n");
30250Sstevel@tonic-gate 	fprintf(fp, "{\n");
30260Sstevel@tonic-gate 	fprintf(fp, "}\n");
30270Sstevel@tonic-gate 	fprintf(fp, "\n");
30280Sstevel@tonic-gate 	fprintf(fp, "\n");
30290Sstevel@tonic-gate 
30300Sstevel@tonic-gate 	fprintf(fp, "/***********************************************************/\n");
30310Sstevel@tonic-gate 	fprintf(fp, "\n");
30320Sstevel@tonic-gate 	fprintf(fp, "void agent_select_callback(fd_set *fdset)\n");
30330Sstevel@tonic-gate 	fprintf(fp, "{\n");
30340Sstevel@tonic-gate 	fprintf(fp, "}\n");
30350Sstevel@tonic-gate 	fprintf(fp, "\n");
30360Sstevel@tonic-gate 	fprintf(fp, "\n");
30370Sstevel@tonic-gate 
30380Sstevel@tonic-gate 	fprintf(fp,"void main(int argc, char** argv)\n");
30390Sstevel@tonic-gate 	fprintf(fp,"{\n");
30400Sstevel@tonic-gate 	fprintf(fp,"\tSSAMain(argc,argv);\n");
30410Sstevel@tonic-gate 	fprintf(fp,"}\n\n");
30420Sstevel@tonic-gate 
30430Sstevel@tonic-gate 	fprintf(fp, "\n");
30440Sstevel@tonic-gate 	fclose(fp);
30450Sstevel@tonic-gate }
30460Sstevel@tonic-gate 
output_trap_c(struct tree * current)30470Sstevel@tonic-gate static void output_trap_c(struct tree *current)
30480Sstevel@tonic-gate {
30490Sstevel@tonic-gate 	FILE *fp;
30500Sstevel@tonic-gate 
30510Sstevel@tonic-gate 	fp = output_file("trap");
30520Sstevel@tonic-gate 	output_trap_structure(fp);
30530Sstevel@tonic-gate 	fclose(fp);
30540Sstevel@tonic-gate }
30550Sstevel@tonic-gate 
output_stub_c(struct tree * current)30560Sstevel@tonic-gate static void output_stub_c(struct tree *current)
30570Sstevel@tonic-gate {
30580Sstevel@tonic-gate 	FILE *fp;
30590Sstevel@tonic-gate 
30600Sstevel@tonic-gate 	fp = output_file("stub");
30610Sstevel@tonic-gate 	output_single_obj_function(fp, current);
30620Sstevel@tonic-gate 	output_entry_function(fp, current);
30630Sstevel@tonic-gate 
30640Sstevel@tonic-gate 	fclose(fp);
30650Sstevel@tonic-gate }
30660Sstevel@tonic-gate 
30670Sstevel@tonic-gate 
30680Sstevel@tonic-gate 
3069