Skip to content

Commit 27cbd4d

Browse files
committed
Change comments to conform to standard C (for code that may be built as part of DMF tools and somewhat out of common NUT setup)
1 parent 675c5ee commit 27cbd4d

5 files changed

Lines changed: 52 additions & 50 deletions

File tree

common/dmfsnmp.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ static void (*xml_push_handler)(ne_xml_parser*,
5151
static int (*xml_parse)(ne_xml_parser*, const char*, size_t);
5252
static void (*xml_destroy)(ne_xml_parser*);
5353

54-
// These used to be needed as extern vars by some legacy code elsewhere...
55-
// also they are referenced below, but I'm not sure it is valid code!
56-
// FIXME: Inspect codebase to see if these are at all needed (used to be in snmp-ups.c/h)
54+
/* These vars used to be needed as extern vars by some legacy code elsewhere...
55+
* also they are referenced below, but I'm not sure it is valid code!
56+
*/
57+
/* FIXME: Inspect codebase to see if these are at all needed (used to be in snmp-ups.{c,h}) */
5758
int input_phases, output_phases, bypass_phases;
5859

5960
#if WITH_DMF_LUA
@@ -738,7 +739,7 @@ mibdmf_parser_new()
738739
{
739740
mibdmf_parser_t *self = (mibdmf_parser_t *) calloc (1, sizeof (mibdmf_parser_t));
740741
assert (self);
741-
// Preallocate the sentinel in tables
742+
/* Preallocate the sentinel in tables */
742743
self->device_table_counter = 1;
743744
self->device_table = (snmp_device_id_t *)calloc(
744745
self->device_table_counter, sizeof(snmp_device_id_t));
@@ -1410,7 +1411,7 @@ mibdmf_parse_file(char *file_name, mibdmf_parser_t *dmp)
14101411
}
14111412
if(!dl_handle_libneon){
14121413
falg_libneon = 1;
1413-
if(load_neon_lib() == ERR) return ERR; // Errors printed by that loader
1414+
if(load_neon_lib() == ERR) return ERR; /* Errors printed by that loader */
14141415
}
14151416
ne_xml_parser *parser = xml_create ();
14161417
xml_push_handler (parser, xml_dict_start_cb,
@@ -1554,7 +1555,7 @@ mibdmf_parse_dir (char *dir_name, mibdmf_parser_t *dmp)
15541555
return ENOENT;
15551556
}
15561557
if(load_neon_lib() == ERR) {
1557-
// Note: do not "die" from the library context; that's up to the caller
1558+
/* Note: do not "die" from the library context; that's up to the caller */
15581559
upslogx(0, "ERROR: can't load Neon library");
15591560
return ERR;
15601561
}

common/str.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <limits.h>
2626
#include <stdlib.h>
2727
#include <string.h>
28-
#include <stdarg.h> // va_*
28+
#include <stdarg.h> /* get the va_* routines */
2929

3030
#include "str.h"
3131

@@ -618,19 +618,19 @@ char * str_concat(size_t count, ...)
618618
size_t i, len, null_pos;
619619
char* merged = NULL;
620620

621-
// Find required length to store merged string
621+
/* Find required length to store merged string */
622622
va_start(ap, count);
623-
len = 1; // room for '\0' in the end
623+
len = 1; /* room for '\0' in the end */
624624
for(i=0 ; i<count ; i++)
625625
len += strlen(va_arg(ap, char*));
626626
va_end(ap);
627627

628-
// Allocate memory to concat strings
628+
/* Allocate memory to concat strings */
629629
merged = (char*)calloc(len,sizeof(char));
630630
if (merged == NULL)
631631
return merged;
632632

633-
// Actually concatenate strings
633+
/* Actually concatenate strings */
634634
va_start(ap, count);
635635
null_pos = 0;
636636
for(i=0 ; i<count ; i++)

include/dmf.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// Compatibility layer for renamed file and may later become home for common
2-
// DMF-related constructs reusable for other applications than current SNMP one
1+
/* Compatibility layer for renamed file and may later become home for common
2+
* DMF-related constructs reusable for other applications than current SNMP one
3+
*/
34

45
/* dmf.h - Header for (TODO:dmf.c) - the Network UPS Tools XML-driver-loader
56
*

tools/nut-scanner/nut-scanner-reindex-dmfsnmp.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#endif
3333
#include "dmf.h"
3434

35-
// These strings are embedded into <nut> tags to show their schema version
36-
// Strings must verbatim match the XSD (no trailing slash etc.)
35+
/* These strings are embedded into <nut> tags to show their schema version */
36+
/* Strings must verbatim match the XSD (no trailing slash etc.) */
3737
#ifndef XSD_DMFNUTSCAN_VERSION
3838
#define XSD_DMFNUTSCAN_VERSION "1.0.0"
3939
#endif
@@ -62,10 +62,10 @@ int main(int argc, char *argv[])
6262
int opt_ret;
6363
int result = 0;
6464
int ret_code = EXIT_SUCCESS;
65-
int proceed_on_errors = 1; // By default, do as much as we can
66-
char *dir_name = NULL; // TODO: Make configurable the dir and/or list of files
65+
int proceed_on_errors = 1; /* By default, do as much as we can */
66+
char *dir_name = NULL; /* TODO: Make configurable the dir and/or list of files */
6767
int dir_name_dynamic = 0;
68-
// TODO: Consider DEFAULT_DMFNUTSCAN_DIR for automatic output mode into a file?
68+
/* TODO: Consider DEFAULT_DMFNUTSCAN_DIR for automatic output mode into a file? */
6969
#ifdef DEFAULT_DMFSNMP_DIR_OVERRIDE
7070
#ifdef DEFAULT_DMFSNMP_DIR
7171
#undef DEFAULT_DMFSNMP_DIR
@@ -79,8 +79,8 @@ int main(int argc, char *argv[])
7979
dir_name = "./";
8080
#endif
8181

82-
// TODO: Usage (help), Command-line args
83-
// option to append just a few (new) files to existing (large) index
82+
/* TODO: Usage (help), Command-line args */
83+
/* option to append just a few (new) files to existing (large) index */
8484

8585
while((opt_ret = getopt_long(argc, argv, optstring, longopts, NULL))!=-1) {
8686

@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
133133
mibdmf_parser_t * dmp = mibdmf_parser_new();
134134
if (!dmp) {
135135
fatalx(EXIT_FAILURE,"=== DMF-Reindex: FATAL: Can not allocate the DMF parsing structures\n");
136-
// TODO: Can we pass this code to fatalx?
136+
/* TODO: Can we pass this code to fatalx? */
137137
return ENOMEM;
138138
}
139139

@@ -142,35 +142,35 @@ int main(int argc, char *argv[])
142142
if ( (result != 0) &&
143143
(result == ERR || proceed_on_errors != 1)
144144
) {
145-
// TODO: Error-checking? Faults in some parses should be fatal or not?
145+
/* TODO: Error-checking? Faults in some parses should be fatal or not? */
146146
fatalx(EXIT_FAILURE,"=== DMF-Reindex: FATAL: Could not find or parse some files (return code %i)\n", result);
147-
// TODO: Can we pass this code to fatalx?
147+
/* TODO: Can we pass this code to fatalx? */
148148
return result;
149149
}
150150

151-
// Loop through discovered device_table and print it back as DMF markup
151+
/* Loop through discovered device_table and print it back as DMF markup */
152152
upsdebugx(2, "=== DMF-Reindex: Print DMF subset for snmp_device_table[]...\n\n");
153153

154154
snmp_device_id_t *devtab = mibdmf_get_device_table(dmp);
155155
if (!devtab)
156156
{
157157
fatalx(EXIT_FAILURE,"=== DMF-Reindex: FATAL: Can not access the parsed device_table\n");
158-
// TODO: Can we pass this code to fatalx?
158+
/* TODO: Can we pass this code to fatalx? */
159159
return ENOMEM;
160160
}
161161

162-
// Below we sprintf the index into a memory string, parse the result as
163-
// a DMF with a new alist and tables (to validate) and test the same data
164-
// is found. And only then output the stdout text.
165-
// TODO: uniquify output, so that an old index that was read in does not
166-
// pollute the parsed results (at least not for completely same items as
167-
// already exist in the table)? What to do about partial hits ~ updates?
162+
/* Below we sprintf the index into a memory string, parse the result as
163+
* a DMF with a new alist and tables (to validate) and test the same data
164+
* is found. And only then output the stdout text. */
165+
/* TODO: uniquify output, so that an old index that was read in does not
166+
* pollute the parsed results (at least not for completely same items as
167+
* already exist in the table)? What to do about partial hits ~ updates? */
168168
size_t i;
169169
size_t newdmf_len=0, newdmf_size=1024;
170170
char *newdmf = (char*)calloc(newdmf_size, sizeof(char));
171171
if (!newdmf) {
172172
fatalx(EXIT_FAILURE,"=== DMF-Reindex: FATAL: Can not allocate the buffer for parsed DMF\n");
173-
// TODO: Can we pass this code to fatalx?
173+
/* TODO: Can we pass this code to fatalx? */
174174
return ENOMEM;
175175
}
176176
newdmf_len += snprintf(newdmf + newdmf_len, (newdmf_size - newdmf_len),
@@ -181,14 +181,14 @@ int main(int argc, char *argv[])
181181
{
182182
upsdebugx(2,"[num=%zu (lenbefore=%zu)]", i, newdmf_len);
183183

184-
// ASSUMPTION: String increments would not exceed these few bytes
184+
/* ASSUMPTION: String increments would not exceed these few bytes */
185185
if ( (newdmf_size - newdmf_len) < 256)
186186
{
187187
newdmf_size += 1024;
188188
newdmf = (char*)realloc(newdmf, newdmf_size * sizeof(char));
189189
if (!newdmf) {
190190
fatalx(EXIT_FAILURE,"=== DMF-Reindex: FATAL: Can not extend the buffer for parsed DMF\n");
191-
// TODO: Can we pass this code to fatalx?
191+
/* TODO: Can we pass this code to fatalx? */
192192
return ENOMEM;
193193
}
194194
upsdebugx(2, "\nExtended the buffer to %zu bytes\n", newdmf_size);
@@ -197,17 +197,17 @@ int main(int argc, char *argv[])
197197
newdmf_len += snprintf(newdmf + newdmf_len, (newdmf_size - newdmf_len),
198198
"\t<mib2nut ");
199199

200-
// This attr is always present, even if as an empty string:
200+
/* This attr is always present, even if as an empty string: */
201201
newdmf_len += snprintf(newdmf + newdmf_len, (newdmf_size - newdmf_len),
202-
"auto_check=\"%s\" ", devtab[i].oid ? devtab[i].oid : ""); // [3 oid_auto_check] oid
202+
"auto_check=\"%s\" ", devtab[i].oid ? devtab[i].oid : ""); /* [3 oid_auto_check] oid */
203203

204204
if (devtab[i].mib != NULL)
205205
newdmf_len += snprintf(newdmf + newdmf_len, (newdmf_size - newdmf_len),
206-
"mib_name=\"%s\" ", devtab[i].mib); // [0 mib_name] mib
206+
"mib_name=\"%s\" ", devtab[i].mib); /* [0 mib_name] mib */
207207

208208
if (devtab[i].sysoid != NULL)
209209
newdmf_len += snprintf(newdmf + newdmf_len, (newdmf_size - newdmf_len),
210-
"oid=\"%s\" ", devtab[i].sysoid); // [5 sysOID] sysoid/NULL
210+
"oid=\"%s\" ", devtab[i].sysoid); /* [5 sysOID] sysoid/NULL */
211211

212212
newdmf_len += snprintf(newdmf + newdmf_len, (newdmf_size - newdmf_len),
213213
"/>\n");
@@ -221,37 +221,37 @@ int main(int argc, char *argv[])
221221
mibdmf_parser_t * newdmp = mibdmf_parser_new();
222222
if (!newdmp) {
223223
fatalx(EXIT_FAILURE,"=== DMF-Reindex: FATAL: Can not allocate the DMF verification parsing structures\n\n");
224-
// TODO: Can we pass this code to fatalx?
224+
/* TODO: Can we pass this code to fatalx? */
225225
return ENOMEM;
226226
}
227227

228228
upsdebugx(1, "=== DMF-Reindex: Loading DMF structures from prepared string (verification)\n\n");
229229
ret_code = mibdmf_parse_str(newdmf, newdmp);
230-
// Error checking for one (just made) document makes sense and is definite
230+
/* Error checking for one (just made) document makes sense and is definite */
231231
if ( result != 0 ) {
232232
fatalx(EXIT_FAILURE, "=== DMF-Reindex: The generated document FAILED syntax verification (return code %d)\n\n", ret_code);
233-
// TODO: Can we pass this code to fatalx?
233+
/* TODO: Can we pass this code to fatalx? */
234234
return ret_code;
235235
}
236236

237-
// Loop through reparsed device_table and compare to original one
237+
/* Loop through reparsed device_table and compare to original one */
238238
upsdebugx(1, "=== DMF-Reindex: Verify reparsed content for snmp_device_table[]...\n\n");
239239
snmp_device_id_t *newdevtab = mibdmf_get_device_table(newdmp);
240240
if (!newdevtab)
241241
{
242242
fatalx(EXIT_FAILURE,"=== DMF-Reindex: FATAL: Can not access the reparsed device_table\n");
243-
// TODO: Can we pass this code to fatalx?
243+
/* TODO: Can we pass this code to fatalx? */
244244
return ENOMEM;
245245
}
246246

247247
size_t j=-1, k=-1;
248248
result=0;
249-
// Make sure that all values we've considered are present in re-parse
249+
/* Make sure that all values we've considered are present in re-parse */
250250
for (k=0; devtab[k].oid != NULL || devtab[k].mib != NULL || devtab[k].sysoid != NULL ; k++)
251251
{
252252
int r = 0;
253253
for (j=0; newdevtab[j].oid != NULL || newdevtab[j].mib != NULL || newdevtab[j].sysoid != NULL ; j++)
254-
{ // Note: OID attribute may be empty or NULL, these are assumed equal
254+
{ /* Note: OID attribute may be empty or NULL, these are assumed equal */
255255
if ( (dmf_streq(newdevtab[j].oid, devtab[k].oid)
256256
||dmf_streq(newdevtab[j].oid, "")
257257
||dmf_streq(newdevtab[j].oid, NULL) )
@@ -287,7 +287,7 @@ int main(int argc, char *argv[])
287287
if ( result != 0 )
288288
{
289289
fatalx(EXIT_FAILURE,"=== DMF-Reindex: The generated document FAILED content verification (%d issues)\n\n", result);
290-
// TODO: Can we pass this code to fatalx?
290+
/* TODO: Can we pass this code to fatalx? */
291291
return result;
292292
}
293293

tools/nut-scanner/nutscan-snmp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#ifndef DEVSCAN_SNMP_H
2222
#define DEVSCAN_SNMP_H
2323

24-
#include <stddef.h> //define NULL
24+
#include <stddef.h> /*define NULL */
2525

2626
typedef struct {
2727
char * oid;
@@ -62,11 +62,11 @@ typedef struct {
6262
# ifndef LIBNUTSCAN_SNMP_DMF
6363
# ifdef DMF_SNMP_H
6464
# define LIBNUTSCAN_SNMP_DMF
65-
// Note: This requires types defined in "dmf.h"
66-
// Variable implemented in scan_snmp.c
65+
/* Note: This requires types defined in "dmf.h" */
66+
/* Variable implemented in scan_snmp.c */
6767
extern char *dmfnutscan_snmp_dir;
6868
extern mibdmf_parser_t *dmfnutscan_snmp_dmp;
69-
// Just reference this to NULLify when client quits and frees DMF stuff
69+
/* Just reference this to NULLify when client quits and frees DMF stuff */
7070
void uninit_snmp_device_table();
7171
# endif /* DMF_SNMP_H already included */
7272
# endif /* LIBNUTSCAN_SNMP_DMF */

0 commit comments

Comments
 (0)