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