Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / programs / view / fgrid.cpp
index 83f66a80a692e38f2650398c2ea4a0f5062c972a..a087852e53fc8d0fba7184782b38b627a8fb27d7 100644 (file)
@@ -34,9 +34,7 @@
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
 #include <ctype.h>
 #include <stdio.h>
@@ -104,9 +102,10 @@ void ReadDlgError(const char *infile, eDLGERR err, const char *s,
 static void ReadAccOpen(const char *infile, FILE *in)
 {
     char buf[STRLEN];
+    int  result;
 
-    fscanf(in, "%4s", buf);
-    if (strcmp(buf, "{") != 0)
+    result = fscanf(in, "%4s", buf);
+    if ((1 != result) || strcmp(buf, "{") != 0)
     {
         ReadDlgErr(infile, eACCOEXP, buf);
     }
@@ -115,9 +114,10 @@ static void ReadAccOpen(const char *infile, FILE *in)
 static void ReadAccClose(const char *infile, FILE *in)
 {
     char buf[STRLEN];
+    int  result;
 
-    fscanf(in, "%4s", buf);
-    if (strcmp(buf, "}") != 0)
+    result = fscanf(in, "%4s", buf);
+    if ((1 != result) || strcmp(buf, "}") != 0)
     {
         ReadDlgErr(infile, eACCCEXP, buf);
     }
@@ -203,7 +203,7 @@ static t_fsimple *NewFSimple(void)
 static void AddFItemName(t_fitem *fitem, char *name)
 {
     srenew(fitem->name, ++fitem->nname);
-    fitem->name[fitem->nname-1] = strdup(name);
+    fitem->name[fitem->nname-1] = gmx_strdup(name);
 }
 
 static t_fgroup *NewFGroup(void)
@@ -358,10 +358,10 @@ static t_fitem *ScanFItem(const char *infile, FILE *in, char *buf)
     ReadQuoteString(infile, in, get);
     ReadQuoteString(infile, in, def);
     ReadQuoteString(infile, in, help);
-    fitem->set  = strdup(set);
-    fitem->get  = strdup(get);
-    fitem->def  = strdup(def);
-    fitem->help = strdup(help);
+    fitem->set  = gmx_strdup(set);
+    fitem->get  = gmx_strdup(get);
+    fitem->def  = gmx_strdup(def);
+    fitem->help = gmx_strdup(help);
 
     return fitem;
 }
@@ -370,15 +370,16 @@ t_fgrid *FGridFromFile(const char *infile)
 {
     FILE      *in;
     char       buf[STRLEN];
+    int        result;
 
     t_fgrid   *fgrid;
     t_fgroup  *fgroup;
     t_fsimple *fsimple;
     int        gridx, gridy;
 
-    in = libopen(infile);
-    fscanf(in, "%6s", buf);
-    if (strcmp(buf, "grid") != 0)
+    in     = libopen(infile);
+    result = fscanf(in, "%6s", buf);
+    if ((1 != result) || strcmp(buf, "grid") != 0)
     {
         ReadDlgErr(infile, eGRIDEXP, buf);
     }
@@ -390,14 +391,14 @@ t_fgrid *FGridFromFile(const char *infile)
     fgrid->w = gridx;
     fgrid->h = gridy;
     ReadAccOpen(infile, in);
-    fscanf(in, "%15s", buf);
-    while (bNotAccClose(buf))
+    result = fscanf(in, "%15s", buf);
+    while ((1 == result) && bNotAccClose(buf))
     {
         if (strcmp(buf, "group") == 0)
         {
             fgroup = AddFGridFGroup(fgrid);
             ReadQuoteString(infile, in, buf);
-            fgroup->name = strdup(buf);
+            fgroup->name = gmx_strdup(buf);
             if ((fscanf(in, "%5d%5d%5d%5d", &fgroup->x, &fgroup->y, &fgroup->w, &fgroup->h)) != 4)
             {
                 ReadDlgErr(infile, eNOVALS, "group x,y,w,h");
@@ -411,11 +412,11 @@ t_fgrid *FGridFromFile(const char *infile)
                 ReadDlgErr(infile, eTOOHIGH, buf);
             }
             ReadAccOpen(infile, in);
-            fscanf(in, "%15s", buf);
-            while (bNotAccClose(buf))
+            result = fscanf(in, "%15s", buf);
+            while ((1 == result) && bNotAccClose(buf))
             {
                 AddFGroupFItem(fgroup, ScanFItem(infile, in, buf));
-                fscanf(in, "%15s", buf);
+                result = fscanf(in, "%15s", buf);
             }
         }
         else if (strcmp(buf, "simple") == 0)
@@ -434,13 +435,26 @@ t_fgrid *FGridFromFile(const char *infile)
                 ReadDlgErr(infile, eTOOHIGH, "simple");
             }
             ReadAccOpen(infile, in);
-            fscanf(in, "%15s", buf);
-            fsimple->fitem = ScanFItem(infile, in, buf);
-            ReadAccClose(infile, in);
+            result = fscanf(in, "%15s", buf);
+            if (1 == result)
+            {
+                fsimple->fitem = ScanFItem(infile, in, buf);
+                ReadAccClose(infile, in);
+            }
+        }
+        if (1 == result)
+        {
+            result = fscanf(in, "%15s", buf);
         }
-        fscanf(in, "%15s", buf);
     }
     gmx_ffclose(in);
+    /* Since we always read one variable at a time the result from
+     * fscanf should always be 1.
+     */
+    if (1 != result)
+    {
+        ReadDlgErr(infile, eNOVALS, "fgrid");
+    }
 
     return fgrid;
 }