home *** CD-ROM | disk | FTP | other *** search
- /* FATCAT(C) by Bill Buckels and George Boudreau
- Version 2.0 final beta
- January 10,1992
-
- F ile
- a
- t
- C ounter
- a
- t
-
-
- This Utility updates the File Counter in The Various Files.BBS
- From Download or FREQ entries in FD.LOG or RA.LOG.
-
- If the Download/FREQ log entry has been updated by FATCAT
- a new log entry has been inserted before the original RA or FD
- entry so FATCAT knows that it has already Updated the FILES.BBS
- stats for the Download or the FREQ.
-
- FATCAT simply skips the entry if word "FATCAT(C)" is not found on
- the line preceding the Download or the FREQ.
-
- If the FREQ has not yet been DOCUMENTED by FATCAT the appropriate
- FILES.BBS stats are updated and then FATCAT Inserts a Marker
- Into The FD.LOG to remind itself that this has been done.
-
- No Callers log is created or updated.
- The RA.LOG or FD.LOG is not removed and is simply Updated.
-
- BTW: No warranty or liability is assumed by me.
- If you don't like FATCAT then don't use it.
-
- */
-
-
- #include <string.h>
- #include <stdio.h>
-
- /* While reading the log if a "Download" is found or if a "FREQ" */
- /* is found to be "Sent"... */
- /* the following function updates the stats for "filename" to */
- /* "listname" while reading "tempname" ("tempname" is the old */
- /* "FILES.BBS"). After updating the stats for "filename" */
- /* "tempname" is removed and we return to continue reading the */
- /* RA or FD log */
-
- int updatefiles(char *filename, char *listname, char *tempname)
- {
-
- FILE *fp,*fp2;
- char *ptr;
- char temp[256];
- char inbuffer[256];
- char outbuffer[256];
-
- char *temptr;
- int i;
-
- /* if we have a problem opening the FILES.BBS for writing */
- /* we get outa here real fast... */
-
- if((fp=fopen(listname,"w"))==NULL)
- {
- fcloseall();
- perror(listname);
- rename(tempname,listname);
- exit(0);
- }
-
- /* if we can't read the original we do a quick clean-up */
- /* and we're outa here... */
-
- if((fp2=fopen(tempname,"r"))==NULL)
- {
- fcloseall();
- perror(tempname);
- remove(listname);
- rename(tempname,listname);
- exit(0);
- }
-
- /* we read every file in the list and look for our match */
-
- while(fgets(inbuffer,256,fp2)!=NULL)
- {
-
- strcpy(outbuffer,inbuffer);
- temptr=strtok(inbuffer," [");
- sprintf(temp,"%s",inbuffer);
-
- /* string compare ignore case */
-
- if(strcmpi(filename,temp)==0)
- {
- ptr=(char *)&outbuffer[14];
- i=atoi(ptr);
- i++;
- if(i>99)
- {
- if(i>999)strcpy(temp,"[999]"); /* we stop at 999 */
- else sprintf(temp,"[%003d]",i);
- }
- if(i<100)sprintf(temp,"[%002d] ",i);
-
- outbuffer[13]=temp[0];
- outbuffer[14]=temp[1];
- outbuffer[15]=temp[2];
- outbuffer[16]=temp[3];
- outbuffer[17]=temp[4];
-
- printf("%s",outbuffer);
- }
-
- fputs(outbuffer,fp);
- }
-
- fclose(fp2);
- fclose(fp);
- remove(tempname);
- return 0;
-
- }
-
-
- /* the following function processes the RA.LOG or FD.LOG looking */
- /* for Downloads or FREQs that have been "Sent" but not DOCUMENTED. */
-
- /* If so then "updatefiles" is called to update the FILES.BBS */
- /* counter in the appropriate directory and a FATCAT marker */
- /* is inserted ahead of the "Download" or FREQ & "Sent" log entries. */
-
-
- int downloaded(char *original_log, char *templog)
- {
-
- FILE *fp,*fp2;
-
- char *ptr,*wordptr;
- char stringbuf[256];
- char backbuf[256],backbuf2[256];
- char stringptr[256];
- char statsptr[256];
- char temptr[256];
-
- unsigned temp,checkit;
-
- /* rename and open the RA.LOG or FD.LOG for reading */
- rename(original_log,templog);
- if((fp=fopen(templog,"r"))==NULL)
- {
- /* nothing to do */
- perror(templog);
- exit(0);
- }
-
- /* open the TEMPORARY.LOG for writing as RA.LOG or FD.LOG */
- if((fp2=fopen(original_log,"w"))==NULL)
- {
- perror(original_log);
- fclose(fp);
- rename(templog,original_log);
- exit(0);
- }
-
-
- #undef OFF
- #define OFF 0
- #undef FDLOG
- #define FDLOG 1
- #undef RALOG
- #define RALOG 2
-
- /* read until we can't read any more */
- while(fgets(stringbuf,256,fp)!=NULL)
- {
-
- /* set the download-freq flag to "OFF" */
-
- checkit=OFF;
-
- /* if we find a FATCAT Log Marker We Read and Write the Next Entry */
- /* and skip the parts that Check Further since the entry counter */
- /* has been updated already in the appropriate FILES.BBS */
-
- if((ptr = strstr(stringbuf,"FATCAT(C)")) != NULL)
- {
- fputs(stringbuf,fp2);
- if(fgets(stringbuf,256,fp)==NULL)goto JUMPLABEL;
- fputs(stringbuf,fp2);
- goto JUMPLABEL;
- }
-
- /* make a copy of the entry... we may need this */
- strcpy(backbuf,stringbuf);
-
- /* if we find a FREQ set the freq flag */
- if((ptr = strstr(stringbuf,"FREQ")) != NULL)checkit=FDLOG;
- /* if we find a Download set the download flag */
- if((ptr = strstr(stringbuf,"Download")) != NULL)checkit=RALOG;
-
- /* if the log entry Does Not Match The Search Criteria */
- /* it is written out again and the next part is skipped */
- if(checkit==OFF)
- {
- fputs(stringbuf,fp2);
- goto JUMPLABEL;
- }
-
- /* If it is an RA.LOG entry... */
- if(checkit==RALOG)
- {
- strcpy(stringptr,"");
- while(*ptr++!=NULL)
- {
- if(ptr[0]==':')
- {
- *ptr--;
- strcpy(stringptr,ptr);
- /* get the colon out of the path */
- *ptr++;
- }
- }
- /* display filename */
- wordptr=strtok(stringptr," \n");
- printf("Adjusting Download Stats for %s.\n",stringptr);
-
- /* display file list */
- strcpy(statsptr,stringptr);
-
- temp=strlen(statsptr);
- wordptr=(char *)&statsptr[temp];
-
- while(*wordptr != '\\')*wordptr--;
- *wordptr='\x00';
- *wordptr++;
- strcpy(stringptr,wordptr);
-
- strcpy(temptr,statsptr);
- strcat(temptr,"\\TEMP.BBS");
- strcat(statsptr,"\\FILES.BBS");
-
- if(rename(statsptr,temptr))
- {
- fprintf(fp2,
- "---------- FATCAT(C) Could Not Update Stats %s\n",
- statsptr);
- fputs(backbuf,fp2);
- }
- else
- {
- updatefiles(stringptr,statsptr,temptr);
- fprintf(fp2,
- "---------- FATCAT(C) Updated Stats Re: %s\n",
- statsptr);
- fputs(backbuf,fp2);
- }
-
- }
-
-
- /* Start update FD.LOG.... */
-
- if(checkit==FDLOG)
- {
- if(fgets(stringbuf,256,fp)==NULL)goto JUMPLABEL;
- /* make a copy of the entry... we may need this */
- strcpy(backbuf2,stringbuf);
-
-
- /* if the next line says "Sent" it is a valid entry */
- /* otherwise we jump past the rest of this... */
- if((ptr = strstr(stringbuf,"Sent"))== NULL)
- {
- fputs(backbuf,fp2);
- fputs(stringbuf,fp2);
- goto JUMPLABEL;
- }
-
- strcpy(stringptr,"");
- while(*ptr++!=NULL)
- {
- if(ptr[0]==':')
- {
- *ptr--;
- strcpy(stringptr,ptr);
- /* get the colon out of the path */
- *ptr++;
- }
- }
- /* display filename */
- wordptr=strtok(stringptr,"; \n");
- printf("Adjusting Download Stats for %s.\n",stringptr);
-
- /* display file list */
- strcpy(statsptr,stringptr);
-
- temp=strlen(statsptr);
- wordptr=(char *)&statsptr[temp];
-
- while(*wordptr != '\\')*wordptr--;
- *wordptr='\x00';
- *wordptr++;
- strcpy(stringptr,wordptr);
-
- strcpy(temptr,statsptr);
- strcat(temptr,"\\TEMP.BBS");
- strcat(statsptr,"\\FILES.BBS");
-
- if(rename(statsptr,temptr))
- {
- fprintf(fp2,
- "---------- FATCAT(C) Could Not Update Stats %s\n",
- statsptr);
- fputs(backbuf,fp2);
- fputs(backbuf2,fp2);
- }
- else
- {
- updatefiles(stringptr,statsptr,temptr);
- fprintf(fp2,
- "---------- FATCAT(C) Updated Stats Re: %s\n",
- statsptr);
- fputs(backbuf,fp2);
- fputs(backbuf2,fp2);
- }
-
- }
-
- /* LOOK OUT BELOW!!!
- |\/\/\/|
- | |
- | |
- | (o)(o)
- C _)
- | ,___| Labels Should Be Clearly Marked If A Goto is Used!
- | /
- /____\
- / BART \
- */
- JUMPLABEL:; /* jumps to here if we've already updated stats */
-
- }
-
- /* close all files and remove the old RA.LOG or FD.LOG */
- fcloseall();
- remove(templog);
-
- return 0;
-
- }
-
-
-
-
- main(int argc, char **argv)
- {
- puts(
- "FATCAT(C) Version 2.0ß (Final) Copyright 1992 Headboard International");
- puts(
- "Written by Bill Buckels and George Boudreau");
-
- if(argc!=2)
- {
- puts(
- "Download Stat Update Utility for RA.LOG or FD.LOG as used with RA");
- puts(
- "\nUsage is \"FATCAT [ (DRIVE:\\PATHNAME\\) FD.LOG or RA.LOG]\"");
- puts(
- "Run from the command line or a batch file.");
- puts(
- "\n Use and Copy Freely!");
- }
- else
- downloaded(argv[1],"FATCAT.$$$");
-
- puts(" Have a Nice Dos!");
- exit(0);
-
- }