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