home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
gdead.berkeley.edu
/
gdead.berkeley.edu.tar
/
gdead.berkeley.edu
/
pub
/
cad-tools
/
ciftomann.tar
/
cmd_dir
/
getargs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-01-28
|
4KB
|
217 lines
#include <stdio.h>
extern char *user_log_file,
*user_out_file,
*cmd_file_name,
*tmp_dir,
basename[],
*cif_file_name;
extern int dont_ask;
extern int silent;
extern int already_flat;
extern FILE *yyin;
extern FILE *cif_file;
FILE *fopen();
#define USAGE "Usage : ciftomann [-ys] [-l log_file] [-t tmp_dir] [-p pat_gen] -f cmd_file -o out_file -i cif_file\n"
/* get_args parses the command line for the various flags */
get_args(argc,argv)
int argc;
char **argv;
{
char *ptr;
FILE *out_file;
yyin = NULL;
if (argc == 1) {
fprintf(stderr,USAGE);
exit(1);
}
while ( argc-- > 1 ) {
if (*(++argv)[0] == '-') {
ptr = argv[0];
switch (ptr[1]) {
case 'a' :
if (ptr[2] != '\0') {
fprintf(stderr,"Usage is '-a basename'\n");
exit(1);
}
if ((++argv)[0] == (char *) 0) {
fprintf(stderr,"Basename is missing in -a option\n");
fprintf(stderr,USAGE);
exit(1);
}
(void) strcpy(basename, argv[0]);
already_flat = 1;
argc--;
break;
case 'f' :
if (ptr[2] != '\0') {
fprintf(stderr,"Usage is '-f cmd_file'\n");
exit(1);
}
if ((++argv)[0] == (char *) 0) {
fprintf(stderr,"Filename is missing in -f option\n");
fprintf(stderr,USAGE);
exit(1);
}
if ( (yyin = fopen(argv[0],"r")) == NULL) {
fprintf(stderr,"Cannot open command file %s\n",
argv[0]);
exit(1);
}
cmd_file_name = argv[0];
argc--;
break;
case 'i' :
if (ptr[2] != '\0') {
fprintf(stderr,"Usage is '-i cif_file'\n");
exit(1);
}
if ((++argv)[0] == (char *) 0) {
fprintf(stderr,"Filename is missing in -i option\n");
fprintf(stderr,USAGE);
exit(1);
}
cif_file_name = argv[0];
if ( (cif_file = fopen(cif_file_name,"r")) == NULL ) {
fprintf(stderr,"Cannot open the cif file %s\n",
argv[0]);
exit(1);
}
fclose(cif_file);
argc--;
break;
case 't' :
if (ptr[2] != '\0') {
fprintf(stderr,"Usage is '-t tmp_dir'\n");
exit(1);
}
if ((++argv)[0] == (char *) 0) {
fprintf(stderr,"Directory name is missing in -t option\n");
exit(1);
}
tmp_dir = *argv;
argc--;
break;
case 'p' :
if (ptr[2] != '\0') {
fprintf(stderr,"Usage is '-p pat_gen'\n");
exit(1);
}
if ((++argv)[0] == (char *) 0) {
fprintf(stderr,"Pattern Generator name is missing in -p option\n");
exit(1);
}
find_pg_desc(*argv);
argc--;
break;
case 'l' :
if (ptr[2] != '\0') {
fprintf(stderr,"Usage is '-l log_file'\n");
exit(1);
}
if ((++argv)[0] == (char *) 0) {
fprintf(stderr,"Filename is missing in -l option\n");
exit(1);
}
user_log_file = *argv;
argc--;
break;
case 'o' :
if (ptr[2] != '\0') {
fprintf(stderr,"Usage is '-o out_file'\n");
exit(1);
}
if ((++argv)[0] == (char *) 0) {
fprintf(stderr,"Filename is missing in -o option\n");
exit(1);
}
user_out_file = *argv;
argc--;
break;
default :
while ( *(++ptr) != '\0' ) {
switch (*ptr) {
case 'y' :
dont_ask++;
break;
case 's' :
silent++;
dont_ask++;
break;
default :
fprintf(stderr,"Unknown flag %c\n",*ptr);
exit(1);
}
}
}
} else {
fprintf(stderr,"Unrecognizable option, '%s'\n",argv[0]);
fprintf(stderr,USAGE);
}
}
if ( user_out_file == (char *) 0 ) {
fprintf(stderr,"No out_file given\n");
fprintf(stderr,USAGE);
exit(1);
}
if ( cif_file_name == (char *) 0 ) {
fprintf(stderr,"No cif_file given\n");
fprintf(stderr,USAGE);
exit(1);
}
if ( yyin == NULL ) {
fprintf(stderr,"No cmd_file given\n");
fprintf(stderr,USAGE);
exit(1);
}
}