Annotation of embedtools/src/direr.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: direr.c,v 1.1.2.3 2010/09/20 23:07:11 misho Exp $
! 7: *
! 8: *************************************************************************/
! 9: #include "global.h"
! 10:
! 11:
! 12: extern char compiled[], compiledby[], compilehost[];
! 13:
! 14: static void
! 15: Usage()
! 16: {
! 17: printf( "-= Direr =- Tool for compare directories by checksum\n"
! 18: "=== %s === %s@%s ===\n\n"
! 19: " Syntax: direr [options] <dir> [cmp_dir]\n\n"
! 20: "\t-s <cksum>\t\tCompare dir with this checksum ...\n"
! 21: "\n", compiled, compiledby, compilehost);
! 22: }
! 23:
! 24: int
! 25: main(int argc, char **argv)
! 26: {
! 27: u_char *md[2], mode = 0;
! 28: char szCmp[MAXPATHLEN], *str[2], ch;
! 29: int ret = 0;
! 30:
! 31: memset(md, 0, sizeof md);
! 32: memset(str, 0, sizeof str);
! 33: memset(szCmp, 0, MAXPATHLEN);
! 34: while ((ch = getopt(argc, argv, "hs:")) != -1)
! 35: switch (ch) {
! 36: case 's':
! 37: str[1] = strdup(optarg);
! 38: mode = 1;
! 39: break;
! 40: case 'h':
! 41: default:
! 42: Usage();
! 43: return 1;
! 44: }
! 45: argc -= optind;
! 46: argv += optind;
! 47:
! 48: if (argc < 1) {
! 49: Usage();
! 50: return 1;
! 51: }
! 52: if (argc > 1) {
! 53: strlcpy(szCmp, argv[1], MAXPATHLEN);
! 54: mode |= 2;
! 55: }
! 56:
! 57: if (sync_dirCSum(argv[0], &md[0]) == -1) {
! 58: printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno));
! 59: return 1;
! 60: }
! 61: str[0] = io_Hex2Ch(md[0], MD5_DIGEST_LENGTH);
! 62: if (!str[0]) {
! 63: free(md[0]);
! 64: return 1;
! 65: }
! 66: printf("1.Directory '%s': %s\n", argv[0], str[0]);
! 67:
! 68: if (mode & 1 && *str[1]) {
! 69: ret |= !strcmp((char*) str[0], (char*) str[1]) << 1;
! 70: printf("Result checksum:: %s %s %s\n\n", str[0], ret & 2 ? "==" : "!=", str[1]);
! 71: free(str[1]);
! 72: }
! 73:
! 74: if (mode & 2 && *szCmp) {
! 75: if (sync_dirCSum(szCmp, &md[1]) == -1) {
! 76: printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno));
! 77: return 1;
! 78: }
! 79: str[1] = io_Hex2Ch(md[1], MD5_DIGEST_LENGTH);
! 80: if (!str[1]) {
! 81: free(md[0]);
! 82: free(str[0]);
! 83: free(md[1]);
! 84: return 1;
! 85: }
! 86: printf("2.Directory '%s': %s\n", szCmp, str[1]);
! 87:
! 88: ret |= (!strcmp((char*) str[0], (char*) str[1]) << 2);
! 89: printf("Result directory:: %s %s %s\n\n", argv[0], ret & 4 ? "==" : "!=", szCmp);
! 90:
! 91: if (str[1])
! 92: free(str[1]);
! 93: if (md[1])
! 94: free(md[1]);
! 95: }
! 96:
! 97: if (str[0])
! 98: free(str[0]);
! 99: if (md[0])
! 100: free(md[0]);
! 101: return ret;
! 102: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>