diff --git a/src/dbStatic/dbExpand.c b/src/dbStatic/dbExpand.c index 02cb448cd..76b8027ca 100644 --- a/src/dbStatic/dbExpand.c +++ b/src/dbStatic/dbExpand.c @@ -26,75 +26,96 @@ DBBASE *pdbbase = NULL; +void usage() +{ + fprintf(stderr, "Usage:\n\tdbExpand -Ipath -ooutfile " + "-S macro=value file1.dbd file2.dbd ...\n"); + fprintf(stderr,"Specifying any path will replace the default of '.'\n"); +} + int main(int argc,char **argv) { - int i; - int strip; char *path = NULL; char *sub = NULL; int pathLength = 0; int subLength = 0; - char **pstr; - char *psep; - int *len; + char *outFilename = NULL; + FILE *outFP = stdout; long status; long returnStatus = 0; static char *pathSep = OSI_PATH_LIST_SEPARATOR; static char *subSep = ","; - /*Look for options*/ - if(argc<2) { - fprintf(stderr, - "usage:\ndbExpand -Ipath -Ipath " - "-S substitutions -S substitutions" - " file1.dbd file2.dbd ...\n"); - fprintf(stderr,"Specifying path will replace the default '.'\n"); - exit(0); + /* Discard program name argv[0] */ + ++argv; + --argc; + + while ((argc > 1) && (**argv == '-')) { + char optLtr = (*argv)[1]; + char *optArg; + + if (strlen(*argv) > 2) { + optArg = *argv+2; + ++argv; + --argc; + } else { + optArg = argv[1]; + argv += 2; + argc -= 2; + } + + switch (optLtr) { + case 'o': + outFilename = optArg; + break; + + case 'I': + dbCatString(&path, &pathLength, optArg, pathSep); + break; + + case 'S': + dbCatString(&sub, &subLength, optArg, subSep); + break; + + default: + fprintf(stderr, "dbExpand: Unknown option '-%c'\n", optLtr); + usage(); + exit(1); + } } - while((strncmp(argv[1],"-I",2)==0)||(strncmp(argv[1],"-S",2)==0)) { - if(strncmp(argv[1],"-I",2)==0) { - pstr = &path; - psep = pathSep; - len = &pathLength; - } else { - pstr = ⊂ - psep = subSep; - len = &subLength; - } - if(strlen(argv[1])==2) { - dbCatString(pstr,len,argv[2],psep); - strip = 2; - } else { - dbCatString(pstr,len,argv[1]+2,psep); - strip = 1; - } - argc -= strip; - for(i=1; i0; --argc, ++argv) { + status = dbReadDatabase(&pdbbase,*argv,path,sub); + if (status) returnStatus = status; } - for(i=1; i