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 1098 by chuckv, Thu Dec 14 19:38:56 2006 UTC vs.
Revision 1596 by gezelter, Mon Jul 25 17:30:53 2011 UTC

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

Comparing trunk/src/applications/dynamicProps/DynamicPropsCmd.c (property svn:keywords):
Revision 1098 by chuckv, Thu Dec 14 19:38:56 2006 UTC vs.
Revision 1596 by gezelter, Mon Jul 25 17:30:53 2011 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines