/************************************************************************* * (C) 2010 AITNET - Sofia/Bulgaria - * by Michael Pounov * * $Author: misho $ * $Id: dpatch.c,v 1.2 2011/06/08 12:45:41 misho Exp $ * *************************************************************************/ #include "global.h" int Verbose, Mode; extern char compiled[], compiledby[], compilehost[]; static void Usage() { printf("-= DELTA PATCH =- Delta patch binaries tool\n" "=== %s === %s@%s ===\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", compiled, compiledby, compilehost); } 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; }