|
|
1.1 ! root 1: /* ! 2: * plook - use keywords to look up a complete reference ! 3: */ ! 4: ! 5: ! 6: # include <stdio.h> ! 7: # include "streams.h" ! 8: # include "bib.h" ! 9: ! 10: char *locate(), *fgets(); ! 11: ! 12: char *plib = PLIB; /* prefer library */ ! 13: char INDEX[maxstr]; /* name of index file */ ! 14: char *DINPUT = BIBFILE; /* default reference database */ ! 15: ! 16: int argc; ! 17: char **argv; ! 18: ! 19: #define USAGE "plook [-p database ] [keys...]\n" ! 20: ! 21: ! 22: main(argcount,arglist) ! 23: int argcount; ! 24: char **arglist; ! 25: { ! 26: char *refs; /* references returned here */ ! 27: char keys[maxstr]; /* keys from command line or stdin */ ! 28: ! 29: ! 30: argc= argcount-1; ! 31: argv= arglist+1; ! 32: ! 33: ! 34: /* make path names: common file, index; get option flags */ ! 35: ! 36: strcpy(INDEX,DINPUT); ! 37: flags(); ! 38: strcat(INDEX,".i"); ! 39: ! 40: ! 41: /* get keys from command line and locate references */ ! 42: ! 43: *keys = '\0'; ! 44: for (; argc>0 ; argc--, argv++) { ! 45: strcat(keys,*argv); ! 46: strcat(keys," "); ! 47: } ! 48: if(*keys != '\0') { ! 49: refs = locate(keys, INDEX); ! 50: if(refs != NULL) { ! 51: if(*refs != NULL) { ! 52: puts(refs); ! 53: exit(0); ! 54: } ! 55: else exit(1); ! 56: } ! 57: else exit(1); ! 58: } ! 59: ! 60: ! 61: /* if no command line keys, take from stdin until EOF */ ! 62: ! 63: while(fgets(keys, sizeof(keys), stdin)) { ! 64: refs = locate(keys, INDEX); ! 65: if(refs != NULL) { ! 66: if(*refs != NULL) ! 67: puts(refs); ! 68: else { ! 69: putchar('\n'); ! 70: } ! 71: } ! 72: else ! 73: exit(1); ! 74: } ! 75: exit(0); ! 76: } ! 77: ! 78: # define operand (strlen(*argv+2)==0 ? (argv++,argc--,*argv) : *argv+2) ! 79: ! 80: ! 81: /* ! 82: * get option flags ! 83: * ! 84: * -p pathname of database file (default BIBFILE) ! 85: */ ! 86: ! 87: flags() ! 88: { ! 89: ! 90: for (; argc>0 && *argv[0]=='-'; argc--,argv++) { ! 91: switch ((*argv)[1]) { ! 92: case 'l': ! 93: case 'c': ! 94: fprintf(stderr,USAGE); ! 95: break; ! 96: case 'p': ! 97: strcpy(INDEX,operand); ! 98: break; ! 99: default: ! 100: fprintf(stderr,USAGE); ! 101: exit(1); ! 102: } ! 103: } ! 104: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.