Deleted Added
sdiff udiff text old ( 15702 ) new ( 15773 )
full compact
1/* Still missing:
2 *
3 * Damage counter
4 * Change counter
5 * Time stamp
6 * prefix
7 * cmd-line args
8 * %100 deltas
9 * delta and Add are different. delta -> Equ.
10 *
11 * mkctm
12 * -B regex Bogus
13 * -I regex Ignore
14 * -D int Damage
15 * -v increase verbosity
16 * -l str control logging.
17 * name cvs-cur
18 * prefix src/secure
19 * dir1 "Soll"
20 * dir2 "Ist"
21 *
22 */
23
24#include <sys/types.h>

--- 6 unchanged lines hidden (view full) ---

31#include <fcntl.h>
32#include <string.h>
33#include <stdlib.h>
34#include <unistd.h>
35#include <md5.h>
36#include <err.h>
37#include <signal.h>
38
39#define DEFAULT_IGNORE "/CVS$|/\\.#"
40#define DEFAULT_BOGUS "\\.core$"
41regex_t reg_ignore, reg_bogus;
42int flag_ignore, flag_bogus;
43
44u_long s1_ignored, s2_ignored;
45u_long s1_bogus, s2_bogus;
46u_long s1_wrong, s2_wrong;
47u_long s_same_dirs, s_same_files, s_same_bytes;
48u_long s_files_chg, s_bytes_add, s_bytes_del;
49u_long s_new_dirs, s_new_files, s_new_bytes;
50u_long s_del_dirs, s_del_files, s_del_bytes;
51u_long s_chg_files, s_chg_bytes;
52u_long s_edit_files, s_edit_bytes, s_edit_saves;
53u_long s_sub_files, s_sub_bytes;
54
55void
56print_stat(FILE *fd, char *pre)
57{
58 fprintf(fd,"%sAvoided:\n",pre);
59 fprintf(fd,"%s ignore: %5lu old %5lu new\n",
60 pre, s1_ignored, s2_ignored);
61 fprintf(fd,"%s bogus: %5lu old %5lu new\n",
62 pre, s1_bogus, s2_bogus);
63 fprintf(fd,"%s wrong: %5lu old %5lu new\n",

--- 49 unchanged lines hidden (view full) ---

113
114 strcpy(buf,dir);
115 strcat(buf,"/"); strcat(buf,name);
116 strcat(buf,"/"); strcat(buf,de->d_name);
117 st = StatFile(buf);
118 printf("%s %s%s %lu %lu %o",
119 pfx, name, de->d_name,
120 st->st_uid, st->st_gid, st->st_mode & ~S_IFMT);
121}
122
123void
124Equ(const char *dir1, const char *dir2, const char *name, struct dirent *de)
125{
126 if (de->d_type == DT_DIR) {
127 char *p = alloca(strlen(name)+strlen(de->d_name)+2);
128
129 strcpy(p,name); strcat(p,de->d_name); strcat(p, "/");
130 DoDir(dir1,dir2,p);
131 s_same_dirs++;
132 } else {
133 char *buf1 = alloca(strlen(dir1) + strlen(name) +
134 strlen(de->d_name) + 3);
135 char *buf2 = alloca(strlen(dir2) + strlen(name) +
136 strlen(de->d_name) + 3);
137 char *m1,md5_1[33],*m2, md5_2[33];
138 void *p1,*p2;
139 int fd1,fd2;
140 struct stat s1,s2;
141
142 strcpy(buf1,dir1);
143 strcat(buf1,"/"); strcat(buf1,name);
144 strcat(buf1,"/"); strcat(buf1,de->d_name);
145 fd1 = open(buf1,O_RDONLY);
146 if(fd1 < 0) { perror(buf1); exit(3); }
147 fstat(fd1,&s1);
148 strcpy(buf2,dir2);
149 strcat(buf2,"/"); strcat(buf2,name);
150 strcat(buf2,"/"); strcat(buf2,de->d_name);
151 fd2 = open(buf2,O_RDONLY);
152 if(fd2 < 0) { perror(buf2); exit(3); }
153 fstat(fd2,&s2);
154#if 1
155 if (s1.st_size == s2.st_size) {
156 s_same_files++;
157 s_same_bytes += s1.st_size;
158 close(fd1);
159 close(fd2);
160 goto finish;
161 }
162#endif

--- 8 unchanged lines hidden (view full) ---

171 /* If identical, we're done. */
172 if((s1.st_size == s2.st_size) && !memcmp(p1,p2,s1.st_size)) {
173 s_same_files++;
174 s_same_bytes += s1.st_size;
175 goto finish;
176 }
177
178 s_files_chg++;
179 if (s1.st_size > s2.st_size)
180 s_bytes_del += (s1.st_size - s2.st_size);
181 else
182 s_bytes_add += (s2.st_size - s1.st_size);
183
184 m1 = MD5Data(p1, s1.st_size, md5_1);
185 m2 = MD5Data(p2, s2.st_size, md5_2);
186
187 /* Just a curiosity... */
188 if(!strcmp(m1,m2)) {
189 if (s1.st_size != s2.st_size)
190 fprintf(stderr,
191 "Notice: MD5 same for files of diffent size:\n\t%s\n\t%s\n",
192 buf1,buf2);
193 goto finish;
194 }
195
196 {
197 u_long l = s1.st_size + s2.st_size;
198 u_char *ob = alloca(l);
199 Dissect(p1,p1+s1.st_size,p2,p2+s2.st_size,ob,&l);
200 if (l && l < s2.st_size) {
201 name_stat("CTMFB",dir2,name,de);
202 printf(" %s %s %d\n",m1,m2,(unsigned)s1.st_size);
203 s_edit_files++;
204 s_edit_bytes += l;
205 s_edit_saves += (s2.st_size - l);
206 fwrite(ob,1,l,stdout);
207 putchar('\n');
208 } else {
209 name_stat("CTMFS",dir2,name,de);
210 printf(" %s %s %u\n",m1,m2,(unsigned)s2.st_size);
211 fwrite(p2,1,s2.st_size,stdout);
212 s_sub_files++;
213 s_sub_bytes += s2.st_size;
214 }
215 }
216 finish:
217 munmap(p1,s1.st_size);
218 munmap(p2,s2.st_size);
219 }
220}
221
222void
223Add(const char *dir1, const char *dir2, const char *name, struct dirent *de)
224{
225 if (de->d_type == DT_DIR) {
226 char *p = alloca(strlen(name)+strlen(de->d_name)+2);
227 strcpy(p,name); strcat(p,de->d_name); strcat(p, "/");
228 name_stat("CTMDM",dir2,name,de);
229 putchar('\n');
230 s_new_dirs++;
231 DoDir(dir1,dir2,p);
232 } else if (de->d_type == DT_REG) {

--- 22 unchanged lines hidden (view full) ---

255 s_new_files++;
256 s_new_bytes += st.st_size;
257 }
258}
259
260void
261Del (const char *dir1, const char *dir2, const char *name, struct dirent *de)
262{
263 if (de->d_type == DT_DIR) {
264 char *p = alloca(strlen(name)+strlen(de->d_name)+2);
265 strcpy(p,name); strcat(p,de->d_name); strcat(p, "/");
266 DoDir(dir1,dir2,p);
267 printf("CTMDR %s%s\n",name,de->d_name);
268 s_del_dirs++;
269 } else if (de->d_type == DT_REG) {
270 char *buf1 = alloca(strlen(dir1) + strlen(name) +

--- 23 unchanged lines hidden (view full) ---

294 if (*dir != '/')
295 strcat(buf,"/");
296 strcat(buf,dir);
297 if (buf[strlen(buf)-1] != '/')
298 strcat(buf,"/");
299 strcat(buf,name);
300 if (buf[strlen(buf)-1] != '/')
301 strcat(buf,"/");
302 fprintf(stderr,">%d<%s>\n",strlen(nl[*i]->d_name),nl[*i]->d_name);
303 fflush(stderr);
304 strcat(buf,nl[*i]->d_name);
305 if (flag_ignore && !regexec(&reg_ignore,buf,0,0,0))
306 (*ignored)++;
307 else if (flag_bogus && !regexec(&reg_bogus,buf,0,0,0))
308 (*bogus)++;
309 else
310 break;
311 free(nl[*i]); nl[*i] = 0;
312 }
313 /* If the filesystem didn't tell us, find type */
314 if (nl[*i]->d_type == DT_UNKNOWN)
315 nl[*i]->d_type = IFTODT(StatFile(buf)->st_mode);
316 if (nl[*i]->d_type == DT_REG || nl[*i]->d_type == DT_DIR)
317 break;
318 (*wrong)++;
319 free(nl[*i]); nl[*i] = 0;
320 }
321}
322
323void
324DoDir(const char *dir1, const char *dir2, const char *name)
325{
326 int i1,i2,n1,n2,i;

--- 5 unchanged lines hidden (view full) ---

332 strcpy(buf2,dir2); strcat(buf2,"/"); strcat(buf2,name);
333 n1 = scandir(buf1, &nl1, dirselect, alphasort);
334 n2 = scandir(buf2, &nl2, dirselect, alphasort);
335 i1 = i2 = -1;
336 GetNext(&i1, &n1, nl1, dir1, name, &s1_ignored, &s1_bogus, &s1_wrong);
337 GetNext(&i2, &n2, nl2, dir2, name, &s2_ignored, &s2_bogus, &s2_wrong);
338 for (;i1 < n1 || i2 < n2;) {
339
340 /* Get next item from list 1 */
341 if (i1 < n1 && !nl1[i1])
342 GetNext(&i1, &n1, nl1, dir1, name,
343 &s1_ignored, &s1_bogus, &s1_wrong);
344
345 /* Get next item from list 2 */
346 if (i2 < n2 && !nl2[i2])
347 GetNext(&i2, &n2, nl2, dir2, name,

--- 40 unchanged lines hidden (view full) ---

388
389int
390main(int argc, char **argv)
391{
392 int i;
393 extern char *optarg;
394 extern int optind;
395
396 if (regcomp(&reg_bogus,DEFAULT_BOGUS, REG_EXTENDED | REG_NEWLINE))
397 /* XXX use regerror to explain it */
398 err(1,"Default regular expression argument to -B is botched");
399 flag_bogus = 1;
400
401 if (regcomp(&reg_ignore,DEFAULT_IGNORE, REG_EXTENDED | REG_NEWLINE))
402 /* XXX use regerror to explain it */
403 err(1,"Default regular expression argument to -I is botched");
404 flag_ignore = 1;
405
406 while ((i = getopt(argc,argv,"I:B:")) != EOF)
407 switch (i) {
408 case 'I':
409 if (flag_ignore)
410 regfree(&reg_ignore);
411 flag_ignore = 0;
412 if (!*optarg)
413 break;
414 if (regcomp(&reg_ignore,optarg,
415 REG_EXTENDED | REG_NEWLINE))

--- 8 unchanged lines hidden (view full) ---

424 if (!*optarg)
425 break;
426 if (regcomp(&reg_bogus,optarg,
427 REG_EXTENDED | REG_NEWLINE))
428 /* XXX use regerror to explain it */
429 err(1,"Regular expression argument to -B is botched");
430 flag_bogus = 1;
431 break;
432 case '?':
433 default:
434 fprintf(stderr,"Usage:\n\t%s: %s\n", argv[0],
435"[-I ignore_re] [-B bogus_re]");
436 return (1);
437 }
438 argc -= optind;
439 argv += optind;
440
441 setbuf(stdout,0);
442
443 signal(SIGINFO,stat_info);
444 printf("CTM_BEGIN 2.0 tst 0 950326022230Z .\n");
445 DoDir(argv[0],argv[1],"");
446 printf("CTM_END ");
447 print_stat(stderr,"");
448 exit(0);
449}