Annotation of embedtools/src/dircmp.c, revision 1.2
1.2 ! misho 1: /*************************************************************************
! 2: * (C) 2010 AITNET - Sofia/Bulgaria - <office@aitbg.com>
! 3: * by Michael Pounov <misho@aitbg.com>
! 4: *
! 5: * $Author: misho $
! 6: * $Id: dircmp.c,v 1.1.2.8 2010/09/20 23:07:11 misho Exp $
! 7: *
! 8: *************************************************************************/
! 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"
! 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"
! 23: "\n", compiled, compiledby, compilehost);
! 24: }
! 25:
! 26: int
! 27: main(int argc, char **argv)
! 28: {
! 29: char ch, szFName[MAXPATHLEN];
! 30: int lm = 0;
! 31: struct tagDirName *list;
! 32: register int i;
! 33: FILE *f = stdout;
! 34: struct stat sb;
! 35:
! 36: while ((ch = getopt(argc, argv, "hlo:")) != -1)
! 37: switch (ch) {
! 38: case 'o':
! 39: lm |= 2;
! 40: strlcpy(szFName, optarg, MAXPATHLEN);
! 41: break;
! 42: case 'l':
! 43: lm |= 1;
! 44: break;
! 45: case 'h':
! 46: default:
! 47: Usage();
! 48: return 127;
! 49: }
! 50: argc -= optind;
! 51: argv += optind;
! 52:
! 53: if (!argc || (!(lm & 2) && argc < 2)) {
! 54: Usage();
! 55: return 127;
! 56: }
! 57: // check for general differences
! 58: if (argc > 1) {
! 59: if (lstat(argv[1], &sb) == -1) {
! 60: printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno));
! 61: return 127;
! 62: }
! 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: }
! 75: }
! 76:
! 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());
! 79: return 127;
! 80: }
! 81:
! 82: if (lm & 2 && strcmp(szFName, "-")) {
! 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: }
! 91: for (i = 0; list[i].ch; i++)
! 92: fprintf(f, "%c %s %s\n", list[i].ch, list[i].name, list[i].extra);
! 93: if (lm & 2)
! 94: fclose(f);
! 95:
! 96: printf("\nTotal count of elements = %d\n", i);
! 97: free(list);
! 98: return 1;
! 99: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>