badformat parser fixed ... for good this time I hope
[rrdtool.git] / src / rrd_graph.c
index 9b46311..17ec03a 100644 (file)
@@ -6,6 +6,9 @@
 
 
 #include <sys/stat.h>
+
+#include "rrd_tool.h"
+
 #ifdef WIN32
 #include <io.h>
 #include <fcntl.h>
@@ -19,8 +22,6 @@
 #include <locale.h>
 #endif
 
-#include "rrd_tool.h"
-
 #include "rrd_graph.h"
 #include "rrd_graph_helper.h"
 
@@ -194,6 +195,7 @@ enum gfx_if_en if_conv(char *string){
     conv_if(PNG,IF_PNG)
     conv_if(SVG,IF_SVG)
     conv_if(EPS,IF_EPS)
+    conv_if(PDF,IF_PDF)
 
     return (-1);
 }
@@ -3241,33 +3243,41 @@ rrd_graph_legend(graph_desc_t *gdp, char *line)
 
 
 int bad_format(char *fmt) {
-       char *ptr;
-       int n=0;
-
-       ptr = fmt;
-       while (*ptr != '\0') {
-               if (*ptr == '%') {ptr++;
-                       if (*ptr == '\0') return 1;
-                       while ((*ptr >= '0' && *ptr <= '9') || *ptr == '.') { 
-                               ptr++;
-                       }
-                       if (*ptr == '\0') return 1;
-                       if (*ptr == 'l') {
-                               ptr++;
-                               n++;
-                               if (*ptr == '\0') return 1;
-                               if (*ptr == 'e' || *ptr == 'f') { 
-                                       ptr++; 
-                                       } else { return 1; }
-                       }
-                       else if (*ptr == 's' || *ptr == 'S' || *ptr == '%') { ++ptr; }
-                       else { return 1; }
-               } else {
-                       ++ptr;
-               }
-       }
-       return (n!=1);
+    char *ptr;
+    int n=0;
+    ptr = fmt;
+    while (*ptr != '\0')
+        if (*ptr++ == '%') {
+             /* line cannot end with percent char */
+             if (*ptr == '\0') return 1;
+             /* '%s', '%S' and '%%' are allowed */
+             if (*ptr == 's' || *ptr == 'S' || *ptr == '%') ptr++;
+
+             /* or else '% 6.2lf' and such are allowed */
+             else {
+   
+                 /* optional padding character */
+                 if (*ptr == ' ' || *ptr == '+' || *ptr == '-') ptr++;
+  
+                 /* This should take care of 'm.n' with all three optional */
+                 while (*ptr >= '0' && *ptr <= '9') ptr++;
+                 if (*ptr == '.') ptr++;
+                 while (*ptr >= '0' && *ptr <= '9') ptr++;
+  
+                 /* Either 'le' or 'lf' must follow here */
+                 if (*ptr++ != 'l') return 1;
+                 if (*ptr == 'e' || *ptr == 'f') ptr++;
+                 else return 1;
+                 n++;
+            }
+         }
+      
+      return (n!=1); 
 }
+
+
 int
 vdef_parse(gdes,str)
 struct graph_desc_t *gdes;
@@ -3354,6 +3364,8 @@ char *str;
     };
     return 0;
 }
+
+
 int
 vdef_calc(im,gdi)
 image_desc_t *im;