Annotation of 42BSD/usr.bin/refer/lookbib.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid = "@(#)lookbib.c   4.3 (Berkeley) 6/28/83";
                      3: #endif
                      4: 
                      5: #include <stdio.h>
                      6: #include <ctype.h>
                      7: 
                      8: main(argc, argv)       /* look in biblio for record matching keywords */
                      9: int argc;
                     10: char **argv;
                     11: {
                     12:        FILE *fp, *hfp, *fopen(), *popen();
                     13:        char s[BUFSIZ], hunt[64], *sprintf();
                     14: 
                     15:        if (argc == 1 || argc > 2)
                     16:        {
                     17:                fputs("Usage:  lookbib database\n",
                     18:                        stderr);
                     19:                fputs("\tfinds citations specified on standard input\n",
                     20:                        stderr);
                     21:                exit(1);
                     22:        }
                     23:        if (!isatty(fileno(stdin)))
                     24:                fp = stdin;
                     25:        else if ((fp = fopen("/dev/tty", "r")) == NULL)
                     26:        {
                     27:                perror("lookbib: /dev/tty");
                     28:                exit(1);
                     29:        }
                     30:        sprintf(s, "%s.ia", argv[1]);
                     31:        if (access(s, 0) == -1) {
                     32:                sprintf (s, "%s", argv[1]);
                     33:                if (access(s, 0) == -1) {
                     34:                        perror(s);
                     35:                        fprintf(stderr, "\tNeither index file %s.ia ", s);
                     36:                        fprintf(stderr, "nor reference file %s found\n", s);
                     37:                        exit(1);
                     38:                }
                     39:        }
                     40:        sprintf(hunt, "/usr/lib/refer/hunt %s", argv[1]);
                     41: 
                     42:        if (isatty(fileno(fp)))
                     43:        {
                     44:                fprintf(stderr, "Instructions? ");
                     45:                fgets(s, BUFSIZ, fp);
                     46:                if (*s == 'y')
                     47:                        instruct();
                     48:        }
                     49:    again:
                     50:        fprintf(stderr, "> ");
                     51:        if (fgets(s, BUFSIZ, fp))
                     52:        {
                     53:                if (*s == '\n')
                     54:                        goto again;
                     55:                if ((hfp = popen(hunt, "w")) == NULL)
                     56:                {
                     57:                        perror("lookbib: /usr/lib/refer/hunt");
                     58:                        exit(1);
                     59:                }
                     60:                map_lower(s);
                     61:                fputs(s, hfp);
                     62:                pclose(hfp);
                     63:                goto again;
                     64:        }
                     65:        fclose(fp);
                     66:        fprintf(stderr, "EOT\n");
                     67:        exit(0);
                     68: }
                     69: 
                     70: map_lower(s)           /* map string s to lower case */
                     71: char *s;
                     72: {
                     73:        for ( ; *s; ++s)
                     74:                if (isupper(*s))
                     75:                        *s = tolower(*s);
                     76: }
                     77: 
                     78: instruct()
                     79: {
                     80:        fputs("\nType keywords (such as author and date) after the > prompt.\n",
                     81:                stderr);
                     82:        fputs("References with those keywords are printed if they exist;\n",
                     83:                stderr);
                     84:        fputs("\tif nothing matches you are given another prompt.\n",
                     85:                stderr);
                     86:        fputs("To quit lookbib, press CTRL-d after the > prompt.\n\n",
                     87:                stderr);
                     88: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.