ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dump2Xyz/Dump2XYZCmd.cpp
(Generate patch)

Comparing:
trunk/src/applications/dump2Xyz/Dump2XYZCmd.c (file contents), Revision 1442 by gezelter, Mon May 10 17:28:26 2010 UTC vs.
trunk/src/applications/dump2Xyz/Dump2XYZCmd.cpp (file contents), Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 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 Dump2XYZ.ggo -F Dump2XYZCmd
4 >  gengetopt --file-name=Dump2XYZCmd --unamed-opts
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 + #ifdef WIN32
25 + #include "utils/wingetopt.h"
26 + #else
27 + #include <getopt.h>
28 + #endif
29 +
30 +
31   #include "Dump2XYZCmd.h"
32  
33 + const char *gengetopt_args_info_purpose = "";
34 +
35 + const char *gengetopt_args_info_usage = "Usage: Dump2XYZ [OPTIONS]... [FILES]...";
36 +
37 + const char *gengetopt_args_info_description = "";
38 +
39 + const char *gengetopt_args_info_help[] = {
40 +  "  -h, --help                    Print help and exit",
41 +  "  -V, --version                 Print version and exit",
42 +  "  -i, --input=filename          input dump file",
43 +  "  -o, --output=filename         output file name",
44 +  "  -n, --frame=INT               print every n frame  (default=`1')",
45 +  "  -w, --water                   skip the the waters  (default=off)",
46 +  "  -m, --periodicBox             map to the periodic box  (default=off)",
47 +  "  -z, --zconstraint             replace the atom types of zconstraint molecules \n                                   (default=off)",
48 +  "  -r, --rigidbody               add a pseudo COM atom to rigidbody  \n                                  (default=off)",
49 +  "  -t, --watertype               replace the atom type of water model  \n                                  (default=on)",
50 +  "  -s, --selection=selection script\n                                general selection syntax",
51 +  "      --originsele=selection script\n                                select origin",
52 +  "      --refsele=selection script\n                                select reference",
53 +  "      --repeatX=INT             The number of images to repeat in the x \n                                  direction  (default=`0')",
54 +  "      --repeatY=INT             The number of images to repeat in the y \n                                  direction  (default=`0')",
55 +  "      --repeatZ=INT             The number of images to repeat in the z \n                                  direction  (default=`0')",
56 +  "  -b, --basetype                Convert to base atom type  (default=off)",
57 +  "  -v, --velocities              Print velocities in xyz file  (default=off)",
58 +  "  -f, --forces                  Print forces xyz file  (default=off)",
59 +  "  -u, --vectors                 Print vectors (dipoles, etc) in xyz file  \n                                  (default=off)",
60 +  "  -c, --charges                 Print charges in xyz file  (default=off)",
61 +  "  -e, --efield                  Print electric field vector in xyz file  \n                                  (default=off)",
62 +    0
63 + };
64 +
65 + typedef enum {ARG_NO
66 +  , ARG_FLAG
67 +  , ARG_STRING
68 +  , ARG_INT
69 + } cmdline_parser_arg_type;
70 +
71   static
72   void clear_given (struct gengetopt_args_info *args_info);
73   static
74   void clear_args (struct gengetopt_args_info *args_info);
75  
76   static int
77 < 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);
77 > cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
78 >                        struct cmdline_parser_params *params, const char *additional_error);
79  
80   static int
81   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
# Line 54 | Line 102 | void clear_given (struct gengetopt_args_info *args_inf
102    args_info->repeatX_given = 0 ;
103    args_info->repeatY_given = 0 ;
104    args_info->repeatZ_given = 0 ;
57  args_info->gb_given = 0 ;
105    args_info->basetype_given = 0 ;
106 <  args_info->printPosOnly_given = 0 ;
106 >  args_info->velocities_given = 0 ;
107 >  args_info->forces_given = 0 ;
108 >  args_info->vectors_given = 0 ;
109 >  args_info->charges_given = 0 ;
110 >  args_info->efield_given = 0 ;
111   }
112  
113   static
114   void clear_args (struct gengetopt_args_info *args_info)
115   {
116 +  FIX_UNUSED (args_info);
117    args_info->input_arg = NULL;
118    args_info->input_orig = NULL;
119    args_info->output_arg = NULL;
# Line 85 | Line 137 | void clear_args (struct gengetopt_args_info *args_info
137    args_info->repeatY_orig = NULL;
138    args_info->repeatZ_arg = 0;
139    args_info->repeatZ_orig = NULL;
88  args_info->gb_arg = NULL;
89  args_info->gb_orig = NULL;
140    args_info->basetype_flag = 0;
141 <  args_info->printPosOnly_flag = 0;
141 >  args_info->velocities_flag = 0;
142 >  args_info->forces_flag = 0;
143 >  args_info->vectors_flag = 0;
144 >  args_info->charges_flag = 0;
145 >  args_info->efield_flag = 0;
146    
147   }
148  
149 + static
150 + void init_args_info(struct gengetopt_args_info *args_info)
151 + {
152 +
153 +
154 +  args_info->help_help = gengetopt_args_info_help[0] ;
155 +  args_info->version_help = gengetopt_args_info_help[1] ;
156 +  args_info->input_help = gengetopt_args_info_help[2] ;
157 +  args_info->output_help = gengetopt_args_info_help[3] ;
158 +  args_info->frame_help = gengetopt_args_info_help[4] ;
159 +  args_info->water_help = gengetopt_args_info_help[5] ;
160 +  args_info->periodicBox_help = gengetopt_args_info_help[6] ;
161 +  args_info->zconstraint_help = gengetopt_args_info_help[7] ;
162 +  args_info->rigidbody_help = gengetopt_args_info_help[8] ;
163 +  args_info->watertype_help = gengetopt_args_info_help[9] ;
164 +  args_info->selection_help = gengetopt_args_info_help[10] ;
165 +  args_info->originsele_help = gengetopt_args_info_help[11] ;
166 +  args_info->refsele_help = gengetopt_args_info_help[12] ;
167 +  args_info->repeatX_help = gengetopt_args_info_help[13] ;
168 +  args_info->repeatY_help = gengetopt_args_info_help[14] ;
169 +  args_info->repeatZ_help = gengetopt_args_info_help[15] ;
170 +  args_info->basetype_help = gengetopt_args_info_help[16] ;
171 +  args_info->velocities_help = gengetopt_args_info_help[17] ;
172 +  args_info->forces_help = gengetopt_args_info_help[18] ;
173 +  args_info->vectors_help = gengetopt_args_info_help[19] ;
174 +  args_info->charges_help = gengetopt_args_info_help[20] ;
175 +  args_info->efield_help = gengetopt_args_info_help[21] ;
176 +  
177 + }
178 +
179   void
180   cmdline_parser_print_version (void)
181   {
182 <  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
182 >  printf ("%s %s\n",
183 >     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
184 >     CMDLINE_PARSER_VERSION);
185   }
186  
187 + static void print_help_common(void) {
188 +  cmdline_parser_print_version ();
189 +
190 +  if (strlen(gengetopt_args_info_purpose) > 0)
191 +    printf("\n%s\n", gengetopt_args_info_purpose);
192 +
193 +  if (strlen(gengetopt_args_info_usage) > 0)
194 +    printf("\n%s\n", gengetopt_args_info_usage);
195 +
196 +  printf("\n");
197 +
198 +  if (strlen(gengetopt_args_info_description) > 0)
199 +    printf("%s\n\n", gengetopt_args_info_description);
200 + }
201 +
202   void
203   cmdline_parser_print_help (void)
204   {
205 <  cmdline_parser_print_version ();
206 <  printf("\nUsage: Dump2XYZ [OPTIONS]...\n\n");
207 <  printf("%s\n","  -h, --help                    Print help and exit");
208 <  printf("%s\n","  -V, --version                 Print version and exit");
108 <  printf("%s\n","  -i, --input=filename          input dump file");
109 <  printf("%s\n","  -o, --output=filename         output file name");
110 <  printf("%s\n","  -n, --frame=INT               print every n frame  (default=`1')");
111 <  printf("%s\n","  -w, --water                   skip the the waters  (default=off)");
112 <  printf("%s\n","  -m, --periodicBox             map to the periodic box  (default=off)");
113 <  printf("%s\n","  -z, --zconstraint             replace the atom types of zconstraint molecules \n                                   (default=off)");
114 <  printf("%s\n","  -r, --rigidbody               add a pseudo COM atom to rigidbody  \n                                  (default=off)");
115 <  printf("%s\n","  -t, --watertype               replace the atom type of water model  \n                                  (default=on)");
116 <  printf("%s\n","  -s, --selection=selection script\n                                general selection syntax");
117 <  printf("%s\n","      --originsele=selection script\n                                select origin");
118 <  printf("%s\n","      --refsele=selection script\n                                select reference");
119 <  printf("%s\n","      --repeatX=INT             The number of images to repeat in the x \n                                  direction  (default=`0')");
120 <  printf("%s\n","      --repeatY=INT             The number of images to repeat in the y \n                                  direction  (default=`0')");
121 <  printf("%s\n","      --repeatZ=INT             The number of images to repeat in the z \n                                  direction  (default=`0')");
122 <  printf("%s\n","      --gb=atomtype             Replace the Gay-Berne atom with four linear \n                                  atoms");
123 <  printf("%s\n","  -b, --basetype                Convert to base atom type  (default=off)");
124 <  printf("%s\n","      --printPosOnly            Print only positions in xyz file  (default=off)");
125 <  
205 >  int i = 0;
206 >  print_help_common();
207 >  while (gengetopt_args_info_help[i])
208 >    printf("%s\n", gengetopt_args_info_help[i++]);
209   }
210  
211   void
# Line 130 | Line 213 | cmdline_parser_init (struct gengetopt_args_info *args_
213   {
214    clear_given (args_info);
215    clear_args (args_info);
216 +  init_args_info (args_info);
217 +
218 +  args_info->inputs = 0;
219 +  args_info->inputs_num = 0;
220   }
221  
222 + void
223 + cmdline_parser_params_init(struct cmdline_parser_params *params)
224 + {
225 +  if (params)
226 +    {
227 +      params->override = 0;
228 +      params->initialize = 1;
229 +      params->check_required = 1;
230 +      params->check_ambiguity = 0;
231 +      params->print_errors = 1;
232 +    }
233 + }
234 +
235 + struct cmdline_parser_params *
236 + cmdline_parser_params_create(void)
237 + {
238 +  struct cmdline_parser_params *params =
239 +    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
240 +  cmdline_parser_params_init(params);  
241 +  return params;
242 + }
243 +
244   static void
245 < cmdline_parser_release (struct gengetopt_args_info *args_info)
245 > free_string_field (char **s)
246   {
247 <  
139 <  if (args_info->input_arg)
247 >  if (*s)
248      {
249 <      free (args_info->input_arg); /* free previous argument */
250 <      args_info->input_arg = 0;
249 >      free (*s);
250 >      *s = 0;
251      }
252 <  if (args_info->input_orig)
253 <    {
254 <      free (args_info->input_orig); /* free previous argument */
255 <      args_info->input_orig = 0;
256 <    }
257 <  if (args_info->output_arg)
258 <    {
259 <      free (args_info->output_arg); /* free previous argument */
260 <      args_info->output_arg = 0;
261 <    }
262 <  if (args_info->output_orig)
263 <    {
264 <      free (args_info->output_orig); /* free previous argument */
265 <      args_info->output_orig = 0;
266 <    }
267 <  if (args_info->frame_orig)
268 <    {
269 <      free (args_info->frame_orig); /* free previous argument */
270 <      args_info->frame_orig = 0;
271 <    }
272 <  if (args_info->selection_arg)
273 <    {
274 <      free (args_info->selection_arg); /* free previous argument */
275 <      args_info->selection_arg = 0;
276 <    }
277 <  if (args_info->selection_orig)
278 <    {
279 <      free (args_info->selection_orig); /* free previous argument */
280 <      args_info->selection_orig = 0;
281 <    }
282 <  if (args_info->originsele_arg)
283 <    {
284 <      free (args_info->originsele_arg); /* free previous argument */
285 <      args_info->originsele_arg = 0;
286 <    }
287 <  if (args_info->originsele_orig)
288 <    {
289 <      free (args_info->originsele_orig); /* free previous argument */
290 <      args_info->originsele_orig = 0;
291 <    }
292 <  if (args_info->refsele_arg)
293 <    {
294 <      free (args_info->refsele_arg); /* free previous argument */
295 <      args_info->refsele_arg = 0;
296 <    }
297 <  if (args_info->refsele_orig)
298 <    {
299 <      free (args_info->refsele_orig); /* free previous argument */
300 <      args_info->refsele_orig = 0;
301 <    }
302 <  if (args_info->repeatX_orig)
195 <    {
196 <      free (args_info->repeatX_orig); /* free previous argument */
197 <      args_info->repeatX_orig = 0;
198 <    }
199 <  if (args_info->repeatY_orig)
200 <    {
201 <      free (args_info->repeatY_orig); /* free previous argument */
202 <      args_info->repeatY_orig = 0;
203 <    }
204 <  if (args_info->repeatZ_orig)
205 <    {
206 <      free (args_info->repeatZ_orig); /* free previous argument */
207 <      args_info->repeatZ_orig = 0;
208 <    }
209 <  if (args_info->gb_arg)
210 <    {
211 <      free (args_info->gb_arg); /* free previous argument */
212 <      args_info->gb_arg = 0;
213 <    }
214 <  if (args_info->gb_orig)
252 > }
253 >
254 >
255 > static void
256 > cmdline_parser_release (struct gengetopt_args_info *args_info)
257 > {
258 >  unsigned int i;
259 >  free_string_field (&(args_info->input_arg));
260 >  free_string_field (&(args_info->input_orig));
261 >  free_string_field (&(args_info->output_arg));
262 >  free_string_field (&(args_info->output_orig));
263 >  free_string_field (&(args_info->frame_orig));
264 >  free_string_field (&(args_info->selection_arg));
265 >  free_string_field (&(args_info->selection_orig));
266 >  free_string_field (&(args_info->originsele_arg));
267 >  free_string_field (&(args_info->originsele_orig));
268 >  free_string_field (&(args_info->refsele_arg));
269 >  free_string_field (&(args_info->refsele_orig));
270 >  free_string_field (&(args_info->repeatX_orig));
271 >  free_string_field (&(args_info->repeatY_orig));
272 >  free_string_field (&(args_info->repeatZ_orig));
273 >  
274 >  
275 >  for (i = 0; i < args_info->inputs_num; ++i)
276 >    free (args_info->inputs [i]);
277 >
278 >  if (args_info->inputs_num)
279 >    free (args_info->inputs);
280 >
281 >  clear_given (args_info);
282 > }
283 >
284 >
285 > static void
286 > write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
287 > {
288 >  FIX_UNUSED (values);
289 >  if (arg) {
290 >    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
291 >  } else {
292 >    fprintf(outfile, "%s\n", opt);
293 >  }
294 > }
295 >
296 >
297 > int
298 > cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
299 > {
300 >  int i = 0;
301 >
302 >  if (!outfile)
303      {
304 <      free (args_info->gb_orig); /* free previous argument */
305 <      args_info->gb_orig = 0;
304 >      fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
305 >      return EXIT_FAILURE;
306      }
307 +
308 +  if (args_info->help_given)
309 +    write_into_file(outfile, "help", 0, 0 );
310 +  if (args_info->version_given)
311 +    write_into_file(outfile, "version", 0, 0 );
312 +  if (args_info->input_given)
313 +    write_into_file(outfile, "input", args_info->input_orig, 0);
314 +  if (args_info->output_given)
315 +    write_into_file(outfile, "output", args_info->output_orig, 0);
316 +  if (args_info->frame_given)
317 +    write_into_file(outfile, "frame", args_info->frame_orig, 0);
318 +  if (args_info->water_given)
319 +    write_into_file(outfile, "water", 0, 0 );
320 +  if (args_info->periodicBox_given)
321 +    write_into_file(outfile, "periodicBox", 0, 0 );
322 +  if (args_info->zconstraint_given)
323 +    write_into_file(outfile, "zconstraint", 0, 0 );
324 +  if (args_info->rigidbody_given)
325 +    write_into_file(outfile, "rigidbody", 0, 0 );
326 +  if (args_info->watertype_given)
327 +    write_into_file(outfile, "watertype", 0, 0 );
328 +  if (args_info->selection_given)
329 +    write_into_file(outfile, "selection", args_info->selection_orig, 0);
330 +  if (args_info->originsele_given)
331 +    write_into_file(outfile, "originsele", args_info->originsele_orig, 0);
332 +  if (args_info->refsele_given)
333 +    write_into_file(outfile, "refsele", args_info->refsele_orig, 0);
334 +  if (args_info->repeatX_given)
335 +    write_into_file(outfile, "repeatX", args_info->repeatX_orig, 0);
336 +  if (args_info->repeatY_given)
337 +    write_into_file(outfile, "repeatY", args_info->repeatY_orig, 0);
338 +  if (args_info->repeatZ_given)
339 +    write_into_file(outfile, "repeatZ", args_info->repeatZ_orig, 0);
340 +  if (args_info->basetype_given)
341 +    write_into_file(outfile, "basetype", 0, 0 );
342 +  if (args_info->velocities_given)
343 +    write_into_file(outfile, "velocities", 0, 0 );
344 +  if (args_info->forces_given)
345 +    write_into_file(outfile, "forces", 0, 0 );
346 +  if (args_info->vectors_given)
347 +    write_into_file(outfile, "vectors", 0, 0 );
348 +  if (args_info->charges_given)
349 +    write_into_file(outfile, "charges", 0, 0 );
350 +  if (args_info->efield_given)
351 +    write_into_file(outfile, "efield", 0, 0 );
352    
353 <  clear_given (args_info);
353 >
354 >  i = EXIT_SUCCESS;
355 >  return i;
356   }
357  
358   int
# Line 234 | Line 369 | cmdline_parser_file_save(const char *filename, struct
369        return EXIT_FAILURE;
370      }
371  
372 <  if (args_info->help_given) {
238 <    fprintf(outfile, "%s\n", "help");
239 <  }
240 <  if (args_info->version_given) {
241 <    fprintf(outfile, "%s\n", "version");
242 <  }
243 <  if (args_info->input_given) {
244 <    if (args_info->input_orig) {
245 <      fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig);
246 <    } else {
247 <      fprintf(outfile, "%s\n", "input");
248 <    }
249 <  }
250 <  if (args_info->output_given) {
251 <    if (args_info->output_orig) {
252 <      fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
253 <    } else {
254 <      fprintf(outfile, "%s\n", "output");
255 <    }
256 <  }
257 <  if (args_info->frame_given) {
258 <    if (args_info->frame_orig) {
259 <      fprintf(outfile, "%s=\"%s\"\n", "frame", args_info->frame_orig);
260 <    } else {
261 <      fprintf(outfile, "%s\n", "frame");
262 <    }
263 <  }
264 <  if (args_info->water_given) {
265 <    fprintf(outfile, "%s\n", "water");
266 <  }
267 <  if (args_info->periodicBox_given) {
268 <    fprintf(outfile, "%s\n", "periodicBox");
269 <  }
270 <  if (args_info->zconstraint_given) {
271 <    fprintf(outfile, "%s\n", "zconstraint");
272 <  }
273 <  if (args_info->rigidbody_given) {
274 <    fprintf(outfile, "%s\n", "rigidbody");
275 <  }
276 <  if (args_info->watertype_given) {
277 <    fprintf(outfile, "%s\n", "watertype");
278 <  }
279 <  if (args_info->selection_given) {
280 <    if (args_info->selection_orig) {
281 <      fprintf(outfile, "%s=\"%s\"\n", "selection", args_info->selection_orig);
282 <    } else {
283 <      fprintf(outfile, "%s\n", "selection");
284 <    }
285 <  }
286 <  if (args_info->originsele_given) {
287 <    if (args_info->originsele_orig) {
288 <      fprintf(outfile, "%s=\"%s\"\n", "originsele", args_info->originsele_orig);
289 <    } else {
290 <      fprintf(outfile, "%s\n", "originsele");
291 <    }
292 <  }
293 <  if (args_info->refsele_given) {
294 <    if (args_info->refsele_orig) {
295 <      fprintf(outfile, "%s=\"%s\"\n", "refsele", args_info->refsele_orig);
296 <    } else {
297 <      fprintf(outfile, "%s\n", "refsele");
298 <    }
299 <  }
300 <  if (args_info->repeatX_given) {
301 <    if (args_info->repeatX_orig) {
302 <      fprintf(outfile, "%s=\"%s\"\n", "repeatX", args_info->repeatX_orig);
303 <    } else {
304 <      fprintf(outfile, "%s\n", "repeatX");
305 <    }
306 <  }
307 <  if (args_info->repeatY_given) {
308 <    if (args_info->repeatY_orig) {
309 <      fprintf(outfile, "%s=\"%s\"\n", "repeatY", args_info->repeatY_orig);
310 <    } else {
311 <      fprintf(outfile, "%s\n", "repeatY");
312 <    }
313 <  }
314 <  if (args_info->repeatZ_given) {
315 <    if (args_info->repeatZ_orig) {
316 <      fprintf(outfile, "%s=\"%s\"\n", "repeatZ", args_info->repeatZ_orig);
317 <    } else {
318 <      fprintf(outfile, "%s\n", "repeatZ");
319 <    }
320 <  }
321 <  if (args_info->gb_given) {
322 <    if (args_info->gb_orig) {
323 <      fprintf(outfile, "%s=\"%s\"\n", "gb", args_info->gb_orig);
324 <    } else {
325 <      fprintf(outfile, "%s\n", "gb");
326 <    }
327 <  }
328 <  if (args_info->basetype_given) {
329 <    fprintf(outfile, "%s\n", "basetype");
330 <  }
331 <  if (args_info->printPosOnly_given) {
332 <    fprintf(outfile, "%s\n", "printPosOnly");
333 <  }
334 <  
372 >  i = cmdline_parser_dump(outfile, args_info);
373    fclose (outfile);
374  
337  i = EXIT_SUCCESS;
375    return i;
376   }
377  
# Line 344 | Line 381 | cmdline_parser_free (struct gengetopt_args_info *args_
381    cmdline_parser_release (args_info);
382   }
383  
384 <
348 < /* gengetopt_strdup() */
349 < /* strdup.c replacement of strdup, which is not standard */
384 > /** @brief replacement of strdup, which is not standard */
385   char *
386   gengetopt_strdup (const char *s)
387   {
388 <  char *result = NULL;
388 >  char *result = 0;
389    if (!s)
390      return result;
391  
# Line 362 | Line 397 | int
397   }
398  
399   int
400 < cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
400 > cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
401   {
402    return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
403   }
404  
405   int
406 < cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
406 > cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
407 >                   struct cmdline_parser_params *params)
408   {
409    int result;
410 +  result = cmdline_parser_internal (argc, argv, args_info, params, 0);
411  
412 <  result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
412 >  if (result == EXIT_FAILURE)
413 >    {
414 >      cmdline_parser_free (args_info);
415 >      exit (EXIT_FAILURE);
416 >    }
417 >  
418 >  return result;
419 > }
420  
421 + int
422 + cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
423 + {
424 +  int result;
425 +  struct cmdline_parser_params params;
426 +  
427 +  params.override = override;
428 +  params.initialize = initialize;
429 +  params.check_required = check_required;
430 +  params.check_ambiguity = 0;
431 +  params.print_errors = 1;
432 +
433 +  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
434 +
435    if (result == EXIT_FAILURE)
436      {
437        cmdline_parser_free (args_info);
# Line 388 | Line 446 | cmdline_parser_required (struct gengetopt_args_info *a
446   {
447    int result = EXIT_SUCCESS;
448  
449 <  if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
449 >  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
450      result = EXIT_FAILURE;
451  
452    if (result == EXIT_FAILURE)
# Line 404 | Line 462 | cmdline_parser_required2 (struct gengetopt_args_info *
462   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
463   {
464    int error = 0;
465 +  FIX_UNUSED (additional_error);
466  
467 +  /* checks for required options */
468    if (! args_info->input_given)
469      {
470        fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
471        error = 1;
472      }
473 +  
474 +  
475 +  /* checks for dependences among options */
476  
477    return error;
478   }
479  
480 +
481 + static char *package_name = 0;
482 +
483 + /**
484 + * @brief updates an option
485 + * @param field the generic pointer to the field to update
486 + * @param orig_field the pointer to the orig field
487 + * @param field_given the pointer to the number of occurrence of this option
488 + * @param prev_given the pointer to the number of occurrence already seen
489 + * @param value the argument for this option (if null no arg was specified)
490 + * @param possible_values the possible values for this option (if specified)
491 + * @param default_value the default value (in case the option only accepts fixed values)
492 + * @param arg_type the type of this option
493 + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
494 + * @param override @see cmdline_parser_params.override
495 + * @param no_free whether to free a possible previous value
496 + * @param multiple_option whether this is a multiple option
497 + * @param long_opt the corresponding long option
498 + * @param short_opt the corresponding short option (or '-' if none)
499 + * @param additional_error possible further error specification
500 + */
501 + static
502 + int update_arg(void *field, char **orig_field,
503 +               unsigned int *field_given, unsigned int *prev_given,
504 +               char *value, const char *possible_values[],
505 +               const char *default_value,
506 +               cmdline_parser_arg_type arg_type,
507 +               int check_ambiguity, int override,
508 +               int no_free, int multiple_option,
509 +               const char *long_opt, char short_opt,
510 +               const char *additional_error)
511 + {
512 +  char *stop_char = 0;
513 +  const char *val = value;
514 +  int found;
515 +  char **string_field;
516 +  FIX_UNUSED (field);
517 +
518 +  stop_char = 0;
519 +  found = 0;
520 +
521 +  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
522 +    {
523 +      if (short_opt != '-')
524 +        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
525 +               package_name, long_opt, short_opt,
526 +               (additional_error ? additional_error : ""));
527 +      else
528 +        fprintf (stderr, "%s: `--%s' option given more than once%s\n",
529 +               package_name, long_opt,
530 +               (additional_error ? additional_error : ""));
531 +      return 1; /* failure */
532 +    }
533 +
534 +  FIX_UNUSED (default_value);
535 +    
536 +  if (field_given && *field_given && ! override)
537 +    return 0;
538 +  if (prev_given)
539 +    (*prev_given)++;
540 +  if (field_given)
541 +    (*field_given)++;
542 +  if (possible_values)
543 +    val = possible_values[found];
544 +
545 +  switch(arg_type) {
546 +  case ARG_FLAG:
547 +    *((int *)field) = !*((int *)field);
548 +    break;
549 +  case ARG_INT:
550 +    if (val) *((int *)field) = strtol (val, &stop_char, 0);
551 +    break;
552 +  case ARG_STRING:
553 +    if (val) {
554 +      string_field = (char **)field;
555 +      if (!no_free && *string_field)
556 +        free (*string_field); /* free previous string */
557 +      *string_field = gengetopt_strdup (val);
558 +    }
559 +    break;
560 +  default:
561 +    break;
562 +  };
563 +
564 +  /* check numeric conversion */
565 +  switch(arg_type) {
566 +  case ARG_INT:
567 +    if (val && !(stop_char && *stop_char == '\0')) {
568 +      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
569 +      return 1; /* failure */
570 +    }
571 +    break;
572 +  default:
573 +    ;
574 +  };
575 +
576 +  /* store the original value */
577 +  switch(arg_type) {
578 +  case ARG_NO:
579 +  case ARG_FLAG:
580 +    break;
581 +  default:
582 +    if (value && orig_field) {
583 +      if (no_free) {
584 +        *orig_field = value;
585 +      } else {
586 +        if (*orig_field)
587 +          free (*orig_field); /* free previous string */
588 +        *orig_field = gengetopt_strdup (value);
589 +      }
590 +    }
591 +  };
592 +
593 +  return 0; /* OK */
594 + }
595 +
596 +
597   int
598 < 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)
598 > cmdline_parser_internal (
599 >  int argc, char **argv, struct gengetopt_args_info *args_info,
600 >                        struct cmdline_parser_params *params, const char *additional_error)
601   {
602    int c;        /* Character of the parsed option.  */
603  
604    int error = 0;
605    struct gengetopt_args_info local_args_info;
606 +  
607 +  int override;
608 +  int initialize;
609 +  int check_required;
610 +  int check_ambiguity;
611 +  
612 +  package_name = argv[0];
613 +  
614 +  override = params->override;
615 +  initialize = params->initialize;
616 +  check_required = params->check_required;
617 +  check_ambiguity = params->check_ambiguity;
618  
619    if (initialize)
620      cmdline_parser_init (args_info);
# Line 428 | Line 622 | cmdline_parser_internal (int argc, char * const *argv,
622    cmdline_parser_init (&local_args_info);
623  
624    optarg = 0;
625 <  optind = 1;
626 <  opterr = 1;
625 >  optind = 0;
626 >  opterr = params->print_errors;
627    optopt = '?';
628  
629    while (1)
630      {
631        int option_index = 0;
438      char *stop_char;
632  
633        static struct option long_options[] = {
634          { "help",       0, NULL, 'h' },
# Line 454 | Line 647 | cmdline_parser_internal (int argc, char * const *argv,
647          { "repeatX",    1, NULL, 0 },
648          { "repeatY",    1, NULL, 0 },
649          { "repeatZ",    1, NULL, 0 },
457        { "gb", 1, NULL, 0 },
650          { "basetype",   0, NULL, 'b' },
651 <        { "printPosOnly",       0, NULL, 0 },
652 <        { NULL, 0, NULL, 0 }
651 >        { "velocities", 0, NULL, 'v' },
652 >        { "forces",     0, NULL, 'f' },
653 >        { "vectors",    0, NULL, 'u' },
654 >        { "charges",    0, NULL, 'c' },
655 >        { "efield",     0, NULL, 'e' },
656 >        { 0,  0, 0, 0 }
657        };
658  
659 <      stop_char = 0;
464 <      c = getopt_long (argc, argv, "hVi:o:n:wmzrts:b", long_options, &option_index);
659 >      c = getopt_long (argc, argv, "hVi:o:n:wmzrts:bvfuce", long_options, &option_index);
660  
661        if (c == -1) break;       /* Exit from `while (1)' loop.  */
662  
# Line 478 | Line 673 | cmdline_parser_internal (int argc, char * const *argv,
673            exit (EXIT_SUCCESS);
674  
675          case 'i':       /* input dump file.  */
676 <          if (local_args_info.input_given)
677 <            {
678 <              fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
679 <              goto failure;
680 <            }
681 <          if (args_info->input_given && ! override)
682 <            continue;
683 <          local_args_info.input_given = 1;
684 <          args_info->input_given = 1;
685 <          if (args_info->input_arg)
491 <            free (args_info->input_arg); /* free previous string */
492 <          args_info->input_arg = gengetopt_strdup (optarg);
493 <          if (args_info->input_orig)
494 <            free (args_info->input_orig); /* free previous string */
495 <          args_info->input_orig = gengetopt_strdup (optarg);
676 >        
677 >        
678 >          if (update_arg( (void *)&(args_info->input_arg),
679 >               &(args_info->input_orig), &(args_info->input_given),
680 >              &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
681 >              check_ambiguity, override, 0, 0,
682 >              "input", 'i',
683 >              additional_error))
684 >            goto failure;
685 >        
686            break;
497
687          case 'o':       /* output file name.  */
688 <          if (local_args_info.output_given)
689 <            {
690 <              fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
691 <              goto failure;
692 <            }
693 <          if (args_info->output_given && ! override)
694 <            continue;
695 <          local_args_info.output_given = 1;
696 <          args_info->output_given = 1;
697 <          if (args_info->output_arg)
509 <            free (args_info->output_arg); /* free previous string */
510 <          args_info->output_arg = gengetopt_strdup (optarg);
511 <          if (args_info->output_orig)
512 <            free (args_info->output_orig); /* free previous string */
513 <          args_info->output_orig = gengetopt_strdup (optarg);
688 >        
689 >        
690 >          if (update_arg( (void *)&(args_info->output_arg),
691 >               &(args_info->output_orig), &(args_info->output_given),
692 >              &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
693 >              check_ambiguity, override, 0, 0,
694 >              "output", 'o',
695 >              additional_error))
696 >            goto failure;
697 >        
698            break;
515
699          case 'n':       /* print every n frame.  */
700 <          if (local_args_info.frame_given)
701 <            {
702 <              fprintf (stderr, "%s: `--frame' (`-n') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
703 <              goto failure;
704 <            }
705 <          if (args_info->frame_given && ! override)
706 <            continue;
707 <          local_args_info.frame_given = 1;
525 <          args_info->frame_given = 1;
526 <          args_info->frame_arg = strtol (optarg, &stop_char, 0);
527 <          if (!(stop_char && *stop_char == '\0')) {
528 <            fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
700 >        
701 >        
702 >          if (update_arg( (void *)&(args_info->frame_arg),
703 >               &(args_info->frame_orig), &(args_info->frame_given),
704 >              &(local_args_info.frame_given), optarg, 0, "1", ARG_INT,
705 >              check_ambiguity, override, 0, 0,
706 >              "frame", 'n',
707 >              additional_error))
708              goto failure;
709 <          }
531 <          if (args_info->frame_orig)
532 <            free (args_info->frame_orig); /* free previous string */
533 <          args_info->frame_orig = gengetopt_strdup (optarg);
709 >        
710            break;
535
711          case 'w':       /* skip the the waters.  */
712 <          if (local_args_info.water_given)
713 <            {
714 <              fprintf (stderr, "%s: `--water' (`-w') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
715 <              goto failure;
716 <            }
717 <          if (args_info->water_given && ! override)
718 <            continue;
719 <          local_args_info.water_given = 1;
545 <          args_info->water_given = 1;
546 <          args_info->water_flag = !(args_info->water_flag);
712 >        
713 >        
714 >          if (update_arg((void *)&(args_info->water_flag), 0, &(args_info->water_given),
715 >              &(local_args_info.water_given), optarg, 0, 0, ARG_FLAG,
716 >              check_ambiguity, override, 1, 0, "water", 'w',
717 >              additional_error))
718 >            goto failure;
719 >        
720            break;
548
721          case 'm':       /* map to the periodic box.  */
722 <          if (local_args_info.periodicBox_given)
723 <            {
724 <              fprintf (stderr, "%s: `--periodicBox' (`-m') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
725 <              goto failure;
726 <            }
727 <          if (args_info->periodicBox_given && ! override)
728 <            continue;
729 <          local_args_info.periodicBox_given = 1;
558 <          args_info->periodicBox_given = 1;
559 <          args_info->periodicBox_flag = !(args_info->periodicBox_flag);
722 >        
723 >        
724 >          if (update_arg((void *)&(args_info->periodicBox_flag), 0, &(args_info->periodicBox_given),
725 >              &(local_args_info.periodicBox_given), optarg, 0, 0, ARG_FLAG,
726 >              check_ambiguity, override, 1, 0, "periodicBox", 'm',
727 >              additional_error))
728 >            goto failure;
729 >        
730            break;
561
731          case 'z':       /* replace the atom types of zconstraint molecules.  */
732 <          if (local_args_info.zconstraint_given)
733 <            {
734 <              fprintf (stderr, "%s: `--zconstraint' (`-z') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
735 <              goto failure;
736 <            }
737 <          if (args_info->zconstraint_given && ! override)
738 <            continue;
739 <          local_args_info.zconstraint_given = 1;
571 <          args_info->zconstraint_given = 1;
572 <          args_info->zconstraint_flag = !(args_info->zconstraint_flag);
732 >        
733 >        
734 >          if (update_arg((void *)&(args_info->zconstraint_flag), 0, &(args_info->zconstraint_given),
735 >              &(local_args_info.zconstraint_given), optarg, 0, 0, ARG_FLAG,
736 >              check_ambiguity, override, 1, 0, "zconstraint", 'z',
737 >              additional_error))
738 >            goto failure;
739 >        
740            break;
574
741          case 'r':       /* add a pseudo COM atom to rigidbody.  */
742 <          if (local_args_info.rigidbody_given)
743 <            {
744 <              fprintf (stderr, "%s: `--rigidbody' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
745 <              goto failure;
746 <            }
747 <          if (args_info->rigidbody_given && ! override)
748 <            continue;
749 <          local_args_info.rigidbody_given = 1;
584 <          args_info->rigidbody_given = 1;
585 <          args_info->rigidbody_flag = !(args_info->rigidbody_flag);
742 >        
743 >        
744 >          if (update_arg((void *)&(args_info->rigidbody_flag), 0, &(args_info->rigidbody_given),
745 >              &(local_args_info.rigidbody_given), optarg, 0, 0, ARG_FLAG,
746 >              check_ambiguity, override, 1, 0, "rigidbody", 'r',
747 >              additional_error))
748 >            goto failure;
749 >        
750            break;
587
751          case 't':       /* replace the atom type of water model.  */
752 <          if (local_args_info.watertype_given)
753 <            {
754 <              fprintf (stderr, "%s: `--watertype' (`-t') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
755 <              goto failure;
756 <            }
757 <          if (args_info->watertype_given && ! override)
758 <            continue;
759 <          local_args_info.watertype_given = 1;
597 <          args_info->watertype_given = 1;
598 <          args_info->watertype_flag = !(args_info->watertype_flag);
752 >        
753 >        
754 >          if (update_arg((void *)&(args_info->watertype_flag), 0, &(args_info->watertype_given),
755 >              &(local_args_info.watertype_given), optarg, 0, 0, ARG_FLAG,
756 >              check_ambiguity, override, 1, 0, "watertype", 't',
757 >              additional_error))
758 >            goto failure;
759 >        
760            break;
600
761          case 's':       /* general selection syntax.  */
762 <          if (local_args_info.selection_given)
763 <            {
764 <              fprintf (stderr, "%s: `--selection' (`-s') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
765 <              goto failure;
766 <            }
767 <          if (args_info->selection_given && ! override)
768 <            continue;
769 <          local_args_info.selection_given = 1;
770 <          args_info->selection_given = 1;
771 <          if (args_info->selection_arg)
772 <            free (args_info->selection_arg); /* free previous string */
613 <          args_info->selection_arg = gengetopt_strdup (optarg);
614 <          if (args_info->selection_orig)
615 <            free (args_info->selection_orig); /* free previous string */
616 <          args_info->selection_orig = gengetopt_strdup (optarg);
617 <          break;
618 <
762 >        
763 >        
764 >          if (update_arg( (void *)&(args_info->selection_arg),
765 >               &(args_info->selection_orig), &(args_info->selection_given),
766 >              &(local_args_info.selection_given), optarg, 0, 0, ARG_STRING,
767 >              check_ambiguity, override, 0, 0,
768 >              "selection", 's',
769 >              additional_error))
770 >            goto failure;
771 >        
772 >          break;
773          case 'b':       /* Convert to base atom type.  */
774 <          if (local_args_info.basetype_given)
775 <            {
776 <              fprintf (stderr, "%s: `--basetype' (`-b') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
777 <              goto failure;
778 <            }
779 <          if (args_info->basetype_given && ! override)
780 <            continue;
781 <          local_args_info.basetype_given = 1;
628 <          args_info->basetype_given = 1;
629 <          args_info->basetype_flag = !(args_info->basetype_flag);
774 >        
775 >        
776 >          if (update_arg((void *)&(args_info->basetype_flag), 0, &(args_info->basetype_given),
777 >              &(local_args_info.basetype_given), optarg, 0, 0, ARG_FLAG,
778 >              check_ambiguity, override, 1, 0, "basetype", 'b',
779 >              additional_error))
780 >            goto failure;
781 >        
782            break;
783 +        case 'v':       /* Print velocities in xyz file.  */
784 +        
785 +        
786 +          if (update_arg((void *)&(args_info->velocities_flag), 0, &(args_info->velocities_given),
787 +              &(local_args_info.velocities_given), optarg, 0, 0, ARG_FLAG,
788 +              check_ambiguity, override, 1, 0, "velocities", 'v',
789 +              additional_error))
790 +            goto failure;
791 +        
792 +          break;
793 +        case 'f':       /* Print forces xyz file.  */
794 +        
795 +        
796 +          if (update_arg((void *)&(args_info->forces_flag), 0, &(args_info->forces_given),
797 +              &(local_args_info.forces_given), optarg, 0, 0, ARG_FLAG,
798 +              check_ambiguity, override, 1, 0, "forces", 'f',
799 +              additional_error))
800 +            goto failure;
801 +        
802 +          break;
803 +        case 'u':       /* Print vectors (dipoles, etc) in xyz file.  */
804 +        
805 +        
806 +          if (update_arg((void *)&(args_info->vectors_flag), 0, &(args_info->vectors_given),
807 +              &(local_args_info.vectors_given), optarg, 0, 0, ARG_FLAG,
808 +              check_ambiguity, override, 1, 0, "vectors", 'u',
809 +              additional_error))
810 +            goto failure;
811 +        
812 +          break;
813 +        case 'c':       /* Print charges in xyz file.  */
814 +        
815 +        
816 +          if (update_arg((void *)&(args_info->charges_flag), 0, &(args_info->charges_given),
817 +              &(local_args_info.charges_given), optarg, 0, 0, ARG_FLAG,
818 +              check_ambiguity, override, 1, 0, "charges", 'c',
819 +              additional_error))
820 +            goto failure;
821 +        
822 +          break;
823 +        case 'e':       /* Print electric field vector in xyz file.  */
824 +        
825 +        
826 +          if (update_arg((void *)&(args_info->efield_flag), 0, &(args_info->efield_given),
827 +              &(local_args_info.efield_given), optarg, 0, 0, ARG_FLAG,
828 +              check_ambiguity, override, 1, 0, "efield", 'e',
829 +              additional_error))
830 +            goto failure;
831 +        
832 +          break;
833  
632
834          case 0: /* Long option with no short option */
835            /* select origin.  */
836            if (strcmp (long_options[option_index].name, "originsele") == 0)
837            {
838 <            if (local_args_info.originsele_given)
839 <              {
840 <                fprintf (stderr, "%s: `--originsele' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
841 <                goto failure;
842 <              }
843 <            if (args_info->originsele_given && ! override)
844 <              continue;
845 <            local_args_info.originsele_given = 1;
846 <            args_info->originsele_given = 1;
847 <            if (args_info->originsele_arg)
647 <              free (args_info->originsele_arg); /* free previous string */
648 <            args_info->originsele_arg = gengetopt_strdup (optarg);
649 <            if (args_info->originsele_orig)
650 <              free (args_info->originsele_orig); /* free previous string */
651 <            args_info->originsele_orig = gengetopt_strdup (optarg);
838 >          
839 >          
840 >            if (update_arg( (void *)&(args_info->originsele_arg),
841 >                 &(args_info->originsele_orig), &(args_info->originsele_given),
842 >                &(local_args_info.originsele_given), optarg, 0, 0, ARG_STRING,
843 >                check_ambiguity, override, 0, 0,
844 >                "originsele", '-',
845 >                additional_error))
846 >              goto failure;
847 >          
848            }
849            /* select reference.  */
850            else if (strcmp (long_options[option_index].name, "refsele") == 0)
851            {
852 <            if (local_args_info.refsele_given)
853 <              {
854 <                fprintf (stderr, "%s: `--refsele' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
855 <                goto failure;
856 <              }
857 <            if (args_info->refsele_given && ! override)
858 <              continue;
859 <            local_args_info.refsele_given = 1;
860 <            args_info->refsele_given = 1;
861 <            if (args_info->refsele_arg)
666 <              free (args_info->refsele_arg); /* free previous string */
667 <            args_info->refsele_arg = gengetopt_strdup (optarg);
668 <            if (args_info->refsele_orig)
669 <              free (args_info->refsele_orig); /* free previous string */
670 <            args_info->refsele_orig = gengetopt_strdup (optarg);
852 >          
853 >          
854 >            if (update_arg( (void *)&(args_info->refsele_arg),
855 >                 &(args_info->refsele_orig), &(args_info->refsele_given),
856 >                &(local_args_info.refsele_given), optarg, 0, 0, ARG_STRING,
857 >                check_ambiguity, override, 0, 0,
858 >                "refsele", '-',
859 >                additional_error))
860 >              goto failure;
861 >          
862            }
863            /* The number of images to repeat in the x direction.  */
864            else if (strcmp (long_options[option_index].name, "repeatX") == 0)
865            {
866 <            if (local_args_info.repeatX_given)
867 <              {
868 <                fprintf (stderr, "%s: `--repeatX' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
869 <                goto failure;
870 <              }
871 <            if (args_info->repeatX_given && ! override)
872 <              continue;
873 <            local_args_info.repeatX_given = 1;
683 <            args_info->repeatX_given = 1;
684 <            args_info->repeatX_arg = strtol (optarg, &stop_char, 0);
685 <            if (!(stop_char && *stop_char == '\0')) {
686 <              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
866 >          
867 >          
868 >            if (update_arg( (void *)&(args_info->repeatX_arg),
869 >                 &(args_info->repeatX_orig), &(args_info->repeatX_given),
870 >                &(local_args_info.repeatX_given), optarg, 0, "0", ARG_INT,
871 >                check_ambiguity, override, 0, 0,
872 >                "repeatX", '-',
873 >                additional_error))
874                goto failure;
875 <            }
689 <            if (args_info->repeatX_orig)
690 <              free (args_info->repeatX_orig); /* free previous string */
691 <            args_info->repeatX_orig = gengetopt_strdup (optarg);
875 >          
876            }
877            /* The number of images to repeat in the y direction.  */
878            else if (strcmp (long_options[option_index].name, "repeatY") == 0)
879            {
880 <            if (local_args_info.repeatY_given)
881 <              {
882 <                fprintf (stderr, "%s: `--repeatY' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
883 <                goto failure;
884 <              }
885 <            if (args_info->repeatY_given && ! override)
886 <              continue;
887 <            local_args_info.repeatY_given = 1;
704 <            args_info->repeatY_given = 1;
705 <            args_info->repeatY_arg = strtol (optarg, &stop_char, 0);
706 <            if (!(stop_char && *stop_char == '\0')) {
707 <              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
880 >          
881 >          
882 >            if (update_arg( (void *)&(args_info->repeatY_arg),
883 >                 &(args_info->repeatY_orig), &(args_info->repeatY_given),
884 >                &(local_args_info.repeatY_given), optarg, 0, "0", ARG_INT,
885 >                check_ambiguity, override, 0, 0,
886 >                "repeatY", '-',
887 >                additional_error))
888                goto failure;
889 <            }
710 <            if (args_info->repeatY_orig)
711 <              free (args_info->repeatY_orig); /* free previous string */
712 <            args_info->repeatY_orig = gengetopt_strdup (optarg);
889 >          
890            }
891            /* The number of images to repeat in the z direction.  */
892            else if (strcmp (long_options[option_index].name, "repeatZ") == 0)
893            {
894 <            if (local_args_info.repeatZ_given)
895 <              {
896 <                fprintf (stderr, "%s: `--repeatZ' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
897 <                goto failure;
898 <              }
899 <            if (args_info->repeatZ_given && ! override)
900 <              continue;
901 <            local_args_info.repeatZ_given = 1;
725 <            args_info->repeatZ_given = 1;
726 <            args_info->repeatZ_arg = strtol (optarg, &stop_char, 0);
727 <            if (!(stop_char && *stop_char == '\0')) {
728 <              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
894 >          
895 >          
896 >            if (update_arg( (void *)&(args_info->repeatZ_arg),
897 >                 &(args_info->repeatZ_orig), &(args_info->repeatZ_given),
898 >                &(local_args_info.repeatZ_given), optarg, 0, "0", ARG_INT,
899 >                check_ambiguity, override, 0, 0,
900 >                "repeatZ", '-',
901 >                additional_error))
902                goto failure;
903 <            }
731 <            if (args_info->repeatZ_orig)
732 <              free (args_info->repeatZ_orig); /* free previous string */
733 <            args_info->repeatZ_orig = gengetopt_strdup (optarg);
903 >          
904            }
735          /* Replace the Gay-Berne atom with four linear atoms.  */
736          else if (strcmp (long_options[option_index].name, "gb") == 0)
737          {
738            if (local_args_info.gb_given)
739              {
740                fprintf (stderr, "%s: `--gb' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
741                goto failure;
742              }
743            if (args_info->gb_given && ! override)
744              continue;
745            local_args_info.gb_given = 1;
746            args_info->gb_given = 1;
747            if (args_info->gb_arg)
748              free (args_info->gb_arg); /* free previous string */
749            args_info->gb_arg = gengetopt_strdup (optarg);
750            if (args_info->gb_orig)
751              free (args_info->gb_orig); /* free previous string */
752            args_info->gb_orig = gengetopt_strdup (optarg);
753          }
754          /* Print only positions in xyz file.  */
755          else if (strcmp (long_options[option_index].name, "printPosOnly") == 0)
756          {
757            if (local_args_info.printPosOnly_given)
758              {
759                fprintf (stderr, "%s: `--printPosOnly' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
760                goto failure;
761              }
762            if (args_info->printPosOnly_given && ! override)
763              continue;
764            local_args_info.printPosOnly_given = 1;
765            args_info->printPosOnly_given = 1;
766            args_info->printPosOnly_flag = !(args_info->printPosOnly_flag);
767          }
905            
906            break;
907          case '?':       /* Invalid option.  */
# Line 789 | Line 926 | cmdline_parser_internal (int argc, char * const *argv,
926    if ( error )
927      return (EXIT_FAILURE);
928  
929 +  if (optind < argc)
930 +    {
931 +      int i = 0 ;
932 +      int found_prog_name = 0;
933 +      /* whether program name, i.e., argv[0], is in the remaining args
934 +         (this may happen with some implementations of getopt,
935 +          but surely not with the one included by gengetopt) */
936 +
937 +      i = optind;
938 +      while (i < argc)
939 +        if (argv[i++] == argv[0]) {
940 +          found_prog_name = 1;
941 +          break;
942 +        }
943 +      i = 0;
944 +
945 +      args_info->inputs_num = argc - optind - found_prog_name;
946 +      args_info->inputs =
947 +        (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
948 +      while (optind < argc)
949 +        if (argv[optind++] != argv[0])
950 +          args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
951 +    }
952 +
953    return 0;
954  
955   failure:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines