4 * Operations to dump SMIng module information.
6 * Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig.
8 * See the file "COPYING" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * @(#) $Id: dump-sming.c 8090 2008-04-18 12:56:29Z strauss $
28 #define INDENT 2 /* indent factor */
29 #define INDENTVALUE 20 /* column to start values, except multiline */
30 #define INDENTTEXTS 4 /* column to start multiline texts */
31 #define INDENTMAX 64 /* max column to fill, break lines otherwise */
35 static char *excludeType[] = {
41 static char *convertType[] = {
42 "INTEGER", "Integer32",
43 "OCTET STRING", "OctetString",
44 "OBJECT IDENTIFIER", "Pointer",
47 "Counter", "Counter32",
48 "NetworkAddress", "IpAddress", /* ??? */
52 static char *convertImport[] = {
53 "SNMPv2-SMI", "MODULE-IDENTITY", NULL, NULL,
54 "SNMPv2-SMI", "OBJECT-IDENTITY", NULL, NULL,
55 "SNMPv2-SMI", "OBJECT-TYPE", NULL, NULL,
56 "SNMPv2-SMI", "NOTIFICATION-TYPE", NULL, NULL,
57 "SNMPv2-SMI", "ObjectName", NULL, NULL,
58 "SNMPv2-SMI", "NotificationName", NULL, NULL,
59 "SNMPv2-SMI", "ObjectSyntax", NULL, NULL,
60 "SNMPv2-SMI", "SimpleSyntax", NULL, NULL,
61 "SNMPv2-SMI", "Integer32", NULL, NULL,
62 "SNMPv2-SMI", "Unsigned32", NULL, NULL,
63 "SNMPv2-SMI", "ApplicationSyntax", NULL, NULL,
64 "SNMPv2-SMI", "IpAddress", "IRTF-NMRG-SMING", "IpAddress",
65 "SNMPv2-SMI", "Counter32", "IRTF-NMRG-SMING", "Counter32",
66 "SNMPv2-SMI", "TimeTicks", "IRTF-NMRG-SMING", "TimeTicks",
67 "SNMPv2-SMI", "Opaque", "IRTF-NMRG-SMING", "Opaque",
68 "SNMPv2-SMI", "Counter64", "IRTF-NMRG-SMING", "Counter64",
69 "SNMPv2-SMI", "Gauge32", "IRTF-NMRG-SMING", "Gauge32",
70 "SNMPv2-SMI", "mib-2", "IRTF-NMRG-SMING-SNMP", "mib-2",
72 "SNMPv2-TC", "TimeStamp", "IRTF-NMRG-SMING", "TimeStamp",
73 "SNMPv2-TC", "TimeInterval", "IRTF-NMRG-SMING", "TimeInterval",
74 "SNMPv2-TC", "DateAndTime", "IRTF-NMRG-SMING", "DateAndTime",
75 "SNMPv2-TC", "TruthValue", "IRTF-NMRG-SMING", "TruthValue",
76 "SNMPv2-TC", "PhysAddress", "IRTF-NMRG-SMING", "PhysAddress",
77 "SNMPv2-TC", "MacAddress", "IRTF-NMRG-SMING", "MacAddress",
78 "SNMPv2-TC", "DisplayString", "IRTF-NMRG-SMING", "DisplayString255",
79 "SNMPv2-TC", "TestAndIncr", "IRTF-NMRG-SMING-SNMP", "TestAndIncr",
80 "SNMPv2-TC", "AutonomousType", "IRTF-NMRG-SMING-SNMP", "AutonomousType",
81 "SNMPv2-TC", "VariablePointer", "IRTF-NMRG-SMING-SNMP", "VariablePointer",
82 "SNMPv2-TC", "RowPointer", "IRTF-NMRG-SMING-SNMP", "RowPointer",
83 "SNMPv2-TC", "RowStatus", "IRTF-NMRG-SMING-SNMP", "RowStatus",
84 "SNMPv2-TC", "StorageType", "IRTF-NMRG-SMING-SNMP", "StorageType",
85 "SNMPv2-TC", "TDomain", "IRTF-NMRG-SMING-SNMP", "TDomain",
86 "SNMPv2-TC", "TAddress", "IRTF-NMRG-SMING-SNMP", "TAddress",
87 "SNMPv2-SMI", NULL, "IRTF-NMRG-SMING", NULL,
88 "SNMPv2-TC", "TEXTUAL-CONVENTION", NULL, NULL,
89 "SNMPv2-TC", NULL, "IRTF-NMRG-SMING-TYPES", NULL,
90 "SNMPv2-CONF", "OBJECT-GROUP", NULL, NULL,
91 "SNMPv2-CONF", "NOTIFICATION-GROUP", NULL, NULL,
92 "SNMPv2-CONF", "MODULE-COMPLIANCE", NULL, NULL,
93 "SNMPv2-CONF", "AGENT-CAPABILITIES", NULL, NULL,
95 "RFC1155-SMI", "OBJECT-TYPE", NULL, NULL,
96 "RFC1155-SMI", "ObjectName", NULL, NULL,
97 "RFC1155-SMI", "ObjectSyntax", NULL, NULL,
98 "RFC1155-SMI", "SimpleSyntax", NULL, NULL,
99 "RFC1155-SMI", "ApplicationSyntax", NULL, NULL,
100 "RFC1155-SMI", "Gauge", "IRTF-NMRG-SMING-TYPES", "Gauge32",
101 "RFC1155-SMI", "Counter", "IRTF-NMRG-SMING-TYPES", "Counter32",
102 "RFC1155-SMI", "TimeTicks", "IRTF-NMRG-SMING-TYPES", "TimeTicks",
103 "RFC1155-SMI", "IpAddress", "IRTF-NMRG-SMING-TYPES", "IpAddress",
104 "RFC1155-SMI", "NetworkAddress", NULL, NULL, /* ??? */
105 "RFC1155-SMI", "Opaque", "IRTF-NMRG-SMING", "Opaque",
106 "RFC1155-SMI", NULL, "IRTF-NMRG-SMING", NULL,
107 "RFC1158-MIB", "DisplayString", "IRTF-NMRG-SMING", "DisplayString255",
108 "RFC-1212", "OBJECT-TYPE", NULL, NULL,
109 "RFC1213-MIB", "mib-2", "IRTF-NMRG-SMING-SNMP", "mib-2",
110 "RFC1213-MIB", "system", "SNMPv2-MIB", "system",
111 "RFC1213-MIB", "interfaces", "IF-MIB", "interfaces",
112 /* "RFC1213-MIB", "at", "RFC1213-MIB", "at", */
113 "RFC1213-MIB", "ip", "IP-MIB", "ip",
114 "RFC1213-MIB", "icmp", "IP-MIB", "icmp",
115 "RFC1213-MIB", "tcp", "TCP-MIB", "tcp",
116 "RFC1213-MIB", "udp", "UDP-MIB", "udp",
117 /* "RFC1213-MIB", "egp", "RFC1213-MIB", "egp", */
118 "RFC1213-MIB", "transmission", "SNMPv2-SMI", "transmission",
119 "RFC1213-MIB", "snmp", "SNMPv2-MIB", "snmp",
120 "RFC1213-MIB", "sysDescr", "SNMPv2-MIB", "sysDescr",
121 "RFC1213-MIB", "sysObjectID", "SNMPv2-MIB", "sysObjectID",
122 "RFC1213-MIB", "sysUpTime", "SNMPv2-MIB", "sysUpTime",
123 "RFC1213-MIB", "ifIndex", "IF-MIB", "ifIndex",
124 /* TODO ...many more objects from RFC1213-MIB.. */
125 "RFC1213-MIB", "DisplayString", "IRTF-NMRG-SMING", "DisplayString255",
126 "RFC1213-MIB", "PhysAddress", "IRTF-NMRG-SMING", "PhysAddress",
127 "RFC-1215", "TRAP-TYPE", NULL, NULL,
132 /* TODO: how to convert more SMIv1 information? */
134 NULL, NULL, NULL, NULL };
136 static int current_column = 0;
137 static int silent = 0;
141 * Structure used to build a list of imported types.
145 typedef struct Import {
148 struct Import *nextPtr;
151 static Import *importList = NULL;
155 static char *getStringStatus(SmiStatus status)
158 (status == SMI_STATUS_CURRENT) ? "current" :
159 (status == SMI_STATUS_DEPRECATED) ? "deprecated" :
160 (status == SMI_STATUS_OBSOLETE) ? "obsolete" :
161 (status == SMI_STATUS_MANDATORY) ? "current" :
162 (status == SMI_STATUS_OPTIONAL) ? "current" :
168 static char *getAccessString(SmiAccess access)
171 (access == SMI_ACCESS_NOT_ACCESSIBLE) ? "noaccess" :
172 (access == SMI_ACCESS_NOTIFY) ? "notifyonly" :
173 (access == SMI_ACCESS_READ_ONLY) ? "readonly" :
174 (access == SMI_ACCESS_READ_WRITE) ? "readwrite" :
180 static char *getStringBasetype(SmiBasetype basetype)
183 (basetype == SMI_BASETYPE_UNKNOWN) ? "<unknown>" :
184 (basetype == SMI_BASETYPE_OCTETSTRING) ? "OctetString" :
185 (basetype == SMI_BASETYPE_OBJECTIDENTIFIER) ? "ObjectIdentifier" :
186 (basetype == SMI_BASETYPE_UNSIGNED32) ? "Unsigned32" :
187 (basetype == SMI_BASETYPE_INTEGER32) ? "Integer32" :
188 (basetype == SMI_BASETYPE_UNSIGNED64) ? "Unsigned64" :
189 (basetype == SMI_BASETYPE_INTEGER64) ? "Integer64" :
190 (basetype == SMI_BASETYPE_FLOAT32) ? "Float32" :
191 (basetype == SMI_BASETYPE_FLOAT64) ? "Float64" :
192 (basetype == SMI_BASETYPE_FLOAT128) ? "Float128" :
193 (basetype == SMI_BASETYPE_ENUM) ? "Enumeration" :
194 (basetype == SMI_BASETYPE_BITS) ? "Bits" :
200 static char *getStringTime(time_t t)
206 sprintf(s, "%04d-%02d-%02d %02d:%02d",
207 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
208 tm->tm_hour, tm->tm_min);
214 static char *getTypeString(SmiBasetype basetype, SmiType *smiType)
217 char *typeModule, *typeName;
219 typeName = smiType ? smiType->name : NULL;
220 typeModule = smiType ? smiGetTypeModule(smiType)->name : NULL;
222 if ((!typeModule) && (typeName) &&
223 (basetype != SMI_BASETYPE_ENUM) &&
224 (basetype != SMI_BASETYPE_BITS)) {
225 for(i=0; convertType[i]; i += 2) {
226 if (!strcmp(typeName, convertType[i])) {
227 return convertType[i+1];
232 if ((!typeModule) || (!strlen(typeModule)) || (!typeName)) {
233 if (basetype == SMI_BASETYPE_ENUM) {
234 return "Enumeration";
236 if (basetype == SMI_BASETYPE_BITS) {
242 return getStringBasetype(basetype);
245 /* TODO: fully qualified if unambigous */
252 static char *getOidString(SmiNode *smiNode, int importedParent)
255 SmiModule *smiModule;
262 parentNode = smiNode;
263 smiModule = smiGetNodeModule(smiNode);
267 if (parentNode->oidlen <= 1) {
271 /* prepend the cut-off subidentifier to `append'. */
273 sprintf(append, ".%u%s", parentNode->oid[parentNode->oidlen-1], s);
275 /* retrieve the parent SmiNode */
276 parentNode = smiGetParentNode(parentNode);
279 sprintf(s, "%s", append);
283 /* found an imported or a local parent node? */
284 if ((parentNode->name && strlen(parentNode->name)) &&
285 (smiIsImported(smiModule, NULL, parentNode->name) ||
287 (smiGetNodeModule(parentNode) == smiModule)) ||
288 (parentNode->oidlen == 1))) {
289 sprintf(s, "%s%s", parentNode->name, append);
293 } while (parentNode);
296 for (i=0; i < smiNode->oidlen; i++) {
297 if (i) strcat(s, ".");
298 sprintf(&s[strlen(s)], "%u", smiNode->oid[i]);
305 static Import* addImport(char *module, char *name)
307 Import **import, *newImport;
310 for (i = 0; convertImport[i]; i += 4) {
311 if (convertImport[i] && convertImport[i+1]
312 && !strcmp(module, convertImport[i])
313 && !strcmp(name, convertImport[i+1])) {
314 module = convertImport[i+2];
315 name = convertImport[i+3];
317 } else if (convertImport[i] && !convertImport[i+1]
318 && !strcmp(module, convertImport[i])) {
319 module = convertImport[i+2];
324 if (!module || !name) {
328 for (import = &importList; *import; import = &(*import)->nextPtr) {
329 int c = strcmp((*import)->module, module);
332 int d = strcmp((*import)->name, name);
334 if (d == 0) return *import;
340 newImport = xmalloc(sizeof(Import));
341 newImport->module = module;
342 newImport->name = name;
343 newImport->nextPtr = *import;
351 static void createImportList(SmiModule *smiModule)
355 SmiModule *smiTypeModule;
356 SmiNodekind kind = SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN;
357 SmiImport *smiImport;
359 for (smiNode = smiGetFirstNode(smiModule, kind);
361 smiNode = smiGetNextNode(smiNode, kind)) {
363 smiType = smiGetNodeType(smiNode);
364 if (smiType && (smiType->decl == SMI_DECL_IMPLICIT_TYPE)) {
365 smiType = smiGetParentType(smiType);
368 smiTypeModule = smiGetTypeModule(smiType);
370 strcmp(smiTypeModule->name, smiModule->name)) {
371 if (strlen(smiTypeModule->name)) {
372 addImport(smiTypeModule->name, smiType->name);
375 if (smiType->basetype == SMI_BASETYPE_INTEGER32) {
376 addImport("SNMPv2-SMI", "Integer32");
381 for (smiImport = smiGetFirstImport(smiModule); smiImport;
382 smiImport = smiGetNextImport(smiImport)) {
383 if (islower((int) smiImport->name[0]) ||
384 (smiImport->module && !strcmp(smiImport->module, "SNMPv2-SMI")) ||
385 (smiImport->module && !strcmp(smiImport->module, "SNMPv2-TC"))) {
386 addImport(smiImport->module, smiImport->name);
393 static void freeImportList(void)
395 Import *import, *freeme;
397 for (import = importList; import; ) {
399 import = import->nextPtr;
407 static void fprint(FILE *f, char *fmt, ...)
414 #ifdef HAVE_VSNPRINTF
415 current_column += vsnprintf(s, sizeof(s), fmt, ap);
417 current_column += vsprintf(s, fmt, ap); /* buffer overwrite */
423 if ((p = strrchr(s, '\n'))) {
424 current_column = strlen(p) - 1;
430 static void fprintSegment(FILE *f, int column, char *string, int length)
432 fprint(f, "%*c%s", column, ' ', string);
434 fprint(f, "%*c", length - strlen(string) - column, ' ');
440 static void fprintWrapped(FILE *f, int column, char *string)
442 if ((current_column + strlen(string)) > INDENTMAX) {
445 fprintSegment(f, column, "", 0);
447 fprint(f, "%s", string);
452 static void fprintMultilineString(FILE *f, int column, const char *s)
456 fprintSegment(f, column - 1 + INDENTTEXTS, "\"", 0);
459 for (i=0; i < len; i++) {
464 fprintSegment(f, column + INDENTTEXTS, "", 0);
474 static char *getValueString(SmiValue *valuePtr, SmiType *typePtr)
484 switch (valuePtr->basetype) {
485 case SMI_BASETYPE_UNSIGNED32:
486 sprintf(s, "%lu", valuePtr->value.unsigned32);
488 case SMI_BASETYPE_INTEGER32:
489 sprintf(s, "%ld", valuePtr->value.integer32);
491 case SMI_BASETYPE_UNSIGNED64:
492 sprintf(s, UINT64_FORMAT, valuePtr->value.unsigned64);
494 case SMI_BASETYPE_INTEGER64:
495 sprintf(s, INT64_FORMAT, valuePtr->value.integer64);
497 case SMI_BASETYPE_FLOAT32:
498 sprintf(s, "%G", valuePtr->value.float32);
500 case SMI_BASETYPE_FLOAT64:
501 sprintf(s, "%lG", valuePtr->value.float64);
503 case SMI_BASETYPE_FLOAT128:
504 sprintf(s, "%LG", valuePtr->value.float128);
507 case SMI_BASETYPE_ENUM:
508 for (nn = smiGetFirstNamedNumber(typePtr); nn;
509 nn = smiGetNextNamedNumber(nn)) {
510 if (nn->value.value.integer32 == valuePtr->value.integer32)
514 sprintf(s, "%s", nn->name);
516 sprintf(s, "%ld", valuePtr->value.integer32);
519 case SMI_BASETYPE_OCTETSTRING:
520 for (i = 0; i < valuePtr->len; i++) {
521 if (!isprint((int)valuePtr->value.ptr[i])) break;
523 if (i == valuePtr->len) {
524 sprintf(s, "\"%s\"", valuePtr->value.ptr);
526 sprintf(s, "0x%*s", 2 * valuePtr->len, "");
527 for (i=0; i < valuePtr->len; i++) {
528 sprintf(ss, "%02x", valuePtr->value.ptr[i]);
529 strncpy(&s[2+2*i], ss, 2);
533 case SMI_BASETYPE_BITS:
535 for (i = 0, n = 0; i < valuePtr->len * 8; i++) {
536 if (valuePtr->value.ptr[i/8] & (1 << (7-(i%8)))) {
538 sprintf(&s[strlen(s)], ", ");
540 for (nn = smiGetFirstNamedNumber(typePtr); nn;
541 nn = smiGetNextNamedNumber(nn)) {
542 /* if (nn->value.value.unsigned64 == ((i/8)*8 + (7-(i%8)))) */
543 if (nn->value.value.unsigned64 == i)
547 sprintf(&s[strlen(s)], "%s", nn->name);
549 sprintf(&s[strlen(s)], "%d", i);
553 sprintf(&s[strlen(s)], ")");
555 case SMI_BASETYPE_UNKNOWN:
557 case SMI_BASETYPE_OBJECTIDENTIFIER:
558 /*nodePtr = smiGetNodeByOID(valuePtr->len, valuePtr->value.oid);
560 sprintf(s, "%s", nodePtr->name);
563 for (i=0; i < valuePtr->len; i++) {
564 if (i) strcat(s, ".");
565 sprintf(&s[strlen(s)], "%u", valuePtr->value.oid[i]);
568 sprintf(s, "%s", typePtr->value.value.ptr);
570 case SMI_BASETYPE_POINTER:
571 /*nodePtr = smiGetNodeByOID(valuePtr->len, valuePtr->value.oid);
573 sprintf(s, "%s", nodePtr->name);
576 for (i=0; i < valuePtr->len; i++) {
577 if (i) strcat(s, ".");
578 sprintf(&s[strlen(s)], "%u", valuePtr->value.oid[i]);
581 sprintf(s, "%s", valuePtr->value.ptr);
584 sprintf(s, "%s", "");
593 static void fprintSubtype(FILE *f, SmiType *smiType)
600 if ((smiType->basetype == SMI_BASETYPE_ENUM) ||
601 (smiType->basetype == SMI_BASETYPE_BITS)) {
602 for(i = 0, nn = smiGetFirstNamedNumber(smiType);
603 nn ; i++, nn = smiGetNextNamedNumber(nn)) {
609 sprintf(s, "%s(%s)", nn->name,
610 getValueString(&nn->value, smiType));
611 fprintWrapped(f, INDENTVALUE + INDENT, s);
616 } else if(smiType->basetype == SMI_BASETYPE_POINTER) {
617 nn = smiGetFirstNamedNumber(smiType);
619 fprint(f, " (%s)",nn->name);
621 for(i = 0, range = smiGetFirstRange(smiType);
622 range ; i++, range = smiGetNextRange(range)) {
628 if (memcmp(&range->minValue, &range->maxValue,
630 sprintf(s, "%s", getValueString(&range->minValue, smiType));
631 sprintf(&s[strlen(s)], "..%s",
632 getValueString(&range->maxValue, smiType));
634 sprintf(s, "%s", getValueString(&range->minValue, smiType));
636 fprintWrapped(f, INDENTVALUE + INDENT, s);
644 static void fprintAttributeSubtype(FILE *f, SmiAttribute *smiAttribute)
651 if ((smiAttribute->basetype == SMI_BASETYPE_ENUM) ||
652 (smiAttribute->basetype == SMI_BASETYPE_BITS)) {
653 for(i = 0, nn = smiGetAttributeFirstNamedNumber(smiAttribute);
654 nn ; i++, nn = smiGetAttributeNextNamedNumber(nn)) {
660 sprintf(s, "%s(%s)", nn->name,
661 getValueString(&nn->value, smiGetAttributeParentType(smiAttribute)));
662 fprintWrapped(f, INDENTVALUE + INDENT, s);
667 } else if(smiAttribute->basetype == SMI_BASETYPE_POINTER) {
668 nn = smiGetAttributeFirstNamedNumber(smiAttribute);
670 fprint(f, " (%s)",nn->name);
672 for(i = 0, range = smiGetAttributeFirstRange(smiAttribute);
673 range ; i++, range = smiGetAttributeNextRange(range)) {
679 if (memcmp(&range->minValue, &range->maxValue,
681 sprintf(s, "%s", getValueString(&range->minValue, smiGetAttributeParentType(smiAttribute)));
682 sprintf(&s[strlen(s)], "..%s",
683 getValueString(&range->maxValue, smiGetAttributeParentType(smiAttribute)));
685 sprintf(s, "%s", getValueString(&range->minValue, smiGetAttributeParentType(smiAttribute)));
687 fprintWrapped(f, INDENTVALUE + INDENT, s);
697 static void fprintImports(FILE *f, SmiModule *smiModule)
700 char *lastModuleName = NULL;
701 int pos = 0, len, maxlen = 0;
703 createImportList(smiModule);
705 for (import = smiGetFirstImport(smiModule); import; import = smiGetNextImport(import)) {
706 len = strlen(import->module);
707 maxlen = (len > maxlen) ? len : maxlen;
710 for (import = smiGetFirstImport(smiModule); import; import = smiGetNextImport(import)) {
711 int yaba = !lastModuleName || strcmp(import->module, lastModuleName);
713 if (lastModuleName) {
716 fprintSegment(f, INDENT, "", 0);
717 fprint(f, "import %-*s (", maxlen, import->module);
718 pos = INDENT + 12 + maxlen;
722 len = strlen(import->name);
723 if (len + pos > INDENTMAX) {
725 fprintSegment(f, INDENT, "", 0);
726 fprintSegment(f, INDENT, "", 0);
727 fprint(f, " %-*s ", maxlen, "");
728 pos = INDENT + 12 + maxlen;
730 fprint(f, "%s", import->name);
732 lastModuleName = import->module;
735 if (lastModuleName) {
747 static void fprintRevisions(FILE *f, SmiModule *smiModule)
750 SmiRevision *smiRevision;
752 for(i = 0, smiRevision = smiGetFirstRevision(smiModule);
753 smiRevision; smiRevision = smiGetNextRevision(smiRevision)) {
754 fprintSegment(f, INDENT, "revision {\n", 0);
755 fprintSegment(f, 2 * INDENT, "date", INDENTVALUE);
756 fprint(f, "\"%s\";\n", getStringTime(smiRevision->date));
757 fprintSegment(f, 2 * INDENT, "description", INDENTVALUE);
759 fprintMultilineString(f, 2 * INDENT, smiRevision->description);
761 fprintSegment(f, INDENT, "};\n", 0);
771 static void fprintTypedefs(FILE *f, SmiModule *smiModule)
776 for(i = 0, smiType = smiGetFirstType(smiModule);
777 smiType; smiType = smiGetNextType(smiType)) {
779 if ((!(strcmp(smiModule->name, "SNMPv2-SMI"))) ||
780 (!(strcmp(smiModule->name, "RFC1155-SMI")))) {
781 for(j=0; excludeType[j]; j++) {
782 if (!strcmp(smiType->name, excludeType[j])) break;
784 if (excludeType[j]) break;
788 fprint(f, "//\n// TYPE DEFINITIONS\n//\n\n");
790 fprintSegment(f, INDENT, "", 0);
791 fprint(f, "typedef %s {\n", smiType->name);
793 fprintSegment(f, 2 * INDENT, "type", INDENTVALUE);
794 fprint(f, "%s", getTypeString(smiType->basetype,
795 smiGetParentType(smiType)));
796 fprintSubtype(f, smiType);
799 if (smiType->value.basetype != SMI_BASETYPE_UNKNOWN) {
800 fprintSegment(f, 2 * INDENT, "default", INDENTVALUE);
801 fprint(f, "%s", getValueString(&smiType->value, smiType));
805 if (smiType->format) {
806 fprintSegment(f, 2 * INDENT, "format", INDENTVALUE);
807 fprint(f, "\"%s\";\n", smiType->format);
809 if (smiType->units) {
810 fprintSegment(f, 2 * INDENT, "units", INDENTVALUE);
811 fprint(f, "\"%s\";\n", smiType->units);
813 if ((smiType->status != SMI_STATUS_UNKNOWN) &&
814 (smiType->status != SMI_STATUS_MANDATORY) &&
815 (smiType->status != SMI_STATUS_OPTIONAL)) {
816 fprintSegment(f, 2 * INDENT, "status", INDENTVALUE);
817 fprint(f, "%s;\n", getStringStatus(smiType->status));
819 fprintSegment(f, 2 * INDENT, "description", INDENTVALUE);
821 fprintMultilineString(f, 2 * INDENT, smiType->description);
823 if (smiType->reference) {
824 fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE);
826 fprintMultilineString(f, 2 * INDENT, smiType->reference);
829 fprintSegment(f, INDENT, "};\n\n", 0);
834 static void fprintIdentities(FILE *f, SmiModule *smiModule)
837 SmiIdentity *smiIdentity;
838 SmiIdentity *tmpIdentity;
840 for(i = 0, smiIdentity = smiGetFirstIdentity(smiModule);
841 smiIdentity; smiIdentity = smiGetNextIdentity(smiIdentity)) {
844 fprint(f, "//\n// IDENTITY DEFINITIONS\n//\n\n");
846 fprintSegment(f, INDENT, "", 0);
847 fprint(f, "identity %s {\n", smiIdentity->name);
849 tmpIdentity = smiGetParentIdentity(smiIdentity);
851 fprintSegment(f, 2 * INDENT, "parent", INDENTVALUE);
852 fprint(f, "%s", tmpIdentity->name);
856 if ((smiIdentity->status != SMI_STATUS_UNKNOWN) &&
857 (smiIdentity->status != SMI_STATUS_MANDATORY) &&
858 (smiIdentity->status != SMI_STATUS_OPTIONAL)) {
859 fprintSegment(f, 2 * INDENT, "status", INDENTVALUE);
860 fprint(f, "%s;\n", getStringStatus(smiIdentity->status));
862 fprintSegment(f, 2 * INDENT, "description", INDENTVALUE);
864 fprintMultilineString(f, 2 * INDENT, smiIdentity->description);
866 if (smiIdentity->reference) {
867 fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE);
869 fprintMultilineString(f, 2 * INDENT, smiIdentity->reference);
872 fprintSegment(f, INDENT, "};\n\n", 0);
877 static void fprintExtensions(FILE *f, SmiModule *smiModule)
882 for(i = 0, smiMacro = smiGetFirstMacro(smiModule);
883 smiMacro; smiMacro = smiGetNextMacro(smiMacro)) {
886 fprint(f, "//\n// EXTENSION DEFINITIONS\n//\n\n");
888 fprintSegment(f, INDENT, "", 0);
889 fprint(f, "extension %s {\n", smiMacro->name);
891 if ((smiMacro->status != SMI_STATUS_UNKNOWN) &&
892 (smiMacro->status != SMI_STATUS_MANDATORY) &&
893 (smiMacro->status != SMI_STATUS_OPTIONAL)) {
894 fprintSegment(f, 2 * INDENT, "status", INDENTVALUE);
895 fprint(f, "%s;\n", getStringStatus(smiMacro->status));
897 fprintSegment(f, 2 * INDENT, "description", INDENTVALUE);
899 fprintMultilineString(f, 2 * INDENT, smiMacro->description);
901 if (smiMacro->reference) {
902 fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE);
904 fprintMultilineString(f, 2 * INDENT, smiMacro->reference);
909 fprintSegment(f, 2 * INDENT, "abnf", INDENTVALUE);
911 fprintMultilineString(f, 2 * INDENT, smiMacro->abnf);
914 fprintSegment(f, INDENT, "};\n\n", 0);
919 static void fprintUniqueStatement(FILE *f, SmiClass *smiClass)
921 SmiAttribute *attributePtr;
924 if(smiIsClassScalar(smiClass))
926 fprintSegment(f, 2 * INDENT, "unique", INDENTVALUE);
930 attributePtr = smiGetFirstUniqueAttribute(smiClass);
932 fprintSegment(f, 2 * INDENT, "unique", INDENTVALUE);
934 for (i=0; attributePtr;
935 attributePtr = smiGetNextUniqueAttribute(attributePtr))
938 fprint(f, ", %s",attributePtr->name);
940 fprint(f, "%s",attributePtr->name);
947 static void fprintAttributes(FILE *f, SmiClass *smiClass)
950 SmiAttribute *smiAttribute;
954 for (i = 0, smiAttribute = smiGetFirstAttribute(smiClass);
955 smiAttribute; smiAttribute = smiGetNextAttribute(smiAttribute)) {
957 fprintSegment(f, 2*INDENT, "", 0);
958 fprint(f, "attribute %s {\n", smiAttribute->name);
960 tmpType = smiGetAttributeParentType(smiAttribute);
962 fprintSegment(f, 3 * INDENT, "type", INDENTVALUE);
963 fprint(f, "%s ", tmpType->name);
964 fprintAttributeSubtype(f, smiAttribute);
966 fprintSegment(f, 3 * INDENT, "access", INDENTVALUE);
967 switch (smiAttribute->access) {
968 case SMI_ACCESS_READ_ONLY:
969 fprint(f, "readonly;\n");
971 case SMI_ACCESS_READ_WRITE:
972 fprint(f, "readwrite;\n");
974 case SMI_ACCESS_EVENT_ONLY:
975 fprint(f, "eventonly;\n");
982 if (smiAttribute->value.basetype != SMI_BASETYPE_UNKNOWN) {
983 fprintSegment(f, 3 * INDENT, "default", INDENTVALUE);
984 fprint(f, "%s", getValueString(&smiAttribute->value, smiGetAttributeParentType(smiAttribute)));
988 if (smiAttribute->format) {
989 fprintSegment(f, 3 * INDENT, "format", INDENTVALUE);
990 fprint(f, "\"%s\";\n", smiAttribute->format);
992 if (smiAttribute->units) {
993 fprintSegment(f, 3 * INDENT, "units", INDENTVALUE);
994 fprint(f, "\"%s\";\n", smiAttribute->units);
998 tmpClass = smiGetAttributeParentClass(smiAttribute);
1000 fprintSegment(f, 3 * INDENT, "type", INDENTVALUE);
1001 fprint(f, "%s;\n", tmpClass->name);
1004 if ((smiAttribute->status != SMI_STATUS_UNKNOWN) &&
1005 (smiAttribute->status != SMI_STATUS_MANDATORY) &&
1006 (smiAttribute->status != SMI_STATUS_OPTIONAL)) {
1007 fprintSegment(f, 3 * INDENT, "status", INDENTVALUE);
1008 fprint(f, "%s;\n", getStringStatus(smiAttribute->status));
1010 fprintSegment(f, 3 * INDENT, "description", INDENTVALUE);
1012 fprintMultilineString(f, 3 * INDENT, smiAttribute->description);
1014 if (smiAttribute->reference) {
1015 fprintSegment(f, 3 * INDENT, "reference", INDENTVALUE);
1017 fprintMultilineString(f, 3 * INDENT, smiAttribute->reference);
1021 fprintSegment(f, 2*INDENT, "};\n\n", 0);
1026 static void fprintEvents(FILE *f, SmiClass *smiClass)
1031 for(i = 0, smiEvent = smiGetFirstEvent(smiClass);
1032 smiEvent; smiEvent = smiGetNextEvent(smiEvent)) {
1034 if (!i && !silent) {
1036 fprintSegment(f, 2 * INDENT, "// ATTRIBUTE DEFINITIONS\n\n",0);
1038 fprintSegment(f, 2*INDENT, "", 0);
1039 fprint(f, "event %s {\n", smiEvent->name);
1041 if ((smiEvent->status != SMI_STATUS_UNKNOWN) &&
1042 (smiEvent->status != SMI_STATUS_MANDATORY) &&
1043 (smiEvent->status != SMI_STATUS_OPTIONAL)) {
1044 fprintSegment(f, 3 * INDENT, "status", INDENTVALUE);
1045 fprint(f, "%s;\n", getStringStatus(smiEvent->status));
1047 fprintSegment(f, 3 * INDENT, "description", INDENTVALUE);
1049 fprintMultilineString(f, 3 * INDENT, smiEvent->description);
1051 if (smiEvent->reference) {
1052 fprintSegment(f, 3 * INDENT, "reference", INDENTVALUE);
1054 fprintMultilineString(f, 3 * INDENT, smiEvent->reference);
1058 fprintSegment(f, 2*INDENT, "};\n\n", 0);
1063 static void fprintClasses(FILE *f, SmiModule *smiModule)
1069 for (i = 0, smiClass = smiGetFirstClass(smiModule);
1070 smiClass; smiClass = smiGetNextClass(smiClass)) {
1072 if (!i && !silent) {
1073 fprint(f, "//\n// CLASS DEFINITIONS\n//\n\n");
1075 fprintSegment(f, INDENT, "", 0);
1076 fprint(f, "class %s {\n", smiClass->name);
1078 tmpClass = smiGetParentClass(smiClass);
1080 fprintSegment(f, 2 * INDENT, "extends", INDENTVALUE);
1081 fprint(f, "%s;\n\n", tmpClass->name);
1084 fprintAttributes(f,smiClass);
1086 fprintUniqueStatement(f,smiClass);
1088 fprintEvents(f,smiClass);
1090 if ((smiClass->status != SMI_STATUS_UNKNOWN) &&
1091 (smiClass->status != SMI_STATUS_MANDATORY) &&
1092 (smiClass->status != SMI_STATUS_OPTIONAL)) {
1093 fprintSegment(f, 2 * INDENT, "status", INDENTVALUE);
1094 fprint(f, "%s;\n", getStringStatus(smiClass->status));
1096 fprintSegment(f, 2 * INDENT, "description", INDENTVALUE);
1098 fprintMultilineString(f, 2 * INDENT, smiClass->description);
1100 if (smiClass->reference) {
1101 fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE);
1103 fprintMultilineString(f, 2 * INDENT, smiClass->reference);
1107 fprintSegment(f, INDENT, "};\n\n", 0);
1112 static void fprintObjects(FILE *f, SmiModule *smiModule)
1115 SmiNode *smiNode, *relatedNode;
1116 SmiElement *smiElement;
1119 int lastindent = -1;
1121 SmiNodekind nodekinds;
1123 nodekinds = SMI_NODEKIND_NODE | SMI_NODEKIND_TABLE |
1124 SMI_NODEKIND_ROW | SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR |
1125 SMI_NODEKIND_CAPABILITIES;
1127 for(i = 0, smiNode = smiGetFirstNode(smiModule, nodekinds);
1128 smiNode; smiNode = smiGetNextNode(smiNode, nodekinds)) {
1130 if (smiNode->nodekind == SMI_NODEKIND_NODE) {
1133 } else if (smiNode->nodekind == SMI_NODEKIND_CAPABILITIES) {
1136 } else if (smiNode->nodekind == SMI_NODEKIND_TABLE) {
1139 } else if (smiNode->nodekind == SMI_NODEKIND_ROW) {
1142 } else if (smiNode->nodekind == SMI_NODEKIND_COLUMN) {
1145 } else if (smiNode->nodekind == SMI_NODEKIND_SCALAR) {
1150 if (!i && !silent) {
1151 fprint(f, "//\n// OBJECT DEFINITIONS\n//\n\n");
1154 for (j = lastindent; j >= indent; j--) {
1155 fprintSegment(f, (1 + j) * INDENT, "", 0);
1159 lastindent = indent;
1161 if (smiNode->nodekind == SMI_NODEKIND_CAPABILITIES) {
1162 fprintSegment(f, (1 + indent) * INDENT, "", 0);
1163 fprint(f, "-- This has been an SMIv2 AGENT-CAPABILITIES node:\n");
1166 fprintSegment(f, (1 + indent) * INDENT, "", 0);
1167 fprint(f, "%s %s {\n", s, smiNode->name);
1170 fprintSegment(f, (2 + indent) * INDENT, "oid", INDENTVALUE);
1171 fprint(f, "%s;\n", getOidString(smiNode, 0));
1174 smiType = smiGetNodeType(smiNode);
1175 if (smiType && (smiType->basetype != SMI_BASETYPE_UNKNOWN)) {
1176 fprintSegment(f, (2 + indent) * INDENT, "type", INDENTVALUE);
1177 if (!smiType->name) {
1179 * an implicitly restricted type.
1181 fprint(f, "%s", getTypeString(smiType->basetype,
1182 smiGetParentType(smiType)));
1183 fprintSubtype(f, smiType);
1187 getTypeString(smiType->basetype, smiType));
1191 if ((smiNode->nodekind != SMI_NODEKIND_TABLE) &&
1192 (smiNode->nodekind != SMI_NODEKIND_ROW) &&
1193 (smiNode->nodekind != SMI_NODEKIND_CAPABILITIES) &&
1194 (smiNode->nodekind != SMI_NODEKIND_NODE)) {
1195 if (smiNode->access != SMI_ACCESS_UNKNOWN) {
1196 fprintSegment(f, (2 + indent) * INDENT, "access", INDENTVALUE);
1197 fprint(f, "%s;\n", getAccessString(smiNode->access));
1201 relatedNode = smiGetRelatedNode(smiNode);
1202 switch (smiNode->indexkind) {
1203 case SMI_INDEX_INDEX:
1204 if (smiNode->implied) {
1205 fprintSegment(f, (2 + indent) * INDENT, "index implied",
1208 fprintSegment(f, (2 + indent) * INDENT, "index", INDENTVALUE);
1211 for (j = 0, smiElement = smiGetFirstElement(smiNode); smiElement;
1212 j++, smiElement = smiGetNextElement(smiElement)) {
1216 fprintWrapped(f, INDENTVALUE + 1,
1217 smiGetElementNode(smiElement)->name);
1218 /* TODO: non-local name if non-local */
1219 } /* TODO: empty? -> print error */
1222 case SMI_INDEX_AUGMENT:
1224 fprintSegment(f, (2 + indent) * INDENT, "augments",
1226 fprint(f, "%s;\n", relatedNode->name);
1227 /* TODO: non-local name if non-local */
1228 } /* TODO: else print error */
1230 case SMI_INDEX_REORDER:
1232 fprintSegment(f, (2 + indent) * INDENT, "", 0);
1233 fprint(f, "reorders %s", relatedNode->name);
1234 /* TODO: non-local name if non-local */
1235 if (smiNode->implied) {
1236 fprint(f, " implied");
1239 for (j = 0, smiElement = smiGetFirstElement(smiNode);
1241 j++, smiElement = smiGetNextElement(smiElement)) {
1245 fprintWrapped(f, INDENTVALUE + 1,
1246 smiGetElementNode(smiElement)->name);
1247 /* TODO: non-local name if non-local */
1248 } /* TODO: empty? -> print error */
1250 } /* TODO: else print error */
1252 case SMI_INDEX_SPARSE:
1254 fprintSegment(f, (2 + indent) * INDENT, "sparse", INDENTVALUE);
1255 fprint(f, "%s;\n", relatedNode->name);
1256 /* TODO: non-local name if non-local */
1257 } /* TODO: else print error */
1259 case SMI_INDEX_EXPAND:
1261 fprintSegment(f, (2 + indent) * INDENT, "", 0);
1262 fprint(f, "expands %s", relatedNode->name);
1263 /* TODO: non-local name if non-local */
1264 if (smiNode->implied) {
1265 fprint(f, " implied");
1268 for (j = 0, smiElement = smiGetFirstElement(smiNode);
1270 j++, smiElement = smiGetNextElement(smiElement)) {
1274 fprintWrapped(f, INDENTVALUE + 1,
1275 smiGetElementNode(smiElement)->name);
1276 /* TODO: non-local name if non-local */
1277 } /* TODO: empty? -> print error */
1279 } /* TODO: else print error */
1281 case SMI_INDEX_UNKNOWN:
1285 if (smiNode->create) {
1286 fprintSegment(f, (2 + indent) * INDENT, "create", INDENTVALUE);
1287 /* TODO: create list */
1291 if (smiNode->value.basetype != SMI_BASETYPE_UNKNOWN) {
1292 fprintSegment(f, (2 + indent) * INDENT, "default", INDENTVALUE);
1293 fprint(f, "%s", getValueString(&smiNode->value, smiType));
1297 if (smiNode->format) {
1298 fprintSegment(f, (2 + indent) * INDENT, "format", INDENTVALUE);
1299 fprint(f, "\"%s\";\n",smiNode->format);
1301 if (smiNode->units) {
1302 fprintSegment(f, (2 + indent) * INDENT, "units", INDENTVALUE);
1303 fprint(f, "\"%s\";\n", smiNode->units);
1305 if ((smiNode->status != SMI_STATUS_CURRENT) &&
1306 (smiNode->status != SMI_STATUS_UNKNOWN) &&
1307 (smiNode->status != SMI_STATUS_MANDATORY) &&
1308 (smiNode->status != SMI_STATUS_OPTIONAL)) {
1309 fprintSegment(f, (2 + indent) * INDENT, "status", INDENTVALUE);
1310 fprint(f, "%s;\n", getStringStatus(smiNode->status));
1312 if (smiNode->description) {
1313 fprintSegment(f, (2 + indent) * INDENT, "description",
1316 fprintMultilineString(f, (2 + indent) * INDENT,
1317 smiNode->description);
1320 if (smiNode->reference) {
1321 fprintSegment(f, (2 + indent) * INDENT, "reference",
1324 fprintMultilineString(f, (2 + indent) * INDENT,
1325 smiNode->reference);
1332 fprintSegment(f, (1 + indent) * INDENT, "", 0);
1333 fprint(f, "};\n\n");
1339 static void fprintNotifications(FILE *f, SmiModule *smiModule)
1343 SmiElement *smiElement;
1345 for(i = 0, smiNode = smiGetFirstNode(smiModule,
1346 SMI_NODEKIND_NOTIFICATION);
1348 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_NOTIFICATION)) {
1350 if (!i && !silent) {
1351 fprint(f, "//\n// NOTIFICATION DEFINITIONS\n//\n\n");
1354 fprintSegment(f, INDENT, "", 0);
1355 fprint(f, "notification %s {\n", smiNode->name);
1358 fprintSegment(f, 2 * INDENT, "oid", INDENTVALUE);
1359 fprint(f, "%s;\n", getOidString(smiNode, 0));
1362 if ((smiElement = smiGetFirstElement(smiNode))) {
1363 fprintSegment(f, 2 * INDENT, "objects", INDENTVALUE);
1365 for (j = 0; smiElement;
1366 j++, smiElement = smiGetNextElement(smiElement)) {
1370 fprintWrapped(f, INDENTVALUE + 1,
1371 smiGetElementNode(smiElement)->name);
1372 /* TODO: non-local name if non-local */
1373 } /* TODO: empty? -> print error */
1377 if ((smiNode->status != SMI_STATUS_CURRENT) &&
1378 (smiNode->status != SMI_STATUS_UNKNOWN) &&
1379 (smiNode->status != SMI_STATUS_MANDATORY) &&
1380 (smiNode->status != SMI_STATUS_OPTIONAL)) {
1381 fprintSegment(f, 2 * INDENT, "status", INDENTVALUE);
1382 fprint(f, "%s;\n", getStringStatus(smiNode->status));
1385 if (smiNode->description) {
1386 fprintSegment(f, 2 * INDENT, "description", INDENTVALUE);
1388 fprintMultilineString(f, 2 * INDENT, smiNode->description);
1392 if (smiNode->reference) {
1393 fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE);
1395 fprintMultilineString(f, 2 * INDENT, smiNode->reference);
1399 fprintSegment(f, INDENT, "", 0);
1400 fprint(f, "};\n\n");
1407 static void fprintGroups(FILE *f, SmiModule *smiModule)
1411 SmiElement *smiElement;
1413 for(i = 0, smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_GROUP);
1414 smiNode; smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_GROUP)) {
1416 if (!i && !silent) {
1417 fprint(f, "//\n// GROUP DEFINITIONS\n//\n\n");
1420 fprintSegment(f, INDENT, "", 0);
1421 fprint(f, "group %s {\n", smiNode->name);
1424 fprintSegment(f, 2 * INDENT, "oid", INDENTVALUE);
1425 fprint(f, "%s;\n", getOidString(smiNode, 0));
1428 fprintSegment(f, 2 * INDENT, "members", INDENTVALUE);
1430 for (j = 0, smiElement = smiGetFirstElement(smiNode); smiElement;
1431 j++, smiElement = smiGetNextElement(smiElement)) {
1435 fprintWrapped(f, INDENTVALUE + 1,
1436 smiGetElementNode(smiElement)->name);
1437 /* TODO: non-local name if non-local */
1438 } /* TODO: empty? -> print error */
1441 if ((smiNode->status != SMI_STATUS_CURRENT) &&
1442 (smiNode->status != SMI_STATUS_UNKNOWN) &&
1443 (smiNode->status != SMI_STATUS_MANDATORY) &&
1444 (smiNode->status != SMI_STATUS_OPTIONAL)) {
1445 fprintSegment(f, 2 * INDENT, "status", INDENTVALUE);
1446 fprint(f, "%s;\n", getStringStatus(smiNode->status));
1449 if (smiNode->description) {
1450 fprintSegment(f, 2 * INDENT, "description", INDENTVALUE);
1452 fprintMultilineString(f, 2 * INDENT, smiNode->description);
1456 if (smiNode->reference) {
1457 fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE);
1459 fprintMultilineString(f, 2 * INDENT, smiNode->reference);
1463 fprintSegment(f, INDENT, "", 0);
1464 fprint(f, "};\n\n");
1471 static void fprintCompliances(FILE *f, SmiModule *smiModule)
1474 SmiNode *smiNode, *smiNode2;
1476 SmiOption *smiOption;
1477 SmiRefinement *smiRefinement;
1478 SmiElement *smiElement;
1480 for(i = 0, smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_COMPLIANCE);
1481 smiNode; smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_COMPLIANCE)) {
1483 if (!i && !silent) {
1484 fprint(f, "//\n// COMPLIANCE DEFINITIONS\n//\n\n");
1487 fprintSegment(f, INDENT, "", 0);
1488 fprint(f, "compliance %s {\n", smiNode->name);
1491 fprintSegment(f, 2 * INDENT, "oid", INDENTVALUE);
1492 fprint(f, "%s;\n", getOidString(smiNode, 0));
1495 if ((smiNode->status != SMI_STATUS_CURRENT) &&
1496 (smiNode->status != SMI_STATUS_UNKNOWN) &&
1497 (smiNode->status != SMI_STATUS_MANDATORY) &&
1498 (smiNode->status != SMI_STATUS_OPTIONAL)) {
1499 fprintSegment(f, 2 * INDENT, "status", INDENTVALUE);
1500 fprint(f, "%s;\n", getStringStatus(smiNode->status));
1503 if (smiNode->description) {
1504 fprintSegment(f, 2 * INDENT, "description", INDENTVALUE);
1506 fprintMultilineString(f, 2 * INDENT, smiNode->description);
1510 if (smiNode->reference) {
1511 fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE);
1513 fprintMultilineString(f, 2 * INDENT, smiNode->reference);
1517 if ((smiElement = smiGetFirstElement(smiNode))) {
1519 fprintSegment(f, 2 * INDENT, "mandatory", INDENTVALUE);
1521 for (j = 0; smiElement;
1522 j++, smiElement = smiGetNextElement(smiElement)) {
1526 fprintWrapped(f, INDENTVALUE + 1,
1527 smiGetElementNode(smiElement)->name);
1528 /* TODO: non-local name if non-local */
1529 } /* TODO: empty? -> print error */
1533 if ((smiOption = smiGetFirstOption(smiNode))) {
1535 for(; smiOption; smiOption = smiGetNextOption(smiOption)) {
1536 smiNode2 = smiGetOptionNode(smiOption);
1537 fprintSegment(f, 2 * INDENT, "", 0);
1538 fprint(f, "optional %s {\n", smiNode2->name);
1539 fprintSegment(f, 3 * INDENT, "description", INDENTVALUE);
1541 fprintMultilineString(f, 3 * INDENT, smiOption->description);
1543 fprintSegment(f, 2 * INDENT, "};\n", 0);
1547 if ((smiRefinement = smiGetFirstRefinement(smiNode))) {
1549 for(; smiRefinement;
1550 smiRefinement = smiGetNextRefinement(smiRefinement)) {
1551 fprintSegment(f, 2 * INDENT, "", 0);
1552 fprint(f, "refine %s {\n",
1553 smiGetRefinementNode(smiRefinement)->name);
1555 smiType = smiGetRefinementType(smiRefinement);
1557 fprintSegment(f, 3 * INDENT, "type", INDENTVALUE);
1559 getTypeString(smiType->basetype,
1560 smiGetParentType(smiType)));
1561 fprintSubtype(f, smiType);
1565 smiType = smiGetRefinementWriteType(smiRefinement);
1567 fprintSegment(f, 3 * INDENT, "writetype", INDENTVALUE);
1569 getTypeString(smiType->basetype,
1570 smiGetParentType(smiType)));
1571 fprintSubtype(f, smiType);
1575 if (smiRefinement->access != SMI_ACCESS_UNKNOWN) {
1576 fprintSegment(f, 3 * INDENT, "access", INDENTVALUE);
1577 fprint(f, "%s;\n", getAccessString(smiRefinement->access));
1579 fprintSegment(f, 3 * INDENT, "description", INDENTVALUE);
1581 fprintMultilineString(f, 3 * INDENT,
1582 smiRefinement->description);
1584 fprintSegment(f, 2 * INDENT, "};\n", 0);
1588 fprintSegment(f, INDENT, "", 0);
1589 fprint(f, "};\n\n");
1596 static void dumpSming(int modc, SmiModule **modv, int flags, char *output)
1598 SmiModule *smiModule;
1603 silent = (flags & SMIDUMP_FLAG_SILENT);
1606 f = fopen(output, "w");
1608 fprintf(stderr, "smidump: cannot open %s for writing: ", output);
1614 for (i = 0; i < modc; i++) {
1616 smiModule = modv[i];
1619 fprint(f, "// This module has been generated by smidump "
1620 SMI_VERSION_STRING ". Do not edit.\n");
1622 fprint(f, "module %s ", smiModule->name);
1626 fprintImports(f, smiModule);
1629 fprint(f, "//\n// MODULE META INFORMATION\n//\n\n");
1631 fprintSegment(f, INDENT, "organization", INDENTVALUE);
1633 fprintMultilineString(f, INDENT, smiModule->organization);
1635 fprintSegment(f, INDENT, "contact", INDENTVALUE);
1637 fprintMultilineString(f, INDENT, smiModule->contactinfo);
1639 fprintSegment(f, INDENT, "description", INDENTVALUE);
1641 fprintMultilineString(f, INDENT, smiModule->description);
1643 if (smiModule->reference) {
1644 fprintSegment(f, INDENT, "reference", INDENTVALUE);
1646 fprintMultilineString(f, INDENT, smiModule->reference);
1650 fprintRevisions(f, smiModule);
1652 smiNode = smiGetModuleIdentityNode(smiModule);
1654 fprintSegment(f, INDENT, "identity", INDENTVALUE);
1655 fprint(f, "%s;\n\n", smiNode->name);
1658 fprintExtensions(f, smiModule);
1659 fprintIdentities(f, smiModule);
1660 fprintTypedefs(f, smiModule);
1661 fprintClasses(f, smiModule);
1662 fprintObjects(f, smiModule);
1663 fprintNotifications(f, smiModule);
1664 fprintGroups(f, smiModule);
1665 fprintCompliances(f, smiModule);
1667 fprint(f, "}; // end of module %s.\n", smiModule->name);
1670 if (fflush(f) || ferror(f)) {
1671 perror("smidump: write error");
1684 static SmidumpDriver driver = {
1688 SMIDUMP_DRIVER_CANT_UNITE,
1694 smidumpRegisterDriver(&driver);