home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / bbs_opus / topten.arj / TOPTEN.C next >
C/C++ Source or Header  |  1991-02-09  |  4KB  |  124 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.    long    offset;
  21.    int     count;
  22. };
  23.  
  24. struct _files  top[10];
  25. int    low;
  26. int        hits;
  27.  
  28.  
  29. void cdecl main(int argc,char *argv[])
  30. {
  31.    struct  _afile  afile;
  32.     char    *description;
  33.    int     datfh;
  34.    FILE    *output;
  35.    int        i,j;
  36.    long    jump;
  37.    long    pos;
  38.    char    outfile[80];
  39.  
  40.     low = 0;
  41.     hits = 0;
  42.  
  43.    if (argc <2)
  44.        strcpy(outfile,"topten.bbs");
  45.    else
  46.        strcpy(outfile,argv[1]);
  47.  
  48.    datfh = open("FILESBBS.DAT",O_RDONLY|O_BINARY);
  49.    pos = 0L;
  50.     while ((read(datfh,(char *)&afile,sizeof(struct _afile))) == sizeof(struct _afile)) {
  51.        jump = (long) afile.descr_len;
  52.        jump += (long) afile.altpath_len;
  53.        jump += (long) afile.upld_by_len;
  54.        lseek(datfh,jump,SEEK_CUR);
  55.         if ((afile.aflag & IS_FILE) && (afile.down_cntr >= low) && (afile.dl_priv < _EXTRA) ) {
  56.  
  57.             if (hits) {
  58.                 i = j = 0;
  59.                 while ((i<10) && (afile.down_cntr < top[i].count))
  60.                    i++;
  61.                if (i<10) {
  62.                    for (j = 9; j > i; j--) {
  63.                        top[j].offset = top[j-1].offset;
  64.                        top[j].count = top[j-1].count;
  65.                        }
  66.                       }
  67.                 }
  68.            else
  69.                i = 0;
  70.                hits++;
  71.  
  72.             if (i<10) {
  73.                 top[i].count = afile.down_cntr;
  74.                 top[i].offset = pos; 
  75.                 }
  76.             low = top[9].count;
  77.            }
  78.         pos = tell(datfh);
  79.         };
  80.     if (!low) {
  81.         printf("\n No files have been downloaded!\n");
  82.         exit(1);
  83.         }
  84.     output = fopen(outfile,"wt");
  85.    if (hits>10)
  86.        hits = 10;
  87.    fprintf(output,"\n\n\t\t\tTop %d Downloads\n",hits);
  88.    printf("\n\n\t\t\tTop %d Downloads\n",hits);
  89.  
  90.    i = 0;
  91.     while (top[i].count) {
  92.        lseek(datfh,top[i].offset,SEEK_SET);
  93.        read(datfh,(char *)&afile,sizeof(struct _afile));
  94.        description = (char *) malloc(afile.descr_len + 1);
  95.        memset(description,'\0',(afile.descr_len+1));
  96.        read(datfh,description,afile.descr_len);
  97.        fprintf(output,"\nCount: %3d  Area: %3d  File: %-13s Size: %7ld Date: %02d-%02d-%02d\n",
  98.            afile.down_cntr,
  99.            afile.area_number,
  100.            afile.name,
  101.            afile.size,
  102.            ((afile.date>>5) & 0x0f),
  103.            (afile.date & 0x1f),
  104.            ((afile.date >> 9) + 80));
  105.        fprintf(output,"%s\n",description);
  106.        printf("\nCount: %3d  Area: %3d  File: %-13s Size: %7ld Date: %02d-%02d-%02d\n",
  107.            afile.down_cntr,
  108.            afile.area_number,
  109.            afile.name,
  110.            afile.size,
  111.            ((afile.date>>5) & 0x0f),
  112.            (afile.date & 0x1f),
  113.            ((afile.date >> 9) + 80));
  114.        printf("%s\n",description);
  115.        free(description);
  116.        i++;
  117.        }
  118.     fputs("\n\r\n\r",output);
  119.     fclose(output);
  120.     close(datfh);
  121.     exit(0);
  122. }
  123.  
  124.