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