- Move pargs.c to C++ compilation to enable some of the below changes.
- Move *scan() routines from statutil.h/.cpp into pargs.cpp and make
them static, as this is the only place where they were used.
- Remove vscan() declaration in statutil.h, as the function was not
defined nor used anywhere.
- Move nenum() declaration from statutil.h to readinp.h, and the
implementation from statutil.cpp to pargs.cpp.
- Remove unused pdesc() in statutil.cpp.
Clarifies the code somewhat, and removes unnecessary declarations from
headers.
Change-Id: I0b70f3622c8bea41bf88b677cbe202143a3e60c9
#include <config.h>
#endif
+#include <ctype.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
+
#include "typedefs.h"
#include "gmx_fatal.h"
#include "statutil.h"
#include "vec.h"
#include "macros.h"
+#include "gromacs/utility/gmxassert.h"
+
/* The source code in this file should be thread-safe.
Please keep it that way. */
+static void usage(const char *type, const char *arg)
+{
+ GMX_ASSERT(arg != NULL, "NULL command-line argument should not occur");
+ gmx_fatal(FARGS, "Expected %s argument for option %s\n", type, arg);
+}
+
+/* Scan an int for argument argv[*i] from argument at argv[*i + 1].
+ * eg: -p 32. argv[*i] is only used for error reporting.
+ * If there is no value, or the conversion is not successful, the
+ * routine exits with an error, otherwise it returns the value found.
+ * *i is incremented once.
+ */
+static int iscan(int argc, char *argv[], int *i)
+{
+ const char *const arg = argv[*i];
+ if (argc <= (*i)+1)
+ {
+ usage("an integer", arg);
+ }
+ const char *const value = argv[++(*i)];
+ char *endptr;
+ int var = std::strtol(value, &endptr, 10);
+ if (*value == '\0' || *endptr != '\0')
+ {
+ usage("an integer", arg);
+ }
+ return var;
+}
+
+/* Same as above, but for large integer values */
+static gmx_large_int_t istepscan(int argc, char *argv[], int *i)
+{
+ const char *const arg = argv[*i];
+ if (argc <= (*i)+1)
+ {
+ usage("an integer", arg);
+ }
+ const char *const value = argv[++(*i)];
+ char *endptr;
+ gmx_large_int_t var = str_to_large_int_t(value, &endptr);
+ if (*value == '\0' || *endptr != '\0')
+ {
+ usage("an integer", arg);
+ }
+ return var;
+}
+
+/* Routine similar to the above, but working on doubles. */
+static double dscan(int argc, char *argv[], int *i)
+{
+ const char *const arg = argv[*i];
+ if (argc <= (*i)+1)
+ {
+ usage("a real", arg);
+ }
+ const char *const value = argv[++(*i)];
+ char *endptr;
+ double var = std::strtod(value, &endptr);
+ if (*value == '\0' || *endptr != '\0')
+ {
+ usage("a real", arg);
+ }
+ return var;
+}
+
+/* Routine similar to the above, but working on strings. The pointer
+ * returned is a pointer to the argv field.
+ */
+static char *sscan(int argc, char *argv[], int *i)
+{
+ if (argc > (*i)+1)
+ {
+ if ( (argv[(*i)+1][0] == '-') && (argc > (*i)+2) &&
+ (argv[(*i)+2][0] != '-') )
+ {
+ fprintf(stderr, "Possible missing string argument for option %s\n\n",
+ argv[*i]);
+ }
+ }
+ else
+ {
+ usage("a string", argv[*i]);
+ }
+
+ return argv[++(*i)];
+}
+
gmx_bool is_hidden(t_pargs *pa)
{
return ((strstr(pa->desc, "HIDDEN") != NULL) ||
(strstr(pa->desc, "[hidden]") != NULL));
}
+int nenum(const char *const enumc[])
+{
+ int i;
+
+ i = 1;
+ /* we *can* compare pointers directly here! */
+ while (enumc[i] && enumc[0] != enumc[i])
+ {
+ i++;
+ }
+
+ return i;
+}
+
void get_pargs(int *argc, char *argv[], int nparg, t_pargs pa[], gmx_bool bKeepArgs)
{
int i, j, k, match;
*
*************************************************************/
-static void usage(const char *type, const char *arg)
-{
- GMX_ASSERT(arg != NULL, "NULL command-line argument should not occur");
- gmx_fatal(FARGS, "Expected %s argument for option %s\n", type, arg);
-}
-
-int iscan(int argc, char *argv[], int *i)
-{
- const char *const arg = argv[*i];
- if (argc <= (*i)+1)
- {
- usage("an integer", arg);
- }
- const char *const value = argv[++(*i)];
- char *endptr;
- int var = std::strtol(value, &endptr, 10);
- if (*value == '\0' || *endptr != '\0')
- {
- usage("an integer", arg);
- }
- return var;
-}
-
-gmx_large_int_t istepscan(int argc, char *argv[], int *i)
-{
- const char *const arg = argv[*i];
- if (argc <= (*i)+1)
- {
- usage("an integer", arg);
- }
- const char *const value = argv[++(*i)];
- char *endptr;
- gmx_large_int_t var = str_to_large_int_t(value, &endptr);
- if (*value == '\0' || *endptr != '\0')
- {
- usage("an integer", arg);
- }
- return var;
-}
-
-double dscan(int argc, char *argv[], int *i)
-{
- const char *const arg = argv[*i];
- if (argc <= (*i)+1)
- {
- usage("a real", arg);
- }
- const char *const value = argv[++(*i)];
- char *endptr;
- double var = std::strtod(value, &endptr);
- if (*value == '\0' || *endptr != '\0')
- {
- usage("a real", arg);
- }
- return var;
-}
-
-char *sscan(int argc, char *argv[], int *i)
-{
- if (argc > (*i)+1)
- {
- if ( (argv[(*i)+1][0] == '-') && (argc > (*i)+2) &&
- (argv[(*i)+2][0] != '-') )
- {
- fprintf(stderr, "Possible missing string argument for option %s\n\n",
- argv[*i]);
- }
- }
- else
- {
- usage("a string", argv[*i]);
- }
-
- return argv[++(*i)];
-}
-
-int nenum(const char *const enumc[])
-{
- int i;
-
- i = 1;
- /* we *can* compare pointers directly here! */
- while (enumc[i] && enumc[0] != enumc[i])
- {
- i++;
- }
-
- return i;
-}
-
-static void pdesc(char *desc)
-{
- char *ptr, *nptr;
-
- ptr = desc;
- if ((int)strlen(ptr) < 70)
- {
- fprintf(stderr, "\t%s\n", ptr);
- }
- else
- {
- for (nptr = ptr+70; (nptr != ptr) && (!std::isspace(*nptr)); nptr--)
- {
- ;
- }
- if (nptr == ptr)
- {
- fprintf(stderr, "\t%s\n", ptr);
- }
- else
- {
- *nptr = '\0';
- nptr++;
- fprintf(stderr, "\t%s\n", ptr);
- pdesc(nptr);
- }
- }
-}
-
static int add_parg(int npargs, t_pargs *pa, t_pargs *pa_add)
{
memcpy(&(pa[npargs]), pa_add, sizeof(*pa_add));
gmx_bool is_hidden(t_pargs *pa);
/* Return TRUE when the option is a secret one */
+int nenum(const char *const enumc[]);
+/* returns ordinal number of selected enum from args
+ * depends on enumc[0] pointing to one of the other elements
+ * array must be terminated by a NULL pointer
+ */
+
int opt2parg_int(const char *option, int nparg, t_pargs pa[]);
gmx_bool opt2parg_gmx_bool(const char *option, int nparg, t_pargs pa[]);
#define PCA_NOT_READ_NODE (1<<16)
/* Is this node not reading: for parallel all nodes but the master */
-int iscan(int argc, char *argv[], int *i);
-/* Scan an int from the argument at *i. If the argument length
- * is > 2, the int is assumed to be in the remainder of the arg,
- * eg: -p32, else the int is assumed to be in the next argument
- * eg: -p 32. If neither is the case the routine exits with an error,
- * otherwise it returns the value found. If the value is in the next
- * argument *i is incremented. You typically would want to pass
- * a loop variable to this routine.
- */
-gmx_large_int_t istepscan(int argc, char *argv[], int *i);
-/* Same as above, but for large integer values */
-
-double dscan(int argc, char *argv[], int *i);
-/* Routine similar to the above, but working on doubles. */
-
-char *sscan(int argc, char *argv[], int *i);
-/* Routine similar to the above, but working on strings. The pointer
- * returned is a pointer to the argv field.
- */
-
-void vscan(int argc, char *argv[], int *i, rvec *vec);
-/* Routine similar to the above, but working on rvecs. */
-
-int nenum(const char *const enumc[]);
-/* returns ordinal number of selected enum from args
- * depends on enumc[0] pointing to one of the other elements
- * array must be terminated by a NULL pointer
- */
-
gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
int nfile, t_filenm fnm[], int npargs, t_pargs *pa,
int ndesc, const char **desc,