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

Defined functions

instruct defined in line 85; used 1 times
  • in line 54
main defined in line 8; never used
map_lower defined in line 77; used 1 times
  • in line 67

Defined variables

sccsid defined in line 2; never used
Last modified: 1996-10-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 435
Valid CSS Valid XHTML 1.0 Strict