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 1455 by gezelter, Mon May 10 17:28:26 2010 UTC vs.
Revision 1456 by gezelter, Fri Jun 25 17:40:24 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines