Annotation of embedtools/src/dpatch.c, revision 1.2.2.1
1.2 misho 1: /*************************************************************************
2: * (C) 2010 AITNET - Sofia/Bulgaria - <office@aitbg.com>
3: * by Michael Pounov <misho@aitbg.com>
4: *
5: * $Author: misho $
1.2.2.1 ! misho 6: * $Id: dpatch.c,v 1.2 2011/06/08 12:45:41 misho Exp $
1.2 misho 7: *
1.2.2.1 ! misho 8: *************************************************************************
! 9: The ELWIX and AITNET software is distributed under the following
! 10: terms:
! 11:
! 12: All of the documentation and software included in the ELWIX and AITNET
! 13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
! 14:
! 15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
! 16: by Michael Pounov <misho@elwix.org>. All rights reserved.
! 17:
! 18: Redistribution and use in source and binary forms, with or without
! 19: modification, are permitted provided that the following conditions
! 20: are met:
! 21: 1. Redistributions of source code must retain the above copyright
! 22: notice, this list of conditions and the following disclaimer.
! 23: 2. Redistributions in binary form must reproduce the above copyright
! 24: notice, this list of conditions and the following disclaimer in the
! 25: documentation and/or other materials provided with the distribution.
! 26: 3. All advertising materials mentioning features or use of this software
! 27: must display the following acknowledgement:
! 28: This product includes software developed by Michael Pounov <misho@elwix.org>
! 29: ELWIX - Embedded LightWeight unIX and its contributors.
! 30: 4. Neither the name of AITNET nor the names of its contributors
! 31: may be used to endorse or promote products derived from this software
! 32: without specific prior written permission.
! 33:
! 34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
! 35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 44: SUCH DAMAGE.
! 45: */
1.2 misho 46: #include "global.h"
47:
48:
49: int Verbose, Mode;
50: extern char compiled[], compiledby[], compilehost[];
51:
52:
53: static void Usage()
54: {
55: printf("-= DELTA PATCH =- Delta patch binaries tool\n"
56: "=== %s === %s@%s ===\n\n"
57: "Syntax: dpatch [option] <mode> <input_file | ->\n\n"
58: "\tMode:: S|sig|signature\t\tCreate Siganture\n"
59: "\tMode:: D|del|delta\t\tCreate Delta patch\n"
60: "\tMode:: P|pat|patch\t\tPatch file from delta\n"
61: "\t-v\t\t\tVerbose (more -v more verbosity)\n"
62: "\t-s <signature_file>\tSignature file (default - stdout)\n"
63: "\t-d <delta_file>\t\tDelta patch file (default - stdout)\n"
64: "\t-p <patch_file>\t\tPatch local binary file (default - stdout)\n"
65: "\n", compiled, compiledby, compilehost);
66: }
67:
68:
69: int main(int argc, char **argv)
70: {
71: char ch, szDltName[MAXPATHLEN] = "-", szSigName[MAXPATHLEN] = "-",
72: szPName[MAXPATHLEN] = "-", szInName[MAXPATHLEN] = "-", Mode = 0;
73:
74: while ((ch = getopt(argc, argv, "hs:d:p:v")) != -1)
75: switch (ch) {
76: case 'v':
77: Verbose++;
78: break;
79: case 's':
80: Mode |= 1;
81: strlcpy(szSigName, optarg, MAXPATHLEN);
82: break;
83: case 'd':
84: Mode |= 2;
85: strlcpy(szDltName, optarg, MAXPATHLEN);
86: break;
87: case 'p':
88: Mode |= 4;
89: strlcpy(szPName, optarg, MAXPATHLEN);
90: break;
91: case 'h':
92: default:
93: Usage();
94: return 1;
95: }
96: argc -= optind;
97: argv += optind;
98: if (2 > argc) {
99: printf("Error:: not enough parameters ...\n");
100: Usage();
101: return 1;
102: } else
103: strlcpy(szInName, argv[1], MAXPATHLEN);
104:
105: if ('S' == *argv[0] || !strncmp(argv[0], "sig", 3)) {
106: VERB(1) printf(">>> Signature mode: signature file=%s to_file=%s\n",
107: szSigName, szInName);
108: if (syncSignature(szInName, szSigName, 2)) {
109: printf("Error:: in create signature #%d - %s\n",
110: sync_GetErrno(), sync_GetError());
111: return 1;
112: }
113: VERB(1) printf(" Done.\n");
114: return 0;
115: }
116: if ('D' == *argv[0] || !strncmp(argv[0], "del", 3)) {
117: if (!*szSigName || '-' == *szSigName) {
118: printf("Error:: missing signature file!\n");
119: return 1;
120: }
121:
122: VERB(1) printf(">>> Delta mode: signature file=%s delta file=%s from_file=%s\n",
123: szSigName, szDltName, szInName);
124: switch (syncDelta(szInName, szSigName, szDltName, 3)) {
125: case -1:
126: printf("Error:: in create delta patch #%d - %s\n",
127: sync_GetErrno(), sync_GetError());
128: return 1;
129: case 1:
130: VERB(1) printf("Info:: Not found differences in file %s\n", szInName);
131: break;
132: case 0:
133: VERB(1) printf("Info:: Create Delta patch file %s\n", szDltName);
134: break;
135: default:
136: printf("Error:: Unknown return code in delta patch!\n");
137: return 2;
138: }
139: VERB(1) printf(" Done.\n");
140: return 0;
141: }
142: if ('P' == *argv[0] || !strncmp(argv[0], "pat", 3)) {
143: if (!*szDltName || '-' == *szDltName) {
144: printf("Error:: missing delta file!\n");
145: return 1;
146: }
147: if (2 > argc)
148: *szInName = 0;
149:
150: VERB(1) printf(">>> Patch mode: to_file=%s delta file=%s *differnt patch file=%s\n",
151: szPName, szDltName, szInName);
152: if (syncPatch(szInName, szDltName, szPName, 1) == -1) {
153: printf("Error:: can`t apply patch #%d - %s\n",
154: sync_GetErrno(), sync_GetError());
155: return 1;
156: }
157:
158: VERB(1) printf(" Done.\n");
159: return 0;
160: }
161:
162: printf("Error:: unknown mode ... %s\n", argv[0]);
163: return 1;
164: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>