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