|
|
1.1 ! root 1: /* DUPEFIND.C */ ! 2: ! 3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */ ! 4: ! 5: #include "sbbs.h" ! 6: #include "crc32.h" ! 7: ! 8: #define DUPEFIND_VER "1.01" ! 9: ! 10: void bail(int code) ! 11: { ! 12: exit(code); ! 13: } ! 14: ! 15: long lputs(char *str) ! 16: { ! 17: char tmp[256]; ! 18: int i,j,k; ! 19: ! 20: j=strlen(str); ! 21: for(i=k=0;i<j;i++) /* remove CRs */ ! 22: if(str[i]==CR && str[i+1]==LF) ! 23: continue; ! 24: else ! 25: tmp[k++]=str[i]; ! 26: tmp[k]=0; ! 27: return(fputs(tmp,stderr)); ! 28: } ! 29: ! 30: /****************************************************************************/ ! 31: /* Performs printf() through local assembly routines */ ! 32: /* Called from everywhere */ ! 33: /****************************************************************************/ ! 34: int lprintf(char *fmat, ...) ! 35: { ! 36: va_list argptr; ! 37: char sbuf[256]; ! 38: int chcount; ! 39: ! 40: va_start(argptr,fmat); ! 41: chcount=vsprintf(sbuf,fmat,argptr); ! 42: va_end(argptr); ! 43: lputs(sbuf); ! 44: return(chcount); ! 45: } ! 46: ! 47: char *display_filename(scfg_t *cfg, ushort dir_num,ushort fil_off) ! 48: { ! 49: static char str[256]; ! 50: char fname[13]; ! 51: int file; ! 52: ! 53: sprintf(str,"%s%s.IXB",cfg->dir[dir_num]->data_dir,cfg->dir[dir_num]->code); ! 54: if((file=nopen(str,O_RDONLY))==-1) ! 55: return("UNKNOWN"); ! 56: lseek(file,(long)(22*(fil_off-1)),SEEK_SET); ! 57: read(file,fname,11); ! 58: close(file); ! 59: ! 60: sprintf(str,"%-8.8s.%c%c%c",fname,fname[8],fname[9],fname[10]); ! 61: return(str); ! 62: } ! 63: ! 64: int main(int argc,char **argv) ! 65: { ! 66: char str[256],*ixbbuf,*p; ! 67: ulong **fcrc,*foundcrc,total_found=0L; ! 68: ushort i,j,k,h,g,start_lib=0,end_lib=0,found=-1; ! 69: int file; ! 70: long l,m; ! 71: scfg_t cfg; ! 72: ! 73: putenv("TZ=UCT0"); ! 74: setvbuf(stdout,NULL,_IONBF,0); ! 75: ! 76: fprintf(stderr,"\nDUPEFIND Version %s (%s) - Synchronet Duplicate File " ! 77: "Finder\n", DUPEFIND_VER, PLATFORM_DESC); ! 78: ! 79: p=getenv("SBBSCTRL"); ! 80: if(p==NULL) { ! 81: fprintf(stderr,"\nSBBSCTRL environment variable must be set.\n"); ! 82: #ifdef __unix__ ! 83: fprintf(stderr,"\nExample: export SBBSCTRL=/sbbs/ctrl\n"); ! 84: #else ! 85: fprintf(stderr,"\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n"); ! 86: #endif ! 87: return(1); } ! 88: ! 89: if(argc>1 && (!stricmp(argv[1],"/?") || !stricmp(argv[1],"?") || !stricmp(argv[1],"-?"))) { ! 90: fprintf(stderr,"\n"); ! 91: fprintf(stderr,"usage: DUPEFIND [start] [end]\n"); ! 92: fprintf(stderr,"where: [start] is the starting library number to check\n"); ! 93: fprintf(stderr," [end] is the final library number to check\n"); ! 94: return(0); } ! 95: ! 96: memset(&cfg,0,sizeof(cfg)); ! 97: cfg.size=sizeof(cfg); ! 98: SAFECOPY(cfg.ctrl_dir,p); ! 99: ! 100: if(!load_cfg(&cfg,NULL,TRUE,str)) { ! 101: fprintf(stderr,"!ERROR loading configuration files: %s\n",str); ! 102: return(1); ! 103: } ! 104: ! 105: chdir(cfg.ctrl_dir); ! 106: ! 107: lputs("\n"); ! 108: ! 109: start_lib=0; ! 110: end_lib=cfg.total_libs-1; ! 111: if(argc>1) ! 112: start_lib=end_lib=atoi(argv[1])-1; ! 113: if(argc>2) ! 114: end_lib=atoi(argv[2])-1; ! 115: ! 116: if((fcrc=(ulong **)malloc(cfg.total_dirs*sizeof(ulong *)))==NULL) { ! 117: printf("Not enough memory for CRCs.\r\n"); ! 118: return(1); } ! 119: ! 120: for(i=0;i<cfg.total_dirs;i++) { ! 121: fprintf(stderr,"Reading directory index %u of %u\r",i+1,cfg.total_dirs); ! 122: sprintf(str,"%s%s.ixb",cfg.dir[i]->data_dir,cfg.dir[i]->code); ! 123: if((file=nopen(str,O_RDONLY|O_BINARY))==-1) { ! 124: fcrc[i]=(ulong *)malloc(1*sizeof(ulong)); ! 125: fcrc[i][0]=0; ! 126: continue; } ! 127: l=filelength(file); ! 128: if(!l || (cfg.dir[i]->lib<start_lib || cfg.dir[i]->lib>end_lib)) { ! 129: close(file); ! 130: fcrc[i]=(ulong *)malloc(1*sizeof(ulong)); ! 131: fcrc[i][0]=0; ! 132: continue; } ! 133: if((fcrc[i]=(ulong *)malloc((l/22+2)*sizeof(ulong)))==NULL) { ! 134: printf("Not enough memory for CRCs.\r\n"); ! 135: return(1); } ! 136: fcrc[i][0]=(ulong)(l/22); ! 137: if((ixbbuf=(char *)malloc(l))==NULL) { ! 138: close(file); ! 139: printf("\7Error allocating memory for index %s.\r\n",str); ! 140: continue; } ! 141: if(read(file,ixbbuf,l)!=l) { ! 142: close(file); ! 143: printf("\7Error reading %s.\r\n",str); ! 144: free(ixbbuf); ! 145: continue; } ! 146: close(file); ! 147: j=1; ! 148: m=0L; ! 149: while(m<l) { ! 150: sprintf(str,"%-11.11s",(ixbbuf+m)); ! 151: strupr(str); ! 152: fcrc[i][j++]=crc32(str,0); ! 153: m+=22; } ! 154: free(ixbbuf); } ! 155: lputs("\n"); ! 156: ! 157: foundcrc=0L; ! 158: for(i=0;i<cfg.total_dirs;i++) { ! 159: if(cfg.dir[i]->lib<start_lib || cfg.dir[i]->lib>end_lib) ! 160: continue; ! 161: lprintf("Scanning %s %s\n",cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->sname); ! 162: for(k=1;k<fcrc[i][0];k++) { ! 163: for(j=i+1;j<cfg.total_dirs;j++) { ! 164: if(cfg.dir[j]->lib<start_lib || cfg.dir[j]->lib>end_lib) ! 165: continue; ! 166: for(h=1;h<fcrc[j][0];h++) { ! 167: if(fcrc[i][k]==fcrc[j][h]) { ! 168: if(found!=k) { ! 169: found=k; ! 170: for(g=0;g<total_found;g++) { ! 171: if(foundcrc[g]==fcrc[i][k]) ! 172: g=total_found+1; } ! 173: if(g==total_found) { ! 174: ++total_found; ! 175: if((foundcrc=(ulong *)realloc(foundcrc ! 176: ,total_found*sizeof(ulong)))==NULL) { ! 177: printf("Out of memory reallocating\r\n"); ! 178: return(1); } } ! 179: else ! 180: found=0; ! 181: printf("\n%-12s is located in : %-*s %s\n" ! 182: "%-12s and : %-*s %s\n" ! 183: ,display_filename(&cfg,i,k) ! 184: ,LEN_GSNAME ! 185: ,cfg.lib[cfg.dir[i]->lib]->sname ! 186: ,cfg.dir[i]->sname ! 187: ,"" ! 188: ,LEN_GSNAME ! 189: ,cfg.lib[cfg.dir[j]->lib]->sname ! 190: ,cfg.dir[j]->sname ! 191: ); } ! 192: else ! 193: printf("%-12s and : %-*s %s\n" ! 194: ,"" ! 195: ,LEN_GSNAME ! 196: ,cfg.lib[cfg.dir[j]->lib]->sname ! 197: ,cfg.dir[j]->sname ! 198: ); } } } } } ! 199: return(0); ! 200: } ! 201:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.