mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 00:06:59 +00:00
maint: coding style fixes
Remove unnecessary type casting, move .gitignore file contents to right location, reindent to use Linux coding style, fix few type mismatches, clean up to help & version output and hint compiler call to these functions will end program. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
68c2d7b8cc
commit
76915512b2
10 changed files with 148 additions and 189 deletions
169
src/output.c
169
src/output.c
|
|
@ -58,8 +58,7 @@ int output_txt(void)
|
|||
if (config.output_file[0]) {
|
||||
outfile = fopen(config.output_file, "w+");
|
||||
if (outfile == NULL) {
|
||||
err(EXIT_FAILURE, "output_txt: %s",
|
||||
config.output_file);
|
||||
err(EXIT_FAILURE, "output_txt: %s", config.output_file);
|
||||
}
|
||||
} else {
|
||||
outfile = stdout;
|
||||
|
|
@ -91,23 +90,24 @@ int output_txt(void)
|
|||
}
|
||||
fprintf(outfile, "%-16s", inet_ntoa(first));
|
||||
fprintf(outfile,
|
||||
" - %-16s %5"PRIu32" %5lu %10.3f %5lu %5lu %9.3f",
|
||||
" - %-16s %5" PRIu32
|
||||
" %5lu %10.3f %5lu %5lu %9.3f",
|
||||
inet_ntoa(last),
|
||||
range_p->last_ip - range_p->first_ip - 1,
|
||||
range_p->count,
|
||||
(float) (100 * range_p->count) /
|
||||
(float)(100 * range_p->count) /
|
||||
(range_p->last_ip - range_p->first_ip - 1),
|
||||
range_p->touched,
|
||||
range_p->touched + range_p->count,
|
||||
(float) (100 *
|
||||
(range_p->touched +
|
||||
range_p->count)) /
|
||||
(range_p->last_ip - range_p->first_ip -
|
||||
1));
|
||||
(float)(100 *
|
||||
(range_p->touched +
|
||||
range_p->count)) / (range_p->last_ip -
|
||||
range_p->first_ip -
|
||||
1));
|
||||
if (0 < num_backups) {
|
||||
fprintf(outfile, "%7lu %8.3f",
|
||||
range_p->backups,
|
||||
(float) (100 * range_p->backups) /
|
||||
(float)(100 * range_p->backups) /
|
||||
(range_p->last_ip -
|
||||
range_p->first_ip - 1));
|
||||
}
|
||||
|
|
@ -135,17 +135,17 @@ int output_txt(void)
|
|||
"%-20s %5lu %5lu %10.3f %7lu %6lu %9.3f",
|
||||
shared_p->name, shared_p->available,
|
||||
shared_p->used,
|
||||
(float) (100 * shared_p->used) /
|
||||
(float)(100 * shared_p->used) /
|
||||
shared_p->available, shared_p->touched,
|
||||
shared_p->touched + shared_p->used,
|
||||
(float) (100 *
|
||||
(shared_p->touched +
|
||||
shared_p->used)) /
|
||||
(float)(100 *
|
||||
(shared_p->touched +
|
||||
shared_p->used)) /
|
||||
shared_p->available);
|
||||
if (0 < num_backups) {
|
||||
fprintf(outfile, "%7lu %8.3f",
|
||||
shared_p->backups,
|
||||
(float) (100 * shared_p->backups) /
|
||||
(float)(100 * shared_p->backups) /
|
||||
shared_p->available);
|
||||
}
|
||||
|
||||
|
|
@ -171,19 +171,19 @@ int output_txt(void)
|
|||
shared_networks->name,
|
||||
shared_networks->available,
|
||||
shared_networks->used,
|
||||
(float) (100 * shared_networks->used) /
|
||||
(float)(100 * shared_networks->used) /
|
||||
shared_networks->available,
|
||||
shared_networks->touched,
|
||||
shared_networks->touched + shared_networks->used,
|
||||
(float) (100 *
|
||||
(shared_networks->touched +
|
||||
shared_networks->used)) /
|
||||
(float)(100 *
|
||||
(shared_networks->touched +
|
||||
shared_networks->used)) /
|
||||
shared_networks->available);
|
||||
|
||||
if (0 < num_backups) {
|
||||
fprintf(outfile, "%7lu %8.3f",
|
||||
shared_networks->backups,
|
||||
(float) (100 * shared_networks->backups) /
|
||||
(float)(100 * shared_networks->backups) /
|
||||
shared_networks->available);
|
||||
}
|
||||
fprintf(outfile, "\n");
|
||||
|
|
@ -216,8 +216,7 @@ int output_xml(void)
|
|||
if (config.output_file[0]) {
|
||||
outfile = fopen(config.output_file, "w+");
|
||||
if (outfile == NULL) {
|
||||
err(EXIT_FAILURE, "output_xml: %s",
|
||||
config.output_file);
|
||||
err(EXIT_FAILURE, "output_xml: %s", config.output_file);
|
||||
}
|
||||
} else {
|
||||
outfile = stdout;
|
||||
|
|
@ -247,17 +246,15 @@ int output_xml(void)
|
|||
"\t<location>%s</location>\n",
|
||||
range_p->shared_net->name);
|
||||
} else {
|
||||
fprintf(outfile,
|
||||
"\t<location></location>\n");
|
||||
fprintf(outfile, "\t<location></location>\n");
|
||||
}
|
||||
|
||||
fprintf(outfile, "\t<network></network>\n");
|
||||
fprintf(outfile, "\t<netmask></netmask>\n");
|
||||
fprintf(outfile, "\t<range>%s ", inet_ntoa(first));
|
||||
fprintf(outfile, "- %s</range>\n",
|
||||
inet_ntoa(last));
|
||||
fprintf(outfile, "- %s</range>\n", inet_ntoa(last));
|
||||
fprintf(outfile, "\t<gateway></gateway>\n");
|
||||
fprintf(outfile, "\t<defined>%"PRIu32"</defined>\n",
|
||||
fprintf(outfile, "\t<defined>%" PRIu32 "</defined>\n",
|
||||
range_p->last_ip - range_p->first_ip - 1);
|
||||
fprintf(outfile, "\t<used>%lu</used>\n",
|
||||
range_p->count);
|
||||
|
|
@ -291,11 +288,9 @@ int output_xml(void)
|
|||
shared_networks->name);
|
||||
fprintf(outfile, "\t<defined>%lu</defined>\n",
|
||||
shared_networks->available);
|
||||
fprintf(outfile, "\t<used>%lu</used>\n",
|
||||
shared_networks->used);
|
||||
fprintf(outfile, "\t<used>%lu</used>\n", shared_networks->used);
|
||||
fprintf(outfile, "\t<free>%lu</free>\n",
|
||||
shared_networks->available -
|
||||
shared_networks->used);
|
||||
shared_networks->available - shared_networks->used);
|
||||
fprintf(outfile, "</summary>\n");
|
||||
}
|
||||
|
||||
|
|
@ -317,8 +312,7 @@ int output_xml(void)
|
|||
|
||||
void html_header(FILE * f)
|
||||
{
|
||||
fprintf(f,
|
||||
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \n");
|
||||
fprintf(f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \n");
|
||||
fprintf(f, " \"http://www.w3.org/TR/html4/strict.dtd\">\n");
|
||||
fprintf(f, "<html>\n");
|
||||
fprintf(f, "<head>\n");
|
||||
|
|
@ -381,7 +375,7 @@ void html_footer(FILE * f)
|
|||
fprintf(f, "<hr>\n");
|
||||
fprintf(f, "<p class=created>\nData generated by ");
|
||||
fprintf(f, "<a href=\"%s\">", PACKAGE_URL);
|
||||
fprintf(f, "dhcpd-pools</a>.\n</p>\n");
|
||||
fprintf(f, "%s</a>.\n</p>\n", PACKAGE_NAME);
|
||||
fprintf(f, "<p class=updated>\n");
|
||||
fprintf(f, "<script type=\"text/javascript\">\n");
|
||||
fprintf(f, " document.write(\"Last Updated On \" + ");
|
||||
|
|
@ -419,7 +413,7 @@ void output_float(FILE * f, char *type, float fl)
|
|||
void table_start(FILE * f)
|
||||
{
|
||||
fprintf(f, "<table width=\"75%%\" ");
|
||||
fprintf(f, "class=\"dhcpd-pools\" ");
|
||||
fprintf(f, "class=\"%s\" ", PACKAGE_NAME);
|
||||
fprintf(f, "summary=\"ISC dhcpd pool usage report\">\n");
|
||||
}
|
||||
|
||||
|
|
@ -492,33 +486,29 @@ int output_html(void)
|
|||
output_line(outfile, "td", "calign",
|
||||
"not_defined");
|
||||
}
|
||||
output_line(outfile, "td", "calign",
|
||||
inet_ntoa(first));
|
||||
output_line(outfile, "td", "calign",
|
||||
inet_ntoa(last));
|
||||
output_line(outfile, "td", "calign", inet_ntoa(first));
|
||||
output_line(outfile, "td", "calign", inet_ntoa(last));
|
||||
output_long(outfile, "td",
|
||||
range_p->last_ip - range_p->first_ip -
|
||||
1);
|
||||
range_p->last_ip - range_p->first_ip - 1);
|
||||
output_long(outfile, "td", range_p->count);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 * range_p->count) /
|
||||
(float)(100 * range_p->count) /
|
||||
(range_p->last_ip -
|
||||
range_p->first_ip - 1));
|
||||
output_long(outfile, "td", range_p->touched);
|
||||
output_long(outfile, "td",
|
||||
range_p->touched + range_p->count);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 *
|
||||
(range_p->touched +
|
||||
range_p->count)) /
|
||||
(float)(100 *
|
||||
(range_p->touched +
|
||||
range_p->count)) /
|
||||
(range_p->last_ip -
|
||||
range_p->first_ip - 1));
|
||||
if (0 < num_backups) {
|
||||
output_long(outfile, "td",
|
||||
range_p->backups);
|
||||
output_long(outfile, "td", range_p->backups);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 *
|
||||
range_p->backups) /
|
||||
(float)(100 *
|
||||
range_p->backups) /
|
||||
(range_p->last_ip -
|
||||
range_p->first_ip - 1));
|
||||
}
|
||||
|
|
@ -548,27 +538,25 @@ int output_html(void)
|
|||
for (i = 0; i < num_shared_networks; i++) {
|
||||
shared_p++;
|
||||
newrow(outfile);
|
||||
output_line(outfile, "td", "calign",
|
||||
shared_p->name);
|
||||
output_line(outfile, "td", "calign", shared_p->name);
|
||||
output_long(outfile, "td", shared_p->available);
|
||||
output_long(outfile, "td", shared_p->used);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 * shared_p->used) /
|
||||
(float)(100 * shared_p->used) /
|
||||
shared_p->available);
|
||||
output_long(outfile, "td", shared_p->touched);
|
||||
output_long(outfile, "td",
|
||||
shared_p->touched + shared_p->used);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 *
|
||||
(shared_p->touched +
|
||||
shared_p->used)) /
|
||||
(float)(100 *
|
||||
(shared_p->touched +
|
||||
shared_p->used)) /
|
||||
shared_p->available);
|
||||
if (0 < num_backups) {
|
||||
output_long(outfile, "td",
|
||||
shared_p->backups);
|
||||
output_long(outfile, "td", shared_p->backups);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 *
|
||||
shared_p->backups) /
|
||||
(float)(100 *
|
||||
shared_p->backups) /
|
||||
shared_p->available);
|
||||
}
|
||||
|
||||
|
|
@ -594,28 +582,25 @@ int output_html(void)
|
|||
}
|
||||
if (config.output_limit[1] & output_limit_bit_3) {
|
||||
newrow(outfile);
|
||||
output_line(outfile, "td", "calign",
|
||||
shared_networks->name);
|
||||
output_line(outfile, "td", "calign", shared_networks->name);
|
||||
output_long(outfile, "td", shared_networks->available);
|
||||
output_long(outfile, "td", shared_networks->used);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 * shared_networks->used) /
|
||||
(float)(100 * shared_networks->used) /
|
||||
shared_networks->available);
|
||||
output_long(outfile, "td", shared_networks->touched);
|
||||
output_long(outfile, "td",
|
||||
shared_networks->touched +
|
||||
shared_networks->used);
|
||||
shared_networks->touched + shared_networks->used);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 *
|
||||
(shared_networks->touched +
|
||||
shared_networks->used)) /
|
||||
(float)(100 *
|
||||
(shared_networks->touched +
|
||||
shared_networks->used)) /
|
||||
shared_networks->available);
|
||||
if (0 < num_backups) {
|
||||
output_long(outfile, "td",
|
||||
shared_networks->backups);
|
||||
output_long(outfile, "td", shared_networks->backups);
|
||||
output_float(outfile, "td",
|
||||
(float) (100 *
|
||||
shared_networks->backups) /
|
||||
(float)(100 *
|
||||
shared_networks->backups) /
|
||||
shared_networks->available);
|
||||
}
|
||||
endrow(outfile);
|
||||
|
|
@ -649,8 +634,7 @@ int output_csv(void)
|
|||
if (config.output_file[0]) {
|
||||
outfile = fopen(config.output_file, "w+");
|
||||
if (outfile == NULL) {
|
||||
err(EXIT_FAILURE, "output_csv: %s",
|
||||
config.output_file);
|
||||
err(EXIT_FAILURE, "output_csv: %s", config.output_file);
|
||||
}
|
||||
} else {
|
||||
outfile = stdout;
|
||||
|
|
@ -680,23 +664,24 @@ int output_csv(void)
|
|||
}
|
||||
fprintf(outfile, "\"%s\",", inet_ntoa(first));
|
||||
fprintf(outfile,
|
||||
"\"%s\",\"%"PRIu32"\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
|
||||
"\"%s\",\"%" PRIu32
|
||||
"\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
|
||||
inet_ntoa(last),
|
||||
range_p->last_ip - range_p->first_ip - 1,
|
||||
range_p->count,
|
||||
(float) (100 * range_p->count) /
|
||||
(float)(100 * range_p->count) /
|
||||
(range_p->last_ip - range_p->first_ip - 1),
|
||||
range_p->touched,
|
||||
range_p->touched + range_p->count,
|
||||
(float) (100 *
|
||||
(range_p->touched +
|
||||
range_p->count)) /
|
||||
(range_p->last_ip - range_p->first_ip -
|
||||
1));
|
||||
(float)(100 *
|
||||
(range_p->touched +
|
||||
range_p->count)) / (range_p->last_ip -
|
||||
range_p->first_ip -
|
||||
1));
|
||||
if (0 < num_backups) {
|
||||
fprintf(outfile, ",\"%lu\",\"%.3f\"",
|
||||
range_p->backups,
|
||||
(float) (100 * range_p->backups) /
|
||||
(float)(100 * range_p->backups) /
|
||||
(range_p->last_ip -
|
||||
range_p->first_ip - 1));
|
||||
}
|
||||
|
|
@ -723,17 +708,17 @@ int output_csv(void)
|
|||
"\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
|
||||
shared_p->name, shared_p->available,
|
||||
shared_p->used,
|
||||
(float) (100 * shared_p->used) /
|
||||
(float)(100 * shared_p->used) /
|
||||
shared_p->available, shared_p->touched,
|
||||
shared_p->touched + shared_p->used,
|
||||
(float) (100 *
|
||||
(shared_p->touched +
|
||||
shared_p->used)) /
|
||||
(float)(100 *
|
||||
(shared_p->touched +
|
||||
shared_p->used)) /
|
||||
shared_p->available);
|
||||
if (0 < num_backups) {
|
||||
fprintf(outfile, ",\"%lu\",\"%.3f\"",
|
||||
shared_p->backups,
|
||||
(float) (100 * shared_p->backups) /
|
||||
(float)(100 * shared_p->backups) /
|
||||
shared_p->available);
|
||||
}
|
||||
|
||||
|
|
@ -756,18 +741,18 @@ int output_csv(void)
|
|||
"\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
|
||||
shared_networks->name, shared_networks->available,
|
||||
shared_networks->used,
|
||||
(float) (100 * shared_networks->used) /
|
||||
(float)(100 * shared_networks->used) /
|
||||
shared_networks->available,
|
||||
shared_networks->touched,
|
||||
shared_networks->touched + shared_networks->used,
|
||||
(float) (100 *
|
||||
(shared_networks->touched +
|
||||
shared_networks->used)) /
|
||||
(float)(100 *
|
||||
(shared_networks->touched +
|
||||
shared_networks->used)) /
|
||||
shared_networks->available);
|
||||
if (0 < num_backups) {
|
||||
fprintf(outfile, "%7lu %8.3f",
|
||||
shared_networks->backups,
|
||||
(float) (100 * shared_networks->backups) /
|
||||
(float)(100 * shared_networks->backups) /
|
||||
shared_networks->available);
|
||||
}
|
||||
fprintf(outfile, "\n");
|
||||
|
|
@ -777,13 +762,11 @@ int output_csv(void)
|
|||
if (ret) {
|
||||
warn("output_cvs: fflush");
|
||||
}
|
||||
|
||||
} else {
|
||||
ret = fclose(outfile);
|
||||
if (ret) {
|
||||
warn("output_cvs: fclose");
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue