static Imports *getImports(SmiModule *smiModule, int *n)
{
    SmiImport *smiImport;
    Imports   *imports;
    int       i;
    size_t    size;
    
    for (smiImport = smiGetFirstImport(smiModule), *n = 0;
	 smiImport; smiImport = smiGetNextImport(smiImport)) {
	(*n)++;
    }

    size = (*n + 1) * sizeof(Imports);
    imports = xmalloc(size);
    memset(imports, 0, size);

    for (smiImport = smiGetFirstImport(smiModule), *n = 0;
	 smiImport; smiImport = smiGetNextImport(smiImport)) {
	
	if (!smiImport->module) continue;
	
	for (i = 0; i < *n; i++) {
	    if (strcmp(smiImport->module, imports[i].module) == 0) {
		break;
	    }
	}
	
	if (i == *n) {
	    imports[i].module = xstrdup(smiImport->module);
	    if (imports[i].module) {
		imports[i].count = 0;
		(*n)++;
	    }
	}
	imports[i].count++;
    }

    return imports;
}
Пример #2
0
static void fprintImports(FILE *f, SmiModule *smiModule)
{
    SmiImport *smiImport;
    int        i;

    for (i = 0, smiImport = smiGetFirstImport(smiModule);
	 smiImport;
	 i++, smiImport = smiGetNextImport(smiImport)) {
	if (i == 0) {
	    fprintSegment(f, INDENT, "<imports>\n", 0);
	}
	fprintImport(f, 2 * INDENT, smiImport);
    }

    if (i) {
	fprintSegment(f, INDENT, "</imports>\n\n", 0);
    }
}
Пример #3
0
static void createImportList(SmiModule *smiModule)
{
    SmiNode     *smiNode;
    SmiType     *smiType;
    SmiModule   *smiTypeModule;
    SmiNodekind kind = SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN;
    SmiImport   *smiImport;
    
    for (smiNode = smiGetFirstNode(smiModule, kind);
	 smiNode;
	 smiNode = smiGetNextNode(smiNode, kind)) {

	smiType = smiGetNodeType(smiNode);
	if (smiType && (smiType->decl == SMI_DECL_IMPLICIT_TYPE)) {
	    smiType = smiGetParentType(smiType);
	}
	if (smiType) {
	    smiTypeModule = smiGetTypeModule(smiType);
	    if (smiTypeModule &&
		strcmp(smiTypeModule->name, smiModule->name)) {
		if (strlen(smiTypeModule->name)) {
		    addImport(smiTypeModule->name, smiType->name);
		}
	    }
	    if (smiType->basetype == SMI_BASETYPE_INTEGER32) {
		addImport("SNMPv2-SMI", "Integer32");
	    }
	}
    }

    for (smiImport = smiGetFirstImport(smiModule); smiImport;
	 smiImport = smiGetNextImport(smiImport)) {
	if (islower((int) smiImport->name[0]) ||
	    (smiImport->module && !strcmp(smiImport->module, "SNMPv2-SMI")) ||
	    (smiImport->module && !strcmp(smiImport->module, "SNMPv2-TC"))) {
	    addImport(smiImport->module, smiImport->name);
	}
    }
}