File:  [ELWIX - Embedded LightWeight unIX -] / embedtools / src / dpatch.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Wed Jun 8 12:45:41 2011 UTC (13 years ago) by misho
Branches: MAIN
CVS tags: tools1_1, TOOLS1_0, HEAD
new ver

    1: /*************************************************************************
    2:  * (C) 2010 AITNET - Sofia/Bulgaria - <office@aitbg.com>
    3:  *  by Michael Pounov <misho@aitbg.com>
    4:  *
    5:  * $Author: misho $
    6:  * $Id: dpatch.c,v 1.2 2011/06/08 12:45:41 misho Exp $
    7:  *
    8:  *************************************************************************/
    9: #include "global.h"
   10: 
   11: 
   12: int Verbose, Mode;
   13: extern char compiled[], compiledby[], compilehost[];
   14: 
   15: 
   16: static void Usage()
   17: {
   18: 	printf("-= DELTA PATCH =- Delta patch binaries tool\n"
   19: 		"=== %s === %s@%s ===\n\n"
   20: 		"Syntax: dpatch [option] <mode> <input_file | ->\n\n"
   21: 		"\tMode:: S|sig|signature\t\tCreate Siganture\n"
   22: 		"\tMode:: D|del|delta\t\tCreate Delta patch\n"
   23: 		"\tMode:: P|pat|patch\t\tPatch file from delta\n"
   24: 		"\t-v\t\t\tVerbose (more -v more verbosity)\n"
   25: 		"\t-s <signature_file>\tSignature file (default - stdout)\n"
   26: 		"\t-d <delta_file>\t\tDelta patch file (default - stdout)\n"
   27: 		"\t-p <patch_file>\t\tPatch local binary file (default - stdout)\n"
   28: 		"\n", compiled, compiledby, compilehost);
   29: }
   30: 
   31: 
   32: int main(int argc, char **argv)
   33: {
   34: 	char ch, szDltName[MAXPATHLEN] = "-", szSigName[MAXPATHLEN] = "-", 
   35: 	     szPName[MAXPATHLEN] = "-", szInName[MAXPATHLEN] = "-", Mode = 0;
   36: 
   37: 	while ((ch = getopt(argc, argv, "hs:d:p:v")) != -1)
   38: 		switch (ch) {
   39: 			case 'v':
   40: 				Verbose++;
   41: 				break;
   42: 			case 's':
   43: 				Mode |= 1;
   44: 				strlcpy(szSigName, optarg, MAXPATHLEN);
   45: 				break;
   46: 			case 'd':
   47: 				Mode |= 2;
   48: 				strlcpy(szDltName, optarg, MAXPATHLEN);
   49: 				break;
   50: 			case 'p':
   51: 				Mode |= 4;
   52: 				strlcpy(szPName, optarg, MAXPATHLEN);
   53: 				break;
   54: 			case 'h':
   55: 			default:
   56: 				Usage();
   57: 				return 1;
   58: 		}
   59: 	argc -= optind;
   60: 	argv += optind;
   61: 	if (2 > argc) {
   62: 		printf("Error:: not enough parameters ...\n");
   63: 		Usage();
   64: 		return 1;
   65: 	} else
   66: 		strlcpy(szInName, argv[1], MAXPATHLEN);
   67: 
   68: 	if ('S' == *argv[0] || !strncmp(argv[0], "sig", 3)) {
   69: 		VERB(1) printf(">>> Signature mode: signature file=%s to_file=%s\n", 
   70: 				szSigName, szInName);
   71: 		if (syncSignature(szInName, szSigName, 2)) {
   72: 			printf("Error:: in create signature #%d - %s\n", 
   73: 					sync_GetErrno(), sync_GetError());
   74: 			return 1;
   75: 		}
   76: 		VERB(1) printf(" Done.\n");
   77: 		return 0;
   78: 	}
   79: 	if ('D' == *argv[0] || !strncmp(argv[0], "del", 3)) {
   80: 		if (!*szSigName || '-' == *szSigName) {
   81: 			printf("Error:: missing signature file!\n");
   82: 			return 1;
   83: 		}
   84: 
   85: 		VERB(1) printf(">>> Delta mode: signature file=%s delta file=%s from_file=%s\n", 
   86: 				szSigName, szDltName, szInName);
   87: 		switch (syncDelta(szInName, szSigName, szDltName, 3)) {
   88: 			case -1:
   89: 				printf("Error:: in create delta patch #%d - %s\n", 
   90: 						sync_GetErrno(), sync_GetError());
   91: 				return 1;
   92: 			case 1:
   93: 				VERB(1) printf("Info:: Not found differences in file %s\n", szInName);
   94: 				break;
   95: 			case 0:
   96: 				VERB(1) printf("Info:: Create Delta patch file %s\n", szDltName);
   97: 				break;
   98: 			default:
   99: 				printf("Error:: Unknown return code in delta patch!\n");
  100: 				return 2;
  101: 		}
  102: 		VERB(1) printf(" Done.\n");
  103: 		return 0;
  104: 	}
  105: 	if ('P' == *argv[0] || !strncmp(argv[0], "pat", 3)) {
  106: 		if (!*szDltName || '-' == *szDltName) {
  107: 			printf("Error:: missing delta file!\n");
  108: 			return 1;
  109: 		}
  110: 		if (2 > argc)
  111: 			*szInName = 0;
  112: 
  113: 		VERB(1) printf(">>> Patch mode: to_file=%s delta file=%s *differnt patch file=%s\n", 
  114: 				szPName, szDltName, szInName);
  115: 		if (syncPatch(szInName, szDltName, szPName, 1) == -1) {
  116: 			printf("Error:: can`t apply patch #%d - %s\n", 
  117: 					sync_GetErrno(), sync_GetError());
  118: 			return 1;
  119: 		}
  120: 
  121: 		VERB(1) printf(" Done.\n");
  122: 		return 0;
  123: 	}
  124: 
  125: 	printf("Error:: unknown mode ... %s\n", argv[0]);
  126: 	return 1;
  127: }

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