ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/DynamicPropsCmd.c
(Generate patch)

Comparing trunk/src/applications/dynamicProps/DynamicPropsCmd.c (file contents):
Revision 1442 by gezelter, Mon May 10 17:28:26 2010 UTC vs.
Revision 1604 by jmichalk, Mon Aug 8 18:53:40 2011 UTC

# Line 1 | Line 1
1   /*
2 <  File autogenerated by gengetopt version 2.14
2 >  File autogenerated by gengetopt version 2.22.4
3    generated with the following command:
4 <  gengetopt -i DynamicProps.ggo -F DynamicPropsCmd
4 >  /usr/local/bin/gengetopt -F DynamicPropsCmd -i DynamicProps.ggo
5  
6    The developers of gengetopt consider the fixed text that goes in all
7    gengetopt output files to be in the public domain:
# Line 17 | Line 17
17   #include <stdlib.h>
18   #include <string.h>
19  
20 < #include "getopt.h"
20 > #ifndef FIX_UNUSED
21 > #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22 > #endif
23  
24 + #include <getopt.h>
25 +
26   #include "DynamicPropsCmd.h"
27  
28 + const char *gengetopt_args_info_purpose = "";
29 +
30 + const char *gengetopt_args_info_usage = "Usage: DynamicProps [OPTIONS]...";
31 +
32 + const char *gengetopt_args_info_description = "";
33 +
34 + const char *gengetopt_args_info_help[] = {
35 +  "  -h, --help                    Print help and exit",
36 +  "  -V, --version                 Print version and exit",
37 +  "  -i, --input=filename          input dump file",
38 +  "  -o, --output=filename         output file name",
39 +  "      --sele1=selection script  select first stuntdouble set",
40 +  "      --sele2=selection script  select second stuntdouble set (if sele2 is not \n                                  set, use script from sele1)",
41 +  "      --order=INT               Lengendre Polynomial Order",
42 +  "  -m, --memory=memory specification\n                                Available memory (defaults to 2G)  \n                                  (default=`2G')",
43 +  "\n Group: dynamicProps\n   an option of this group is required",
44 +  "  -r, --rcorr                   rmsd",
45 +  "  -v, --vcorr                   velocity correlation function",
46 +  "  -d, --dcorr                   dipole correlation function",
47 +  "  -l, --lcorr                   Lengendre correlation function",
48 +  "  -s, --sdcorr                  System dipole correlation function",
49 +  "      --r_rcorr                 Radial rmsd",
50 +  "      --thetacorr               Angular rmsd",
51 +  "      --drcorr                  Directional rmsd for particles with unit \n                                  vectors",
52 +  "      --helfandEcorr            Helfand moment for thermal conductvity",
53 +  "      --stresscorr              Stress tensor correlation function",
54 +    0
55 + };
56 +
57 + typedef enum {ARG_NO
58 +  , ARG_STRING
59 +  , ARG_INT
60 + } cmdline_parser_arg_type;
61 +
62   static
63   void clear_given (struct gengetopt_args_info *args_info);
64   static
65   void clear_args (struct gengetopt_args_info *args_info);
66  
67   static int
68 < cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
68 > cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
69 >                        struct cmdline_parser_params *params, const char *additional_error);
70  
71   static int
72   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
# Line 45 | Line 84 | void clear_given (struct gengetopt_args_info *args_inf
84    args_info->sele1_given = 0 ;
85    args_info->sele2_given = 0 ;
86    args_info->order_given = 0 ;
87 +  args_info->memory_given = 0 ;
88    args_info->rcorr_given = 0 ;
89    args_info->vcorr_given = 0 ;
90    args_info->dcorr_given = 0 ;
91    args_info->lcorr_given = 0 ;
92 +  args_info->sdcorr_given = 0 ;
93    args_info->r_rcorr_given = 0 ;
94    args_info->thetacorr_given = 0 ;
95    args_info->drcorr_given = 0 ;
96    args_info->helfandEcorr_given = 0 ;
97 +  args_info->stresscorr_given = 0 ;
98    args_info->dynamicProps_group_counter = 0 ;
99   }
100  
101   static
102   void clear_args (struct gengetopt_args_info *args_info)
103   {
104 +  FIX_UNUSED (args_info);
105    args_info->input_arg = NULL;
106    args_info->input_orig = NULL;
107    args_info->output_arg = NULL;
# Line 68 | Line 111 | void clear_args (struct gengetopt_args_info *args_info
111    args_info->sele2_arg = NULL;
112    args_info->sele2_orig = NULL;
113    args_info->order_orig = NULL;
114 +  args_info->memory_arg = gengetopt_strdup ("2G");
115 +  args_info->memory_orig = NULL;
116    
117   }
118  
119 + static
120 + void init_args_info(struct gengetopt_args_info *args_info)
121 + {
122 +
123 +
124 +  args_info->help_help = gengetopt_args_info_help[0] ;
125 +  args_info->version_help = gengetopt_args_info_help[1] ;
126 +  args_info->input_help = gengetopt_args_info_help[2] ;
127 +  args_info->output_help = gengetopt_args_info_help[3] ;
128 +  args_info->sele1_help = gengetopt_args_info_help[4] ;
129 +  args_info->sele2_help = gengetopt_args_info_help[5] ;
130 +  args_info->order_help = gengetopt_args_info_help[6] ;
131 +  args_info->memory_help = gengetopt_args_info_help[7] ;
132 +  args_info->rcorr_help = gengetopt_args_info_help[9] ;
133 +  args_info->vcorr_help = gengetopt_args_info_help[10] ;
134 +  args_info->dcorr_help = gengetopt_args_info_help[11] ;
135 +  args_info->lcorr_help = gengetopt_args_info_help[12] ;
136 +  args_info->sdcorr_help = gengetopt_args_info_help[13] ;
137 +  args_info->r_rcorr_help = gengetopt_args_info_help[14] ;
138 +  args_info->thetacorr_help = gengetopt_args_info_help[15] ;
139 +  args_info->drcorr_help = gengetopt_args_info_help[16] ;
140 +  args_info->helfandEcorr_help = gengetopt_args_info_help[17] ;
141 +  args_info->stresscorr_help = gengetopt_args_info_help[18] ;
142 +  
143 + }
144 +
145   void
146   cmdline_parser_print_version (void)
147   {
148 <  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
148 >  printf ("%s %s\n",
149 >     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
150 >     CMDLINE_PARSER_VERSION);
151   }
152  
153 + static void print_help_common(void) {
154 +  cmdline_parser_print_version ();
155 +
156 +  if (strlen(gengetopt_args_info_purpose) > 0)
157 +    printf("\n%s\n", gengetopt_args_info_purpose);
158 +
159 +  if (strlen(gengetopt_args_info_usage) > 0)
160 +    printf("\n%s\n", gengetopt_args_info_usage);
161 +
162 +  printf("\n");
163 +
164 +  if (strlen(gengetopt_args_info_description) > 0)
165 +    printf("%s\n\n", gengetopt_args_info_description);
166 + }
167 +
168   void
169   cmdline_parser_print_help (void)
170   {
171 <  cmdline_parser_print_version ();
172 <  printf("\nUsage: DynamicProps [OPTIONS]...\n\n");
173 <  printf("%s\n","  -h, --help                    Print help and exit");
174 <  printf("%s\n","  -V, --version                 Print version and exit");
87 <  printf("%s\n","  -i, --input=filename          input dump file");
88 <  printf("%s\n","  -o, --output=filename         output file name");
89 <  printf("%s\n","      --sele1=selection script  select first stuntdouble set");
90 <  printf("%s\n","      --sele2=selection script  select second stuntdouble set (if sele2 is not \n                                  set, use script from sele1)");
91 <  printf("%s\n","      --order=INT               Lengendre Polynomial Order");
92 <  printf("%s\n","\n Group: dynamicProps\n   an option of this group is required");
93 <  printf("%s\n","  -r, --rcorr                   rmsd");
94 <  printf("%s\n","  -v, --vcorr                   velocity correlation function");
95 <  printf("%s\n","  -d, --dcorr                   dipole correlation function");
96 <  printf("%s\n","  -l, --lcorr                   Lengendre correlation function");
97 <  printf("%s\n","      --r_rcorr                 Radial rmsd");
98 <  printf("%s\n","      --thetacorr               Angular rmsd");
99 <  printf("%s\n","      --drcorr                  Directional rmsd for particles with unit \n                                  vectors");
100 <  printf("%s\n","      --helfandEcorr            Helfand moment for thermal conductvity");
101 <  
171 >  int i = 0;
172 >  print_help_common();
173 >  while (gengetopt_args_info_help[i])
174 >    printf("%s\n", gengetopt_args_info_help[i++]);
175   }
176  
177   void
# Line 106 | Line 179 | cmdline_parser_init (struct gengetopt_args_info *args_
179   {
180    clear_given (args_info);
181    clear_args (args_info);
182 +  init_args_info (args_info);
183   }
184  
185 + void
186 + cmdline_parser_params_init(struct cmdline_parser_params *params)
187 + {
188 +  if (params)
189 +    {
190 +      params->override = 0;
191 +      params->initialize = 1;
192 +      params->check_required = 1;
193 +      params->check_ambiguity = 0;
194 +      params->print_errors = 1;
195 +    }
196 + }
197 +
198 + struct cmdline_parser_params *
199 + cmdline_parser_params_create(void)
200 + {
201 +  struct cmdline_parser_params *params =
202 +    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
203 +  cmdline_parser_params_init(params);  
204 +  return params;
205 + }
206 +
207   static void
208 < cmdline_parser_release (struct gengetopt_args_info *args_info)
208 > free_string_field (char **s)
209   {
210 <  
115 <  if (args_info->input_arg)
210 >  if (*s)
211      {
212 <      free (args_info->input_arg); /* free previous argument */
213 <      args_info->input_arg = 0;
212 >      free (*s);
213 >      *s = 0;
214      }
215 <  if (args_info->input_orig)
216 <    {
217 <      free (args_info->input_orig); /* free previous argument */
218 <      args_info->input_orig = 0;
219 <    }
220 <  if (args_info->output_arg)
221 <    {
222 <      free (args_info->output_arg); /* free previous argument */
223 <      args_info->output_arg = 0;
224 <    }
225 <  if (args_info->output_orig)
226 <    {
227 <      free (args_info->output_orig); /* free previous argument */
228 <      args_info->output_orig = 0;
229 <    }
230 <  if (args_info->sele1_arg)
231 <    {
232 <      free (args_info->sele1_arg); /* free previous argument */
233 <      args_info->sele1_arg = 0;
234 <    }
235 <  if (args_info->sele1_orig)
236 <    {
237 <      free (args_info->sele1_orig); /* free previous argument */
238 <      args_info->sele1_orig = 0;
239 <    }
240 <  if (args_info->sele2_arg)
241 <    {
242 <      free (args_info->sele2_arg); /* free previous argument */
243 <      args_info->sele2_arg = 0;
244 <    }
245 <  if (args_info->sele2_orig)
246 <    {
247 <      free (args_info->sele2_orig); /* free previous argument */
248 <      args_info->sele2_orig = 0;
249 <    }
250 <  if (args_info->order_orig)
215 > }
216 >
217 >
218 > static void
219 > cmdline_parser_release (struct gengetopt_args_info *args_info)
220 > {
221 >
222 >  free_string_field (&(args_info->input_arg));
223 >  free_string_field (&(args_info->input_orig));
224 >  free_string_field (&(args_info->output_arg));
225 >  free_string_field (&(args_info->output_orig));
226 >  free_string_field (&(args_info->sele1_arg));
227 >  free_string_field (&(args_info->sele1_orig));
228 >  free_string_field (&(args_info->sele2_arg));
229 >  free_string_field (&(args_info->sele2_orig));
230 >  free_string_field (&(args_info->order_orig));
231 >  free_string_field (&(args_info->memory_arg));
232 >  free_string_field (&(args_info->memory_orig));
233 >  
234 >  
235 >
236 >  clear_given (args_info);
237 > }
238 >
239 >
240 > static void
241 > write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
242 > {
243 >  FIX_UNUSED (values);
244 >  if (arg) {
245 >    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
246 >  } else {
247 >    fprintf(outfile, "%s\n", opt);
248 >  }
249 > }
250 >
251 >
252 > int
253 > cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
254 > {
255 >  int i = 0;
256 >
257 >  if (!outfile)
258      {
259 <      free (args_info->order_orig); /* free previous argument */
260 <      args_info->order_orig = 0;
259 >      fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
260 >      return EXIT_FAILURE;
261      }
262 +
263 +  if (args_info->help_given)
264 +    write_into_file(outfile, "help", 0, 0 );
265 +  if (args_info->version_given)
266 +    write_into_file(outfile, "version", 0, 0 );
267 +  if (args_info->input_given)
268 +    write_into_file(outfile, "input", args_info->input_orig, 0);
269 +  if (args_info->output_given)
270 +    write_into_file(outfile, "output", args_info->output_orig, 0);
271 +  if (args_info->sele1_given)
272 +    write_into_file(outfile, "sele1", args_info->sele1_orig, 0);
273 +  if (args_info->sele2_given)
274 +    write_into_file(outfile, "sele2", args_info->sele2_orig, 0);
275 +  if (args_info->order_given)
276 +    write_into_file(outfile, "order", args_info->order_orig, 0);
277 +  if (args_info->memory_given)
278 +    write_into_file(outfile, "memory", args_info->memory_orig, 0);
279 +  if (args_info->rcorr_given)
280 +    write_into_file(outfile, "rcorr", 0, 0 );
281 +  if (args_info->vcorr_given)
282 +    write_into_file(outfile, "vcorr", 0, 0 );
283 +  if (args_info->dcorr_given)
284 +    write_into_file(outfile, "dcorr", 0, 0 );
285 +  if (args_info->lcorr_given)
286 +    write_into_file(outfile, "lcorr", 0, 0 );
287 +  if (args_info->sdcorr_given)
288 +    write_into_file(outfile, "sdcorr", 0, 0 );
289 +  if (args_info->r_rcorr_given)
290 +    write_into_file(outfile, "r_rcorr", 0, 0 );
291 +  if (args_info->thetacorr_given)
292 +    write_into_file(outfile, "thetacorr", 0, 0 );
293 +  if (args_info->drcorr_given)
294 +    write_into_file(outfile, "drcorr", 0, 0 );
295 +  if (args_info->helfandEcorr_given)
296 +    write_into_file(outfile, "helfandEcorr", 0, 0 );
297 +  if (args_info->stresscorr_given)
298 +    write_into_file(outfile, "stresscorr", 0, 0 );
299    
300 <  clear_given (args_info);
300 >
301 >  i = EXIT_SUCCESS;
302 >  return i;
303   }
304  
305   int
# Line 175 | Line 316 | cmdline_parser_file_save(const char *filename, struct
316        return EXIT_FAILURE;
317      }
318  
319 <  if (args_info->help_given) {
179 <    fprintf(outfile, "%s\n", "help");
180 <  }
181 <  if (args_info->version_given) {
182 <    fprintf(outfile, "%s\n", "version");
183 <  }
184 <  if (args_info->input_given) {
185 <    if (args_info->input_orig) {
186 <      fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig);
187 <    } else {
188 <      fprintf(outfile, "%s\n", "input");
189 <    }
190 <  }
191 <  if (args_info->output_given) {
192 <    if (args_info->output_orig) {
193 <      fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
194 <    } else {
195 <      fprintf(outfile, "%s\n", "output");
196 <    }
197 <  }
198 <  if (args_info->sele1_given) {
199 <    if (args_info->sele1_orig) {
200 <      fprintf(outfile, "%s=\"%s\"\n", "sele1", args_info->sele1_orig);
201 <    } else {
202 <      fprintf(outfile, "%s\n", "sele1");
203 <    }
204 <  }
205 <  if (args_info->sele2_given) {
206 <    if (args_info->sele2_orig) {
207 <      fprintf(outfile, "%s=\"%s\"\n", "sele2", args_info->sele2_orig);
208 <    } else {
209 <      fprintf(outfile, "%s\n", "sele2");
210 <    }
211 <  }
212 <  if (args_info->order_given) {
213 <    if (args_info->order_orig) {
214 <      fprintf(outfile, "%s=\"%s\"\n", "order", args_info->order_orig);
215 <    } else {
216 <      fprintf(outfile, "%s\n", "order");
217 <    }
218 <  }
219 <  if (args_info->rcorr_given) {
220 <    fprintf(outfile, "%s\n", "rcorr");
221 <  }
222 <  if (args_info->vcorr_given) {
223 <    fprintf(outfile, "%s\n", "vcorr");
224 <  }
225 <  if (args_info->dcorr_given) {
226 <    fprintf(outfile, "%s\n", "dcorr");
227 <  }
228 <  if (args_info->lcorr_given) {
229 <    fprintf(outfile, "%s\n", "lcorr");
230 <  }
231 <  if (args_info->r_rcorr_given) {
232 <    fprintf(outfile, "%s\n", "r_rcorr");
233 <  }
234 <  if (args_info->thetacorr_given) {
235 <    fprintf(outfile, "%s\n", "thetacorr");
236 <  }
237 <  if (args_info->drcorr_given) {
238 <    fprintf(outfile, "%s\n", "drcorr");
239 <  }
240 <  if (args_info->helfandEcorr_given) {
241 <    fprintf(outfile, "%s\n", "helfandEcorr");
242 <  }
243 <  
319 >  i = cmdline_parser_dump(outfile, args_info);
320    fclose (outfile);
321  
246  i = EXIT_SUCCESS;
322    return i;
323   }
324  
# Line 253 | Line 328 | cmdline_parser_free (struct gengetopt_args_info *args_
328    cmdline_parser_release (args_info);
329   }
330  
331 <
257 < /* gengetopt_strdup() */
258 < /* strdup.c replacement of strdup, which is not standard */
331 > /** @brief replacement of strdup, which is not standard */
332   char *
333   gengetopt_strdup (const char *s)
334   {
335 <  char *result = NULL;
335 >  char *result = 0;
336    if (!s)
337      return result;
338  
# Line 271 | Line 344 | static void
344   }
345  
346   static void
274 reset_group_dynamicProps(struct gengetopt_args_info *args_info);
275
276 static void
347   reset_group_dynamicProps(struct gengetopt_args_info *args_info)
348   {
349    if (! args_info->dynamicProps_group_counter)
# Line 283 | Line 353 | reset_group_dynamicProps(struct gengetopt_args_info *a
353    args_info->vcorr_given = 0 ;
354    args_info->dcorr_given = 0 ;
355    args_info->lcorr_given = 0 ;
356 +  args_info->sdcorr_given = 0 ;
357    args_info->r_rcorr_given = 0 ;
358    args_info->thetacorr_given = 0 ;
359    args_info->drcorr_given = 0 ;
360    args_info->helfandEcorr_given = 0 ;
361 +  args_info->stresscorr_given = 0 ;
362  
363    args_info->dynamicProps_group_counter = 0;
364   }
365  
366   int
367 < cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
367 > cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
368   {
369    return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
370   }
371  
372   int
373 < cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
373 > cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
374 >                   struct cmdline_parser_params *params)
375   {
376    int result;
377 +  result = cmdline_parser_internal (argc, argv, args_info, params, 0);
378  
379 <  result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
379 >  if (result == EXIT_FAILURE)
380 >    {
381 >      cmdline_parser_free (args_info);
382 >      exit (EXIT_FAILURE);
383 >    }
384 >  
385 >  return result;
386 > }
387  
388 + int
389 + cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
390 + {
391 +  int result;
392 +  struct cmdline_parser_params params;
393 +  
394 +  params.override = override;
395 +  params.initialize = initialize;
396 +  params.check_required = check_required;
397 +  params.check_ambiguity = 0;
398 +  params.print_errors = 1;
399 +
400 +  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
401 +
402    if (result == EXIT_FAILURE)
403      {
404        cmdline_parser_free (args_info);
# Line 318 | Line 413 | cmdline_parser_required (struct gengetopt_args_info *a
413   {
414    int result = EXIT_SUCCESS;
415  
416 <  if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
416 >  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
417      result = EXIT_FAILURE;
418  
419    if (result == EXIT_FAILURE)
# Line 334 | Line 429 | cmdline_parser_required2 (struct gengetopt_args_info *
429   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
430   {
431    int error = 0;
432 +  FIX_UNUSED (additional_error);
433  
434 +  /* checks for required options */
435    if (! args_info->input_given)
436      {
437        fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
438        error = 1;
439      }
440 +  
441    if (args_info->dynamicProps_group_counter == 0)
442      {
443 <      fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required.%s\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : ""));
443 >      fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : ""));
444        error = 1;
445      }
446    
447  
448 +  /* checks for dependences among options */
449 +
450    return error;
451   }
452  
453 +
454 + static char *package_name = 0;
455 +
456 + /**
457 + * @brief updates an option
458 + * @param field the generic pointer to the field to update
459 + * @param orig_field the pointer to the orig field
460 + * @param field_given the pointer to the number of occurrence of this option
461 + * @param prev_given the pointer to the number of occurrence already seen
462 + * @param value the argument for this option (if null no arg was specified)
463 + * @param possible_values the possible values for this option (if specified)
464 + * @param default_value the default value (in case the option only accepts fixed values)
465 + * @param arg_type the type of this option
466 + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
467 + * @param override @see cmdline_parser_params.override
468 + * @param no_free whether to free a possible previous value
469 + * @param multiple_option whether this is a multiple option
470 + * @param long_opt the corresponding long option
471 + * @param short_opt the corresponding short option (or '-' if none)
472 + * @param additional_error possible further error specification
473 + */
474 + static
475 + int update_arg(void *field, char **orig_field,
476 +               unsigned int *field_given, unsigned int *prev_given,
477 +               char *value, const char *possible_values[],
478 +               const char *default_value,
479 +               cmdline_parser_arg_type arg_type,
480 +               int check_ambiguity, int override,
481 +               int no_free, int multiple_option,
482 +               const char *long_opt, char short_opt,
483 +               const char *additional_error)
484 + {
485 +  char *stop_char = 0;
486 +  const char *val = value;
487 +  int found;
488 +  char **string_field;
489 +  FIX_UNUSED (field);
490 +
491 +  stop_char = 0;
492 +  found = 0;
493 +
494 +  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
495 +    {
496 +      if (short_opt != '-')
497 +        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
498 +               package_name, long_opt, short_opt,
499 +               (additional_error ? additional_error : ""));
500 +      else
501 +        fprintf (stderr, "%s: `--%s' option given more than once%s\n",
502 +               package_name, long_opt,
503 +               (additional_error ? additional_error : ""));
504 +      return 1; /* failure */
505 +    }
506 +
507 +  FIX_UNUSED (default_value);
508 +    
509 +  if (field_given && *field_given && ! override)
510 +    return 0;
511 +  if (prev_given)
512 +    (*prev_given)++;
513 +  if (field_given)
514 +    (*field_given)++;
515 +  if (possible_values)
516 +    val = possible_values[found];
517 +
518 +  switch(arg_type) {
519 +  case ARG_INT:
520 +    if (val) *((int *)field) = strtol (val, &stop_char, 0);
521 +    break;
522 +  case ARG_STRING:
523 +    if (val) {
524 +      string_field = (char **)field;
525 +      if (!no_free && *string_field)
526 +        free (*string_field); /* free previous string */
527 +      *string_field = gengetopt_strdup (val);
528 +    }
529 +    break;
530 +  default:
531 +    break;
532 +  };
533 +
534 +  /* check numeric conversion */
535 +  switch(arg_type) {
536 +  case ARG_INT:
537 +    if (val && !(stop_char && *stop_char == '\0')) {
538 +      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
539 +      return 1; /* failure */
540 +    }
541 +    break;
542 +  default:
543 +    ;
544 +  };
545 +
546 +  /* store the original value */
547 +  switch(arg_type) {
548 +  case ARG_NO:
549 +    break;
550 +  default:
551 +    if (value && orig_field) {
552 +      if (no_free) {
553 +        *orig_field = value;
554 +      } else {
555 +        if (*orig_field)
556 +          free (*orig_field); /* free previous string */
557 +        *orig_field = gengetopt_strdup (value);
558 +      }
559 +    }
560 +  };
561 +
562 +  return 0; /* OK */
563 + }
564 +
565 +
566   int
567 < cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
567 > cmdline_parser_internal (
568 >  int argc, char **argv, struct gengetopt_args_info *args_info,
569 >                        struct cmdline_parser_params *params, const char *additional_error)
570   {
571    int c;        /* Character of the parsed option.  */
572  
573    int error = 0;
574    struct gengetopt_args_info local_args_info;
575 +  
576 +  int override;
577 +  int initialize;
578 +  int check_required;
579 +  int check_ambiguity;
580 +  
581 +  package_name = argv[0];
582 +  
583 +  override = params->override;
584 +  initialize = params->initialize;
585 +  check_required = params->check_required;
586 +  check_ambiguity = params->check_ambiguity;
587  
588    if (initialize)
589      cmdline_parser_init (args_info);
# Line 364 | Line 591 | cmdline_parser_internal (int argc, char * const *argv,
591    cmdline_parser_init (&local_args_info);
592  
593    optarg = 0;
594 <  optind = 1;
595 <  opterr = 1;
594 >  optind = 0;
595 >  opterr = params->print_errors;
596    optopt = '?';
597  
598    while (1)
599      {
600        int option_index = 0;
374      char *stop_char;
601  
602        static struct option long_options[] = {
603          { "help",       0, NULL, 'h' },
# Line 381 | Line 607 | cmdline_parser_internal (int argc, char * const *argv,
607          { "sele1",      1, NULL, 0 },
608          { "sele2",      1, NULL, 0 },
609          { "order",      1, NULL, 0 },
610 +        { "memory",     1, NULL, 'm' },
611          { "rcorr",      0, NULL, 'r' },
612          { "vcorr",      0, NULL, 'v' },
613          { "dcorr",      0, NULL, 'd' },
614          { "lcorr",      0, NULL, 'l' },
615 +        { "sdcorr",     0, NULL, 's' },
616          { "r_rcorr",    0, NULL, 0 },
617          { "thetacorr",  0, NULL, 0 },
618          { "drcorr",     0, NULL, 0 },
619          { "helfandEcorr",       0, NULL, 0 },
620 <        { NULL, 0, NULL, 0 }
620 >        { "stresscorr", 0, NULL, 0 },
621 >        { 0,  0, 0, 0 }
622        };
623  
624 <      stop_char = 0;
396 <      c = getopt_long (argc, argv, "hVi:o:rvdl", long_options, &option_index);
624 >      c = getopt_long (argc, argv, "hVi:o:m:rvdls", long_options, &option_index);
625  
626        if (c == -1) break;       /* Exit from `while (1)' loop.  */
627  
# Line 410 | Line 638 | cmdline_parser_internal (int argc, char * const *argv,
638            exit (EXIT_SUCCESS);
639  
640          case 'i':       /* input dump file.  */
641 <          if (local_args_info.input_given)
642 <            {
643 <              fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
644 <              goto failure;
645 <            }
646 <          if (args_info->input_given && ! override)
647 <            continue;
648 <          local_args_info.input_given = 1;
649 <          args_info->input_given = 1;
650 <          if (args_info->input_arg)
423 <            free (args_info->input_arg); /* free previous string */
424 <          args_info->input_arg = gengetopt_strdup (optarg);
425 <          if (args_info->input_orig)
426 <            free (args_info->input_orig); /* free previous string */
427 <          args_info->input_orig = gengetopt_strdup (optarg);
641 >        
642 >        
643 >          if (update_arg( (void *)&(args_info->input_arg),
644 >               &(args_info->input_orig), &(args_info->input_given),
645 >              &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
646 >              check_ambiguity, override, 0, 0,
647 >              "input", 'i',
648 >              additional_error))
649 >            goto failure;
650 >        
651            break;
429
652          case 'o':       /* output file name.  */
653 <          if (local_args_info.output_given)
654 <            {
655 <              fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
656 <              goto failure;
657 <            }
658 <          if (args_info->output_given && ! override)
659 <            continue;
660 <          local_args_info.output_given = 1;
661 <          args_info->output_given = 1;
662 <          if (args_info->output_arg)
441 <            free (args_info->output_arg); /* free previous string */
442 <          args_info->output_arg = gengetopt_strdup (optarg);
443 <          if (args_info->output_orig)
444 <            free (args_info->output_orig); /* free previous string */
445 <          args_info->output_orig = gengetopt_strdup (optarg);
653 >        
654 >        
655 >          if (update_arg( (void *)&(args_info->output_arg),
656 >               &(args_info->output_orig), &(args_info->output_given),
657 >              &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
658 >              check_ambiguity, override, 0, 0,
659 >              "output", 'o',
660 >              additional_error))
661 >            goto failure;
662 >        
663            break;
664 <
664 >        case 'm':       /* Available memory (defaults to 2G).  */
665 >        
666 >        
667 >          if (update_arg( (void *)&(args_info->memory_arg),
668 >               &(args_info->memory_orig), &(args_info->memory_given),
669 >              &(local_args_info.memory_given), optarg, 0, "2G", ARG_STRING,
670 >              check_ambiguity, override, 0, 0,
671 >              "memory", 'm',
672 >              additional_error))
673 >            goto failure;
674 >        
675 >          break;
676          case 'r':       /* rmsd.  */
677 <          if (local_args_info.rcorr_given)
450 <            {
451 <              fprintf (stderr, "%s: `--rcorr' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
452 <              goto failure;
453 <            }
454 <          if (args_info->rcorr_given && ! override)
455 <            continue;
456 <          local_args_info.rcorr_given = 1;
457 <          args_info->rcorr_given = 1;
677 >        
678            if (args_info->dynamicProps_group_counter && override)
679              reset_group_dynamicProps (args_info);
680            args_info->dynamicProps_group_counter += 1;
681 +        
682 +          if (update_arg( 0 ,
683 +               0 , &(args_info->rcorr_given),
684 +              &(local_args_info.rcorr_given), optarg, 0, 0, ARG_NO,
685 +              check_ambiguity, override, 0, 0,
686 +              "rcorr", 'r',
687 +              additional_error))
688 +            goto failure;
689 +        
690            break;
462
691          case 'v':       /* velocity correlation function.  */
692 <          if (local_args_info.vcorr_given)
465 <            {
466 <              fprintf (stderr, "%s: `--vcorr' (`-v') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
467 <              goto failure;
468 <            }
469 <          if (args_info->vcorr_given && ! override)
470 <            continue;
471 <          local_args_info.vcorr_given = 1;
472 <          args_info->vcorr_given = 1;
692 >        
693            if (args_info->dynamicProps_group_counter && override)
694              reset_group_dynamicProps (args_info);
695            args_info->dynamicProps_group_counter += 1;
696 +        
697 +          if (update_arg( 0 ,
698 +               0 , &(args_info->vcorr_given),
699 +              &(local_args_info.vcorr_given), optarg, 0, 0, ARG_NO,
700 +              check_ambiguity, override, 0, 0,
701 +              "vcorr", 'v',
702 +              additional_error))
703 +            goto failure;
704 +        
705            break;
477
706          case 'd':       /* dipole correlation function.  */
707 <          if (local_args_info.dcorr_given)
480 <            {
481 <              fprintf (stderr, "%s: `--dcorr' (`-d') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
482 <              goto failure;
483 <            }
484 <          if (args_info->dcorr_given && ! override)
485 <            continue;
486 <          local_args_info.dcorr_given = 1;
487 <          args_info->dcorr_given = 1;
707 >        
708            if (args_info->dynamicProps_group_counter && override)
709              reset_group_dynamicProps (args_info);
710            args_info->dynamicProps_group_counter += 1;
711 <          break;
712 <
711 >        
712 >          if (update_arg( 0 ,
713 >               0 , &(args_info->dcorr_given),
714 >              &(local_args_info.dcorr_given), optarg, 0, 0, ARG_NO,
715 >              check_ambiguity, override, 0, 0,
716 >              "dcorr", 'd',
717 >              additional_error))
718 >            goto failure;
719 >        
720 >          break;
721          case 'l':       /* Lengendre correlation function.  */
722 <          if (local_args_info.lcorr_given)
495 <            {
496 <              fprintf (stderr, "%s: `--lcorr' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
497 <              goto failure;
498 <            }
499 <          if (args_info->lcorr_given && ! override)
500 <            continue;
501 <          local_args_info.lcorr_given = 1;
502 <          args_info->lcorr_given = 1;
722 >        
723            if (args_info->dynamicProps_group_counter && override)
724              reset_group_dynamicProps (args_info);
725            args_info->dynamicProps_group_counter += 1;
726 +        
727 +          if (update_arg( 0 ,
728 +               0 , &(args_info->lcorr_given),
729 +              &(local_args_info.lcorr_given), optarg, 0, 0, ARG_NO,
730 +              check_ambiguity, override, 0, 0,
731 +              "lcorr", 'l',
732 +              additional_error))
733 +            goto failure;
734 +        
735            break;
736 +        case 's':       /* System dipole correlation function.  */
737 +        
738 +          if (args_info->dynamicProps_group_counter && override)
739 +            reset_group_dynamicProps (args_info);
740 +          args_info->dynamicProps_group_counter += 1;
741 +        
742 +          if (update_arg( 0 ,
743 +               0 , &(args_info->sdcorr_given),
744 +              &(local_args_info.sdcorr_given), optarg, 0, 0, ARG_NO,
745 +              check_ambiguity, override, 0, 0,
746 +              "sdcorr", 's',
747 +              additional_error))
748 +            goto failure;
749 +        
750 +          break;
751  
508
752          case 0: /* Long option with no short option */
753            /* select first stuntdouble set.  */
754            if (strcmp (long_options[option_index].name, "sele1") == 0)
755            {
756 <            if (local_args_info.sele1_given)
757 <              {
758 <                fprintf (stderr, "%s: `--sele1' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
759 <                goto failure;
760 <              }
761 <            if (args_info->sele1_given && ! override)
762 <              continue;
763 <            local_args_info.sele1_given = 1;
764 <            args_info->sele1_given = 1;
765 <            if (args_info->sele1_arg)
523 <              free (args_info->sele1_arg); /* free previous string */
524 <            args_info->sele1_arg = gengetopt_strdup (optarg);
525 <            if (args_info->sele1_orig)
526 <              free (args_info->sele1_orig); /* free previous string */
527 <            args_info->sele1_orig = gengetopt_strdup (optarg);
756 >          
757 >          
758 >            if (update_arg( (void *)&(args_info->sele1_arg),
759 >                 &(args_info->sele1_orig), &(args_info->sele1_given),
760 >                &(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING,
761 >                check_ambiguity, override, 0, 0,
762 >                "sele1", '-',
763 >                additional_error))
764 >              goto failure;
765 >          
766            }
767            /* select second stuntdouble set (if sele2 is not set, use script from sele1).  */
768            else if (strcmp (long_options[option_index].name, "sele2") == 0)
769            {
770 <            if (local_args_info.sele2_given)
771 <              {
772 <                fprintf (stderr, "%s: `--sele2' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
773 <                goto failure;
774 <              }
775 <            if (args_info->sele2_given && ! override)
776 <              continue;
777 <            local_args_info.sele2_given = 1;
778 <            args_info->sele2_given = 1;
779 <            if (args_info->sele2_arg)
542 <              free (args_info->sele2_arg); /* free previous string */
543 <            args_info->sele2_arg = gengetopt_strdup (optarg);
544 <            if (args_info->sele2_orig)
545 <              free (args_info->sele2_orig); /* free previous string */
546 <            args_info->sele2_orig = gengetopt_strdup (optarg);
770 >          
771 >          
772 >            if (update_arg( (void *)&(args_info->sele2_arg),
773 >                 &(args_info->sele2_orig), &(args_info->sele2_given),
774 >                &(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING,
775 >                check_ambiguity, override, 0, 0,
776 >                "sele2", '-',
777 >                additional_error))
778 >              goto failure;
779 >          
780            }
781            /* Lengendre Polynomial Order.  */
782            else if (strcmp (long_options[option_index].name, "order") == 0)
783            {
784 <            if (local_args_info.order_given)
785 <              {
786 <                fprintf (stderr, "%s: `--order' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
787 <                goto failure;
788 <              }
789 <            if (args_info->order_given && ! override)
790 <              continue;
791 <            local_args_info.order_given = 1;
792 <            args_info->order_given = 1;
793 <            args_info->order_arg = strtol (optarg,&stop_char,0);
561 <            if (args_info->order_orig)
562 <              free (args_info->order_orig); /* free previous string */
563 <            args_info->order_orig = gengetopt_strdup (optarg);
784 >          
785 >          
786 >            if (update_arg( (void *)&(args_info->order_arg),
787 >                 &(args_info->order_orig), &(args_info->order_given),
788 >                &(local_args_info.order_given), optarg, 0, 0, ARG_INT,
789 >                check_ambiguity, override, 0, 0,
790 >                "order", '-',
791 >                additional_error))
792 >              goto failure;
793 >          
794            }
795            /* Radial rmsd.  */
796            else if (strcmp (long_options[option_index].name, "r_rcorr") == 0)
797            {
798 <            if (local_args_info.r_rcorr_given)
569 <              {
570 <                fprintf (stderr, "%s: `--r_rcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
571 <                goto failure;
572 <              }
573 <            if (args_info->r_rcorr_given && ! override)
574 <              continue;
575 <            local_args_info.r_rcorr_given = 1;
576 <            args_info->r_rcorr_given = 1;
798 >          
799              if (args_info->dynamicProps_group_counter && override)
800                reset_group_dynamicProps (args_info);
801              args_info->dynamicProps_group_counter += 1;
802 <            break;
802 >          
803 >            if (update_arg( 0 ,
804 >                 0 , &(args_info->r_rcorr_given),
805 >                &(local_args_info.r_rcorr_given), optarg, 0, 0, ARG_NO,
806 >                check_ambiguity, override, 0, 0,
807 >                "r_rcorr", '-',
808 >                additional_error))
809 >              goto failure;
810 >          
811            }
812            /* Angular rmsd.  */
813            else if (strcmp (long_options[option_index].name, "thetacorr") == 0)
814            {
815 <            if (local_args_info.thetacorr_given)
586 <              {
587 <                fprintf (stderr, "%s: `--thetacorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
588 <                goto failure;
589 <              }
590 <            if (args_info->thetacorr_given && ! override)
591 <              continue;
592 <            local_args_info.thetacorr_given = 1;
593 <            args_info->thetacorr_given = 1;
815 >          
816              if (args_info->dynamicProps_group_counter && override)
817                reset_group_dynamicProps (args_info);
818              args_info->dynamicProps_group_counter += 1;
819 <            break;
819 >          
820 >            if (update_arg( 0 ,
821 >                 0 , &(args_info->thetacorr_given),
822 >                &(local_args_info.thetacorr_given), optarg, 0, 0, ARG_NO,
823 >                check_ambiguity, override, 0, 0,
824 >                "thetacorr", '-',
825 >                additional_error))
826 >              goto failure;
827 >          
828            }
829            /* Directional rmsd for particles with unit vectors.  */
830            else if (strcmp (long_options[option_index].name, "drcorr") == 0)
831            {
832 <            if (local_args_info.drcorr_given)
603 <              {
604 <                fprintf (stderr, "%s: `--drcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
605 <                goto failure;
606 <              }
607 <            if (args_info->drcorr_given && ! override)
608 <              continue;
609 <            local_args_info.drcorr_given = 1;
610 <            args_info->drcorr_given = 1;
832 >          
833              if (args_info->dynamicProps_group_counter && override)
834                reset_group_dynamicProps (args_info);
835              args_info->dynamicProps_group_counter += 1;
836 <            break;
836 >          
837 >            if (update_arg( 0 ,
838 >                 0 , &(args_info->drcorr_given),
839 >                &(local_args_info.drcorr_given), optarg, 0, 0, ARG_NO,
840 >                check_ambiguity, override, 0, 0,
841 >                "drcorr", '-',
842 >                additional_error))
843 >              goto failure;
844 >          
845            }
846            /* Helfand moment for thermal conductvity.  */
847            else if (strcmp (long_options[option_index].name, "helfandEcorr") == 0)
848            {
849 <            if (local_args_info.helfandEcorr_given)
620 <              {
621 <                fprintf (stderr, "%s: `--helfandEcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
622 <                goto failure;
623 <              }
624 <            if (args_info->helfandEcorr_given && ! override)
625 <              continue;
626 <            local_args_info.helfandEcorr_given = 1;
627 <            args_info->helfandEcorr_given = 1;
849 >          
850              if (args_info->dynamicProps_group_counter && override)
851                reset_group_dynamicProps (args_info);
852              args_info->dynamicProps_group_counter += 1;
853 <            break;
853 >          
854 >            if (update_arg( 0 ,
855 >                 0 , &(args_info->helfandEcorr_given),
856 >                &(local_args_info.helfandEcorr_given), optarg, 0, 0, ARG_NO,
857 >                check_ambiguity, override, 0, 0,
858 >                "helfandEcorr", '-',
859 >                additional_error))
860 >              goto failure;
861 >          
862            }
863 +          /* Stress tensor correlation function.  */
864 +          else if (strcmp (long_options[option_index].name, "stresscorr") == 0)
865 +          {
866            
867 +            if (args_info->dynamicProps_group_counter && override)
868 +              reset_group_dynamicProps (args_info);
869 +            args_info->dynamicProps_group_counter += 1;
870 +          
871 +            if (update_arg( 0 ,
872 +                 0 , &(args_info->stresscorr_given),
873 +                &(local_args_info.stresscorr_given), optarg, 0, 0, ARG_NO,
874 +                check_ambiguity, override, 0, 0,
875 +                "stresscorr", '-',
876 +                additional_error))
877 +              goto failure;
878 +          
879 +          }
880 +          
881            break;
882          case '?':       /* Invalid option.  */
883            /* `getopt_long' already printed an error message.  */
# Line 644 | Line 891 | cmdline_parser_internal (int argc, char * const *argv,
891  
892    if (args_info->dynamicProps_group_counter > 1)
893      {
894 <      fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required.%s\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : ""));
894 >      fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : ""));
895        error = 1;
896      }
897    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines