mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 07:47:00 +00:00
output: save and reuse output helper results
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
d5ae2a80c0
commit
4fc4bcd083
1 changed files with 18 additions and 22 deletions
|
|
@ -54,6 +54,7 @@
|
|||
struct expl {
|
||||
struct range_t *range_p;
|
||||
struct shared_network_t *shnet_p;
|
||||
struct output_helper_t oh;
|
||||
int current;
|
||||
};
|
||||
|
||||
|
|
@ -73,7 +74,6 @@ static int must_put_range(void *closure, const char *name, int escape
|
|||
__attribute__ ((unused)), FILE *file)
|
||||
{
|
||||
struct expl *e = closure;
|
||||
struct output_helper_t oh;
|
||||
|
||||
if (!strcmp(name, "location")) {
|
||||
fprintf(file, "%s", e->range_p->shared_net->name);
|
||||
|
|
@ -100,25 +100,24 @@ static int must_put_range(void *closure, const char *name, int escape
|
|||
fprintf(file, "%g", e->range_p->touched);
|
||||
return 0;
|
||||
}
|
||||
range_output_helper(&oh, e->range_p);
|
||||
if (!strcmp(name, "defined")) {
|
||||
fprintf(file, "%g", oh.range_size);
|
||||
fprintf(file, "%g", e->oh.range_size);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "free")) {
|
||||
fprintf(file, "%g", oh.range_size - e->range_p->count);
|
||||
fprintf(file, "%g", e->oh.range_size - e->range_p->count);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "percent")) {
|
||||
fprintf(file, "%g", oh.percent);
|
||||
fprintf(file, "%g", e->oh.percent);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "touch_count")) {
|
||||
fprintf(file, "%g", oh.tc);
|
||||
fprintf(file, "%g", e->oh.tc);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "touch_percent")) {
|
||||
fprintf(file, "%g", oh.tcp);
|
||||
fprintf(file, "%g", e->oh.tcp);
|
||||
return 0;
|
||||
}
|
||||
if (config.backups_found == 1) {
|
||||
|
|
@ -127,12 +126,12 @@ static int must_put_range(void *closure, const char *name, int escape
|
|||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "backup_percent")) {
|
||||
fprintf(file, "%g", oh.bup);
|
||||
fprintf(file, "%g", e->oh.bup);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!strcmp(name, "status")) {
|
||||
fprintf(file, "%d", oh.status);
|
||||
fprintf(file, "%d", e->oh.status);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -142,7 +141,6 @@ static int must_put_shnet(void *closure, const char *name, int escape
|
|||
__attribute__ ((unused)), FILE *file)
|
||||
{
|
||||
struct expl *e = closure;
|
||||
struct output_helper_t oh;
|
||||
|
||||
if (!strcmp(name, "location")) {
|
||||
fprintf(file, "%s", e->shnet_p->name);
|
||||
|
|
@ -160,21 +158,20 @@ static int must_put_shnet(void *closure, const char *name, int escape
|
|||
fprintf(file, "%g", e->shnet_p->touched);
|
||||
return 0;
|
||||
}
|
||||
shnet_output_helper(&oh, e->shnet_p);
|
||||
if (!strcmp(name, "free")) {
|
||||
fprintf(file, "%g", e->shnet_p->available - e->shnet_p->used);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "percent")) {
|
||||
fprintf(file, "%g", oh.percent);
|
||||
fprintf(file, "%g", e->oh.percent);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "touch_count")) {
|
||||
fprintf(file, "%g", oh.tc);
|
||||
fprintf(file, "%g", e->oh.tc);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "touch_percent")) {
|
||||
fprintf(file, "%g", oh.tcp);
|
||||
fprintf(file, "%g", e->oh.tcp);
|
||||
return 0;
|
||||
}
|
||||
if (config.backups_found == 1) {
|
||||
|
|
@ -183,12 +180,12 @@ static int must_put_shnet(void *closure, const char *name, int escape
|
|||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "backup_percent")) {
|
||||
fprintf(file, "%g", oh.bup);
|
||||
fprintf(file, "%g", e->oh.bup);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!strcmp(name, "status")) {
|
||||
fprintf(file, "%d", oh.status);
|
||||
fprintf(file, "%d", e->oh.status);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -197,30 +194,28 @@ static int must_put_shnet(void *closure, const char *name, int escape
|
|||
static int must_next_range(void *closure)
|
||||
{
|
||||
struct expl *e = closure;
|
||||
struct output_helper_t oh;
|
||||
|
||||
do {
|
||||
e->range_p++;
|
||||
e->current--;
|
||||
if (e->current <= 0)
|
||||
return 0;
|
||||
range_output_helper(&oh, e->range_p);
|
||||
} while (config.skip_ok && oh.status == STATUS_OK);
|
||||
range_output_helper(&e->oh, e->range_p);
|
||||
} while (config.skip_ok && e->oh.status == STATUS_OK);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int must_next_shnet(void *closure)
|
||||
{
|
||||
struct expl *e = closure;
|
||||
struct output_helper_t oh;
|
||||
|
||||
do {
|
||||
e->shnet_p++;
|
||||
e->current--;
|
||||
if (e->current <= 0)
|
||||
return 0;
|
||||
shnet_output_helper(&oh, e->shnet_p);
|
||||
} while (config.skip_ok && oh.status == STATUS_OK);
|
||||
shnet_output_helper(&e->oh, e->shnet_p);
|
||||
} while (config.skip_ok && e->oh.status == STATUS_OK);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -248,6 +243,7 @@ static int must_enter(void *closure, const char *name)
|
|||
itf.put = must_put_shnet;
|
||||
itf.next = must_next_shnet;
|
||||
e->shnet_p = shared_networks;
|
||||
shnet_output_helper(&e->oh, e->shnet_p);
|
||||
e->current = 1;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue