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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines