File:  [ELWIX - Embedded LightWeight unIX -] / embedtools / src / dircmp.c
Revision 1.1.2.6: download - view: text, annotated - select for diffs - revision graph
Tue Jul 13 15:17:58 2010 UTC (14 years ago) by misho
Branches: tools1_0
move all shits to libaitsync

    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"
   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"
   15: 		"\n", compiled, compiledby, compilehost);
   16: }
   17: 
   18: int
   19: main(int argc, char **argv)
   20: {
   21: 	char ch, szFName[MAXPATHLEN];
   22: 	int lm = 0;
   23: 	struct tagDirName *list;
   24: 	register int i;
   25: 	FILE *f = stdout;
   26: 	struct stat sb;
   27: 
   28: 	while ((ch = getopt(argc, argv, "hlo:")) != -1)
   29: 		switch (ch) {
   30: 			case 'o':
   31: 				lm |= 2;
   32: 				strlcpy(szFName, optarg, MAXPATHLEN);
   33: 				break;
   34: 			case 'l':
   35: 				lm |= 1;
   36: 				break;
   37: 			case 'h':
   38: 			default:
   39: 				Usage();
   40: 				return 127;
   41: 		}
   42: 	argc -= optind;
   43: 	argv += optind;
   44: 
   45: 	if (!argc || (!(lm & 2) && argc < 2)) {
   46: 		Usage();
   47: 		return 127;
   48: 	}
   49: 	// check for general differences
   50: 	if (argc > 1) {
   51: 		if (lstat(argv[1], &sb) == -1) {
   52: 			printf("Error:: %s(%d) #%d - %s\n", __func__, __LINE__, errno, strerror(errno));
   53: 			return 127;
   54: 		}
   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: 			}
   67: 	}
   68: 
   69: 	if (sync_dircmpList(argv[0], argc > 1 ? argv[1] : NULL, lm, &list) == -1)
   70: 		return 127;
   71: 
   72: 	if (lm & 2 && strcmp(szFName, "-")) {
   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: 	}
   81: 	for (i = 0; list[i].ch; i++)
   82: 		fprintf(f, "%c  %s %s\n", list[i].ch, list[i].name, list[i].extra);
   83: 	if (lm & 2)
   84: 		fclose(f);
   85: 
   86: 	printf("\nTotal count of elements = %d\n", i);
   87: 	free(list);
   88: 	return 1;
   89: }

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