home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / bbs_opus / count.arj / COUNT.C next >
Encoding:
C/C++ Source or Header  |  1991-01-21  |  3.6 KB  |  113 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* COUNT.C by Doug Boone, Reads Opus 1.20 FILESBBS.DAT files and generates  */
  3. /* a list of files that have been downloaded recently. You're welcome to    */
  4. /* modify the source for your own needs, so long as any programs you        */
  5. /* distribute based on it are freely available. (Shareware is freely        */
  6. /* available even if it isn't free.)            Doug Boone 1:119/5          */
  7. /*                                              1-21-91                     */
  8. /*--------------------------------------------------------------------------*/
  9. #include    <dos.h>
  10. #include    <stdio.h>
  11. #include    <fcntl.h>
  12. #include    <io.h>
  13. #include    <errno.h>
  14. #include    <stdlib.h>
  15. #include    <string.h>
  16. #include    "opus.h"
  17. #include    "nfile.h"
  18.  
  19. struct _files {
  20.     char    name[14];
  21.     int     count;
  22.     long    offset;
  23.     struct  _files *next;
  24. };
  25.  
  26. struct  _files  *head;
  27. struct  _files  *current;
  28. struct  _files  *next;
  29.  
  30. void cdecl main(int argc,char *argv[])
  31. {
  32.     struct  _afile  afile;
  33.     char    *description;
  34.     int     datfh;
  35.     FILE    *output;
  36.     unsigned long    Pos = 0L;
  37.     word    where;
  38.     int     max;
  39.     int     target = 2;
  40.  
  41.     max = 0;
  42.     datfh = open("FILESBBS.DAT",O_RDONLY|O_BINARY);
  43.     head = current = NULL;
  44.     Pos = tell(datfh);
  45.     if (argc>1)
  46.         target = atoi(argv[1]);
  47.  
  48.     while ((read(datfh,(char *)&afile,sizeof(struct _afile))) == sizeof(struct _afile)) {
  49.         if ((afile.aflag & IS_FILE) && (afile.down_cntr > target) && (afile.dl_priv < _EXTRA)) {
  50.             printf("\n%-13s  %3d  %lu",afile.name,afile.down_cntr,Pos);
  51.             if (NULL == head) {
  52.                 head = (struct _files *) malloc(sizeof(struct _files));
  53.                 current = head;
  54.                 }
  55.             else {
  56.                 current->next = (struct _files *) malloc(sizeof(struct _files));
  57.                 current = current->next;
  58.                 }
  59.             strcpy(current->name,afile.name);
  60.             current->count = afile.down_cntr;
  61.             if (max < afile.down_cntr)
  62.                 max = afile.down_cntr;
  63.             current->offset = Pos;
  64.             current->next = NULL;
  65.             }
  66.         where = afile.descr_len;
  67.         where += afile.upld_by_len;
  68.         where += afile.altpath_len;
  69.         lseek(datfh,((long)(where)),SEEK_CUR);
  70.         Pos = tell(datfh);
  71.         };
  72.     if (head == NULL) {
  73.         printf("\n No files have been downloaded more than %d times!\n",target);
  74.         exit(1);
  75.         }
  76.     output = fopen("COUNT.BBS","wt");
  77.     while (max > target) {
  78.         current = head;
  79.         max--;
  80.         do {
  81.             if (current->count > max) {
  82.                 lseek(datfh,current->offset,SEEK_SET);
  83.                 read(datfh,(char *)&afile,sizeof(struct _afile));
  84.                 description = (char *) malloc(afile.descr_len + 1);
  85.                 memset(description,'\0',(afile.descr_len+1));
  86.                 read(datfh,description,afile.descr_len);
  87.                 fprintf(output,"\nCount: %3d  Area: %3d  File: %-13s Size: %7ld %02d-%02d-%02d\n",
  88.                     afile.down_cntr,
  89.                     afile.area_number,
  90.                     afile.name,
  91.                     afile.size,
  92.                     ((afile.date>>5) & 0x0f),
  93.                     (afile.date & 0x1f),
  94.                     ((afile.date >> 9) + 80));
  95.                 fprintf(output,"%s\n",description);
  96.                 current->count = 0;
  97.                 free(description);
  98.                 }
  99.             current = current->next;
  100.             } while (current != NULL);
  101.         }
  102.     fclose(output);
  103.     close(datfh);
  104.     current = head;
  105.     do {
  106.         next = current->next;
  107.         free(current);
  108.         current = next;
  109.         } while (current != NULL);
  110.     exit(0);
  111. }
  112.  
  113.