home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / misc / buildrecent.lha / BuildRECENT.c next >
Encoding:
C/C++ Source or Header  |  1995-01-21  |  2.8 KB  |  81 lines

  1. /*  BuildRECENT.c   --  Copyright © Jan. 20, 1995 by Travis Pascoe
  2.  
  3. Program will build a 'RECENT' index file from the master AmiNET
  4. INDEX file according to the args provided.  WARNING:  The regular
  5. INDEX file (pub/aminet/INDEX) will NOT work!  Use the file
  6. pub/aminet/info/index/INDEX because it contains a 'days old'
  7. column.
  8.  
  9. Usage:  BuildRECENT <AmiNET_indexfile> <x> [<y>]
  10.  
  11.  <x>    Program will output all files uploaded less than or equal
  12.         to <x> days ago.  If <x> is negative, only files uploaded
  13.         exactly <x> days ago will be output.
  14.  
  15. [<y>]   Only optional parameter.  If <y> is specified only files
  16.         uploaded between <x> and <y> days ago are output.
  17.    
  18. */
  19.  
  20. #include <stdio.h>
  21.  
  22. main(int ac, char **av)
  23. {
  24.     FILE *fp;
  25.     char line[300];
  26.     int  days_x, days_y, days_old, i;
  27.  
  28.     if ((ac != 3) && (ac != 4)) {
  29.       printf("BuildRECENT  Copyright © Jan. 20, 1995 by Travis Pascoe\n");
  30.       printf("Usage:  %s <AmiNET_indexfile> <x> [<y>]\n", av[0]);
  31.       printf("\nProgram will build a 'RECENT' index file from the master AmiNET\n");
  32.       printf("INDEX file according to the args provided.  WARNING:  The regular\n");
  33.       printf("INDEX file (pub/aminet/INDEX) will NOT work!  Use the file\n");
  34.       printf("pub/aminet/info/index/INDEX because it contains a 'days old'\n");
  35.       printf("column.\n\n");
  36.       printf("Usage:  %s <AmiNET_indexfile> <x> [<y>]\n\n", av[0]);
  37.       printf(" <x>    Program will output all files uploaded less than or equal\n");
  38.       printf("        to <x> days ago.  If <x> is negative, only files uploaded\n");
  39.       printf("        exactly <x> days ago will be output.\n\n");
  40.       printf("[<y>]   Only optional parameter.  If <y> is specified only files\n");
  41.       printf("        uploaded between <x> and <y> days ago are output.\n\n");
  42.       exit(10);
  43.     }
  44.     fp = fopen(av[1], "r");
  45.     if (fp == NULL) {
  46.       printf("ERROR:  Unable to open index file:  %s\n", av[1]);
  47.       exit(10);
  48.     }
  49.     for(i = 0; i <= 6; i++) fscanf(fp, "%*[^\n]");   /*skip header*/
  50.     sscanf(av[2], "%d", &days_x);
  51.     if (ac == 4) {
  52.       sscanf(av[3], "%d", &days_y);
  53.       days_y = abs(days_y);
  54.       days_x = abs(days_x);
  55.       if (days_y < days_x) {
  56.         i = days_y;
  57.         days_y = days_x;
  58.         days_x = i;
  59.       }
  60.       while (fscanf(fp, "%[^\n]", line) == 1) {
  61.         sscanf(line, "%*37c%d", &days_old);
  62.         if ((days_old >= days_x)&&(days_old <= days_y)) printf("%s\n", line);
  63.       }
  64.       fclose(fp);
  65.       exit(0);
  66.     }
  67.     if (days_x >= 0)
  68.       while (fscanf(fp, "%[^\n]", line) == 1) {
  69.         sscanf(line, "%*37c%d", &days_old);
  70.         if (days_old <= days_x) printf("%s\n", line);
  71.       }
  72.     else {
  73.       days_x = abs(days_x);
  74.       while (fscanf(fp, "%[^\n]", line) == 1) {
  75.         sscanf(line, "%*37c%d", &days_old);
  76.         if (days_old == days_x) printf("%s\n", line);
  77.       }
  78.     }
  79.     fclose(fp);
  80. }
  81.