home *** CD-ROM | disk | FTP | other *** search
/ Between Heaven & Hell 2 / BetweenHeavenHell.cdr / 100 / 76 / mfind.c < prev    next >
Text File  |  1985-04-14  |  4KB  |  154 lines

  1. /* Copyright 1985 The Balkan Group
  2.  * Author:  Eric Balkan             Date written:  4/7/85
  3.  * 
  4.  * mfind: locates argument strings within a movie record
  5.  *        movie files must consist of two letter filenames within the
  6.  *          current directory on the currently logged-in drive
  7.  *
  8.  * Requires DeSmet C compiler and Greenleaf general function library
  9.  *        or equivalent
  10.  */
  11.  
  12. #include "stdio.h"
  13.  
  14. char *malloc();
  15. char *gets();
  16.  
  17. char rec[23 * 99 + 1];
  18. char *recs_found[25][200];   /* array of pointers to found records */
  19. char *wd[25][4];             /* array of pointers to search arguments */
  20. char *arg[25];
  21. int cur_arg;
  22. int match[25];
  23. int om = 0;
  24.  
  25.  
  26. main(argc, argv)
  27.    int argc;
  28.    char *argv[];
  29.    {
  30.    int  i, fp, end;
  31.    char buf[99 + 1];
  32.    char filename[15];
  33.    char operator[51];
  34.    char op[25];
  35.    int num_args;
  36.    char str[101];
  37.    char wd1[51], wd3[51];
  38.    int ctr = 0;
  39.    for (i = 0; i < 25; ++i)
  40.       match[i] = 0;
  41.    for (cur_arg = 0; ; ++cur_arg)
  42.       {
  43.       printf(
  44.        " Search criteria set #%d (e.g. Winger and Nolte) (Null line to end):\n",
  45.                    cur_arg);
  46.       gets(str);
  47.       if (str[0] == '\0')
  48.          break;
  49.       if ((arg[cur_arg] = malloc(strlen(str) + 1)) == 0)
  50.          {
  51.          printf("Out of memory\n");
  52.          return(ERR);
  53.          }
  54.       strcpy(arg[cur_arg], str);
  55.       sscanf(str, "%s%s%s", wd1, operator, wd3);
  56.       if ((wd[cur_arg][1] = malloc(strlen(wd1) + 1)) == 0 ||
  57.            (wd[cur_arg][3] = malloc(strlen(wd3) + 1)) == 0)
  58.          {
  59.          printf("\nOut of memory\n");
  60.          return(ERR);
  61.          }
  62.       strcpy(wd[cur_arg][1], wd1);
  63.       strcpy(wd[cur_arg][3], wd3);
  64.       if (strcmp(operator, "OR") == 0 || strcmp(operator, "or") == 0)
  65.          op[cur_arg] = 'O';
  66.       else if (strcmp(operator, "AND") == 0 || strcmp(operator, "and") == 0)
  67.          op[cur_arg] = 'A';
  68.       else
  69.          op[cur_arg] = 0;
  70.       }
  71.    num_args = cur_arg - 1;
  72.    dosfirst("??", 0, filename);
  73.    printf("**Checking file:");
  74.    for (; om == 0;)
  75.       {
  76.       fclose(fp);
  77.       if ((fp = fopen(filename, "r")) != NULL)  /* opened OK */
  78.          {
  79.          end = 0;
  80.          printf(" *%s* ", filename); 
  81.          for (; om == 0;)
  82.             {
  83.             rec[0] = '\0';
  84.             for (i = 0; (end = fgets(buf, 100, fp)) != NULL && om == 0; ++i)
  85.                {
  86.                if (buf[0] == '.' && buf[1] == '.')
  87.                   {
  88.                   ctr++;
  89.                   break;
  90.                   }
  91.                strcat(rec, buf);
  92.                }
  93.             if (end == NULL)
  94.                break;
  95.             for (cur_arg = 0; cur_arg <= num_args; ++cur_arg)
  96.                { 
  97.                if (op[cur_arg] == 'O')
  98.                   {
  99.                   if (strfind(rec, wd[cur_arg][1]) > 0
  100.                          || strfind(rec, wd[cur_arg][3]) > 0)
  101.                      hit();
  102.                   }
  103.                else if (op[cur_arg] == 'A')
  104.                   {
  105.                   if (strfind(rec, wd[cur_arg][1]) > 0
  106.                         && strfind(rec, wd[cur_arg][3]) > 0)
  107.                      hit();
  108.                   }
  109.                else
  110.                   {
  111.                   if (strfind(rec, arg[cur_arg]) > 0)
  112.                      hit();
  113.                   }
  114.                }
  115.             }
  116.          }
  117.       else printf("Couldn't open file: %s\n", filename);
  118.       if (dosnext("*", 0, filename) != 0)
  119.          break;
  120.       }
  121.    for (cur_arg = 0; cur_arg <= num_args; ++cur_arg)
  122.       {
  123.       printf("\n\nSearched %d movies for:  %s ", ctr, arg[cur_arg]);
  124.       printf("\nFound: %d\n", match[cur_arg]);
  125.       printf("Review these again (Y/N)? ");
  126.       if (getyn())
  127.          {
  128.          for (i = 0; i < match[cur_arg]; ++i)
  129.             {
  130.             puts("\n----------------------------------------\n\n");
  131.             puts(recs_found[cur_arg][i]);
  132.             puts("----------------------------------------\n");
  133.             }
  134.          }
  135.       }
  136.    return(0);
  137.    
  138.    }
  139.  
  140. hit()
  141.    {
  142.    puts("\n----------------------------------------\n\n");
  143.    puts(rec);
  144.    puts("----------------------------------------\n");
  145.    if ((recs_found[cur_arg][match[cur_arg]] = malloc(strlen(rec) + 1)) == 0)
  146.       {
  147.       printf("\nOut of memory\n");
  148.       om = 1;
  149.       return(ERR);
  150.       }
  151.    strcpy(recs_found[cur_arg][match[cur_arg]++], rec);
  152.    }
  153.  
  154.