ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
optmatch.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
7 
12 #include <adstring.hpp>
13 
25 int option_match(int argc, char* argv[], const char* option)
26 {
27  int match = -1;
28  if (argv)
29  {
30  for (int i = 0; i < argc; i++)
31  {
32  const char* argvi = argv[i];
33  if (argvi && !strcmp(argvi, option))
34  {
35  return i;
36  }
37  }
38  }
39  return match;
40 }
46 int option_match(char* _s, const char* option)
47 {
48  adstring ss = _s;
49  char* s = (char*)ss;
50  int rval = -1;
51  int i = 1;
52  char* p = strtok(s," ");
53  while (p != NULL)
54  {
55  if (!strcmp(p, option))
56  {
57  rval = i;
58  break;
59  }
60  i++;
61  p = strtok(NULL, " ");
62  }
63 
64  return rval;
65 }
72 int option_match(char* _s, const char* option, int& nopt)
73 {
74  adstring ss = _s;
75  char* s = (char*)ss;
76  int rval = -1;
77  int i = 1;
78  nopt = 0;
79  char* p = strtok(s," ");
80  while (p)
81  {
82  if (!strcmp(p, option))
83  {
84  rval = i;
85  break;
86  }
87  p = strtok(NULL, " ");
88  i++;
89  }
90 
91  bool found = false;
92  do
93  {
94  p = strtok(NULL, " ");
95  if (!p) break;
96  if (p[0] == '-')
97  found = true;
98  nopt++;
99  }
100  while(!found);
101 
102  return rval;
103 }
118 int option_match(int argc, char *argv[], const char *option, int& nopt)
119 {
120  int match = -1;
121  nopt=0;
122 
123  int i = option_match(argc, argv, option);
124  if (i >= 0)
125  {
126  match = i;
127 
128  for (int j = i + 1; j < argc; j++)
129  {
130  if (argv[j][0] == '-') break;
131  nopt++;
132  }
133  }
134 
135  return match;
136 }
int option_match(int argc, char *argv[], const char *string)
Checks if the program has been invoked with a particular command line argument (&quot;string&quot;).
Definition: optmatch.cpp:25