home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / database / bplus / lookup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-22  |  1.6 KB  |  62 lines

  1. /*****************************************************************
  2.  |  lookup - lookup a name in the names data base
  3.  |----------------------------------------------------------------
  4.  |  finds all occurrences of the name(s) on the command line and
  5.  |  displays the matching records from the original text file.
  6.  |  Locates records with name fields starting with the string
  7.  |  argument. "lookup j" finds all records with a first or last
  8.  |  name starting with j.
  9.  ****************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <ctype.h>
  13. #include "bplus.h"
  14.  
  15. IX_DESC namesfile;
  16. ENTRY index;
  17. FILE *namedata, *fopen();
  18.  
  19. main(argc, argv)
  20. int argc;
  21. char *argv[];
  22. {
  23.     int n, status, keylen;
  24.     char uckey[MAXKEY];
  25.     int ch, chindex;
  26.  
  27.     status = open_index("phdata.idx", &namesfile, 1);
  28.     namedata = fopen("phdata", "r");
  29.     
  30.     for (n = 1; n < argc; ++n) {
  31.         for (chindex = 0; ch = argv[n][chindex]; ++chindex) {
  32.             if (islower(ch)) ch = toupper(ch);
  33.             uckey[chindex] = ch;
  34.         }
  35.         
  36.         clearkey(&index);
  37.         strcpy(index.key, uckey);
  38.         status = locate_key(&index, &namesfile);
  39.         if (status == EOIX) continue;
  40.         keylen = strlen(uckey);
  41.         
  42.         dumprec(index.recptr);
  43.         while (next_key(&index, &namesfile) == IX_OK &&
  44.             (strncmp(index.key, uckey, keylen) == 0))
  45.         {
  46.             dumprec(index.recptr);
  47.         }
  48.     }
  49.  
  50.     close_index(&namesfile);
  51. }
  52.  
  53. dumprec(seekloc)
  54. long seekloc;
  55. {
  56.     char line[132];
  57.     
  58.     fseek(namedata, seekloc, 0);
  59.     fgets(line, 132, namedata);
  60.     fputs(line, stdout);
  61. }
  62.