Merge branch release-5-1
[alexxy/gromacs.git] / src / gromacs / fileio / readinp.cpp
index 6a5f63f40ab3e82496a83d155032172dd5d9510f..0f182a718c5389f1d44efd70aa0d843b3e8780e3 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -83,6 +83,9 @@ t_inpfile *read_inpfile(const char *fn, int *ninp,
         set_warning_line(wi, fn, lc);
         if (ptr)
         {
+            // TODO This parsing should be using strip_comment, trim,
+            // strchr, etc. rather than re-inventing wheels.
+
             /* Strip comment */
             if ((cptr = std::strchr(buf, COMMENTSIGN)) != NULL)
             {
@@ -376,6 +379,7 @@ static int get_einp(int *ninp, t_inpfile **inp, const char *name)
     }
 }
 
+/* Note that sanitizing the trailing part of (*inp)[ii].value was the responsibility of read_inpfile() */
 int get_eint(int *ninp, t_inpfile **inp, const char *name, int def,
              warninp_t wi)
 {
@@ -395,7 +399,7 @@ int get_eint(int *ninp, t_inpfile **inp, const char *name, int def,
     else
     {
         ret = std::strtol((*inp)[ii].value, &ptr, 10);
-        if (ptr == (*inp)[ii].value)
+        if (*ptr != '\0')
         {
             sprintf(warn_buf, "Right hand side '%s' for parameter '%s' in parameter file is not an integer value\n", (*inp)[ii].value, (*inp)[ii].name);
             warning_error(wi, warn_buf);
@@ -405,6 +409,7 @@ int get_eint(int *ninp, t_inpfile **inp, const char *name, int def,
     }
 }
 
+/* Note that sanitizing the trailing part of (*inp)[ii].value was the responsibility of read_inpfile() */
 gmx_int64_t get_eint64(int *ninp, t_inpfile **inp,
                        const char *name, gmx_int64_t def,
                        warninp_t wi)
@@ -425,7 +430,7 @@ gmx_int64_t get_eint64(int *ninp, t_inpfile **inp,
     else
     {
         ret = str_to_int64_t((*inp)[ii].value, &ptr);
-        if (ptr == (*inp)[ii].value)
+        if (*ptr != '\0')
         {
             sprintf(warn_buf, "Right hand side '%s' for parameter '%s' in parameter file is not an integer value\n", (*inp)[ii].value, (*inp)[ii].name);
             warning_error(wi, warn_buf);
@@ -435,6 +440,7 @@ gmx_int64_t get_eint64(int *ninp, t_inpfile **inp,
     }
 }
 
+/* Note that sanitizing the trailing part of (*inp)[ii].value was the responsibility of read_inpfile() */
 double get_ereal(int *ninp, t_inpfile **inp, const char *name, double def,
                  warninp_t wi)
 {
@@ -454,7 +460,7 @@ double get_ereal(int *ninp, t_inpfile **inp, const char *name, double def,
     else
     {
         ret = strtod((*inp)[ii].value, &ptr);
-        if (ptr == (*inp)[ii].value)
+        if (*ptr != '\0')
         {
             sprintf(warn_buf, "Right hand side '%s' for parameter '%s' in parameter file is not a real value\n", (*inp)[ii].value, (*inp)[ii].name);
             warning_error(wi, warn_buf);
@@ -464,6 +470,7 @@ double get_ereal(int *ninp, t_inpfile **inp, const char *name, double def,
     }
 }
 
+/* Note that sanitizing the trailing part of (*inp)[ii].value was the responsibility of read_inpfile() */
 const char *get_estr(int *ninp, t_inpfile **inp, const char *name, const char *def)
 {
     char buf[32];
@@ -491,6 +498,7 @@ const char *get_estr(int *ninp, t_inpfile **inp, const char *name, const char *d
     }
 }
 
+/* Note that sanitizing the trailing part of (*inp)[ii].value was the responsibility of read_inpfile() */
 int get_eeenum(int *ninp, t_inpfile **inp, const char *name, const char **defs,
                warninp_t wi)
 {