FreeBSD/contrib/bsnmp/gensnmptree/gensnmptree.c
/*
 * Generate the header file with the function declarations.
 */
Generate the header file with the function declarations.
Generate the header file with the function declarations .
static void
gen_header(FILE *fp, struct node *np, u_int oidlen, const char *func)
{
	char f[MAXSTR + 4];
	struct node *sub;
	struct func *ptr;
	oidlen++;
	if (np->type == NODE_TREE) {
		TAILQ_FOREACH(sub, &np->u.tree.subs, link)
			gen_header(fp, sub, oidlen, NULL);
		return;
	}
	if (np->type == NODE_ENTRY) {
		TAILQ_FOREACH(sub, &np->u.entry.subs, link)
			gen_header(fp, sub, oidlen, np->u.entry.func);
		return;
	}
 	if((np->flags & (FL_GET|FL_SET)) == 0)
		return;
	if (np->type == NODE_COLUMN) {
		if (func == NULL)
			errx(1, "column without function (%s) - probably "
			    "outside of a table", np->name);
		sprintf(f, "%s", func);
	} else
		sprintf(f, "%s", np->u.leaf.func);
	LIST_FOREACH(ptr, &funcs, link)
		if (strcmp(ptr->name, f) == 0)
			break;
	if (ptr == NULL) {
		ptr = xalloc(sizeof(*ptr));
		ptr->name = savestr(f);
		LIST_INSERT_HEAD(&funcs, ptr, link);
		fprintf(fp, "int	%s(struct snmp_context *, "
		    "struct snmp_value *, u_int, u_int, "
		    "enum snmp_op);\n", f);
	}
	fprintf(fp, "# define LEAF_%s %u\n", np->name, np->id);
}
static void gen_header ( FILE * fp , struct node * np , u_int oidlen , const char * func ) { char f [ MAXSTR + 4 ] ; struct node * sub ; struct func * ptr ; oidlen ++ ; if ( np -> type == NODE_TREE ) { TAILQ_FOREACH ( sub , & np -> u . tree . subs , link ) gen_header ( fp , sub , oidlen , NULL ) ; return ; } if ( np -> type == NODE_ENTRY ) { TAILQ_FOREACH ( sub , & np -> u . entry . subs , link ) gen_header ( fp , sub , oidlen , np -> u . entry . func ) ; return ; } if ( ( np -> flags & ( FL_GET | FL_SET ) ) == 0 ) return ; if ( np -> type == NODE_COLUMN ) { if ( func == NULL ) errx ( 1 , " " " " , np -> name ) ; sprintf ( f , " " , func ) ; } else sprintf ( f , " " , np -> u . leaf . func ) ; LIST_FOREACH ( ptr , & funcs , link ) if ( strcmp ( ptr -> name , f ) == 0 ) break ; if ( ptr == NULL ) { ptr = xalloc ( sizeof ( * ptr ) ) ; ptr -> name = savestr ( f ) ; LIST_INSERT_HEAD ( & funcs , ptr , link ) ; fprintf ( fp , " " " " " \n " , f ) ; } fprintf ( fp , " \n " , np -> name , np -> id ) ; }
Generate the header file with the function declarations.
Generate the header file with the function declarations .