d325bf0ae538f6dd45799a2804b65bcc8abdbc3d
1 /**********************************************************
2 *** Several generic helper functions for rrd_graph.c ***
3 **********************************************************/
5 #include "rrd_graph.h"
6 #include "rrd_graph_helper.h"
8 /**********************************************************
9 *** Helper functions for parsing command file ***
10 **********************************************************/
12 /* Parse a VNAME followed by an equal sign ( CDEF:VNAME= )
13 *
14 * Input: pointer to argv
15 * Input: pointer to im structure
16 * Input: pointer to error string
17 * Output: number of chars eaten (0 means error)
18 *
19 * Usage: n=parse_vname( &argv[i][argstart],&im, "VDEF");
20 * if (n==0) { error } else { argstart+=n };
21 */
22 int
23 parse_vname1(cptr,im,err)
24 char * cptr;
25 image_desc_t * im;
26 char * err;
27 {
28 int n=0,vidx;
30 sscanf(cptr, DEF_NAM_FMT "=%n",im->gdes[im->gdes_c-1].vname,&n);
32 /* Check if the sequence matches, including the
33 * terminating equal sign */
34 if (n==0) {
35 im_free(im);
36 rrd_set_error("Can't parse VNAME in %s: '%s'",err,cptr);
37 return 0;
38 }
40 /* Check if this is an unused variable */
41 vidx=find_var(im,im->gdes[im->gdes_c-1].vname);
42 if (vidx!=-1) {
43 switch(im->gdes[vidx].gf) {
44 case GF_DEF:
45 rrd_set_error("Duplicate variable in %s: '%s' defined as DEF",
46 err,im->gdes[im->gdes_c-1].vname);
47 break;
48 case GF_CDEF:
49 rrd_set_error("Duplicate variable in %s: '%s' defined as CDEF",
50 err,im->gdes[im->gdes_c-1].vname);
51 break;
52 case GF_VDEF:
53 rrd_set_error("Duplicate variable in %s: '%s' defined as VDEF",
54 err,im->gdes[im->gdes_c-1].vname);
55 break;
56 default:
57 rrd_set_error("Duplicate variable in %s: '%s' defined",
58 err,im->gdes[im->gdes_c-1].vname);
59 break;
60 };
61 im_free(im);
62 return 0;
63 }
65 /* VNAME must start with a character other than numeric */
66 if (isdigit(im->gdes[im->gdes_c-1].vname[0])) {
67 rrd_set_error("Variable in %s starts with a digit: '%s'",
68 err,im->gdes[im->gdes_c-1].vname);
69 im_free(im);
70 return 0;
71 };
73 /* Reserved words checking. Not at the moment. */
75 return n;
76 }
78 /**********************************************************
79 *** ***
80 **********************************************************/