FreeBSD/contrib/bsnmp/gensnmptree/gensnmptree.c
/*
 * Generate the C-code table part for one node.
 */
Generate the C-code table part for one node.
Generate the C - code table part for one node .
static void
gen_node(FILE *fp, struct node *np, struct asn_oid *oid, u_int idx,
    const char *func)
{
	u_int n;
	struct node *sub;
	u_int syntax;
	if (oid->len == ASN_MAXOIDLEN)
		report_node(np, "OID too long");
	oid->subs[oid->len++] = np->id;
	if (np->type == NODE_TREE) {
		TAILQ_FOREACH(sub, &np->u.tree.subs, link)
			gen_node(fp, sub, oid, 0, NULL);
		oid->len--;
		return;
	}
	if (np->type == NODE_ENTRY) {
		TAILQ_FOREACH(sub, &np->u.entry.subs, link)
			gen_node(fp, sub, oid, np->u.entry.index,
			    np->u.entry.func);
		oid->len--;
		return;
	}
	if ((np->flags & (FL_GET|FL_SET)) == 0) {
		oid->len--;
		return;
	}
	fprintf(fp, "    {{ %u, {", oid->len);
	for (n = 0; n < oid->len; n++)
		fprintf(fp, " %u,", oid->subs[n]);
	fprintf(fp, " }}, \"%s\", ", np->name);
	if (np->type == NODE_COLUMN) {
		syntax = np->u.column.syntax;
		fprintf(fp, "SNMP_NODE_COLUMN, ");
	} else {
		syntax = np->u.leaf.syntax;
		fprintf(fp, "SNMP_NODE_LEAF, ");
	}
	switch (syntax) {
	  case SNMP_SYNTAX_NULL:
		fprintf(fp, "SNMP_SYNTAX_NULL, ");
		break;
	  case SNMP_SYNTAX_INTEGER:
		fprintf(fp, "SNMP_SYNTAX_INTEGER, ");
		break;
	  case SNMP_SYNTAX_OCTETSTRING:
		fprintf(fp, "SNMP_SYNTAX_OCTETSTRING, ");
		break;
	  case SNMP_SYNTAX_IPADDRESS:
		fprintf(fp, "SNMP_SYNTAX_IPADDRESS, ");
		break;
	  case SNMP_SYNTAX_OID:
		fprintf(fp, "SNMP_SYNTAX_OID, ");
		break;
	  case SNMP_SYNTAX_TIMETICKS:
		fprintf(fp, "SNMP_SYNTAX_TIMETICKS, ");
		break;
	  case SNMP_SYNTAX_COUNTER:
		fprintf(fp, "SNMP_SYNTAX_COUNTER, ");
		break;
	  case SNMP_SYNTAX_GAUGE:
		fprintf(fp, "SNMP_SYNTAX_GAUGE, ");
		break;
	  case SNMP_SYNTAX_COUNTER64:
		fprintf(fp, "SNMP_SYNTAX_COUNTER64, ");
		break;
	  case SNMP_SYNTAX_NOSUCHOBJECT:
	  case SNMP_SYNTAX_NOSUCHINSTANCE:
	  case SNMP_SYNTAX_ENDOFMIBVIEW:
		abort();
	}
	if (np->type == NODE_COLUMN)
		fprintf(fp, "%s, ", func);
	else
		fprintf(fp, "%s, ", np->u.leaf.func);
	fprintf(fp, "0");
	if (np->flags & FL_SET)
		fprintf(fp, "|SNMP_NODE_CANSET");
	fprintf(fp, ", %#x, NULL, NULL },\n", idx);
	oid->len--;
	return;
}
static void gen_node ( FILE * fp , struct node * np , struct asn_oid * oid , u_int idx , const char * func ) { u_int n ; struct node * sub ; u_int syntax ; if ( oid -> len == ASN_MAXOIDLEN ) report_node ( np , " " ) ; oid -> subs [ oid -> len ++ ] = np -> id ; if ( np -> type == NODE_TREE ) { TAILQ_FOREACH ( sub , & np -> u . tree . subs , link ) gen_node ( fp , sub , oid , 0 , NULL ) ; oid -> len -- ; return ; } if ( np -> type == NODE_ENTRY ) { TAILQ_FOREACH ( sub , & np -> u . entry . subs , link ) gen_node ( fp , sub , oid , np -> u . entry . index , np -> u . entry . func ) ; oid -> len -- ; return ; } if ( ( np -> flags & ( FL_GET | FL_SET ) ) == 0 ) { oid -> len -- ; return ; } fprintf ( fp , " " , oid -> len ) ; for ( n = 0 ; n < oid -> len ; n ++ ) fprintf ( fp , " " , oid -> subs [ n ] ) ; fprintf ( fp , " \" \" " , np -> name ) ; if ( np -> type == NODE_COLUMN ) { syntax = np -> u . column . syntax ; fprintf ( fp , " " ) ; } else { syntax = np -> u . leaf . syntax ; fprintf ( fp , " " ) ; } switch ( syntax ) { case SNMP_SYNTAX_NULL : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_INTEGER : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_OCTETSTRING : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_IPADDRESS : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_OID : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_TIMETICKS : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_COUNTER : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_GAUGE : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_COUNTER64 : fprintf ( fp , " " ) ; break ; case SNMP_SYNTAX_NOSUCHOBJECT : case SNMP_SYNTAX_NOSUCHINSTANCE : case SNMP_SYNTAX_ENDOFMIBVIEW : abort ( ) ; } if ( np -> type == NODE_COLUMN ) fprintf ( fp , " " , func ) ; else fprintf ( fp , " " , np -> u . leaf . func ) ; fprintf ( fp , " " ) ; if ( np -> flags & FL_SET ) fprintf ( fp , " " ) ; fprintf ( fp , " \n " , idx ) ; oid -> len -- ; return ; }
Generate the C-code table part for one node.
Generate the C - code table part for one node .
/* leaf or column */