2 * dump-compliances.c --
4 * Operations to dump compliances in a human readable format.
6 * Copyright (c) 2005 J. Schoenwaelder, International University Bremen.
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-compliances.c 1571 2003-07-14 22:58:42Z schoenw $
23 static char *getFlags(SmiNode *smiNode)
26 switch (smiNode->access) {
27 case SMI_ACCESS_UNKNOWN:
29 case SMI_ACCESS_NOT_ACCESSIBLE:
31 case SMI_ACCESS_NOTIFY:
33 case SMI_ACCESS_EVENT_ONLY:
35 case SMI_ACCESS_READ_ONLY:
37 case SMI_ACCESS_READ_WRITE:
39 case SMI_ACCESS_NOT_IMPLEMENTED:
41 case SMI_ACCESS_INSTALL:
43 case SMI_ACCESS_INSTALL_NOTIFY:
45 case SMI_ACCESS_REPORT_ONLY:
54 static char getStatusChar(SmiStatus status)
57 case SMI_STATUS_UNKNOWN:
59 case SMI_STATUS_CURRENT:
61 case SMI_STATUS_DEPRECATED:
63 case SMI_STATUS_MANDATORY:
65 case SMI_STATUS_OPTIONAL:
67 case SMI_STATUS_OBSOLETE:
76 static char *getTypeName(SmiNode *smiNode)
79 SmiType *smiType, *parentType;
81 smiType = smiGetNodeType(smiNode);
83 if (!smiType || smiNode->nodekind == SMI_NODEKIND_TABLE)
86 if (smiType->decl == SMI_DECL_IMPLICIT_TYPE) {
87 parentType = smiGetParentType(smiType);
93 type = xstrdup(smiType->name);
99 static void fprintGroup(FILE *f, SmiNode *smiNode, char c,
100 int *typelen, int *namelen, int pass)
102 SmiElement *smiElement;
104 SmiModule *smiModule;
106 int tlen = 9, nlen = 9;
108 switch (smiNode->nodekind) {
109 case SMI_NODEKIND_GROUP:
110 for (smiElement = smiGetFirstElement(smiNode);
112 smiElement = smiGetNextElement(smiElement)) {
113 smiObject = smiGetElementNode(smiElement);
114 smiModule = smiGetNodeModule(smiNode);
115 type_name = getTypeName(smiObject);
118 int newlen = strlen(type_name);
119 tlen = (tlen < newlen) ? newlen : tlen;
121 if (smiObject->name) {
122 int newlen = strlen(smiObject->name);
123 nlen = (nlen < newlen) ? newlen : nlen;
125 } else if (pass == 2) {
126 fprintf(f, " %c%c%s %-*s %-*s (%s)\n",
127 getStatusChar(smiObject->status), c,
129 *typelen, type_name ? type_name : "-",
130 *namelen, smiObject->name, smiNode->name);
135 case SMI_NODEKIND_SCALAR:
136 case SMI_NODEKIND_COLUMN:
138 type_name = getTypeName(smiObject);
141 int newlen = strlen(type_name);
142 tlen = tlen < newlen ? newlen : tlen;
144 if (smiObject->name) {
145 int newlen = strlen(smiObject->name);
146 nlen = (nlen < newlen) ? newlen : nlen;
148 } else if (pass == 2) {
149 fprintf(f, " %c%c%s %-*s %s\n",
150 getStatusChar(smiObject->status), 'r',
152 *typelen, type_name ? type_name : "-",
162 if (typelen) *typelen = tlen;
163 if (namelen) *namelen = nlen;
169 static void fprintCompliance(FILE *f, SmiNode *smiNode,
170 int *typelen, int *namelen, int pass)
172 SmiElement *smiElement;
173 SmiOption *smiOption;
174 SmiRefinement *smiRefinement;
175 int tlen = 0, nlen = 0;
177 for (smiElement = smiGetFirstElement(smiNode);
179 smiElement = smiGetNextElement(smiElement)) {
180 fprintGroup(f, smiGetElementNode(smiElement), 'm',
181 (pass == 1) ? &tlen : typelen,
182 (pass == 1) ? &nlen : namelen, pass);
185 *typelen = *typelen < tlen ? tlen : *typelen;
188 *namelen = *namelen < nlen ? nlen : *namelen;
193 for(smiOption = smiGetFirstOption(smiNode);
195 smiOption = smiGetNextOption(smiOption)) {
196 fprintGroup(f, smiGetOptionNode(smiOption), 'c',
197 (pass == 1) ? &tlen : typelen,
198 (pass == 1) ? &nlen : namelen, pass);
201 *typelen = *typelen < tlen ? tlen : *typelen;
204 *namelen = *namelen < nlen ? nlen : *namelen;
209 for (smiRefinement = smiGetFirstRefinement(smiNode);
211 smiRefinement = smiGetNextRefinement(smiRefinement)) {
212 fprintGroup(f, smiGetRefinementNode(smiRefinement), 'r',
213 (pass == 1) ? &tlen : typelen,
214 (pass == 1) ? &nlen : namelen, pass);
217 *typelen = *typelen < tlen ? tlen : *typelen;
220 *namelen = *namelen < nlen ? nlen : *namelen;
228 static void fprintCompliances(FILE *f, SmiModule *smiModule)
231 int i, typelen = 0, namelen = 0;
233 for (i = 0, smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_COMPLIANCE);
235 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_COMPLIANCE), i++) {
236 fprintf(f, "%s%s:\n", i ? "\n" : "", smiNode->name);
237 fprintCompliance(f, smiNode, &typelen, &namelen, 1);
238 fprintCompliance(f, smiNode, &typelen, &namelen, 2);
245 dumpCompliances(int modc, SmiModule **modv, int flags, char *output)
251 f = fopen(output, "w");
253 fprintf(stderr, "smidump: cannot open %s for writing: ", output);
259 for (i = 0; i < modc; i++) {
260 if (! (flags & SMIDUMP_FLAG_SILENT)) {
261 fprintf(f, "# %s compliances (generated by smidump "
262 SMI_VERSION_STRING ")\n\n", modv[i]->name);
265 if (! (flags & SMIDUMP_FLAG_SILENT) && (flags & SMIDUMP_FLAG_ERROR)) {
266 fprintf(f, "# WARNING: this output may be incorrect due to "
267 "significant parse errors\n\n");
270 fprintCompliances(f, modv[i]);
273 if (fflush(f) || ferror(f)) {
274 perror("smidump: write error");
285 void initCompliances()
287 static SmidumpDriver driver = {
291 SMIDUMP_DRIVER_CANT_UNITE,
292 "compliances with all included objects / notifications",
297 smidumpRegisterDriver(&driver);