home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cshot103.zip / CS-HOT.C < prev    next >
C/C++ Source or Header  |  1993-03-08  |  8KB  |  235 lines

  1. /*  CS-HOT version 1.03        Copyright (C) 1993 by Jim Robeson
  2.  *                                                      3/08/93
  3.  *  Function:
  4.  *    Read the output of PCBCS143 (arg-1),
  5.  *      and strip it down to a "hotfile" report (arg-2),
  6.  *      according to the FORMat requested (arg-3),
  7.  *      dropping files uploaded only X-MANY times (arg-4).
  8.  *         "FORM" must be 1 or 2 or 3
  9.  *                1 = output only "files downloaded" section
  10.  *                2 = also include the "1st page stats" section
  11.  *                3 = also include the "multi-node" section,
  12.  *                    (if it exists).
  13.  *         "XMANY" must be 0 to 9
  14.  *
  15.  *  Other uses:
  16.  *    None.
  17.  *
  18.  *  Execution:
  19.  *    Run from command line or .BAT:
  20.  *      CS-HOT drv:\path\in-file-name drv:\path\out-file-name FORM XMANY
  21.  *    If run without arguments, a bit of help appears.
  22.  *
  23.  *  Compiled with:
  24.  *    Borland's Turbo C 2.0.
  25.  *    tcc cs-hot
  26.  *
  27.  *  Disclaimer:
  28.  *    This program is contributed to the Public Domain.  It can be
  29.  *    freely used, modified and/or distributed by anyone. The only
  30.  *    thing I ask is that you remember that I am not responsible
  31.  *    for anything that might go wrong through the use of this
  32.  *    program.  I have tested the program enough for my own use.
  33.  *    I also realize that bugs can appear in most every program.
  34.  *    Therefore, YOU USE THIS PROGRAM AT YOUR OWN RISK.
  35.  *
  36.  *  To-do:
  37.  *
  38.  *  Enjoy,
  39.  *  Jim Robeson
  40.  *  The Cricket BBS, Pacific Grove CA,  408-373-3773
  41.  */
  42.  
  43. #include "stdio.h"         /* Standard I/O definitions */
  44. #include "string.h"
  45.  
  46. #define TRUE 1
  47. #define FALSE 0
  48.  
  49. void showhelp ( );         /* prototype */
  50.  
  51.   FILE *infile;            /* the IN file */
  52.   FILE *outfile;           /* the OUT file */
  53.   char inbuf[BUFSIZ];      /* line buffer for reading from file */
  54.                            /* BUFSIZ = 512 in stdio.h */
  55.   int ipt,opt,i;           /* index pointers */
  56.   int phase;
  57.   int linecnt;
  58.  
  59. char *isitTTL = "            PCB Caller Statistics Version 1.43";
  60. char *isitMLT = "                              Multinode Statistics";
  61. char *isitHOT = "                         Files downloaded --- by Count";
  62. char *isitALP = "                          Files downloaded --- by Name";
  63.  
  64. /* ========================================= */
  65. /* ===  MAIN                             === */
  66. /* ========================================= */
  67. main(int argc, char *argv[])       /* main reads command args  */
  68. {
  69.   char *progname;
  70.   char *filein;
  71.   char *fileout;
  72.   char *form;
  73.   char *xmany;
  74.  
  75. /*  Display a little how-to "help" if arguments are null or improper  */
  76.  
  77.   if (argc != 5)           /*  should be 4 args + prognam */
  78.      { if (argc != 1)
  79.          printf("\nERROR: needs 4 arguments\n");
  80.        showhelp();
  81.        exit (1); }               /* exit with errorlevel=1 */
  82.  
  83.   progname = argv[0];
  84.   filein   = argv[1];
  85.   fileout  = argv[2];
  86.   form     = argv[3];
  87.   xmany    = argv[4];
  88.  
  89.   if (form[0] == '1' || form[0] == '2' || form[0] == '3') ;
  90.      else
  91.      { printf("\nERROR: FORM MUST = 1, 2 OR 3\n");
  92.        showhelp();
  93.        exit (1); }               /* exit with errorlevel=1 */
  94.  
  95.   if (xmany[0] == '0' || xmany[0] == '1' || xmany[0] == '2' ||
  96.       xmany[0] == '3' || xmany[0] == '4' || xmany[0] == '5' ||
  97.       xmany[0] == '6' || xmany[0] == '7' || xmany[0] == '8' ||
  98.       xmany[0] == '9') ;
  99.      else
  100.      { printf("\nERROR: XMANY MUST = 0 to 9\n");
  101.        showhelp();
  102.        exit (1); }               /* exit with errorlevel=1 */
  103.  
  104.   printf("\nCS-HOT IS RUNNING.  Input = %s, Output = %s, FORM = %s, XMANY = %s.\n",filein,fileout,form,xmany);
  105.  
  106.   infile = fopen(filein,"r");          /* open the input file */
  107.   if (infile == NULL)
  108.     {
  109.     fprintf(stderr,"\n\007%s can't open the INPUT file: %s.\n",progname,filein);
  110.     exit (1);
  111.     }
  112.  
  113.   outfile = fopen(fileout,"w");          /* open the output file */
  114.   if (outfile == NULL)
  115.     {
  116.     fprintf(stderr,"\n\007%s can't open the OUTPUT file: %s.\n",progname,fileout);
  117.     exit (1);
  118.     }
  119.  
  120.   phase = 1;
  121.   linecnt = 0;
  122.  /* ========================  copy the file ========================= */
  123.   while ( fgets(inbuf,BUFSIZ,infile) != NULL )  /* TOP-OF-LOOP */
  124.     {
  125.  
  126.     switch (phase)
  127.  
  128.       { case 1 :       /* copy the first 3 lines as-is */
  129.           fprintf(outfile,"%s",inbuf);
  130.           linecnt++;
  131.           if (linecnt == 4) phase = 2;
  132.           break;
  133.  
  134.         case 2 :       /* copy 1st STAT PAGE until next title */
  135.           if ( strncmp(inbuf,isitTTL,strlen(isitTTL)) == 0 )    /* test for Vern's page title */
  136.             { fprintf(outfile,"\n");  /* found it, stuff a blank line */
  137.               phase = 3;
  138.               break;
  139.             }
  140.           if (form[0] == '2' || form[0] == '3')
  141.             fprintf(outfile,"%s",inbuf);
  142.           break;
  143.  
  144.         case 3 :       /* now, skip to the multi-node section */
  145.           if ( strncmp(inbuf,isitHOT,strlen(isitHOT)) == 0 )    /* test for mulit-node line */
  146.             { fprintf(outfile,"%s",inbuf);    /* write it out */
  147.               phase = 6;
  148.               break;
  149.             }
  150.           if ( strncmp(inbuf,isitMLT,strlen(isitMLT)) == 0 )    /* test for mulit-node line */
  151.             { if (form[0] == '3')
  152.                 fprintf(outfile,"%s",inbuf);    /* write it out */
  153.               phase = 4;
  154.               break;
  155.             }
  156.           break;
  157.  
  158.         case 4 :       /* copy MULTI-NODE report until next title */
  159.           if ( strncmp(inbuf,isitTTL,strlen(isitTTL)) == 0 )    /* test for Vern's page title */
  160.             { fprintf(outfile,"\n");  /* found it, stuff a blank line */
  161.               phase = 5;
  162.               break;
  163.             }
  164.           if (form[0] == '3')
  165.             fprintf(outfile,"%s",inbuf);
  166.           break;
  167.  
  168.         case 5 :       /* now, skip to the hot-file section */
  169.           if ( strncmp(inbuf,isitHOT,strlen(isitHOT)) == 0 )    /* test for mulit-node line */
  170.             { fprintf(outfile,"%s",inbuf);  /* write it out */
  171.               fprintf(outfile,"\n");        /* & stuff a blank line */
  172.               phase = 6;
  173.               break;
  174.             }
  175.           break;
  176.  
  177.         case 6 :       /* copy the HOTFILES to end, except page titles */
  178.           if ( strncmp(inbuf,isitTTL,strlen(isitTTL)) == 0 )    /* test for Vern's page title */
  179.              break;
  180.           if (xmany[0] == '0')
  181.             { fprintf(outfile,"%s",inbuf);
  182.               break;
  183.             }
  184.           else             /* skip internal headers */
  185.             { if ( strncmp(inbuf,isitHOT,strlen(isitHOT)) == 0 )
  186.                  break;
  187.               if (inbuf[0] == '\n')  /* skip internal blank lines */
  188.                  break;
  189.               if ( strncmp(inbuf,isitALP,strlen(isitALP)) == 0 )
  190.                 { phase = 7;   /* quit when ALPHA header shows up */
  191.                   break;
  192.                 }          /* skip when file count is less than XMANY */
  193.               if ( inbuf[17] == ' ' && inbuf[18] >= '1' && inbuf[18] <= xmany[0])
  194.                   break;
  195.               fprintf(outfile,"%s",inbuf);
  196.               break;
  197.             }
  198.  
  199.         case 7 :       /* skip to the end */
  200.           break;
  201.  
  202.         default:
  203.           fprintf(stderr,"\nYO, HOW DID I GET HERE, OH MASTER?\n");
  204.           exit (1);
  205.       } /* end of switch */
  206.  
  207.     } /* end of while at TOP-OF-LOOP */
  208.  
  209.   /* === Since we dropped through,  ============== */
  210.   /* === implies end of file found. ============== */
  211.  
  212.   fclose(infile);
  213.   fclose(outfile);
  214.  
  215.   printf("CS-HOT IS FINISHED.\n");
  216.   exit (0);      /* job done, get out, errorvalue = 0 */
  217.  
  218. }  /* ------------- end of main ------------------------------- */
  219.  
  220. /* ========================================= */
  221. /* ===  SHOWHELP                         === */
  222. /* ========================================= */
  223. void showhelp ()
  224. {
  225.   printf("\nCS-HOT v1.03:\n");
  226.   printf("    Strip PCBCS reports into a smaller form.\n");
  227.   printf("    by Jim Robeson,  3-08-93\n\n");
  228.   printf("USAGE:\n");
  229.   printf("    CS-HOT drv:\path\in-file-name drv:\path\out-file-name FORM XMANY\n\n");
  230.   printf("           where  1 <= FORM <= 3   &   0 <= XMANY <= 9\n");
  231.   return;
  232. }  /* ------------- end of showhelp --------------------------- */
  233.  
  234. /*------------- End of CS-HOT.C ------------------------------------*/
  235.