ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/sysbuilder/simpleBuilderCmd.c
(Generate patch)

Comparing trunk/OOPSE-1.0/utils/sysbuilder/simpleBuilderCmd.c (file contents):
Revision 1424 by tim, Wed Jul 28 04:59:35 2004 UTC vs.
Revision 1436 by tim, Thu Jul 29 19:12:00 2004 UTC

# Line 37 | Line 37 | cmdline_parser_print_help (void)
37    printf("\n");
38    printf("  -h, --help                Print help and exit\n");
39    printf("  -V, --version             Print version and exit\n");
40  printf("  -I, --include=STRING      File name that should be included at the top of \n                              the output bass file.\n");
40    printf("  -o, --output=STRING       Output file name\n");
41 <  printf("      --latticetype=STRING  Lattice type string. Valid types are fcc,hcp,bcc \n                              and hcp-water.\n");
42 <  printf("      --density=DOUBLE      density g/cm^3\n");
44 <  printf("      --ndensity=DOUBLE     number density\n");
41 >  printf("      --latticetype=STRING  Lattice type string. Valid types are fcc,hcp,bcc \n                              and hcp-water.  (default=`fcc')\n");
42 >  printf("      --density=DOUBLE      density (g/cm^3)\n");
43    printf("      --nx=INT              number of unit cells in x\n");
44    printf("      --ny=INT              number of unit cells in y\n");
45    printf("      --nz=INT              number of unit cells in z\n");
48  printf("      --a1=DOUBLE           lattice spacing in Angstroms h - for cubic \n                              lattice, specify this parameter\n");
49  printf("      --a2=DOUBLE           lattice spacing in Angstroms k\n");
50  printf("      --a3=DOUBLE           lattice spacing in Angstroms l\n");
46   }
47  
48  
# Line 69 | Line 64 | cmdline_parser (int argc, char * const *argv, struct g
64   cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
65   {
66    int c;        /* Character of the parsed option.  */
72  int i;        /* Counter */
73  struct include_list
74  {
75    char * include_arg;
76    struct include_list * next;
77  };
78  struct include_list * include_list = NULL,* include_new = NULL;
79  
67    int missing_required_options = 0;
68  
69    args_info->help_given = 0 ;
70    args_info->version_given = 0 ;
84  args_info->include_given = 0 ;
71    args_info->output_given = 0 ;
72    args_info->latticetype_given = 0 ;
73    args_info->density_given = 0 ;
88  args_info->ndensity_given = 0 ;
74    args_info->nx_given = 0 ;
75    args_info->ny_given = 0 ;
76    args_info->nz_given = 0 ;
92  args_info->a1_given = 0 ;
93  args_info->a2_given = 0 ;
94  args_info->a3_given = 0 ;
77   #define clear_args() { \
96  args_info->include_arg = NULL; \
78    args_info->output_arg = NULL; \
79 <  args_info->latticetype_arg = NULL; \
79 >  args_info->latticetype_arg = gengetopt_strdup("fcc") ;\
80   }
81  
82    clear_args();
# Line 116 | Line 97 | cmdline_parser (int argc, char * const *argv, struct g
97        static struct option long_options[] = {
98          { "help",       0, NULL, 'h' },
99          { "version",    0, NULL, 'V' },
119        { "include",    1, NULL, 'I' },
100          { "output",     1, NULL, 'o' },
101          { "latticetype",        1, NULL, 0 },
102          { "density",    1, NULL, 0 },
123        { "ndensity",   1, NULL, 0 },
103          { "nx", 1, NULL, 0 },
104          { "ny", 1, NULL, 0 },
105          { "nz", 1, NULL, 0 },
127        { "a1", 1, NULL, 0 },
128        { "a2", 1, NULL, 0 },
129        { "a3", 1, NULL, 0 },
106          { NULL, 0, NULL, 0 }
107        };
108  
109        stop_char = 0;
110 <      c = getopt_long (argc, argv, "hVI:o:", long_options, &option_index);
110 >      c = getopt_long (argc, argv, "hVo:", long_options, &option_index);
111  
112        if (c == -1) break;       /* Exit from `while (1)' loop.  */
113  
# Line 147 | Line 123 | cmdline_parser (int argc, char * const *argv, struct g
123            cmdline_parser_print_version ();
124            exit (EXIT_SUCCESS);
125  
150        case 'I':       /* File name that should be included at the top of the output bass file..  */
151          args_info->include_given++;
152          include_new = (struct include_list *) malloc (sizeof (struct include_list));
153          include_new->next = include_list;
154          include_list = include_new;
155          include_new->include_arg = gengetopt_strdup (optarg);
156          break;
157
126          case 'o':       /* Output file name.  */
127            if (args_info->output_given)
128              {
# Line 178 | Line 146 | cmdline_parser (int argc, char * const *argv, struct g
146                  exit (EXIT_FAILURE);
147                }
148              args_info->latticetype_given = 1;
149 +            if (args_info->latticetype_arg)
150 +              free (args_info->latticetype_arg); /* free default string */
151              args_info->latticetype_arg = gengetopt_strdup (optarg);
152              break;
153            }
154            
155 <          /* density g/cm^3.  */
155 >          /* density (g/cm^3).  */
156            else if (strcmp (long_options[option_index].name, "density") == 0)
157            {
158              if (args_info->density_given)
# Line 196 | Line 166 | cmdline_parser (int argc, char * const *argv, struct g
166              break;
167            }
168            
199          /* number density.  */
200          else if (strcmp (long_options[option_index].name, "ndensity") == 0)
201          {
202            if (args_info->ndensity_given)
203              {
204                fprintf (stderr, "%s: `--ndensity' option given more than once\n", CMDLINE_PARSER_PACKAGE);
205                clear_args ();
206                exit (EXIT_FAILURE);
207              }
208            args_info->ndensity_given = 1;
209            args_info->ndensity_arg = strtod (optarg, NULL);
210            break;
211          }
212          
169            /* number of unit cells in x.  */
170            else if (strcmp (long_options[option_index].name, "nx") == 0)
171            {
# Line 249 | Line 205 | cmdline_parser (int argc, char * const *argv, struct g
205                }
206              args_info->nz_given = 1;
207              args_info->nz_arg = strtol (optarg,&stop_char,0);
252            break;
253          }
254          
255          /* lattice spacing in Angstroms h - for cubic lattice, specify this parameter.  */
256          else if (strcmp (long_options[option_index].name, "a1") == 0)
257          {
258            if (args_info->a1_given)
259              {
260                fprintf (stderr, "%s: `--a1' option given more than once\n", CMDLINE_PARSER_PACKAGE);
261                clear_args ();
262                exit (EXIT_FAILURE);
263              }
264            args_info->a1_given = 1;
265            args_info->a1_arg = strtod (optarg, NULL);
208              break;
209            }
210            
269          /* lattice spacing in Angstroms k.  */
270          else if (strcmp (long_options[option_index].name, "a2") == 0)
271          {
272            if (args_info->a2_given)
273              {
274                fprintf (stderr, "%s: `--a2' option given more than once\n", CMDLINE_PARSER_PACKAGE);
275                clear_args ();
276                exit (EXIT_FAILURE);
277              }
278            args_info->a2_given = 1;
279            args_info->a2_arg = strtod (optarg, NULL);
280            break;
281          }
282          
283          /* lattice spacing in Angstroms l.  */
284          else if (strcmp (long_options[option_index].name, "a3") == 0)
285          {
286            if (args_info->a3_given)
287              {
288                fprintf (stderr, "%s: `--a3' option given more than once\n", CMDLINE_PARSER_PACKAGE);
289                clear_args ();
290                exit (EXIT_FAILURE);
291              }
292            args_info->a3_given = 1;
293            args_info->a3_arg = strtod (optarg, NULL);
294            break;
295          }
296          
211  
212          case '?':       /* Invalid option.  */
213            /* `getopt_long' already printed an error message.  */
# Line 306 | Line 220 | cmdline_parser (int argc, char * const *argv, struct g
220      } /* while */
221  
222  
223 +  if (! args_info->density_given)
224 +    {
225 +      fprintf (stderr, "%s: '--density' option required\n", CMDLINE_PARSER_PACKAGE);
226 +      missing_required_options = 1;
227 +    }
228    if (! args_info->nx_given)
229      {
230        fprintf (stderr, "%s: '--nx' option required\n", CMDLINE_PARSER_PACKAGE);
# Line 321 | Line 240 | cmdline_parser (int argc, char * const *argv, struct g
240        fprintf (stderr, "%s: '--nz' option required\n", CMDLINE_PARSER_PACKAGE);
241        missing_required_options = 1;
242      }
324  if (! args_info->a1_given)
325    {
326      fprintf (stderr, "%s: '--a1' option required\n", CMDLINE_PARSER_PACKAGE);
327      missing_required_options = 1;
328    }
243    if ( missing_required_options )
244      exit (EXIT_FAILURE);
245  
332  if (args_info->include_given)
333    {
334      args_info->include_arg = (char * *) malloc (args_info->include_given * sizeof (char *));
335      for (i = 0; i < args_info->include_given; i++)
336        {
337          args_info->include_arg [i] = include_list->include_arg;
338          include_list = include_list->next;
339        }
340    }
341  
246    if (optind < argc)
247      {
248        int i = 0 ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines