File:
[ELWIX - Embedded LightWeight unIX -] /
libaitsync /
example /
test.c
Revision
1.2:
download - view:
text,
annotated -
select for diffs -
revision graph
Tue Nov 13 14:19:39 2012 UTC (11 years, 10 months ago) by
misho
Branches:
MAIN
CVS tags:
sync2_3,
sync2_2,
sync2_1,
sync2_0,
sync1_3,
SYNC2_2,
SYNC2_1,
SYNC2_0,
SYNC1_3,
SYNC1_2,
HEAD
version 1.2
1: /*************************************************************************
2: * (C) 2010 AITNET - Sofia/Bulgaria - <office@aitbg.com>
3: * by Michael Pounov <misho@aitbg.com>
4: *
5: * $Author: misho $
6: * $Id: test.c,v 1.2 2012/11/13 14:19:39 misho Exp $
7: *
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, 2012
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: */
46: #include <stdio.h>
47: #include <stdlib.h>
48: #include <unistd.h>
49: #include <sys/types.h>
50: #include <sys/param.h>
51: #include <aitsync.h>
52:
53:
54: #define VERB(x) if ((x) <= Verbose)
55:
56:
57: int Verbose, Mode;
58:
59:
60: static void Usage()
61: {
62: printf("-= DELTA PATCH =- Delta patch test\n"
63: "====================\n\n"
64: "Syntax: dpatch [option] <mode> <input_file | ->\n\n"
65: "\tMode:: S|sig|signature\t\tCreate Siganture\n"
66: "\tMode:: D|del|delta\t\tCreate Delta patch\n"
67: "\tMode:: P|pat|patch\t\tPatch file from delta\n"
68: "\t-v\t\t\tVerbose (more -v more verbosity)\n"
69: "\t-s <signature_file>\tSignature file (default - stdout)\n"
70: "\t-d <delta_file>\t\tDelta patch file (default - stdout)\n"
71: "\t-p <patch_file>\t\tPatch local binary file (default - stdout)\n"
72: "\n");
73: }
74:
75:
76: int main(int argc, char **argv)
77: {
78: char ch, szDltName[MAXPATHLEN] = "-", szSigName[MAXPATHLEN] = "-",
79: szPName[MAXPATHLEN] = "-", szInName[MAXPATHLEN] = "-", Mode = 0;
80:
81: while ((ch = getopt(argc, argv, "hs:d:p:v")) != -1)
82: switch (ch) {
83: case 'v':
84: Verbose++;
85: break;
86: case 's':
87: Mode |= 1;
88: strlcpy(szSigName, optarg, MAXPATHLEN);
89: break;
90: case 'd':
91: Mode |= 2;
92: strlcpy(szDltName, optarg, MAXPATHLEN);
93: break;
94: case 'p':
95: Mode |= 4;
96: strlcpy(szPName, optarg, MAXPATHLEN);
97: break;
98: case 'h':
99: default:
100: Usage();
101: return 1;
102: }
103: argc -= optind;
104: argv += optind;
105: if (2 > argc) {
106: printf("Error:: not enough parameters ...\n");
107: Usage();
108: return 1;
109: } else
110: strlcpy(szInName, argv[1], MAXPATHLEN);
111:
112: if ('S' == *argv[0] || !strncmp(argv[0], "sig", 3)) {
113: VERB(1) printf(">>> Signature mode: signature file=%s to_file=%s\n",
114: szSigName, szInName);
115: if (syncSignature(szInName, szSigName, 2)) {
116: printf("Error:: in create signature #%d - %s\n",
117: sync_GetErrno(), sync_GetError());
118: return 1;
119: }
120: VERB(1) printf(" Done.\n");
121: return 0;
122: }
123: if ('D' == *argv[0] || !strncmp(argv[0], "del", 3)) {
124: if (!*szSigName || '-' == *szSigName) {
125: printf("Error:: missing signature file!\n");
126: return 1;
127: }
128:
129: VERB(1) printf(">>> Delta mode: signature file=%s delta file=%s from_file=%s\n",
130: szSigName, szDltName, szInName);
131: switch (syncDelta(szInName, szSigName, szDltName, 3)) {
132: case -1:
133: printf("Error:: in create delta patch #%d - %s\n",
134: sync_GetErrno(), sync_GetError());
135: return 1;
136: case 1:
137: VERB(1) printf("Info:: Not found differences in file %s\n", szInName);
138: break;
139: case 0:
140: VERB(1) printf("Info:: Create Delta patch file %s\n", szDltName);
141: break;
142: default:
143: printf("Error:: Unknown return code in delta patch!\n");
144: return 2;
145: }
146: VERB(1) printf(" Done.\n");
147: return 0;
148: }
149: if ('P' == *argv[0] || !strncmp(argv[0], "pat", 3)) {
150: if (!*szDltName || '-' == *szDltName) {
151: printf("Error:: missing delta file!\n");
152: return 1;
153: }
154: if (2 > argc)
155: *szInName = 0;
156:
157: VERB(1) printf(">>> Patch mode: to_file=%s delta file=%s *differnt patch file=%s\n",
158: szPName, szDltName, szInName);
159: if (syncPatch(szInName, szDltName, szPName, 1) == -1) {
160: printf("Error:: can`t apply patch #%d - %s\n",
161: sync_GetErrno(), sync_GetError());
162: return 1;
163: }
164:
165: VERB(1) printf(" Done.\n");
166: return 0;
167: }
168:
169: printf("Error:: unknown mode ... %s\n", argv[0]);
170: return 1;
171: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>