Annotation of embedtools/src/dircmp.c, revision 1.1.2.6
1.1.2.1 misho 1: #include "global.h"
2:
3:
4: extern char compiled[], compiledby[], compilehost[];
5:
6:
7: static void
8: Usage()
9: {
10: printf( "-= DirCmp =- Tool for compare directories and show differences\n"
11: "=== %s === %s@%s ===\n\n"
1.1.2.4 misho 12: " Syntax: dircmp [options] <dir> [<cmp_dir>]\n\n"
13: "\t-l\t\tLong directory output ...\n"
14: "\t-o <filename>\tOutput diff to filename\n"
1.1.2.1 misho 15: "\n", compiled, compiledby, compilehost);
16: }
17:
18: int
19: main(int argc, char **argv)
20: {
1.1.2.4 misho 21: char ch, szFName[MAXPATHLEN];
1.1.2.6 ! misho 22: int lm = 0;
1.1.2.1 misho 23: struct tagDirName *list;
24: register int i;
1.1.2.4 misho 25: FILE *f = stdout;
1.1.2.6 ! misho 26: struct stat sb;
1.1.2.1 misho 27:
1.1.2.6 ! misho 28: while ((ch = getopt(argc, argv, "hlo:")) != -1)
1.1.2.1 misho 29: switch (ch) {
1.1.2.4 misho 30: case 'o':
31: lm |= 2;
32: strlcpy(szFName, optarg, MAXPATHLEN);
33: break;
1.1.2.1 misho 34: case 'l':
1.1.2.4 misho 35: lm |= 1;
1.1.2.1 misho 36: break;
37: case 'h':
38: default:
39: Usage();
40: return 127;
41: }
42: argc -= optind;
43: argv += optind;
44:
1.1.2.5 misho 45: if (!argc || (!(lm & 2) && argc < 2)) {
1.1.2.1 misho 46: Usage();
47: return 127;
48: }
49: // check for general differences
1.1.2.6 ! misho 50: if (argc > 1) {
! 51: if (lstat(argv[1], &sb) == -1) {
! 52: printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno));
1.1.2.4 misho 53: return 127;
54: }
1.1.2.6 ! misho 55:
! 56: if (S_ISDIR(sb.st_mode))
! 57: switch (sync_dircmp(argv[0], argv[1])) {
! 58: case -1:
! 59: printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno));
! 60: return 127;
! 61: case 0:
! 62: printf("Directory %s == %s\n\n", argv[0], argv[1]);
! 63: return 0;
! 64: case 1:
! 65: printf("Directory %s != %s ::\n\n", argv[0], argv[1]);
! 66: }
1.1.2.1 misho 67: }
68:
1.1.2.6 ! misho 69: if (sync_dircmpList(argv[0], argc > 1 ? argv[1] : NULL, lm, &list) == -1)
1.1.2.1 misho 70: return 127;
71:
1.1.2.5 misho 72: if (lm & 2 && strcmp(szFName, "-")) {
1.1.2.4 misho 73: f = fopen(szFName, "w");
74: if (!f) {
75: printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno));
76: if (list)
77: free(list);
78: return 0;
79: }
80: }
1.1.2.1 misho 81: for (i = 0; list[i].ch; i++)
1.1.2.4 misho 82: fprintf(f, "%c %s %s\n", list[i].ch, list[i].name, list[i].extra);
83: if (lm & 2)
84: fclose(f);
1.1.2.1 misho 85:
1.1.2.4 misho 86: printf("\nTotal count of elements = %d\n", i);
1.1.2.1 misho 87: free(list);
88: return 1;
89: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>