--- libaitsync/example/test.c 2012/11/13 10:05:13 1.1 +++ libaitsync/example/test.c 2012/11/13 14:19:39 1.2 @@ -0,0 +1,171 @@ +/************************************************************************* + * (C) 2010 AITNET - Sofia/Bulgaria - + * by Michael Pounov + * + * $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 + +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 + by Michael Pounov . 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 +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 +#include +#include +#include +#include +#include + + +#define VERB(x) if ((x) <= Verbose) + + +int Verbose, Mode; + + +static void Usage() +{ + printf("-= DELTA PATCH =- Delta patch test\n" + "====================\n\n" + "Syntax: dpatch [option] \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 \tSignature file (default - stdout)\n" + "\t-d \t\tDelta patch file (default - stdout)\n" + "\t-p \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; +}