home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / database / cdbms / index.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-01  |  1.0 KB  |  40 lines

  1. /* --------------------- index.c ----------------------- */
  2. #include <stdio.h>
  3. #include "cdata.h"
  4. extern RPTR curr_a [];    /* current record file address    */
  5.  
  6. main (argc, argv)
  7. char *argv [];
  8. {
  9.     int f = 1, i;
  10.     static int fs [MXFILS+1];
  11.     char *malloc(), *bf, *path;
  12.  
  13.     if (argc < 2)    {
  14.         printf("\nFile name or 'all' required");
  15.         exit();
  16.     }
  17.     if (strcmp("all", argv [1]) == 0)    /* index all */
  18.         for (f = 0; dbfiles [f]; f++) /* put files in list */
  19.             fs [f] = f;
  20.     else if ((*fs = filename(argv[1])) == ERROR)
  21.         exit();
  22.     fs [f] = (-1);    /* terminator (file,file,...,-1) */
  23.     path = argc > 2 ? argv[2] : "";
  24.     /* delete and rebuild indexes
  25.                 in the data base files being indexed */
  26.     for (i = 0; (f = fs [i]) != (-1); i++)
  27.         build_index(path, f);
  28.     /* Open the data base files. */
  29.     db_open(path, fs);
  30.     for (i = 0; (f = fs [i]) != (-1); i++)    {
  31.         printf("\nIndexing %s", dbfiles [f]);
  32.         bf = malloc(rlen(f));                
  33.         while (seqrcd(f, bf) != ERROR)        
  34.             add_indexes(f, bf, curr_a [f]); 
  35.         free(bf);                            
  36.     }
  37.     db_cls();
  38. }
  39.  
  40.