Supporting functions for rrd_graph. Functions that are used frequently
authoralex <alex@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Thu, 26 Jul 2001 02:27:46 +0000 (02:27 +0000)
committeralex <alex@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Thu, 26 Jul 2001 02:27:46 +0000 (02:27 +0000)
and/or from different places should be added here in stead of repeating
them in rrd_graph.c over and over again.

git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@48 a5681a0c-68f1-0310-ab6d-d61299d08faa

src/rrd_graph_helper.c [new file with mode: 0644]
src/rrd_graph_helper.h [new file with mode: 0644]

diff --git a/src/rrd_graph_helper.c b/src/rrd_graph_helper.c
new file mode 100644 (file)
index 0000000..d325bf0
--- /dev/null
@@ -0,0 +1,81 @@
+/**********************************************************
+ *** Several generic helper functions for rrd_graph.c   ***
+ **********************************************************/
+
+#include "rrd_graph.h"
+#include "rrd_graph_helper.h"
+
+/**********************************************************
+ *** Helper functions for parsing command file          ***
+ **********************************************************/
+
+/* Parse a VNAME followed by an equal sign ( CDEF:VNAME= )
+ *
+ * Input:      pointer to argv
+ * Input:      pointer to im structure
+ * Input:      pointer to error string
+ * Output:     number of chars eaten (0 means error)
+ *
+ * Usage:      n=parse_vname( &argv[i][argstart],&im, "VDEF");
+ *             if (n==0) { error } else { argstart+=n };
+ */
+int
+parse_vname1(cptr,im,err)
+char *         cptr;
+image_desc_t * im;
+char *         err;
+{
+    int                n=0,vidx;
+
+    sscanf(cptr, DEF_NAM_FMT "=%n",im->gdes[im->gdes_c-1].vname,&n);
+
+    /* Check if the sequence matches, including the
+     * terminating equal sign */
+    if (n==0) {
+       im_free(im);
+       rrd_set_error("Can't parse VNAME in %s: '%s'",err,cptr);
+       return 0;
+    }
+
+    /* Check if this is an unused variable */
+    vidx=find_var(im,im->gdes[im->gdes_c-1].vname);
+    if (vidx!=-1) {
+       switch(im->gdes[vidx].gf) {
+           case GF_DEF:
+               rrd_set_error("Duplicate variable in %s: '%s' defined as DEF",
+                       err,im->gdes[im->gdes_c-1].vname);
+               break;
+           case GF_CDEF:
+               rrd_set_error("Duplicate variable in %s: '%s' defined as CDEF",
+                       err,im->gdes[im->gdes_c-1].vname);
+               break;
+           case GF_VDEF:
+               rrd_set_error("Duplicate variable in %s: '%s' defined as VDEF",
+                       err,im->gdes[im->gdes_c-1].vname);
+               break;
+           default:
+               rrd_set_error("Duplicate variable in %s: '%s' defined",
+                       err,im->gdes[im->gdes_c-1].vname);
+               break;
+       };
+       im_free(im);
+       return 0;
+    }
+
+    /* VNAME must start with a character other than numeric */
+    if (isdigit(im->gdes[im->gdes_c-1].vname[0])) {
+       rrd_set_error("Variable in %s starts with a digit: '%s'",
+               err,im->gdes[im->gdes_c-1].vname);
+       im_free(im);
+       return 0;
+    };
+
+    /* Reserved words checking.  Not at the moment. */
+
+    return n;
+}
+
+/**********************************************************
+ ***                                                    ***
+ **********************************************************/
+
diff --git a/src/rrd_graph_helper.h b/src/rrd_graph_helper.h
new file mode 100644 (file)
index 0000000..8decc72
--- /dev/null
@@ -0,0 +1 @@
+int parse_vname1(char *, image_desc_t *, char *);