diff options
Diffstat (limited to 'plugins/utils.c')
-rw-r--r-- | plugins/utils.c | 250 |
1 files changed, 153 insertions, 97 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index 09649429..41fe5fcf 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -89,41 +89,46 @@ bool is_numeric(char *number) { | |||
89 | char tmp[1]; | 89 | char tmp[1]; |
90 | float x; | 90 | float x; |
91 | 91 | ||
92 | if (!number) | 92 | if (!number) { |
93 | return false; | 93 | return false; |
94 | else if (sscanf(number, "%f%c", &x, tmp) == 1) | 94 | } else if (sscanf(number, "%f%c", &x, tmp) == 1) { |
95 | return true; | 95 | return true; |
96 | else | 96 | } else { |
97 | return false; | 97 | return false; |
98 | } | ||
98 | } | 99 | } |
99 | 100 | ||
100 | bool is_positive(char *number) { | 101 | bool is_positive(char *number) { |
101 | if (is_numeric(number) && atof(number) > 0.0) | 102 | if (is_numeric(number) && atof(number) > 0.0) { |
102 | return true; | 103 | return true; |
103 | else | 104 | } else { |
104 | return false; | 105 | return false; |
106 | } | ||
105 | } | 107 | } |
106 | 108 | ||
107 | bool is_negative(char *number) { | 109 | bool is_negative(char *number) { |
108 | if (is_numeric(number) && atof(number) < 0.0) | 110 | if (is_numeric(number) && atof(number) < 0.0) { |
109 | return true; | 111 | return true; |
110 | else | 112 | } else { |
111 | return false; | 113 | return false; |
114 | } | ||
112 | } | 115 | } |
113 | 116 | ||
114 | bool is_nonnegative(char *number) { | 117 | bool is_nonnegative(char *number) { |
115 | if (is_numeric(number) && atof(number) >= 0.0) | 118 | if (is_numeric(number) && atof(number) >= 0.0) { |
116 | return true; | 119 | return true; |
117 | else | 120 | } else { |
118 | return false; | 121 | return false; |
122 | } | ||
119 | } | 123 | } |
120 | 124 | ||
121 | bool is_percentage(char *number) { | 125 | bool is_percentage(char *number) { |
122 | int x; | 126 | int x; |
123 | if (is_numeric(number) && (x = atof(number)) >= 0 && x <= 100) | 127 | if (is_numeric(number) && (x = atof(number)) >= 0 && x <= 100) { |
124 | return true; | 128 | return true; |
125 | else | 129 | } else { |
126 | return false; | 130 | return false; |
131 | } | ||
127 | } | 132 | } |
128 | 133 | ||
129 | bool is_percentage_expression(const char str[]) { | 134 | bool is_percentage_expression(const char str[]) { |
@@ -156,36 +161,41 @@ bool is_percentage_expression(const char str[]) { | |||
156 | bool is_integer(char *number) { | 161 | bool is_integer(char *number) { |
157 | long int n; | 162 | long int n; |
158 | 163 | ||
159 | if (!number || (strspn(number, "-0123456789 ") != strlen(number))) | 164 | if (!number || (strspn(number, "-0123456789 ") != strlen(number))) { |
160 | return false; | 165 | return false; |
166 | } | ||
161 | 167 | ||
162 | n = strtol(number, NULL, 10); | 168 | n = strtol(number, NULL, 10); |
163 | 169 | ||
164 | if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX) | 170 | if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX) { |
165 | return true; | 171 | return true; |
166 | else | 172 | } else { |
167 | return false; | 173 | return false; |
174 | } | ||
168 | } | 175 | } |
169 | 176 | ||
170 | bool is_intpos(char *number) { | 177 | bool is_intpos(char *number) { |
171 | if (is_integer(number) && atoi(number) > 0) | 178 | if (is_integer(number) && atoi(number) > 0) { |
172 | return true; | 179 | return true; |
173 | else | 180 | } else { |
174 | return false; | 181 | return false; |
182 | } | ||
175 | } | 183 | } |
176 | 184 | ||
177 | bool is_intneg(char *number) { | 185 | bool is_intneg(char *number) { |
178 | if (is_integer(number) && atoi(number) < 0) | 186 | if (is_integer(number) && atoi(number) < 0) { |
179 | return true; | 187 | return true; |
180 | else | 188 | } else { |
181 | return false; | 189 | return false; |
190 | } | ||
182 | } | 191 | } |
183 | 192 | ||
184 | bool is_intnonneg(char *number) { | 193 | bool is_intnonneg(char *number) { |
185 | if (is_integer(number) && atoi(number) >= 0) | 194 | if (is_integer(number) && atoi(number) >= 0) { |
186 | return true; | 195 | return true; |
187 | else | 196 | } else { |
188 | return false; | 197 | return false; |
198 | } | ||
189 | } | 199 | } |
190 | 200 | ||
191 | /* | 201 | /* |
@@ -247,19 +257,21 @@ bool is_uint64(char *number, uint64_t *target) { | |||
247 | 257 | ||
248 | bool is_intpercent(char *number) { | 258 | bool is_intpercent(char *number) { |
249 | int i; | 259 | int i; |
250 | if (is_integer(number) && (i = atoi(number)) >= 0 && i <= 100) | 260 | if (is_integer(number) && (i = atoi(number)) >= 0 && i <= 100) { |
251 | return true; | 261 | return true; |
252 | else | 262 | } else { |
253 | return false; | 263 | return false; |
264 | } | ||
254 | } | 265 | } |
255 | 266 | ||
256 | bool is_option(char *str) { | 267 | bool is_option(char *str) { |
257 | if (!str) | 268 | if (!str) { |
258 | return false; | 269 | return false; |
259 | else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) | 270 | } else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) { |
260 | return true; | 271 | return true; |
261 | else | 272 | } else { |
262 | return false; | 273 | return false; |
274 | } | ||
263 | } | 275 | } |
264 | 276 | ||
265 | #ifdef NEED_GETTIMEOFDAY | 277 | #ifdef NEED_GETTIMEOFDAY |
@@ -273,7 +285,8 @@ double delta_time(struct timeval tv) { | |||
273 | struct timeval now; | 285 | struct timeval now; |
274 | 286 | ||
275 | gettimeofday(&now, NULL); | 287 | gettimeofday(&now, NULL); |
276 | return ((double)(now.tv_sec - tv.tv_sec) + (double)(now.tv_usec - tv.tv_usec) / (double)1000000); | 288 | return ((double)(now.tv_sec - tv.tv_sec) + |
289 | (double)(now.tv_usec - tv.tv_usec) / (double)1000000); | ||
277 | } | 290 | } |
278 | 291 | ||
279 | long deltime(struct timeval tv) { | 292 | long deltime(struct timeval tv) { |
@@ -288,10 +301,11 @@ void strip(char *buffer) { | |||
288 | 301 | ||
289 | for (x = strlen(buffer); x >= 1; x--) { | 302 | for (x = strlen(buffer); x >= 1; x--) { |
290 | i = x - 1; | 303 | i = x - 1; |
291 | if (buffer[i] == ' ' || buffer[i] == '\r' || buffer[i] == '\n' || buffer[i] == '\t') | 304 | if (buffer[i] == ' ' || buffer[i] == '\r' || buffer[i] == '\n' || buffer[i] == '\t') { |
292 | buffer[i] = '\0'; | 305 | buffer[i] = '\0'; |
293 | else | 306 | } else { |
294 | break; | 307 | break; |
308 | } | ||
295 | } | 309 | } |
296 | return; | 310 | return; |
297 | } | 311 | } |
@@ -309,8 +323,9 @@ void strip(char *buffer) { | |||
309 | *****************************************************************************/ | 323 | *****************************************************************************/ |
310 | 324 | ||
311 | char *strscpy(char *dest, const char *src) { | 325 | char *strscpy(char *dest, const char *src) { |
312 | if (src == NULL) | 326 | if (src == NULL) { |
313 | return NULL; | 327 | return NULL; |
328 | } | ||
314 | 329 | ||
315 | xasprintf(&dest, "%s", src); | 330 | xasprintf(&dest, "%s", src); |
316 | 331 | ||
@@ -369,17 +384,21 @@ char *strscpy(char *dest, const char *src) { | |||
369 | 384 | ||
370 | char *strnl(char *str) { | 385 | char *strnl(char *str) { |
371 | size_t len; | 386 | size_t len; |
372 | if (str == NULL) | 387 | if (str == NULL) { |
373 | return NULL; | 388 | return NULL; |
389 | } | ||
374 | str = strpbrk(str, "\r\n"); | 390 | str = strpbrk(str, "\r\n"); |
375 | if (str == NULL) | 391 | if (str == NULL) { |
376 | return NULL; | 392 | return NULL; |
393 | } | ||
377 | len = strspn(str, "\r\n"); | 394 | len = strspn(str, "\r\n"); |
378 | if (str[len] == '\0') | 395 | if (str[len] == '\0') { |
379 | return NULL; | 396 | return NULL; |
397 | } | ||
380 | str += len; | 398 | str += len; |
381 | if (strlen(str) == 0) | 399 | if (strlen(str) == 0) { |
382 | return NULL; | 400 | return NULL; |
401 | } | ||
383 | return str; | 402 | return str; |
384 | } | 403 | } |
385 | 404 | ||
@@ -402,15 +421,18 @@ char *strnl(char *str) { | |||
402 | char *strpcpy(char *dest, const char *src, const char *str) { | 421 | char *strpcpy(char *dest, const char *src, const char *str) { |
403 | size_t len; | 422 | size_t len; |
404 | 423 | ||
405 | if (src) | 424 | if (src) { |
406 | len = strcspn(src, str); | 425 | len = strcspn(src, str); |
407 | else | 426 | } else { |
408 | return NULL; | 427 | return NULL; |
428 | } | ||
409 | 429 | ||
410 | if (dest == NULL || strlen(dest) < len) | 430 | if (dest == NULL || strlen(dest) < len) { |
411 | dest = realloc(dest, len + 1); | 431 | dest = realloc(dest, len + 1); |
412 | if (dest == NULL) | 432 | } |
433 | if (dest == NULL) { | ||
413 | die(STATE_UNKNOWN, _("failed realloc in strpcpy\n")); | 434 | die(STATE_UNKNOWN, _("failed realloc in strpcpy\n")); |
435 | } | ||
414 | 436 | ||
415 | strncpy(dest, src, len); | 437 | strncpy(dest, src, len); |
416 | dest[len] = '\0'; | 438 | dest[len] = '\0'; |
@@ -434,10 +456,11 @@ char *strpcpy(char *dest, const char *src, const char *str) { | |||
434 | char *strpcat(char *dest, const char *src, const char *str) { | 456 | char *strpcat(char *dest, const char *src, const char *str) { |
435 | size_t len, l2; | 457 | size_t len, l2; |
436 | 458 | ||
437 | if (dest) | 459 | if (dest) { |
438 | len = strlen(dest); | 460 | len = strlen(dest); |
439 | else | 461 | } else { |
440 | len = 0; | 462 | len = 0; |
463 | } | ||
441 | 464 | ||
442 | if (src) { | 465 | if (src) { |
443 | l2 = strcspn(src, str); | 466 | l2 = strcspn(src, str); |
@@ -446,8 +469,9 @@ char *strpcat(char *dest, const char *src, const char *str) { | |||
446 | } | 469 | } |
447 | 470 | ||
448 | dest = realloc(dest, len + l2 + 1); | 471 | dest = realloc(dest, len + l2 + 1); |
449 | if (dest == NULL) | 472 | if (dest == NULL) { |
450 | die(STATE_UNKNOWN, _("failed malloc in strscat\n")); | 473 | die(STATE_UNKNOWN, _("failed malloc in strscat\n")); |
474 | } | ||
451 | 475 | ||
452 | strncpy(dest + len, src, l2); | 476 | strncpy(dest + len, src, l2); |
453 | dest[len + l2] = '\0'; | 477 | dest[len + l2] = '\0'; |
@@ -463,8 +487,9 @@ char *strpcat(char *dest, const char *src, const char *str) { | |||
463 | 487 | ||
464 | int xvasprintf(char **strp, const char *fmt, va_list ap) { | 488 | int xvasprintf(char **strp, const char *fmt, va_list ap) { |
465 | int result = vasprintf(strp, fmt, ap); | 489 | int result = vasprintf(strp, fmt, ap); |
466 | if (result == -1 || *strp == NULL) | 490 | if (result == -1 || *strp == NULL) { |
467 | die(STATE_UNKNOWN, _("failed malloc in xvasprintf\n")); | 491 | die(STATE_UNKNOWN, _("failed malloc in xvasprintf\n")); |
492 | } | ||
468 | return result; | 493 | return result; |
469 | } | 494 | } |
470 | 495 | ||
@@ -483,126 +508,147 @@ int xasprintf(char **strp, const char *fmt, ...) { | |||
483 | * | 508 | * |
484 | ******************************************************************************/ | 509 | ******************************************************************************/ |
485 | 510 | ||
486 | char *perfdata(const char *label, long int val, const char *uom, int warnp, long int warn, int critp, long int crit, int minp, | 511 | char *perfdata(const char *label, long int val, const char *uom, bool warnp, long int warn, |
487 | long int minv, int maxp, long int maxv) { | 512 | bool critp, long int crit, bool minp, long int minv, bool maxp, long int maxv) { |
488 | char *data = NULL; | 513 | char *data = NULL; |
489 | 514 | ||
490 | if (strpbrk(label, "'= ")) | 515 | if (strpbrk(label, "'= ")) { |
491 | xasprintf(&data, "'%s'=%ld%s;", label, val, uom); | 516 | xasprintf(&data, "'%s'=%ld%s;", label, val, uom); |
492 | else | 517 | } else { |
493 | xasprintf(&data, "%s=%ld%s;", label, val, uom); | 518 | xasprintf(&data, "%s=%ld%s;", label, val, uom); |
519 | } | ||
494 | 520 | ||
495 | if (warnp) | 521 | if (warnp) { |
496 | xasprintf(&data, "%s%ld;", data, warn); | 522 | xasprintf(&data, "%s%ld;", data, warn); |
497 | else | 523 | } else { |
498 | xasprintf(&data, "%s;", data); | 524 | xasprintf(&data, "%s;", data); |
525 | } | ||
499 | 526 | ||
500 | if (critp) | 527 | if (critp) { |
501 | xasprintf(&data, "%s%ld;", data, crit); | 528 | xasprintf(&data, "%s%ld;", data, crit); |
502 | else | 529 | } else { |
503 | xasprintf(&data, "%s;", data); | 530 | xasprintf(&data, "%s;", data); |
531 | } | ||
504 | 532 | ||
505 | if (minp) | 533 | if (minp) { |
506 | xasprintf(&data, "%s%ld;", data, minv); | 534 | xasprintf(&data, "%s%ld;", data, minv); |
507 | else | 535 | } else { |
508 | xasprintf(&data, "%s;", data); | 536 | xasprintf(&data, "%s;", data); |
537 | } | ||
509 | 538 | ||
510 | if (maxp) | 539 | if (maxp) { |
511 | xasprintf(&data, "%s%ld", data, maxv); | 540 | xasprintf(&data, "%s%ld", data, maxv); |
541 | } | ||
512 | 542 | ||
513 | return data; | 543 | return data; |
514 | } | 544 | } |
515 | 545 | ||
516 | char *perfdata_uint64(const char *label, uint64_t val, const char *uom, int warnp, /* Warning present */ | 546 | char *perfdata_uint64(const char *label, uint64_t val, const char *uom, |
517 | uint64_t warn, int critp, /* Critical present */ | 547 | bool warnp, /* Warning present */ |
518 | uint64_t crit, int minp, /* Minimum present */ | 548 | uint64_t warn, bool critp, /* Critical present */ |
519 | uint64_t minv, int maxp, /* Maximum present */ | 549 | uint64_t crit, bool minp, /* Minimum present */ |
550 | uint64_t minv, bool maxp, /* Maximum present */ | ||
520 | uint64_t maxv) { | 551 | uint64_t maxv) { |
521 | char *data = NULL; | 552 | char *data = NULL; |
522 | 553 | ||
523 | if (strpbrk(label, "'= ")) | 554 | if (strpbrk(label, "'= ")) { |
524 | xasprintf(&data, "'%s'=%" PRIu64 "%s;", label, val, uom); | 555 | xasprintf(&data, "'%s'=%" PRIu64 "%s;", label, val, uom); |
525 | else | 556 | } else { |
526 | xasprintf(&data, "%s=%" PRIu64 "%s;", label, val, uom); | 557 | xasprintf(&data, "%s=%" PRIu64 "%s;", label, val, uom); |
558 | } | ||
527 | 559 | ||
528 | if (warnp) | 560 | if (warnp) { |
529 | xasprintf(&data, "%s%" PRIu64 ";", data, warn); | 561 | xasprintf(&data, "%s%" PRIu64 ";", data, warn); |
530 | else | 562 | } else { |
531 | xasprintf(&data, "%s;", data); | 563 | xasprintf(&data, "%s;", data); |
564 | } | ||
532 | 565 | ||
533 | if (critp) | 566 | if (critp) { |
534 | xasprintf(&data, "%s%" PRIu64 ";", data, crit); | 567 | xasprintf(&data, "%s%" PRIu64 ";", data, crit); |
535 | else | 568 | } else { |
536 | xasprintf(&data, "%s;", data); | 569 | xasprintf(&data, "%s;", data); |
570 | } | ||
537 | 571 | ||
538 | if (minp) | 572 | if (minp) { |
539 | xasprintf(&data, "%s%" PRIu64 ";", data, minv); | 573 | xasprintf(&data, "%s%" PRIu64 ";", data, minv); |
540 | else | 574 | } else { |
541 | xasprintf(&data, "%s;", data); | 575 | xasprintf(&data, "%s;", data); |
576 | } | ||
542 | 577 | ||
543 | if (maxp) | 578 | if (maxp) { |
544 | xasprintf(&data, "%s%" PRIu64, data, maxv); | 579 | xasprintf(&data, "%s%" PRIu64, data, maxv); |
580 | } | ||
545 | 581 | ||
546 | return data; | 582 | return data; |
547 | } | 583 | } |
548 | 584 | ||
549 | char *perfdata_int64(const char *label, int64_t val, const char *uom, int warnp, /* Warning present */ | 585 | char *perfdata_int64(const char *label, int64_t val, const char *uom, |
550 | int64_t warn, int critp, /* Critical present */ | 586 | bool warnp, /* Warning present */ |
551 | int64_t crit, int minp, /* Minimum present */ | 587 | int64_t warn, bool critp, /* Critical present */ |
552 | int64_t minv, int maxp, /* Maximum present */ | 588 | int64_t crit, bool minp, /* Minimum present */ |
589 | int64_t minv, bool maxp, /* Maximum present */ | ||
553 | int64_t maxv) { | 590 | int64_t maxv) { |
554 | char *data = NULL; | 591 | char *data = NULL; |
555 | 592 | ||
556 | if (strpbrk(label, "'= ")) | 593 | if (strpbrk(label, "'= ")) { |
557 | xasprintf(&data, "'%s'=%" PRId64 "%s;", label, val, uom); | 594 | xasprintf(&data, "'%s'=%" PRId64 "%s;", label, val, uom); |
558 | else | 595 | } else { |
559 | xasprintf(&data, "%s=%" PRId64 "%s;", label, val, uom); | 596 | xasprintf(&data, "%s=%" PRId64 "%s;", label, val, uom); |
597 | } | ||
560 | 598 | ||
561 | if (warnp) | 599 | if (warnp) { |
562 | xasprintf(&data, "%s%" PRId64 ";", data, warn); | 600 | xasprintf(&data, "%s%" PRId64 ";", data, warn); |
563 | else | 601 | } else { |
564 | xasprintf(&data, "%s;", data); | 602 | xasprintf(&data, "%s;", data); |
603 | } | ||
565 | 604 | ||
566 | if (critp) | 605 | if (critp) { |
567 | xasprintf(&data, "%s%" PRId64 ";", data, crit); | 606 | xasprintf(&data, "%s%" PRId64 ";", data, crit); |
568 | else | 607 | } else { |
569 | xasprintf(&data, "%s;", data); | 608 | xasprintf(&data, "%s;", data); |
609 | } | ||
570 | 610 | ||
571 | if (minp) | 611 | if (minp) { |
572 | xasprintf(&data, "%s%" PRId64 ";", data, minv); | 612 | xasprintf(&data, "%s%" PRId64 ";", data, minv); |
573 | else | 613 | } else { |
574 | xasprintf(&data, "%s;", data); | 614 | xasprintf(&data, "%s;", data); |
615 | } | ||
575 | 616 | ||
576 | if (maxp) | 617 | if (maxp) { |
577 | xasprintf(&data, "%s%" PRId64, data, maxv); | 618 | xasprintf(&data, "%s%" PRId64, data, maxv); |
619 | } | ||
578 | 620 | ||
579 | return data; | 621 | return data; |
580 | } | 622 | } |
581 | 623 | ||
582 | char *fperfdata(const char *label, double val, const char *uom, int warnp, double warn, int critp, double crit, int minp, double minv, | 624 | char *fperfdata(const char *label, double val, const char *uom, bool warnp, double warn, bool critp, |
583 | int maxp, double maxv) { | 625 | double crit, bool minp, double minv, bool maxp, double maxv) { |
584 | char *data = NULL; | 626 | char *data = NULL; |
585 | 627 | ||
586 | if (strpbrk(label, "'= ")) | 628 | if (strpbrk(label, "'= ")) { |
587 | xasprintf(&data, "'%s'=", label); | 629 | xasprintf(&data, "'%s'=", label); |
588 | else | 630 | } else { |
589 | xasprintf(&data, "%s=", label); | 631 | xasprintf(&data, "%s=", label); |
632 | } | ||
590 | 633 | ||
591 | xasprintf(&data, "%s%f", data, val); | 634 | xasprintf(&data, "%s%f", data, val); |
592 | xasprintf(&data, "%s%s;", data, uom); | 635 | xasprintf(&data, "%s%s;", data, uom); |
593 | 636 | ||
594 | if (warnp) | 637 | if (warnp) { |
595 | xasprintf(&data, "%s%f", data, warn); | 638 | xasprintf(&data, "%s%f", data, warn); |
639 | } | ||
596 | 640 | ||
597 | xasprintf(&data, "%s;", data); | 641 | xasprintf(&data, "%s;", data); |
598 | 642 | ||
599 | if (critp) | 643 | if (critp) { |
600 | xasprintf(&data, "%s%f", data, crit); | 644 | xasprintf(&data, "%s%f", data, crit); |
645 | } | ||
601 | 646 | ||
602 | xasprintf(&data, "%s;", data); | 647 | xasprintf(&data, "%s;", data); |
603 | 648 | ||
604 | if (minp) | 649 | if (minp) { |
605 | xasprintf(&data, "%s%f", data, minv); | 650 | xasprintf(&data, "%s%f", data, minv); |
651 | } | ||
606 | 652 | ||
607 | if (maxp) { | 653 | if (maxp) { |
608 | xasprintf(&data, "%s;", data); | 654 | xasprintf(&data, "%s;", data); |
@@ -612,28 +658,33 @@ char *fperfdata(const char *label, double val, const char *uom, int warnp, doubl | |||
612 | return data; | 658 | return data; |
613 | } | 659 | } |
614 | 660 | ||
615 | char *sperfdata(const char *label, double val, const char *uom, char *warn, char *crit, int minp, double minv, int maxp, double maxv) { | 661 | char *sperfdata(const char *label, double val, const char *uom, char *warn, char *crit, bool minp, |
662 | double minv, bool maxp, double maxv) { | ||
616 | char *data = NULL; | 663 | char *data = NULL; |
617 | if (strpbrk(label, "'= ")) | 664 | if (strpbrk(label, "'= ")) { |
618 | xasprintf(&data, "'%s'=", label); | 665 | xasprintf(&data, "'%s'=", label); |
619 | else | 666 | } else { |
620 | xasprintf(&data, "%s=", label); | 667 | xasprintf(&data, "%s=", label); |
668 | } | ||
621 | 669 | ||
622 | xasprintf(&data, "%s%f", data, val); | 670 | xasprintf(&data, "%s%f", data, val); |
623 | xasprintf(&data, "%s%s;", data, uom); | 671 | xasprintf(&data, "%s%s;", data, uom); |
624 | 672 | ||
625 | if (warn != NULL) | 673 | if (warn != NULL) { |
626 | xasprintf(&data, "%s%s", data, warn); | 674 | xasprintf(&data, "%s%s", data, warn); |
675 | } | ||
627 | 676 | ||
628 | xasprintf(&data, "%s;", data); | 677 | xasprintf(&data, "%s;", data); |
629 | 678 | ||
630 | if (crit != NULL) | 679 | if (crit != NULL) { |
631 | xasprintf(&data, "%s%s", data, crit); | 680 | xasprintf(&data, "%s%s", data, crit); |
681 | } | ||
632 | 682 | ||
633 | xasprintf(&data, "%s;", data); | 683 | xasprintf(&data, "%s;", data); |
634 | 684 | ||
635 | if (minp) | 685 | if (minp) { |
636 | xasprintf(&data, "%s%f", data, minv); | 686 | xasprintf(&data, "%s%f", data, minv); |
687 | } | ||
637 | 688 | ||
638 | if (maxp) { | 689 | if (maxp) { |
639 | xasprintf(&data, "%s;", data); | 690 | xasprintf(&data, "%s;", data); |
@@ -643,28 +694,33 @@ char *sperfdata(const char *label, double val, const char *uom, char *warn, char | |||
643 | return data; | 694 | return data; |
644 | } | 695 | } |
645 | 696 | ||
646 | char *sperfdata_int(const char *label, int val, const char *uom, char *warn, char *crit, int minp, int minv, int maxp, int maxv) { | 697 | char *sperfdata_int(const char *label, int val, const char *uom, char *warn, char *crit, bool minp, |
698 | int minv, bool maxp, int maxv) { | ||
647 | char *data = NULL; | 699 | char *data = NULL; |
648 | if (strpbrk(label, "'= ")) | 700 | if (strpbrk(label, "'= ")) { |
649 | xasprintf(&data, "'%s'=", label); | 701 | xasprintf(&data, "'%s'=", label); |
650 | else | 702 | } else { |
651 | xasprintf(&data, "%s=", label); | 703 | xasprintf(&data, "%s=", label); |
704 | } | ||
652 | 705 | ||
653 | xasprintf(&data, "%s%d", data, val); | 706 | xasprintf(&data, "%s%d", data, val); |
654 | xasprintf(&data, "%s%s;", data, uom); | 707 | xasprintf(&data, "%s%s;", data, uom); |
655 | 708 | ||
656 | if (warn != NULL) | 709 | if (warn != NULL) { |
657 | xasprintf(&data, "%s%s", data, warn); | 710 | xasprintf(&data, "%s%s", data, warn); |
711 | } | ||
658 | 712 | ||
659 | xasprintf(&data, "%s;", data); | 713 | xasprintf(&data, "%s;", data); |
660 | 714 | ||
661 | if (crit != NULL) | 715 | if (crit != NULL) { |
662 | xasprintf(&data, "%s%s", data, crit); | 716 | xasprintf(&data, "%s%s", data, crit); |
717 | } | ||
663 | 718 | ||
664 | xasprintf(&data, "%s;", data); | 719 | xasprintf(&data, "%s;", data); |
665 | 720 | ||
666 | if (minp) | 721 | if (minp) { |
667 | xasprintf(&data, "%s%d", data, minv); | 722 | xasprintf(&data, "%s%d", data, minv); |
723 | } | ||
668 | 724 | ||
669 | if (maxp) { | 725 | if (maxp) { |
670 | xasprintf(&data, "%s;", data); | 726 | xasprintf(&data, "%s;", data); |