1 /****************************************************************************
2 * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010
3 ****************************************************************************
4 * rrd_graph_helper.c commandline parser functions
5 * this code initially written by Alex van den Bogaerdt
6 ****************************************************************************/
10 #define dprintf if (gdp->debug) printf
14 * we use the following:
16 * i=0; sscanf(&line[*eaten], "what to find%n", variables, &i)
18 * Usually you want to find a separator as well. Example:
19 * i=0; sscanf(&line[*eaten], "%li:%n", &someint, &i)
21 * When the separator is not found, i is not set and thus remains zero.
22 * Another way would be to compare strlen() to i
24 * Why is this important? Because 12345abc should not be matched as
30 * "if ((gdp->vidx=find_var(im, l))!=-1)" is not good enough, at least
33 * A vname as a result of a VDEF is quite different from a vname
34 * resulting of a DEF or CDEF.
39 * A vname called "123" is not to be parsed as the number 123
43 /* Define prototypes for the parsing methods.
45 const char *const line - a fixed pointer to a fixed string
46 unsigned int *const eaten - a fixed pointer to a changing index in that line
47 graph_desc_t *const gdp - a fixed pointer to a changing graph description
48 image_desc_t *const im - a fixed pointer to a changing image description
51 int rrd_parse_find_gf(
65 int rrd_parse_textalign(
95 int rrd_parse_PVHLAST(
101 int rrd_parse_make_vname(
105 image_desc_t *const);
107 int rrd_parse_find_vname(
111 image_desc_t *const);
117 image_desc_t *const);
123 image_desc_t *const);
129 image_desc_t *const);
131 int rrd_parse_find_gf(
132 const char *const line,
133 unsigned int *const eaten,
134 graph_desc_t *const gdp)
136 char funcname[11], c1 = 0;
139 /* start an argument with DEBUG to be able to see how it is parsed */
140 sscanf(&line[*eaten], "DEBUG%n", &i);
145 dprintf("Scanning line '%s'\n", &line[*eaten]);
149 sscanf(&line[*eaten], "%10[A-Z]%n%c", funcname, &i, &c1);
151 rrd_set_error("Could not make sense out of '%s'", line);
155 if ((int) (gdp->gf = gf_conv(funcname)) == -1) {
156 rrd_set_error("'%s' is not a valid function name", funcname);
159 dprintf("- found function name '%s'\n", funcname);
163 rrd_set_error("Function %s needs parameters. Line: %s\n", funcname,
170 /* Some commands have a parameter before the colon
171 * (currently only LINE)
177 dprintf("- using default width of 1\n");
180 sscanf(&line[*eaten], "%lf:%n", &gdp->linewidth, &i);
182 rrd_set_error("Cannot parse line width '%s' in line '%s'\n",
183 &line[*eaten], line);
186 dprintf("- scanned width %f\n", gdp->linewidth);
187 if (isnan(gdp->linewidth)) {
189 ("LINE width '%s' is not a number in line '%s'\n",
190 &line[*eaten], line);
193 if (isinf(gdp->linewidth)) {
195 ("LINE width '%s' is out of range in line '%s'\n",
196 &line[*eaten], line);
199 if (gdp->linewidth < 0) {
201 ("LINE width '%s' is less than 0 in line '%s'\n",
202 &line[*eaten], line);
212 rrd_set_error("Malformed '%s' command in line '%s'\n", &line[*eaten],
216 if (line[*eaten] == '\0') {
217 rrd_set_error("Expected some arguments after '%s'\n", line);
223 int rrd_parse_legend(
224 const char *const line,
225 unsigned int *const eaten,
226 graph_desc_t *const gdp)
230 if (line[*eaten] == '\0' || line[*eaten] == ':') {
231 dprintf("- no (or: empty) legend found\n");
235 i = scan_for_col(&line[*eaten], FMT_LEG_LEN, gdp->legend);
239 if (line[*eaten] != '\0' && line[*eaten] != ':') {
240 rrd_set_error("Legend too long");
248 const char *const string,
249 graph_desc_t *const gdp)
251 unsigned int r = 0, g = 0, b = 0, a = 0, i;
253 /* matches the following formats:
261 while (string[i] && isxdigit((unsigned int) string[i]))
263 if (string[i] != '\0')
264 return 1; /* garbage follows hexdigits */
268 sscanf(string, "%1x%1x%1x%1x", &r, &g, &b, &a);
278 sscanf(string, "%02x%02x%02x%02x", &r, &g, &b, &a);
283 return 1; /* wrong number of digits */
285 gdp->col = gfx_hex_to_col(r << 24 | g << 16 | b << 8 | a);
290 const char *const line,
291 unsigned int *const eaten,
292 graph_desc_t *const gdp,
295 char symname[CF_NAM_SIZE];
298 sscanf(&line[*eaten], CF_NAM_FMT "%n", symname, &i);
299 if ((!i) || ((line[(*eaten) + i] != '\0') && (line[(*eaten) + i] != ':'))) {
300 rrd_set_error("Cannot parse CF in '%s'", line);
304 dprintf("- using CF '%s'\n", symname);
306 if ((int) (*cf = cf_conv(symname)) == -1) {
307 rrd_set_error("Unknown CF '%s' in '%s'", symname, line);
311 if (line[*eaten] != '\0')
316 /* Try to match next token as a vname.
319 * -1 an error occured and the error string is set
320 * other the vname index number
322 * *eaten is incremented only when a vname is found.
324 int rrd_parse_find_vname(
325 const char *const line,
326 unsigned int *const eaten,
327 graph_desc_t *const gdp,
328 image_desc_t *const im)
330 char tmpstr[MAX_VNAME_LEN + 1];
335 sscanf(&line[*eaten], DEF_NAM_FMT "%n", tmpstr, &i);
337 rrd_set_error("Could not parse line '%s'", line);
340 if (line[*eaten + i] != ':' && line[*eaten + i] != '\0') {
341 rrd_set_error("Could not parse line '%s'", line);
344 dprintf("- Considering '%s'\n", tmpstr);
346 if ((vidx = find_var(im, tmpstr)) < 0) {
347 dprintf("- Not a vname\n");
348 rrd_set_error("Not a valid vname: %s in line %s", tmpstr, line);
351 dprintf("- Found vname '%s' vidx '%li'\n", tmpstr, gdp->vidx);
352 if (line[*eaten + i] == ':')
358 /* Parsing old-style xPRINT and new-style xPRINT */
360 const char *const line,
361 unsigned int *const eaten,
362 graph_desc_t *const gdp,
363 image_desc_t *const im)
365 /* vname:CF:format in case of DEF-based vname
366 ** vname:CF:format in case of CDEF-based vname
367 ** vname:format[:strftime] in case of VDEF-based vname
369 if ((gdp->vidx = rrd_parse_find_vname(line, eaten, gdp, im)) < 0)
372 switch (im->gdes[gdp->vidx].gf) {
375 dprintf("- vname is of type DEF or CDEF, looking for CF\n");
376 if (rrd_parse_CF(line, eaten, gdp, &gdp->cf))
380 dprintf("- vname is of type VDEF\n");
383 rrd_set_error("Encountered unknown type variable '%s'",
384 im->gdes[gdp->vidx].vname);
388 if (rrd_parse_legend(line, eaten, gdp))
390 /* for *PRINT the legend itself gets rendered later. We only
391 get the format at this juncture */
392 strcpy(gdp->format, gdp->legend);
393 gdp->legend[0] = '\0';
394 /* this is a very crud test, parsing :style flags should be in a function */
395 if (im->gdes[gdp->vidx].gf == GF_VDEF
396 && strcmp(line + (*eaten), ":strftime") == 0) {
398 (*eaten) += strlen(":strftime");
403 /* SHIFT:_def_or_cdef:_vdef_or_number_
406 const char *const line,
407 unsigned int *const eaten,
408 graph_desc_t *const gdp,
409 image_desc_t *const im)
413 if ((gdp->vidx = rrd_parse_find_vname(line, eaten, gdp, im)) < 0)
416 switch (im->gdes[gdp->vidx].gf) {
419 dprintf("- vname is of type DEF or CDEF, OK\n");
422 rrd_set_error("Cannot shift a VDEF: '%s' in line '%s'\n",
423 im->gdes[gdp->vidx].vname, line);
426 rrd_set_error("Encountered unknown type variable '%s' in line '%s'",
427 im->gdes[gdp->vidx].vname, line);
431 if ((gdp->shidx = rrd_parse_find_vname(line, eaten, gdp, im)) >= 0) {
432 switch (im->gdes[gdp->shidx].gf) {
435 rrd_set_error("Offset cannot be a (C)DEF: '%s' in line '%s'\n",
436 im->gdes[gdp->shidx].vname, line);
439 dprintf("- vname is of type VDEF, OK\n");
443 ("Encountered unknown type variable '%s' in line '%s'",
444 im->gdes[gdp->vidx].vname, line);
452 sscanf(&line[*eaten], "%li%n", &time_tmp, &i);
453 gdp->shval = time_tmp;
454 if (i != (int) strlen(&line[*eaten])) {
455 rrd_set_error("Not a valid offset: %s in line %s", &line[*eaten],
460 dprintf("- offset is number %li\n", gdp->shval);
466 /* XPORT:_def_or_cdef[:legend]
469 const char *const line,
470 unsigned int *const eaten,
471 graph_desc_t *const gdp,
472 image_desc_t *const im)
474 if ((gdp->vidx = rrd_parse_find_vname(line, eaten, gdp, im)) < 0)
477 switch (im->gdes[gdp->vidx].gf) {
480 dprintf("- vname is of type DEF or CDEF, OK\n");
483 rrd_set_error("Cannot xport a VDEF: '%s' in line '%s'\n",
484 im->gdes[gdp->vidx].vname, line);
487 rrd_set_error("Encountered unknown type variable '%s' in line '%s'",
488 im->gdes[gdp->vidx].vname, line);
491 dprintf("- looking for legend in '%s'\n", &line[*eaten]);
492 if (rrd_parse_legend(line, eaten, gdp))
497 int rrd_parse_textalign(
498 const char *const line,
499 unsigned int *const eaten,
500 graph_desc_t *const gdp)
502 if (strcmp(&line[*eaten], "left") == 0) {
503 gdp->txtalign = TXA_LEFT;
504 } else if (strcmp(&line[*eaten], "right") == 0) {
505 gdp->txtalign = TXA_RIGHT;
506 } else if (strcmp(&line[*eaten], "justified") == 0) {
507 gdp->txtalign = TXA_JUSTIFIED;
508 } else if (strcmp(&line[*eaten], "center") == 0) {
509 gdp->txtalign = TXA_CENTER;
511 rrd_set_error("Unknown alignement type '%s'", &line[*eaten]);
514 *eaten += strlen(&line[*eaten]);
519 /* Parsing of VRULE, HRULE, LINE, AREA, STACK and TICK
520 ** is done in one function.
522 ** Stacking VRULE, HRULE or TICK is not allowed.
524 ** If a number (which is valid to enter) is more than a
525 ** certain amount of characters, it is caught as an error.
526 ** While this is arguable, so is entering fixed numbers
527 ** with more than MAX_VNAME_LEN significant digits.
529 int rrd_parse_PVHLAST(
530 const char *const line,
531 unsigned int *const eaten,
532 graph_desc_t *const gdp,
533 image_desc_t *const im)
537 char tmpstr[MAX_VNAME_LEN + 10]; /* vname#RRGGBBAA\0 */
538 static int spacecnt = 0;
541 float one_space = gfx_get_text_width(im, 0,
543 text_prop[TEXT_PROP_LEGEND].
545 im->tabwidth, " ") / 4.0;
546 float target_space = gfx_get_text_width(im, 0,
549 [TEXT_PROP_LEGEND].font_desc,
552 spacecnt = target_space / one_space;
553 dprintf("- spacecnt: %i onespace: %f targspace: %f\n", spacecnt,
554 one_space, target_space);
558 dprintf("- parsing '%s'\n", &line[*eaten]);
560 /* have simpler code in the drawing section */
561 if (gdp->gf == GF_STACK) {
565 i = scan_for_col(&line[*eaten], MAX_VNAME_LEN + 9, tmpstr);
566 if (line[*eaten + i] != '\0' && line[*eaten + i] != ':') {
567 rrd_set_error("Cannot parse line '%s'", line);
572 while (j > 0 && tmpstr[j] != '#')
574 //see if there is a second color
576 while (j2 > 0 && tmpstr[j2] != '#')
578 if (j && j2) { //yes, swap j and j2, so that j is first color, j2 is second
591 * tmpstr[0] containing vname
592 * tmpstr[j] if j!=0 then containing color
593 * tmpstr[j2] if j2!=0 then containing second color
595 * j if j!=0 then size of vname
596 * j2 if j2!=0 then size of vname + first color
600 * If it is an existing vname, that's OK, provided that it is a
601 * valid type (need time for VRULE, not a float)
602 * Else see if it parses as a number.
604 dprintf("- examining string '%s'\n", tmpstr);
605 if ((gdp->vidx = find_var(im, tmpstr)) >= 0) {
606 dprintf("- found vname: '%s' vidx %li\n", tmpstr, gdp->vidx);
610 if (im->gdes[gdp->vidx].gf != GF_VDEF) {
611 rrd_set_error("Using vname %s of wrong type in line %s\n",
612 im->gdes[gdp->gf].vname, line);
621 dprintf("- it is not an existing vname\n");
625 sscanf(tmpstr, "%li%n", &time_tmp, &k);
626 gdp->xrule = time_tmp;
627 if (((j != 0) && (k == j)) || ((j == 0) && (k == i))) {
628 dprintf("- found time: %li\n", gdp->xrule);
630 dprintf("- is is not a valid number: %li\n", gdp->xrule);
632 ("parameter '%s' does not represent time in line %s\n",
638 sscanf(tmpstr, "%lf%n", &gdp->yrule, &k);
639 if (((j != 0) && (k == j)) || ((j == 0) && (k == i))) {
640 dprintf("- found number: %lf\n", gdp->yrule);
642 dprintf("- is is not a valid number: %lf\n", gdp->yrule);
644 ("parameter '%s' does not represent a number in line %s\n",
653 dprintf("- examining color '%s'\n", &tmpstr[j]);
654 if (rrd_parse_color(&tmpstr[j], gdp)) {
655 rrd_set_error("Could not parse color in '%s'", &tmpstr[j]);
658 dprintf("- parsed color %0.0f,%0.0f,%0.0f,%0.0f\n", gdp->col.red,
659 gdp->col.green, gdp->col.blue, gdp->col.alpha);
661 if (j2) { //second color?
663 dprintf("- examining second color '%s'\n", &tmpstr[j2]);
664 //TODO: maybe rrd_parse_color should take a pointer to gdp->col instead of gdp
665 struct gfx_color_t firstcol = gdp->col;
666 if (rrd_parse_color(&tmpstr[j2], gdp)) {
667 rrd_set_error("Could not parse color in '%s'", &tmpstr[j2]);
670 dprintf("- parsed color %0.0f,%0.0f,%0.0f,%0.0f\n", gdp->col.red,
671 gdp->col.green, gdp->col.blue, gdp->col.alpha);
672 gdp->col2 = gdp->col;
674 //we now have a mandatory grid height
676 if (line[*eaten] != '\0') {
679 dprintf("- examining gradient height\n");
680 i = scan_for_col(&line[*eaten], MAX_VNAME_LEN + 9, tmpstr);
681 sscanf(tmpstr, "%lf%n", &gdp->gradheight, &j);
683 rrd_set_error("Could not parse gradient height in '%s'", tmpstr);
686 dprintf("- parsed gradientheight %0.0f\n", gdp->gradheight);
689 dprintf("- no color present in '%s'\n", tmpstr);
692 (*eaten) += i; /* after vname#color */
693 if (line[*eaten] != '\0') {
694 (*eaten)++; /* after colon */
697 if (gdp->gf == GF_TICK) {
698 dprintf("- parsing '%s'\n", &line[*eaten]);
699 dprintf("- looking for optional TICK number\n");
701 sscanf(&line[*eaten], "%lf%n", &gdp->yrule, &j);
703 if (line[*eaten + j] != '\0' && line[*eaten + j] != ':') {
704 rrd_set_error("Cannot parse TICK fraction '%s'", line);
707 dprintf("- found number %f\n", gdp->yrule);
708 if (gdp->yrule > 1.0 || gdp->yrule < -1.0) {
709 rrd_set_error("Tick factor should be <= 1.0");
714 dprintf("- not found, defaulting to 0.1\n");
717 if (line[*eaten] == '\0') {
718 dprintf("- done parsing line\n");
721 if (line[*eaten] == ':') {
724 rrd_set_error("Can't make sense of that TICK line");
730 dprintf("- parsing '%s'\n", &line[*eaten]);
732 /* Legend is next. A legend without a color is an error.
733 ** Stacking an item without having a legend is OK however
734 ** then an empty legend should be specified.
735 ** LINE:val#color:STACK means legend is string "STACK"
736 ** LINE:val#color::STACK means no legend, and do STACK
737 ** LINE:val:STACK is an error (legend but no color)
738 ** LINE:val::STACK means no legend, and do STACK
742 char *linecp = strdup(line);
744 dprintf("- looking for optional legend\n");
746 dprintf("- examining '%s'\n", &line[*eaten]);
747 if (linecp[*eaten] != '\0' && linecp[*eaten] != ':') {
750 /* If the legend is not empty, it has to be prefixed with spacecnt ' ' characters. This then gets
751 * replaced by the color box later on. */
752 for (spi = 0; spi < spacecnt && (*eaten) > 1; spi++) {
753 linecp[--(*eaten)] = ' ';
757 if (rrd_parse_legend(linecp, eaten, gdp))
763 dprintf("- found legend '%s'\n", &gdp->legend[2]);
765 dprintf("- skipping empty legend\n");
766 if (line[*eaten] != '\0' && line[*eaten] != ':') {
767 rrd_set_error("Legend set but no color: %s", &line[*eaten]);
771 if (line[*eaten] == '\0') {
772 dprintf("- done parsing line\n");
775 (*eaten)++; /* after colon */
777 /* HRULE, VRULE and TICK cannot be stacked. */
778 if ((gdp->gf != GF_HRULE)
779 && (gdp->gf != GF_VRULE)
780 && (gdp->gf != GF_TICK)) {
782 dprintf("- parsing '%s', looking for STACK\n", &line[*eaten]);
783 j = scan_for_col(&line[*eaten], 5, tmpstr);
784 if (!strcmp("STACK", tmpstr)) {
785 dprintf("- found STACK\n");
788 if (line[*eaten] == ':') {
790 } else if (line[*eaten] == '\0') {
791 dprintf("- done parsing line\n");
794 dprintf("- found %s instead of just STACK\n", &line[*eaten]);
795 rrd_set_error("STACK expected but %s found", &line[*eaten]);
799 dprintf("- not STACKing\n");
802 dprintf("- still more, should be dashes[=...]\n");
803 dprintf("- parsing '%s'\n", &line[*eaten]);
804 if (line[*eaten] != '\0') {
805 /* parse dash arguments here. Possible options:
807 - dashes=n_on[,n_off[,n_on,n_off]]
808 - dashes[=n_on[,n_off[,n_on,n_off]]]:dash-offset=offset
809 allowing 64 characters for definition of dash style */
810 j = scan_for_col(&line[*eaten], 64, tmpstr);
811 /* start with dashes */
812 if (strcmp(tmpstr, "dashes") == 0) {
813 /* if line was "dashes" or "dashes:dash-offset=xdashes="
814 tmpstr will be "dashes" */
815 dprintf("- found %s\n", tmpstr);
816 /* initialise all required variables we need for dashed lines
817 using default dash length of 5 pixels */
819 gdp->p_dashes = (double *) malloc(sizeof(double));
820 gdp->p_dashes[0] = 5;
824 } else if (sscanf(tmpstr, "dashes=%s", tmpstr)) {
825 /* dashes=n_on[,n_off[,n_on,n_off]] */
834 pch = strtok_r(tmpstr, ",", &saveptr);
835 while (pch != NULL) {
836 pch = strtok_r(NULL, ",", &saveptr);
839 dprintf("- %d dash value(s) found: ", count);
843 gdp->p_dashes = (double *) malloc(sizeof(double) * count);
844 pch = strtok_r(csv, ",", &saveptr);
846 while (pch != NULL) {
847 if (sscanf(pch, "%f", &dsh)) {
848 gdp->p_dashes[count] = (double) dsh;
849 dprintf("%.1f ", gdp->p_dashes[count]);
852 pch = strtok_r(NULL, ",", &saveptr);
856 dprintf("- syntax error. No dash lengths found!\n");
859 dprintf("- error: expected dashes[=...], found %s\n", tmpstr);
860 if (line[*eaten] == ':') {
862 } else if (line[*eaten] == '\0') {
863 dprintf("- done parsing line\n");
866 /* dashes[=n_on[,n_off[,n_on,n_off]]]:dash-offset=offset
867 allowing 16 characters for dash-offset=....
868 => 4 characters for the offset value */
869 j = scan_for_col(&line[*eaten], 16, tmpstr);
870 if (sscanf(tmpstr, "dash-offset=%lf", &gdp->offset)) {
871 dprintf("- found dash-offset=%.1f\n", gdp->offset);
874 if (line[*eaten] == ':')
877 if (line[*eaten] == '\0') {
878 dprintf("- done parsing line\n");
882 if (line[*eaten] == '\0') {
883 dprintf("- done parsing line\n");
887 dprintf("- parsing '%s'\n", &line[*eaten]);
892 int rrd_parse_make_vname(
893 const char *const line,
894 unsigned int *const eaten,
895 graph_desc_t *const gdp,
896 image_desc_t *const im)
898 char tmpstr[MAX_VNAME_LEN + 10];
901 sscanf(&line[*eaten], DEF_NAM_FMT "=%n", tmpstr, &i);
903 rrd_set_error("Cannot parse vname from '%s'", line);
906 if (line[*eaten+i] == '\0') {
907 rrd_set_error("String ends after the = sign on '%s'", line);
910 dprintf("- found candidate '%s'\n", tmpstr);
912 if ((gdp->vidx = find_var(im, tmpstr)) >= 0) {
913 rrd_set_error("Attempting to reuse '%s'", im->gdes[gdp->vidx].vname);
916 strcpy(gdp->vname, tmpstr);
917 dprintf("- created vname '%s' vidx %lu\n", gdp->vname, im->gdes_c - 1);
923 const char *const line,
924 unsigned int *const eaten,
925 graph_desc_t *const gdp,
926 image_desc_t *const im)
929 char command[7]; /* step, start, end, reduce */
931 rrd_time_value_t start_tv, end_tv;
932 time_t start_tmp = 0, end_tmp = 0;
933 char *parsetime_error = NULL;
935 start_tv.type = end_tv.type = ABSOLUTE_TIME;
936 start_tv.offset = end_tv.offset = 0;
937 localtime_r(&gdp->start, &start_tv.tm);
938 localtime_r(&gdp->end, &end_tv.tm);
940 dprintf("- parsing '%s'\n", &line[*eaten]);
941 dprintf("- from line '%s'\n", line);
943 if (rrd_parse_make_vname(line, eaten, gdp, im))
945 i = scan_for_col(&line[*eaten], sizeof(gdp->rrd) - 1, gdp->rrd);
946 if (line[*eaten + i] != ':') {
947 rrd_set_error("Problems reading database name");
951 dprintf("- using file '%s'\n", gdp->rrd);
954 sscanf(&line[*eaten], DS_NAM_FMT ":%n", gdp->ds_nam, &i);
956 rrd_set_error("Cannot parse DS in '%s'", line);
960 dprintf("- using DS '%s'\n", gdp->ds_nam);
962 if (rrd_parse_CF(line, eaten, gdp, &gdp->cf))
964 gdp->cf_reduce = gdp->cf;
966 if (line[*eaten] == '\0')
970 dprintf("- optional parameter follows: %s\n", &line[*eaten]);
972 sscanf(&line[*eaten], "%6[a-z]=%n", command, &i);
974 rrd_set_error("Parse error in '%s'", line);
978 dprintf("- processing '%s'\n", command);
979 if (!strcmp("reduce", command)) {
980 if (rrd_parse_CF(line, eaten, gdp, &gdp->cf_reduce))
982 if (line[*eaten] != '\0')
984 } else if (!strcmp("step", command)) {
986 sscanf(&line[*eaten], "%lu%n", &gdp->step, &i);
987 gdp->step_orig = gdp->step;
989 dprintf("- using step %lu\n", gdp->step);
990 } else if (!strcmp("start", command)) {
991 i = scan_for_col(&line[*eaten], 255, tmpstr);
993 if ((parsetime_error = rrd_parsetime(tmpstr, &start_tv))) {
994 rrd_set_error("start time: %s", parsetime_error);
997 dprintf("- done parsing: '%s'\n", &line[*eaten]);
998 } else if (!strcmp("end", command)) {
999 i = scan_for_col(&line[*eaten], 255, tmpstr);
1001 if ((parsetime_error = rrd_parsetime(tmpstr, &end_tv))) {
1002 rrd_set_error("end time: %s", parsetime_error);
1005 dprintf("- done parsing: '%s'\n", &line[*eaten]);
1006 } else if (!strcmp("daemon", command)) {
1007 i = scan_for_col(&line[*eaten],
1008 sizeof (gdp->daemon), gdp->daemon);
1010 dprintf("- using daemon '%s'\n", gdp->daemon);
1012 rrd_set_error("Parse error in '%s'", line);
1015 if (line[*eaten] == '\0')
1017 if (line[*eaten] != ':') {
1018 dprintf("- Expected to see end of string but got '%s'\n",
1020 rrd_set_error("Parse error in '%s'", line);
1025 if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
1026 /* error string is set in rrd_parsetime.c */
1029 if (start_tmp < 3600 * 24 * 365 * 10) {
1030 rrd_set_error("the first entry to fetch should be "
1031 "after 1980 (%ld)", start_tmp);
1035 if (end_tmp < start_tmp) {
1036 rrd_set_error("start (%ld) should be less than end (%ld)",
1037 start_tmp, end_tmp);
1041 gdp->start = start_tmp;
1043 gdp->start_orig = start_tmp;
1044 gdp->end_orig = end_tmp;
1046 dprintf("- start time %lu\n", gdp->start);
1047 dprintf("- end time %lu\n", gdp->end);
1053 const char *const line,
1054 unsigned int *const eaten,
1055 graph_desc_t *const gdp,
1056 image_desc_t *const im)
1058 char tmpstr[MAX_VNAME_LEN + 1]; /* vname\0 */
1061 dprintf("- parsing '%s'\n", &line[*eaten]);
1062 if (rrd_parse_make_vname(line, eaten, gdp, im))
1065 sscanf(&line[*eaten], DEF_NAM_FMT ",%n", tmpstr, &i);
1067 rrd_set_error("Cannot parse line '%s'", line);
1070 if ((gdp->vidx = find_var(im, tmpstr)) < 0) {
1071 rrd_set_error("Not a valid vname: %s in line %s", tmpstr, line);
1074 if (im->gdes[gdp->vidx].gf != GF_DEF && im->gdes[gdp->vidx].gf != GF_CDEF) {
1075 rrd_set_error("variable '%s' not DEF nor "
1076 "CDEF in VDEF '%s'", tmpstr, gdp->vname);
1079 dprintf("- found vname: '%s' vidx %li\n", tmpstr, gdp->vidx);
1082 dprintf("- calling vdef_parse with param '%s'\n", &line[*eaten]);
1083 vdef_parse(gdp, &line[*eaten]);
1084 while (line[*eaten] != '\0' && line[*eaten] != ':')
1091 const char *const line,
1092 unsigned int *const eaten,
1093 graph_desc_t *const gdp,
1094 image_desc_t *const im)
1096 dprintf("- parsing '%s'\n", &line[*eaten]);
1097 if (rrd_parse_make_vname(line, eaten, gdp, im))
1099 if ((gdp->rpnp = rpn_parse((void *) im, &line[*eaten], &find_var_wrapper)
1101 rrd_set_error("invalid rpn expression in: %s", &line[*eaten]);
1104 while (line[*eaten] != '\0' && line[*eaten] != ':')
1109 void rrd_graph_script(
1112 image_desc_t *const im,
1117 /* save state for STACK backward compat function */
1118 enum gf_en last_gf = GF_PRINT;
1119 float last_linewidth = 0.0;
1121 for (i = optind + optno; i < argc; i++) {
1123 unsigned int eaten = 0;
1126 return; /* the error string is already set */
1127 gdp = &im->gdes[im->gdes_c - 1];
1132 if (rrd_parse_find_gf(argv[i], &eaten, gdp))
1136 case GF_SHIFT: /* vname:value */
1137 if (rrd_parse_shift(argv[i], &eaten, gdp, im))
1140 case GF_TEXTALIGN: /* left|right|center|justified */
1141 if (rrd_parse_textalign(argv[i], &eaten, gdp))
1145 if (rrd_parse_xport(argv[i], &eaten, gdp, im))
1148 case GF_PRINT: /* vname:CF:format -or- vname:format */
1150 case GF_GPRINT: /* vname:CF:format -or- vname:format */
1151 if (rrd_parse_print(argv[i], &eaten, gdp, im))
1154 case GF_COMMENT: /* text */
1155 if (rrd_parse_legend(argv[i], &eaten, gdp))
1158 case GF_VRULE: /* value#color[:legend] */
1159 case GF_HRULE: /* value#color[:legend] */
1160 case GF_LINE: /* vname-or-value[#color[:legend]][:STACK] */
1161 case GF_AREA: /* vname-or-value[#color[:legend]][:STACK] */
1162 case GF_GRAD: /* vname-or-value[#color[:legend][#color[:gradientheight]]][:STACK] */
1163 case GF_TICK: /* vname#color[:num[:legend]] */
1164 if (rrd_parse_PVHLAST(argv[i], &eaten, gdp, im))
1167 last_linewidth = gdp->linewidth;
1169 case GF_STACK: /* vname-or-value[#color[:legend]] */
1170 if (rrd_parse_PVHLAST(argv[i], &eaten, gdp, im))
1172 if (last_gf == GF_LINE || last_gf == GF_AREA || last_gf == GF_GRAD) {
1174 gdp->linewidth = last_linewidth;
1176 rrd_set_error("STACK must follow LINE or AREA! command:\n%s",
1177 &argv[i][eaten], argv[i]);
1181 /* data acquisition */
1182 case GF_DEF: /* vname=x:DS:CF:[:step=#][:start=#][:end=#] */
1183 if (rrd_parse_def(argv[i], &eaten, gdp, im))
1186 case GF_CDEF: /* vname=rpn-expression */
1187 if (rrd_parse_cdef(argv[i], &eaten, gdp, im))
1190 case GF_VDEF: /* vname=rpn-expression */
1191 if (rrd_parse_vdef(argv[i], &eaten, gdp, im))
1196 dprintf("used %i out of %zi chars\n", eaten, strlen(argv[i]));
1197 dprintf("parsed line: '%s'\n", argv[i]);
1198 dprintf("remaining: '%s'\n", &argv[i][eaten]);
1199 if (eaten >= strlen(argv[i]))
1200 dprintf("Command finished successfully\n");
1202 if (eaten < strlen(argv[i])) {
1203 rrd_set_error("I don't understand '%s' in command: '%s'.",
1204 &argv[i][eaten], argv[i]);