/* * POF! - Plenty Of Files * ---------------------- * * POF! is a file list maker for BBS systems having files.bbs-like * download areas. * * Public domain: this program may be copied and sold freely. * * Porting: under unix it should be easy, all defines are below, * and just compile with "cc -DUNIX -DNO_LDIFFTIME -o pof -c pof.c". * Potential unix problems: long filenames, case. */ #include #include #include #include #include #include #include /* for download */ #include /* all configuration is here */ #ifdef ATARI /* Atari ST */ #define POFVERS "1.1/tos" #define SYSSEPAR '\\' #define SYSSTRSEPAR "\\" #endif #ifdef UNIX /* Unix (tested on BSD,etc) */ #define POFVERS "1.1/unix" #define SYSSEPAR '/' /* directory separator */ #define SYSSTRSEPAR "/" #define stricmp strcasecmp #define strnicmp strncasecmp #endif #ifdef WIN32 /* Windows NT */ #define POFVERS "1.1/wnt" #define SYSSEPAR '\\' #define SYSSTRSEPAR "\\" #endif /*efine NO_LDIFFTIME */ /* define if you don't want to use the ansi difftime that requires float point libs, and if your system time_t is in seconds since sometimes */ /* more config, don't change normally */ #define POFSTR 150 #define FILESBBS "files.bbs" #define FBBSCUTLEN 45 /* download() */ #define FBBSSTRINGLEN 31 #ifdef NO_LDIFFTIME #define difftime(a,b) (a-b) #endif #define DEBUG /**/ int total_files=0; long total_kb=0; int total_missing=0; /* ================================================== UTILITY FUNCTIONS */ /* * Insert one space at the beginning of a string */ void strspins(char *str) { int maxlen,i; maxlen=strlen(str); for(i=maxlen+1;i>=0;i--) str[i+1]=str[i]; str[0]=' '; } /* * strcln: remove a char from string */ void strcln(char *string, char c) { char *s=string; while(*s) { if((c!=-1 && *s==c) || (c==-1 && *s<0x20 && *s>0)) strcpy(s,s+1); s++; } } /* * add a directory separator at the end of a string if !there */ void addslash(char *s) { if(*s) { if(s[strlen(s)-1]!=SYSSEPAR) strcat(s,SYSSTRSEPAR); } } /* * find next string format "plouf tralala ; comment */ char *nextstr(char *str) { char* s=str; while((*s!='\0') && (*s!=' ') && (*s!='\x09')) s++; if(*s=='\0') return NULL; while((*s==' ') || (*s=='\x09')) s++; if((*s=='\0') || (*s==';')) return NULL; return s; } /* * copy string until space (in dest) */ void strspacecpy(char *dest, char *srce) { int i=0,j=0; while((srce[i]!='\0') && (srce[i]!=' ') && (srce[i]!='\x09') && (i' ') { dest[j]=srce[i]; j++; } i++; } dest[i]='\0'; } /* ================================================= LOG FILE FUNCTIONS */ FILE *logfile=NULL; /* * logline: Log a line in the logfile and output to screen */ void logline(char *line, ...) { time_t timer; char temp[100], out[100],tdate[20]; va_list param; struct tm *tim; if(!logfile) return; /* error */ /* process */ va_start(param, line); vsprintf(temp, line, param); va_end(param); time (&timer); tim = localtime (&timer); strftime (tdate, 20, "%d %b %H:%M:%S", tim); sprintf (out, "+ %s POF %s", tdate, temp); /* log to file */ fputs(out,logfile); #ifdef DEBUG fflush(logfile); #endif } /* * openlog: create logfile */ void open_the_log(char *nm) { logfile=fopen(nm,"a"); if(logfile) return; printf("Can't open logfile!\n"); } /* * closelog: close logfile */ void close_the_log(void ) { if(logfile) fclose(logfile); } /* * process @ line */ void include(char *text) { char oneline[POFSTR]; FILE *txt; if(!text) return; txt=fopen(text,"r"); if(txt) { while(fgets(oneline,POFSTR,txt)) { strcln(oneline,-1); if(strlen(oneline)>79) oneline[78]=0; puts(oneline); } fclose(txt); } else logline("Error including text"); } /* * process area line */ void doarea(char *area, int days) { struct stat mystat; char area2[POFSTR]; char *temp; char file[POFSTR]; char filebbs[POFSTR]; FILE *fbbs; time_t now; int i; int area_files=0; long area_kb=0; /* get now */ time(&now); /* clean copy of area */ strcpy(area2,area); addslash(area2); strcpy(filebbs,area2); strcat(filebbs,FILESBBS); fbbs=fopen(filebbs,"r"); if(!fbbs) logline("Can't find %s in area %s",filebbs,area); else { temp=malloc((POFSTR*10)+1); if(!temp) logline("Can't malloc temp buffer in doarea()"); else { while(fgets(temp,POFSTR*10,fbbs)) { if(!isalnum(*temp)) /* thats a comment */ { strcln(temp,-1); if(strlen(temp)>75) temp[72]=0; puts(temp); } else { /* that's a file name */ char filen[POFSTR]; char unknown[POFSTR]; char date[POFSTR]; char *desc; int lastspace,idx,lastcut; strcpy(unknown,"-none-"); strcpy(file,area2); /* file \ */ strspacecpy(filen,temp); strcat(file,filen); desc=nextstr(temp); /* desc: description */ if(!desc) desc=unknown; strcln(desc,-1); /* multiline */ idx=0; lastspace=0; lastcut=0; while(desc[idx]) { if(desc[idx]==' ') lastspace=idx; if((idx-lastcut)>FBBSCUTLEN) { for(i=0;i1) { strcln(oneline,-1); if(oneline[0]=='@') include(oneline+1); else if(oneline[0]=='#') puts(oneline+1); else if(oneline[0]==';') ; else { doarea(oneline,days); total_area++; } } } fclose(txt); } printf("\n\n Stats:\n ------\n\n"); printf(" Total number of files : %d\n",total_files); printf(" Total size of listed files : %d KB\n",total_kb); printf(" Average file lenght : %d KB\n",total_kb/total_files); printf(" Number of areas listed : %d\n",total_area); printf(" Number of missing file(s) : %d\n\n\n",total_missing); if(days<=0) printf(" Full filelist compiled on %s by POF! vers. %s.\n\n",date,POFVERS); else printf(" Filelist of NEW FILES SINCE %d DAYS compiled on %s.\n\n",days,date); } /* ============================================================= MAIN */ void usage(void ) { printf("pof: [-d] [-l] config-file\n\n"); } int main(int argc, char **argv) { char myconfig[POFSTR]; int keepdays=0; int i; myconfig[0]=0; /* parse command line */ for(i=1;i