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, 11 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
/*************************************************************************
* (C) 2010 AITNET - Sofia/Bulgaria - <office@aitbg.com>
* by Michael Pounov <misho@aitbg.com>
*
* $Author: misho $
* $Id: test.c,v 1.2 2012/11/13 14:19:39 misho Exp $
*
*************************************************************************
The ELWIX and AITNET software is distributed under the following
terms:
All of the documentation and software included in the ELWIX and AITNET
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
by Michael Pounov <misho@elwix.org>. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by Michael Pounov <misho@elwix.org>
ELWIX - Embedded LightWeight unIX and its contributors.
4. Neither the name of AITNET nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <aitsync.h>
#define VERB(x) if ((x) <= Verbose)
int Verbose, Mode;
static void Usage()
{
printf("-= DELTA PATCH =- Delta patch test\n"
"====================\n\n"
"Syntax: dpatch [option] <mode> <input_file | ->\n\n"
"\tMode:: S|sig|signature\t\tCreate Siganture\n"
"\tMode:: D|del|delta\t\tCreate Delta patch\n"
"\tMode:: P|pat|patch\t\tPatch file from delta\n"
"\t-v\t\t\tVerbose (more -v more verbosity)\n"
"\t-s <signature_file>\tSignature file (default - stdout)\n"
"\t-d <delta_file>\t\tDelta patch file (default - stdout)\n"
"\t-p <patch_file>\t\tPatch local binary file (default - stdout)\n"
"\n");
}
int main(int argc, char **argv)
{
char ch, szDltName[MAXPATHLEN] = "-", szSigName[MAXPATHLEN] = "-",
szPName[MAXPATHLEN] = "-", szInName[MAXPATHLEN] = "-", Mode = 0;
while ((ch = getopt(argc, argv, "hs:d:p:v")) != -1)
switch (ch) {
case 'v':
Verbose++;
break;
case 's':
Mode |= 1;
strlcpy(szSigName, optarg, MAXPATHLEN);
break;
case 'd':
Mode |= 2;
strlcpy(szDltName, optarg, MAXPATHLEN);
break;
case 'p':
Mode |= 4;
strlcpy(szPName, optarg, MAXPATHLEN);
break;
case 'h':
default:
Usage();
return 1;
}
argc -= optind;
argv += optind;
if (2 > argc) {
printf("Error:: not enough parameters ...\n");
Usage();
return 1;
} else
strlcpy(szInName, argv[1], MAXPATHLEN);
if ('S' == *argv[0] || !strncmp(argv[0], "sig", 3)) {
VERB(1) printf(">>> Signature mode: signature file=%s to_file=%s\n",
szSigName, szInName);
if (syncSignature(szInName, szSigName, 2)) {
printf("Error:: in create signature #%d - %s\n",
sync_GetErrno(), sync_GetError());
return 1;
}
VERB(1) printf(" Done.\n");
return 0;
}
if ('D' == *argv[0] || !strncmp(argv[0], "del", 3)) {
if (!*szSigName || '-' == *szSigName) {
printf("Error:: missing signature file!\n");
return 1;
}
VERB(1) printf(">>> Delta mode: signature file=%s delta file=%s from_file=%s\n",
szSigName, szDltName, szInName);
switch (syncDelta(szInName, szSigName, szDltName, 3)) {
case -1:
printf("Error:: in create delta patch #%d - %s\n",
sync_GetErrno(), sync_GetError());
return 1;
case 1:
VERB(1) printf("Info:: Not found differences in file %s\n", szInName);
break;
case 0:
VERB(1) printf("Info:: Create Delta patch file %s\n", szDltName);
break;
default:
printf("Error:: Unknown return code in delta patch!\n");
return 2;
}
VERB(1) printf(" Done.\n");
return 0;
}
if ('P' == *argv[0] || !strncmp(argv[0], "pat", 3)) {
if (!*szDltName || '-' == *szDltName) {
printf("Error:: missing delta file!\n");
return 1;
}
if (2 > argc)
*szInName = 0;
VERB(1) printf(">>> Patch mode: to_file=%s delta file=%s *differnt patch file=%s\n",
szPName, szDltName, szInName);
if (syncPatch(szInName, szDltName, szPName, 1) == -1) {
printf("Error:: can`t apply patch #%d - %s\n",
sync_GetErrno(), sync_GetError());
return 1;
}
VERB(1) printf(" Done.\n");
return 0;
}
printf("Error:: unknown mode ... %s\n", argv[0]);
return 1;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>