Annotation of embedtools/src/dircmp.c, revision 1.1.2.7

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 $
        !             6:  * $Id: get1steth.c,v 1.1.2.9 2010/03/24 16:43:01 misho Exp $
        !             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.6   misho      77:        if (sync_dircmpList(argv[0], argc > 1 ? argv[1] : NULL, lm, &list) == -1)
1.1.2.1   misho      78:                return 127;
                     79: 
1.1.2.5   misho      80:        if (lm & 2 && strcmp(szFName, "-")) {
1.1.2.4   misho      81:                f = fopen(szFName, "w");
                     82:                if (!f) {
                     83:                        printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno));
                     84:                        if (list)
                     85:                                free(list);
                     86:                        return 0;
                     87:                }
                     88:        }
1.1.2.1   misho      89:        for (i = 0; list[i].ch; i++)
1.1.2.4   misho      90:                fprintf(f, "%c  %s %s\n", list[i].ch, list[i].name, list[i].extra);
                     91:        if (lm & 2)
                     92:                fclose(f);
1.1.2.1   misho      93: 
1.1.2.4   misho      94:        printf("\nTotal count of elements = %d\n", i);
1.1.2.1   misho      95:        free(list);
                     96:        return 1;
                     97: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>