1*11a8fa6cSceastha /*
2*11a8fa6cSceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3*11a8fa6cSceastha * Use is subject to license terms.
4*11a8fa6cSceastha */
5*11a8fa6cSceastha
67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
77c478bd9Sstevel@tonic-gate /* All Rights Reserved */
87c478bd9Sstevel@tonic-gate
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate */
147c478bd9Sstevel@tonic-gate
157c478bd9Sstevel@tonic-gate #include <stdio.h>
167c478bd9Sstevel@tonic-gate #include <ctype.h>
177c478bd9Sstevel@tonic-gate #include <locale.h>
187c478bd9Sstevel@tonic-gate
19*11a8fa6cSceastha static void instruct(void);
20*11a8fa6cSceastha static void map_lower(char *);
21*11a8fa6cSceastha
22*11a8fa6cSceastha /* look in biblio for record matching keywords */
23*11a8fa6cSceastha int
main(int argc,char ** argv)24*11a8fa6cSceastha main(int argc, char **argv)
257c478bd9Sstevel@tonic-gate {
267c478bd9Sstevel@tonic-gate FILE *hfp, *fopen(), *popen();
277c478bd9Sstevel@tonic-gate char s[BUFSIZ], hunt[64];
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
327c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate if (argc == 1 || argc > 2) {
377c478bd9Sstevel@tonic-gate fputs(gettext("Usage: lookbib database\n\
387c478bd9Sstevel@tonic-gate \tfinds citations specified on standard input\n"), stderr);
397c478bd9Sstevel@tonic-gate exit(1);
407c478bd9Sstevel@tonic-gate }
417c478bd9Sstevel@tonic-gate sprintf(s, "%s.ia", argv[1]);
427c478bd9Sstevel@tonic-gate if (access(s, 0) == -1) {
437c478bd9Sstevel@tonic-gate sprintf(s, "%s", argv[1]);
447c478bd9Sstevel@tonic-gate if (access(s, 0) == -1) {
457c478bd9Sstevel@tonic-gate perror(s);
467c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("\tNeither index file %s.ia \
477c478bd9Sstevel@tonic-gate nor reference file %s found\n"), s, s);
487c478bd9Sstevel@tonic-gate exit(1);
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate }
517c478bd9Sstevel@tonic-gate sprintf(hunt, "/usr/lib/refer/hunt %s", argv[1]);
527c478bd9Sstevel@tonic-gate if (isatty(fileno(stdin))) {
537c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("Instructions? "));
547c478bd9Sstevel@tonic-gate fgets(s, BUFSIZ, stdin);
557c478bd9Sstevel@tonic-gate if (*s == 'y')
567c478bd9Sstevel@tonic-gate instruct();
577c478bd9Sstevel@tonic-gate }
587c478bd9Sstevel@tonic-gate again:
597c478bd9Sstevel@tonic-gate fprintf(stderr, "> ");
607c478bd9Sstevel@tonic-gate if (fgets(s, BUFSIZ, stdin)) {
617c478bd9Sstevel@tonic-gate if (*s == '\n')
627c478bd9Sstevel@tonic-gate goto again;
637c478bd9Sstevel@tonic-gate if (strlen(s) <= 3)
647c478bd9Sstevel@tonic-gate goto again;
657c478bd9Sstevel@tonic-gate if ((hfp = popen(hunt, "w")) == NULL) {
667c478bd9Sstevel@tonic-gate perror(gettext("lookbib: /usr/lib/refer/hunt"));
677c478bd9Sstevel@tonic-gate exit(1);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate map_lower(s);
707c478bd9Sstevel@tonic-gate fputs(s, hfp);
717c478bd9Sstevel@tonic-gate pclose(hfp);
727c478bd9Sstevel@tonic-gate goto again;
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("EOT\n"));
75*11a8fa6cSceastha return (0);
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate
78*11a8fa6cSceastha static void
map_lower(char * s)79*11a8fa6cSceastha map_lower(char *s) /* map string s to lower case */
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate for (; *s; ++s)
827c478bd9Sstevel@tonic-gate if (isupper(*s))
837c478bd9Sstevel@tonic-gate *s = tolower(*s);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate
86*11a8fa6cSceastha static void
instruct(void)87*11a8fa6cSceastha instruct(void)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate fputs(gettext(
907c478bd9Sstevel@tonic-gate "\nType keywords (such as author and date) after the > prompt.\n\
917c478bd9Sstevel@tonic-gate References with those keywords are printed if they exist;\n\
927c478bd9Sstevel@tonic-gate \tif nothing matches you are given another prompt.\n\
937c478bd9Sstevel@tonic-gate To quit lookbib, press CTRL-d after the > prompt.\n\n"), stderr);
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate }
96