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 302 by tim, Mon Feb 7 21:11:22 2005 UTC vs.
trunk/src/applications/dump2Xyz/Dump2XYZCmd.cpp (file contents), Revision 1795 by gezelter, Fri Sep 7 18:13:55 2012 UTC

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

Comparing:
trunk/src/applications/dump2Xyz/Dump2XYZCmd.c (property svn:keywords), Revision 302 by tim, Mon Feb 7 21:11:22 2005 UTC vs.
trunk/src/applications/dump2Xyz/Dump2XYZCmd.cpp (property svn:keywords), Revision 1795 by gezelter, Fri Sep 7 18:13:55 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines