예제 #1
0
파일: dump-xml.c 프로젝트: pan0007/libsmi
static void fprintModule(FILE *f, SmiModule *smiModule)
{
    SmiRevision *smiRevision;
    SmiNode     *smiNode;
    int         i;
    char	*lang;

    lang = getStringLanguage(smiModule->language);

    fprintSegment(f, INDENT, "", 0);
    if (lang) {
	fprint(f, "<module name=\"%s\" language=\"%s\">\n",
	       smiModule->name, lang);
    } else {
	fprint(f, "<module name=\"%s\">\n", smiModule->name);
    }

    if (smiModule->organization) {
	fprintSegment(f, 2 * INDENT, "<organization>", INDENTVALUE);
	fprint(f, "\n");
	fprintMultilineString(f, 2 * INDENT, smiModule->organization);
	fprint(f, "\n");
	fprintSegment(f, 2 * INDENT, "</organization>\n", 0);
    }

    if (smiModule->contactinfo) {
	fprintSegment(f, 2 * INDENT, "<contact>", INDENTVALUE);
	fprint(f, "\n");
	fprintMultilineString(f, 2 * INDENT, smiModule->contactinfo);
	fprint(f, "\n");
	fprintSegment(f, 2 * INDENT, "</contact>\n", 0);
    }
    fprintDescription(f, 2 * INDENT, smiModule->description);
    fprintReference(f, 2 * INDENT, smiModule->reference);

    for(i = 0, smiRevision = smiGetFirstRevision(smiModule);
	smiRevision; smiRevision = smiGetNextRevision(smiRevision)) {
	fprintSegment(f, 2 * INDENT, "", 0);
	fprint(f, "<revision date=\"%s\">\n",
	       getTimeString(smiRevision->date));
	fprintDescription(f, 3 * INDENT, smiRevision->description);
        fprintSegment(f, 2 * INDENT, "</revision>\n", 0);
	i++;
    }

    smiNode = smiGetModuleIdentityNode(smiModule);
    if (smiNode) {
	fprintSegment(f, 2 * INDENT, "", 0);
	fprint(f, "<identity node=\"%s\"/>\n", smiNode->name);
    }

    fprintSegment(f, INDENT, "</module>\n\n", 0);
}
예제 #2
0
static void dumpSming(int modc, SmiModule **modv, int flags, char *output)
{
    SmiModule   *smiModule;
    SmiNode	*smiNode;
    int		i;
    FILE	*f = stdout;

    silent = (flags & SMIDUMP_FLAG_SILENT);

    if (output) {
	f = fopen(output, "w");
	if (!f) {
	    fprintf(stderr, "smidump: cannot open %s for writing: ", output);
	    perror(NULL);
	    exit(1);
	}
    }

    for (i = 0; i < modc; i++) {

	smiModule = modv[i];
    
	fprint(f, "//\n");
	fprint(f, "// This module has been generated by smidump "
	       SMI_VERSION_STRING ". Do not edit.\n");
	fprint(f, "//\n");
	fprint(f, "module %s ", smiModule->name);
	fprint(f, "{\n");
	fprint(f, "\n");
	
	fprintImports(f, smiModule);
	
	if (! silent) {
	    fprint(f, "//\n// MODULE META INFORMATION\n//\n\n");
	}
	fprintSegment(f, INDENT, "organization", INDENTVALUE);
	fprint(f, "\n");
	fprintMultilineString(f, INDENT, smiModule->organization);
	fprint(f, ";\n\n");
	fprintSegment(f, INDENT, "contact", INDENTVALUE);
	fprint(f, "\n");
	fprintMultilineString(f, INDENT, smiModule->contactinfo);
	fprint(f, ";\n\n");
	fprintSegment(f, INDENT, "description", INDENTVALUE);
	fprint(f, "\n");
	fprintMultilineString(f, INDENT, smiModule->description);
	fprint(f, ";\n\n");
	if (smiModule->reference) {
	    fprintSegment(f, INDENT, "reference", INDENTVALUE);
	    fprint(f, "\n");
	    fprintMultilineString(f, INDENT, smiModule->reference);
	    fprint(f, ";\n\n");
	}
	
	fprintRevisions(f, smiModule);
	
	smiNode = smiGetModuleIdentityNode(smiModule);
	if (smiNode) {
	    fprintSegment(f, INDENT, "identity", INDENTVALUE);
	    fprint(f, "%s;\n\n", smiNode->name);
	}
	
	fprintTypedefs(f, smiModule);
	fprintObjects(f, smiModule);
	fprintNotifications(f, smiModule);
	fprintGroups(f, smiModule);
	fprintCompliances(f, smiModule);
	
	fprint(f, "}; // end of module %s.\n", smiModule->name);
    }
    
    if (fflush(f) || ferror(f)) {
	perror("smidump: write error");
	exit(1);
    }

    if (output) {
	fclose(f);
    }
}
예제 #3
0
int MibViewLoader::PruneSubTree(SmiNode *smiNode)
{
    SmiNode   *childNode;
    
    const int confmask = (SMI_NODEKIND_GROUP | SMI_NODEKIND_COMPLIANCE);
    const int leafmask = (SMI_NODEKIND_GROUP | SMI_NODEKIND_COMPLIANCE
                          | SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR
                          | SMI_NODEKIND_ROW | SMI_NODEKIND_NOTIFICATION);
    
    if (! smiNode) {
        return 1;
    }
    
    /*
     * First, prune all nodes which the user has told us to ignore.
     * In the case of ignoreleafs, we have to special case nodes with
     * an unknown status (which actually represent OBJECT-IDENTITY
     * definitions). More special case code is needed to exclude
     * module identity nodes.
     */
    
    if (ignoreconformance && (smiNode->nodekind & confmask)) {
        return 1;
    }
    
    if (ignoreleafs) {
        if (smiNode->nodekind & leafmask) {
            return 1;
        }
        if (smiNode->nodekind == SMI_NODEKIND_NODE
            && smiNode->status != SMI_STATUS_UNKNOWN) {
            SmiModule *smiModule = smiGetNodeModule(smiNode);
            if (smiModule && smiNode != smiGetModuleIdentityNode(smiModule)) {
                return 1;
            }
        }
    }
    
    /*
      * Next, generally do not prune nodes that belong to the set of
      * modules we are looking at.
      */
    
    if (IsPartOfLoadedModules(smiNode)) {
        if (!ignoreconformance || !smiGetFirstChildNode(smiNode)) {
            return 0;
        }
    }
    
    /*
     * Finally, prune all nodes where all child nodes are pruned.
     */
    
    for (childNode = smiGetFirstChildNode(smiNode);
    childNode;
    childNode = smiGetNextChildNode(childNode)) {
        
        /*
         * In the case of ignoreleafs, we have to peek at the child
         * nodes. Otherwise, we would prune too much. we still want to
         * see the path to the leafs we have pruned away. This also
         * interact with the semantics of ignoreconformance since we
         * still want in combination with ignoreleafs to see the path
         * to the pruned conformance leafs.
         */
        
        if (ignoreleafs && (childNode->nodekind & leafmask)) {
            if (IsPartOfLoadedModules(childNode)) {
                if (ignoreconformance && (childNode->nodekind & confmask)) {
                    return 1;
                }
                return 0;
            }
        }
        
        if (! PruneSubTree(childNode)) {
            return 0;
        }
    }
    
    return 1;
}