1*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 3*7c478bd9Sstevel@tonic-gate 4*7c478bd9Sstevel@tonic-gate 5*7c478bd9Sstevel@tonic-gate /* 6*7c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 7*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 8*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 9*7c478bd9Sstevel@tonic-gate */ 10*7c478bd9Sstevel@tonic-gate 11*7c478bd9Sstevel@tonic-gate /* 12*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. 13*7c478bd9Sstevel@tonic-gate * All Rights Reserved. 14*7c478bd9Sstevel@tonic-gate */ 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 17*7c478bd9Sstevel@tonic-gate 18*7c478bd9Sstevel@tonic-gate #include <stdio.h> 19*7c478bd9Sstevel@tonic-gate #include <ctype.h> 20*7c478bd9Sstevel@tonic-gate #include <locale.h> 21*7c478bd9Sstevel@tonic-gate 22*7c478bd9Sstevel@tonic-gate main(argc, argv) /* look in biblio for record matching keywords */ 23*7c478bd9Sstevel@tonic-gate int argc; 24*7c478bd9Sstevel@tonic-gate char **argv; 25*7c478bd9Sstevel@tonic-gate { 26*7c478bd9Sstevel@tonic-gate FILE *hfp, *fopen(), *popen(); 27*7c478bd9Sstevel@tonic-gate char s[BUFSIZ], hunt[64]; 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 32*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 33*7c478bd9Sstevel@tonic-gate #endif 34*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate if (argc == 1 || argc > 2) { 37*7c478bd9Sstevel@tonic-gate fputs(gettext("Usage: lookbib database\n\ 38*7c478bd9Sstevel@tonic-gate \tfinds citations specified on standard input\n"), stderr); 39*7c478bd9Sstevel@tonic-gate exit(1); 40*7c478bd9Sstevel@tonic-gate } 41*7c478bd9Sstevel@tonic-gate sprintf(s, "%s.ia", argv[1]); 42*7c478bd9Sstevel@tonic-gate if (access(s, 0) == -1) { 43*7c478bd9Sstevel@tonic-gate sprintf (s, "%s", argv[1]); 44*7c478bd9Sstevel@tonic-gate if (access(s, 0) == -1) { 45*7c478bd9Sstevel@tonic-gate perror(s); 46*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("\tNeither index file %s.ia \ 47*7c478bd9Sstevel@tonic-gate nor reference file %s found\n"), s, s); 48*7c478bd9Sstevel@tonic-gate exit(1); 49*7c478bd9Sstevel@tonic-gate } 50*7c478bd9Sstevel@tonic-gate } 51*7c478bd9Sstevel@tonic-gate sprintf(hunt, "/usr/lib/refer/hunt %s", argv[1]); 52*7c478bd9Sstevel@tonic-gate if (isatty(fileno(stdin))) { 53*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("Instructions? ")); 54*7c478bd9Sstevel@tonic-gate fgets(s, BUFSIZ, stdin); 55*7c478bd9Sstevel@tonic-gate if (*s == 'y') 56*7c478bd9Sstevel@tonic-gate instruct(); 57*7c478bd9Sstevel@tonic-gate } 58*7c478bd9Sstevel@tonic-gate again: 59*7c478bd9Sstevel@tonic-gate fprintf(stderr, "> "); 60*7c478bd9Sstevel@tonic-gate if (fgets(s, BUFSIZ, stdin)) { 61*7c478bd9Sstevel@tonic-gate if (*s == '\n') 62*7c478bd9Sstevel@tonic-gate goto again; 63*7c478bd9Sstevel@tonic-gate if (strlen(s) <= 3) 64*7c478bd9Sstevel@tonic-gate goto again; 65*7c478bd9Sstevel@tonic-gate if ((hfp = popen(hunt, "w")) == NULL) { 66*7c478bd9Sstevel@tonic-gate perror(gettext("lookbib: /usr/lib/refer/hunt")); 67*7c478bd9Sstevel@tonic-gate exit(1); 68*7c478bd9Sstevel@tonic-gate } 69*7c478bd9Sstevel@tonic-gate map_lower(s); 70*7c478bd9Sstevel@tonic-gate fputs(s, hfp); 71*7c478bd9Sstevel@tonic-gate pclose(hfp); 72*7c478bd9Sstevel@tonic-gate goto again; 73*7c478bd9Sstevel@tonic-gate } 74*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("EOT\n")); 75*7c478bd9Sstevel@tonic-gate exit(0); 76*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 77*7c478bd9Sstevel@tonic-gate } 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate map_lower(s) /* map string s to lower case */ 80*7c478bd9Sstevel@tonic-gate char *s; 81*7c478bd9Sstevel@tonic-gate { 82*7c478bd9Sstevel@tonic-gate for ( ; *s; ++s) 83*7c478bd9Sstevel@tonic-gate if (isupper(*s)) 84*7c478bd9Sstevel@tonic-gate *s = tolower(*s); 85*7c478bd9Sstevel@tonic-gate } 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate instruct() 88*7c478bd9Sstevel@tonic-gate { 89*7c478bd9Sstevel@tonic-gate fputs(gettext( 90*7c478bd9Sstevel@tonic-gate "\nType keywords (such as author and date) after the > prompt.\n\ 91*7c478bd9Sstevel@tonic-gate References with those keywords are printed if they exist;\n\ 92*7c478bd9Sstevel@tonic-gate \tif nothing matches you are given another prompt.\n\ 93*7c478bd9Sstevel@tonic-gate To quit lookbib, press CTRL-d after the > prompt.\n\n"), stderr); 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate } 96