\doxysubsection{rdiff.\+c}
\label{rdiff_8c_source}\index{rdiff.c@{rdiff.c}}
\mbox{\hyperlink{rdiff_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*= -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * librsync -\/-\/ the library for network deltas}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00006 \textcolor{comment}{ *}}
\DoxyCodeLine{00007 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{00008 \textcolor{comment}{ * it under the terms of the GNU Lesser General Public License as published by}}
\DoxyCodeLine{00009 \textcolor{comment}{ * the Free Software Foundation; either version 2.1 of the License, or}}
\DoxyCodeLine{00010 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{00011 \textcolor{comment}{ *}}
\DoxyCodeLine{00012 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{00013 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00014 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{00015 \textcolor{comment}{ * GNU Lesser General Public License for more details.}}
\DoxyCodeLine{00016 \textcolor{comment}{ *}}
\DoxyCodeLine{00017 \textcolor{comment}{ * You should have received a copy of the GNU Lesser General Public License}}
\DoxyCodeLine{00018 \textcolor{comment}{ * along with this program; if not, write to the Free Software}}
\DoxyCodeLine{00019 \textcolor{comment}{ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\DoxyCodeLine{00020 \textcolor{comment}{ */}}
\DoxyCodeLine{00021 }
\DoxyCodeLine{00022                               \textcolor{comment}{/*=}}
\DoxyCodeLine{00023 \textcolor{comment}{                               | .. after a year and a day, mourning is}}
\DoxyCodeLine{00024 \textcolor{comment}{                               | dangerous to the survivor and troublesome}}
\DoxyCodeLine{00025 \textcolor{comment}{                               | to the dead.}}
\DoxyCodeLine{00026 \textcolor{comment}{                               |              -\/-\/ Harold Bloom}}
\DoxyCodeLine{00027 \textcolor{comment}{                               */}}
\DoxyCodeLine{00028 \textcolor{comment}{}}
\DoxyCodeLine{00029 \textcolor{comment}{/** \(\backslash\)file rdiff.c}}
\DoxyCodeLine{00030 \textcolor{comment}{ * Command-\/line network-\/delta tool.}}
\DoxyCodeLine{00031 \textcolor{comment}{ *}}
\DoxyCodeLine{00032 \textcolor{comment}{ * \(\backslash\)todo Add a -\/z option to gzip/gunzip patches. This would be somewhat useful,}}
\DoxyCodeLine{00033 \textcolor{comment}{ * but more importantly a good test of the streaming API. Also add -\/I for}}
\DoxyCodeLine{00034 \textcolor{comment}{ * bzip2.}}
\DoxyCodeLine{00035 \textcolor{comment}{ *}}
\DoxyCodeLine{00036 \textcolor{comment}{ * \(\backslash\)todo If built with debug support and we have mcheck, then turn it on.}}
\DoxyCodeLine{00037 \textcolor{comment}{ * (Optionally?)}}
\DoxyCodeLine{00038 \textcolor{comment}{ *}}
\DoxyCodeLine{00039 \textcolor{comment}{ * \(\backslash\)todo popt doesn't handle single dashes very well at the moment: we'd like}}
\DoxyCodeLine{00040 \textcolor{comment}{ * to use them as arguments to indicate stdin/stdout, but it turns them into}}
\DoxyCodeLine{00041 \textcolor{comment}{ * options. I sent a patch to the popt maintainers; hopefully it will be fixed}}
\DoxyCodeLine{00042 \textcolor{comment}{ * in the future.}}
\DoxyCodeLine{00043 \textcolor{comment}{ *}}
\DoxyCodeLine{00044 \textcolor{comment}{ * \(\backslash\)todo Add an option for delta to check whether the files are identical. */}}
\DoxyCodeLine{00045 }
\DoxyCodeLine{00046 \textcolor{preprocessor}{\#include "{}config.h"{}}             \textcolor{comment}{/* IWYU pragma: keep */}}
\DoxyCodeLine{00047 \textcolor{preprocessor}{\#include <stdlib.h>}}
\DoxyCodeLine{00048 \textcolor{preprocessor}{\#include <stdarg.h>}}
\DoxyCodeLine{00049 \textcolor{preprocessor}{\#include <string.h>}}
\DoxyCodeLine{00050 \textcolor{preprocessor}{\#include <popt.h>}}
\DoxyCodeLine{00051 \textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{00052 \textcolor{preprocessor}{\#include "{}librsync.h"{}}}
\DoxyCodeLine{00053 \textcolor{preprocessor}{\#include "{}isprefix.h"{}}}
\DoxyCodeLine{00054 }
\DoxyCodeLine{00055 \textcolor{keyword}{static} \textcolor{keywordtype}{int} block\_len = 0;}
\DoxyCodeLine{00056 \textcolor{keyword}{static} \textcolor{keywordtype}{int} strong\_len = 0;}
\DoxyCodeLine{00057 }
\DoxyCodeLine{00058 \textcolor{keyword}{static} \textcolor{keywordtype}{int} show\_stats = 0;}
\DoxyCodeLine{00059 }
\DoxyCodeLine{00060 \textcolor{keyword}{static} \textcolor{keywordtype}{int} bzip2\_level = 0;}
\DoxyCodeLine{00061 \textcolor{keyword}{static} \textcolor{keywordtype}{int} gzip\_level = 0;}
\DoxyCodeLine{00062 \textcolor{keyword}{static} \textcolor{keywordtype}{int} file\_force = 0;}
\DoxyCodeLine{00063 }
\DoxyCodeLine{00064 \textcolor{keyword}{enum} \{}
\DoxyCodeLine{00065     OPT\_GZIP = 1069, OPT\_BZIP2}
\DoxyCodeLine{00066 \};}
\DoxyCodeLine{00067 }
\DoxyCodeLine{00068 \textcolor{keywordtype}{char} *rs\_hash\_name;}
\DoxyCodeLine{00069 \textcolor{keywordtype}{char} *rs\_rollsum\_name;}
\DoxyCodeLine{00070 }
\DoxyCodeLine{00071 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rdiff\_usage(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *error, ...)}
\DoxyCodeLine{00072 \{}
\DoxyCodeLine{00073     va\_list va;}
\DoxyCodeLine{00074     \textcolor{keywordtype}{char} buf[256];}
\DoxyCodeLine{00075 }
\DoxyCodeLine{00076     va\_start(va, error);}
\DoxyCodeLine{00077     vsnprintf(buf, \textcolor{keyword}{sizeof}(buf), error, va);}
\DoxyCodeLine{00078     va\_end(va);}
\DoxyCodeLine{00079     fprintf(stderr, \textcolor{stringliteral}{"{}rdiff: \%s\(\backslash\)n\(\backslash\)nTry `rdiff -\/-\/help' for more information.\(\backslash\)n"{}},}
\DoxyCodeLine{00080             buf);}
\DoxyCodeLine{00081 \}}
\DoxyCodeLine{00082 }
\DoxyCodeLine{00083 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rdiff\_no\_more\_args(poptContext opcon)}
\DoxyCodeLine{00084 \{}
\DoxyCodeLine{00085     \textcolor{keywordflow}{if} (poptGetArg(opcon)) \{}
\DoxyCodeLine{00086         rdiff\_usage(\textcolor{stringliteral}{"{}Too many arguments."{}});}
\DoxyCodeLine{00087         exit(RS\_SYNTAX\_ERROR);}
\DoxyCodeLine{00088     \}}
\DoxyCodeLine{00089 \}}
\DoxyCodeLine{00090 }
\DoxyCodeLine{00091 \textcolor{keyword}{static} \textcolor{keywordtype}{void} bad\_option(poptContext opcon, \textcolor{keywordtype}{int} error)}
\DoxyCodeLine{00092 \{}
\DoxyCodeLine{00093     rdiff\_usage(\textcolor{stringliteral}{"{}\%s: \%s"{}}, poptStrerror(error), poptBadOption(opcon, 0));}
\DoxyCodeLine{00094     exit(RS\_SYNTAX\_ERROR);}
\DoxyCodeLine{00095 \}}
\DoxyCodeLine{00096 }
\DoxyCodeLine{00097 \textcolor{keyword}{static} \textcolor{keywordtype}{void} help(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00098 \{}
\DoxyCodeLine{00099     printf(\textcolor{stringliteral}{"{}Usage: rdiff [OPTIONS] signature [BASIS [SIGNATURE]]\(\backslash\)n"{}}}
\DoxyCodeLine{00100            \textcolor{stringliteral}{"{}             [OPTIONS] delta SIGNATURE [NEWFILE [DELTA]]\(\backslash\)n"{}}}
\DoxyCodeLine{00101            \textcolor{stringliteral}{"{}             [OPTIONS] patch BASIS [DELTA [NEWFILE]]\(\backslash\)n"{}} \textcolor{stringliteral}{"{}\(\backslash\)n"{}}}
\DoxyCodeLine{00102            \textcolor{stringliteral}{"{}Options:\(\backslash\)n"{}}}
\DoxyCodeLine{00103            \textcolor{stringliteral}{"{}  -\/v, -\/-\/verbose             Trace internal processing\(\backslash\)n"{}}}
\DoxyCodeLine{00104            \textcolor{stringliteral}{"{}  -\/V, -\/-\/version             Show program version\(\backslash\)n"{}}}
\DoxyCodeLine{00105            \textcolor{stringliteral}{"{}  -\/?, -\/-\/help                Show this help message\(\backslash\)n"{}}}
\DoxyCodeLine{00106            \textcolor{stringliteral}{"{}  -\/s, -\/-\/statistics          Show performance statistics\(\backslash\)n"{}}}
\DoxyCodeLine{00107            \textcolor{stringliteral}{"{}  -\/f, -\/-\/force               Force overwriting existing files\(\backslash\)n"{}}}
\DoxyCodeLine{00108            \textcolor{stringliteral}{"{}Signature generation options:\(\backslash\)n"{}}}
\DoxyCodeLine{00109            \textcolor{stringliteral}{"{}  -\/H, -\/-\/hash=ALG            Hash algorithm: blake2 (default), md4\(\backslash\)n"{}}}
\DoxyCodeLine{00110            \textcolor{stringliteral}{"{}  -\/R, -\/-\/rollsum=ALG         Rollsum algorithm: rabinkarp (default), rollsum\(\backslash\)n"{}}}
\DoxyCodeLine{00111            \textcolor{stringliteral}{"{}Delta-\/encoding options:\(\backslash\)n"{}}}
\DoxyCodeLine{00112            \textcolor{stringliteral}{"{}  -\/b, -\/-\/block-\/size=BYTES    Signature block size, 0 (default) for recommended\(\backslash\)n"{}}}
\DoxyCodeLine{00113            \textcolor{stringliteral}{"{}  -\/S, -\/-\/sum-\/size=BYTES      Signature strength, 0 (default) for max, -\/1 for min\(\backslash\)n"{}}}
\DoxyCodeLine{00114            \textcolor{stringliteral}{"{}IO options:\(\backslash\)n"{}} \textcolor{stringliteral}{"{}  -\/I, -\/-\/input-\/size=BYTES    Input buffer size\(\backslash\)n"{}}}
\DoxyCodeLine{00115            \textcolor{stringliteral}{"{}  -\/O, -\/-\/output-\/size=BYTES   Output buffer size\(\backslash\)n"{}}}
\DoxyCodeLine{00116            \textcolor{stringliteral}{"{}  -\/z, -\/-\/gzip[=LEVEL]        gzip-\/compress deltas\(\backslash\)n"{}}}
\DoxyCodeLine{00117            \textcolor{stringliteral}{"{}  -\/i, -\/-\/bzip2[=LEVEL]       bzip2-\/compress deltas\(\backslash\)n"{}});}
\DoxyCodeLine{00118 \}}
\DoxyCodeLine{00119 }
\DoxyCodeLine{00120 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rdiff\_show\_version(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00121 \{}
\DoxyCodeLine{00122     \textcolor{keywordtype}{char} \textcolor{keyword}{const} *bzlib = \textcolor{stringliteral}{"{}"{}}, *zlib = \textcolor{stringliteral}{"{}"{}}, *trace = \textcolor{stringliteral}{"{}"{}};}
\DoxyCodeLine{00123 }
\DoxyCodeLine{00124 \textcolor{preprocessor}{\#if 0}}
\DoxyCodeLine{00125     \textcolor{comment}{/* Compression isn't implemented so don't mention it. */}}
\DoxyCodeLine{00126 \textcolor{preprocessor}{\#  ifdef HAVE\_LIBZ}}
\DoxyCodeLine{00127     zlib = \textcolor{stringliteral}{"{}, gzip"{}};}
\DoxyCodeLine{00128 \textcolor{preprocessor}{\#  endif}}
\DoxyCodeLine{00129 }
\DoxyCodeLine{00130 \textcolor{preprocessor}{\#  ifdef HAVE\_LIBBZ2}}
\DoxyCodeLine{00131     bzlib = \textcolor{stringliteral}{"{}, bzip2"{}};}
\DoxyCodeLine{00132 \textcolor{preprocessor}{\#  endif}}
\DoxyCodeLine{00133 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00134 }
\DoxyCodeLine{00135 \textcolor{preprocessor}{\#ifndef DO\_RS\_TRACE}}
\DoxyCodeLine{00136     trace = \textcolor{stringliteral}{"{}, trace disabled"{}};}
\DoxyCodeLine{00137 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00138 }
\DoxyCodeLine{00139     printf(\textcolor{stringliteral}{"{}rdiff (\%s)\(\backslash\)n"{}}}
\DoxyCodeLine{00140            \textcolor{stringliteral}{"{}Copyright (C) 1997-\/2016 by Martin Pool, Andrew Tridgell and others.\(\backslash\)n"{}}}
\DoxyCodeLine{00141            \textcolor{stringliteral}{"{}http://librsync.sourcefrog.net/\(\backslash\)n"{}}}
\DoxyCodeLine{00142            \textcolor{stringliteral}{"{}Capabilities: \%ld bit files\%s\%s\%s\(\backslash\)n"{}} \textcolor{stringliteral}{"{}\(\backslash\)n"{}}}
\DoxyCodeLine{00143            \textcolor{stringliteral}{"{}librsync comes with NO WARRANTY, to the extent permitted by law.\(\backslash\)n"{}}}
\DoxyCodeLine{00144            \textcolor{stringliteral}{"{}You may redistribute copies of librsync under the terms of the GNU\(\backslash\)n"{}}}
\DoxyCodeLine{00145            \textcolor{stringliteral}{"{}Lesser General Public License.  For more information about these\(\backslash\)n"{}}}
\DoxyCodeLine{00146            \textcolor{stringliteral}{"{}matters, see the files named COPYING.\(\backslash\)n"{}}, rs\_librsync\_version,}
\DoxyCodeLine{00147            (\textcolor{keywordtype}{long})(8 * \textcolor{keyword}{sizeof}(rs\_long\_t)), zlib, bzlib, trace);}
\DoxyCodeLine{00148 \}}
\DoxyCodeLine{00149 }
\DoxyCodeLine{00150 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rdiff\_options(poptContext opcon)}
\DoxyCodeLine{00151 \{}
\DoxyCodeLine{00152     \textcolor{keywordtype}{int} c;}
\DoxyCodeLine{00153     \textcolor{keywordtype}{char} \textcolor{keyword}{const} *a;}
\DoxyCodeLine{00154 }
\DoxyCodeLine{00155     \textcolor{keywordflow}{while} ((c = poptGetNextOpt(opcon)) != -\/1) \{}
\DoxyCodeLine{00156         \textcolor{keywordflow}{switch} (c) \{}
\DoxyCodeLine{00157         \textcolor{keywordflow}{case} \textcolor{charliteral}{'h'}:}
\DoxyCodeLine{00158             help();}
\DoxyCodeLine{00159             exit(RS\_DONE);}
\DoxyCodeLine{00160         \textcolor{keywordflow}{case} \textcolor{charliteral}{'V'}:}
\DoxyCodeLine{00161             rdiff\_show\_version();}
\DoxyCodeLine{00162             exit(RS\_DONE);}
\DoxyCodeLine{00163         \textcolor{keywordflow}{case} \textcolor{charliteral}{'v'}:}
\DoxyCodeLine{00164             \textcolor{keywordflow}{if} (!rs\_supports\_trace()) \{}
\DoxyCodeLine{00165                 fprintf(stderr, \textcolor{stringliteral}{"{}rdiff: Library does not support trace.\(\backslash\)n"{}});}
\DoxyCodeLine{00166             \}}
\DoxyCodeLine{00167             rs\_trace\_set\_level(RS\_LOG\_DEBUG);}
\DoxyCodeLine{00168             \textcolor{keywordflow}{break};}
\DoxyCodeLine{00169 }
\DoxyCodeLine{00170         \textcolor{keywordflow}{case} OPT\_GZIP:}
\DoxyCodeLine{00171         \textcolor{keywordflow}{case} OPT\_BZIP2:}
\DoxyCodeLine{00172             \textcolor{keywordflow}{if} ((a = poptGetOptArg(opcon))) \{}
\DoxyCodeLine{00173                 \textcolor{keywordtype}{int} l = atoi(a);}
\DoxyCodeLine{00174                 \textcolor{keywordflow}{if} (c == OPT\_GZIP)}
\DoxyCodeLine{00175                     gzip\_level = l;}
\DoxyCodeLine{00176                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{00177                     bzip2\_level = l;}
\DoxyCodeLine{00178             \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{00179                 \textcolor{keywordflow}{if} (c == OPT\_GZIP)}
\DoxyCodeLine{00180                     gzip\_level = -\/1;    \textcolor{comment}{/* library default */}}
\DoxyCodeLine{00181                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{00182                     bzip2\_level = 9;    \textcolor{comment}{/* demand the best */}}
\DoxyCodeLine{00183             \}}
\DoxyCodeLine{00184             rdiff\_usage(\textcolor{stringliteral}{"{}Sorry, compression is not implemented yet."{}});}
\DoxyCodeLine{00185             exit(RS\_UNIMPLEMENTED);}
\DoxyCodeLine{00186 }
\DoxyCodeLine{00187         \textcolor{keywordflow}{default}:}
\DoxyCodeLine{00188             bad\_option(opcon, c);}
\DoxyCodeLine{00189         \}}
\DoxyCodeLine{00190     \}}
\DoxyCodeLine{00191 \}}
\DoxyCodeLine{00192 \textcolor{comment}{}}
\DoxyCodeLine{00193 \textcolor{comment}{/** Generate signature from remaining command line arguments. */}}
\DoxyCodeLine{00194 \textcolor{keyword}{static} rs\_result rdiff\_sig(poptContext opcon)}
\DoxyCodeLine{00195 \{}
\DoxyCodeLine{00196     FILE *basis\_file, *sig\_file;}
\DoxyCodeLine{00197     rs\_stats\_t stats;}
\DoxyCodeLine{00198     rs\_result result;}
\DoxyCodeLine{00199     rs\_magic\_number sig\_magic;}
\DoxyCodeLine{00200 }
\DoxyCodeLine{00201     basis\_file = rs\_file\_open(poptGetArg(opcon), \textcolor{stringliteral}{"{}rb"{}}, file\_force);}
\DoxyCodeLine{00202     sig\_file = rs\_file\_open(poptGetArg(opcon), \textcolor{stringliteral}{"{}wb"{}}, file\_force);}
\DoxyCodeLine{00203 }
\DoxyCodeLine{00204     rdiff\_no\_more\_args(opcon);}
\DoxyCodeLine{00205 }
\DoxyCodeLine{00206     \textcolor{keywordflow}{if} (!rs\_hash\_name || !strcmp(rs\_hash\_name, \textcolor{stringliteral}{"{}blake2"{}})) \{}
\DoxyCodeLine{00207         sig\_magic = RS\_BLAKE2\_SIG\_MAGIC;}
\DoxyCodeLine{00208     \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strcmp(rs\_hash\_name, \textcolor{stringliteral}{"{}md4"{}})) \{}
\DoxyCodeLine{00209         sig\_magic = RS\_MD4\_SIG\_MAGIC;}
\DoxyCodeLine{00210     \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{00211         rdiff\_usage(\textcolor{stringliteral}{"{}Unknown hash algorithm '\%s'."{}}, rs\_hash\_name);}
\DoxyCodeLine{00212         exit(RS\_SYNTAX\_ERROR);}
\DoxyCodeLine{00213     \}}
\DoxyCodeLine{00214     \textcolor{keywordflow}{if} (!rs\_rollsum\_name || !strcmp(rs\_rollsum\_name, \textcolor{stringliteral}{"{}rabinkarp"{}})) \{}
\DoxyCodeLine{00215         \textcolor{comment}{/* The RabinKarp magics are 0x10 greater than the rollsum magics. */}}
\DoxyCodeLine{00216         sig\_magic += 0x10;}
\DoxyCodeLine{00217     \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (strcmp(rs\_rollsum\_name, \textcolor{stringliteral}{"{}rollsum"{}})) \{}
\DoxyCodeLine{00218         rdiff\_usage(\textcolor{stringliteral}{"{}Unknown rollsum algorithm '\%s'."{}}, rs\_rollsum\_name);}
\DoxyCodeLine{00219         exit(RS\_SYNTAX\_ERROR);}
\DoxyCodeLine{00220     \}}
\DoxyCodeLine{00221 }
\DoxyCodeLine{00222     result =}
\DoxyCodeLine{00223         rs\_sig\_file(basis\_file, sig\_file, block\_len, strong\_len, sig\_magic,}
\DoxyCodeLine{00224                     \&stats);}
\DoxyCodeLine{00225 }
\DoxyCodeLine{00226     rs\_file\_close(sig\_file);}
\DoxyCodeLine{00227     rs\_file\_close(basis\_file);}
\DoxyCodeLine{00228     \textcolor{keywordflow}{if} (result != RS\_DONE)}
\DoxyCodeLine{00229         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00230 }
\DoxyCodeLine{00231     \textcolor{keywordflow}{if} (show\_stats)}
\DoxyCodeLine{00232         rs\_log\_stats(\&stats);}
\DoxyCodeLine{00233 }
\DoxyCodeLine{00234     \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00235 \}}
\DoxyCodeLine{00236 }
\DoxyCodeLine{00237 \textcolor{keyword}{static} rs\_result rdiff\_delta(poptContext opcon)}
\DoxyCodeLine{00238 \{}
\DoxyCodeLine{00239     FILE *sig\_file, *new\_file, *delta\_file;}
\DoxyCodeLine{00240     \textcolor{keywordtype}{char} \textcolor{keyword}{const} *sig\_name;}
\DoxyCodeLine{00241     rs\_result result;}
\DoxyCodeLine{00242     rs\_signature\_t *sumset;}
\DoxyCodeLine{00243     rs\_stats\_t stats;}
\DoxyCodeLine{00244 }
\DoxyCodeLine{00245     \textcolor{keywordflow}{if} (!(sig\_name = poptGetArg(opcon))) \{}
\DoxyCodeLine{00246         rdiff\_usage(\textcolor{stringliteral}{"{}Usage for delta: "{}}}
\DoxyCodeLine{00247                     \textcolor{stringliteral}{"{}rdiff [OPTIONS] delta SIGNATURE [NEWFILE [DELTA]]"{}});}
\DoxyCodeLine{00248         exit(RS\_SYNTAX\_ERROR);}
\DoxyCodeLine{00249     \}}
\DoxyCodeLine{00250 }
\DoxyCodeLine{00251     sig\_file = rs\_file\_open(sig\_name, \textcolor{stringliteral}{"{}rb"{}}, file\_force);}
\DoxyCodeLine{00252     new\_file = rs\_file\_open(poptGetArg(opcon), \textcolor{stringliteral}{"{}rb"{}}, file\_force);}
\DoxyCodeLine{00253     delta\_file = rs\_file\_open(poptGetArg(opcon), \textcolor{stringliteral}{"{}wb"{}}, file\_force);}
\DoxyCodeLine{00254 }
\DoxyCodeLine{00255     rdiff\_no\_more\_args(opcon);}
\DoxyCodeLine{00256 }
\DoxyCodeLine{00257     result = rs\_loadsig\_file(sig\_file, \&sumset, \&stats);}
\DoxyCodeLine{00258     \textcolor{keywordflow}{if} (result != RS\_DONE)}
\DoxyCodeLine{00259         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00260 }
\DoxyCodeLine{00261     \textcolor{keywordflow}{if} (show\_stats)}
\DoxyCodeLine{00262         rs\_log\_stats(\&stats);}
\DoxyCodeLine{00263 }
\DoxyCodeLine{00264     \textcolor{keywordflow}{if} ((result = rs\_build\_hash\_table(sumset)) != RS\_DONE)}
\DoxyCodeLine{00265         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00266 }
\DoxyCodeLine{00267     result = rs\_delta\_file(sumset, new\_file, delta\_file, \&stats);}
\DoxyCodeLine{00268 }
\DoxyCodeLine{00269     rs\_file\_close(delta\_file);}
\DoxyCodeLine{00270     rs\_file\_close(new\_file);}
\DoxyCodeLine{00271     rs\_file\_close(sig\_file);}
\DoxyCodeLine{00272 }
\DoxyCodeLine{00273     \textcolor{keywordflow}{if} (show\_stats) \{}
\DoxyCodeLine{00274         rs\_signature\_log\_stats(sumset);}
\DoxyCodeLine{00275         rs\_log\_stats(\&stats);}
\DoxyCodeLine{00276     \}}
\DoxyCodeLine{00277 }
\DoxyCodeLine{00278     rs\_free\_sumset(sumset);}
\DoxyCodeLine{00279 }
\DoxyCodeLine{00280     \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00281 \}}
\DoxyCodeLine{00282 }
\DoxyCodeLine{00283 \textcolor{keyword}{static} rs\_result rdiff\_patch(poptContext opcon)}
\DoxyCodeLine{00284 \{}
\DoxyCodeLine{00285     \textcolor{comment}{/* patch BASIS [DELTA [NEWFILE]] */}}
\DoxyCodeLine{00286     FILE *basis\_file, *delta\_file, *new\_file;}
\DoxyCodeLine{00287     \textcolor{keywordtype}{char} \textcolor{keyword}{const} *basis\_name;}
\DoxyCodeLine{00288     rs\_stats\_t stats;}
\DoxyCodeLine{00289     rs\_result result;}
\DoxyCodeLine{00290 }
\DoxyCodeLine{00291     \textcolor{keywordflow}{if} (!(basis\_name = poptGetArg(opcon))) \{}
\DoxyCodeLine{00292         rdiff\_usage(\textcolor{stringliteral}{"{}Usage for patch: "{}}}
\DoxyCodeLine{00293                     \textcolor{stringliteral}{"{}rdiff [OPTIONS] patch BASIS [DELTA [NEW]]"{}});}
\DoxyCodeLine{00294         exit(RS\_SYNTAX\_ERROR);}
\DoxyCodeLine{00295     \}}
\DoxyCodeLine{00296 }
\DoxyCodeLine{00297     basis\_file = rs\_file\_open(basis\_name, \textcolor{stringliteral}{"{}rb"{}}, file\_force);}
\DoxyCodeLine{00298     delta\_file = rs\_file\_open(poptGetArg(opcon), \textcolor{stringliteral}{"{}rb"{}}, file\_force);}
\DoxyCodeLine{00299     new\_file = rs\_file\_open(poptGetArg(opcon), \textcolor{stringliteral}{"{}wb"{}}, file\_force);}
\DoxyCodeLine{00300 }
\DoxyCodeLine{00301     rdiff\_no\_more\_args(opcon);}
\DoxyCodeLine{00302 }
\DoxyCodeLine{00303     result = rs\_patch\_file(basis\_file, delta\_file, new\_file, \&stats);}
\DoxyCodeLine{00304 }
\DoxyCodeLine{00305     rs\_file\_close(new\_file);}
\DoxyCodeLine{00306     rs\_file\_close(delta\_file);}
\DoxyCodeLine{00307     rs\_file\_close(basis\_file);}
\DoxyCodeLine{00308 }
\DoxyCodeLine{00309     \textcolor{keywordflow}{if} (show\_stats)}
\DoxyCodeLine{00310         rs\_log\_stats(\&stats);}
\DoxyCodeLine{00311 }
\DoxyCodeLine{00312     \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00313 \}}
\DoxyCodeLine{00314 }
\DoxyCodeLine{00315 \textcolor{keyword}{static} rs\_result rdiff\_action(poptContext opcon)}
\DoxyCodeLine{00316 \{}
\DoxyCodeLine{00317     \textcolor{keyword}{const} \textcolor{keywordtype}{char} *action;}
\DoxyCodeLine{00318 }
\DoxyCodeLine{00319     action = poptGetArg(opcon);}
\DoxyCodeLine{00320     \textcolor{keywordflow}{if} (!action) ;}
\DoxyCodeLine{00321     \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (isprefix(action, \textcolor{stringliteral}{"{}signature"{}}))}
\DoxyCodeLine{00322         \textcolor{keywordflow}{return} rdiff\_sig(opcon);}
\DoxyCodeLine{00323     \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (isprefix(action, \textcolor{stringliteral}{"{}delta"{}}))}
\DoxyCodeLine{00324         \textcolor{keywordflow}{return} rdiff\_delta(opcon);}
\DoxyCodeLine{00325     \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (isprefix(action, \textcolor{stringliteral}{"{}patch"{}}))}
\DoxyCodeLine{00326         \textcolor{keywordflow}{return} rdiff\_patch(opcon);}
\DoxyCodeLine{00327 }
\DoxyCodeLine{00328     rdiff\_usage}
\DoxyCodeLine{00329         (\textcolor{stringliteral}{"{}You must specify an action: `signature', `delta', or `patch'."{}});}
\DoxyCodeLine{00330     exit(RS\_SYNTAX\_ERROR);}
\DoxyCodeLine{00331 \}}
\DoxyCodeLine{00332 }
\DoxyCodeLine{00333 \textcolor{keywordtype}{int} main(\textcolor{keyword}{const} \textcolor{keywordtype}{int} argc, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *argv[])}
\DoxyCodeLine{00334 \{}
\DoxyCodeLine{00335     \textcolor{comment}{/* Initialize opts at runtime to avoid unknown address values. */}}
\DoxyCodeLine{00336     \textcolor{keyword}{const} \textcolor{keyword}{struct }poptOption opts[] = \{}
\DoxyCodeLine{00337         \{\textcolor{stringliteral}{"{}verbose"{}}, \textcolor{charliteral}{'v'}, POPT\_ARG\_NONE, 0, \textcolor{charliteral}{'v'}\},}
\DoxyCodeLine{00338         \{\textcolor{stringliteral}{"{}version"{}}, \textcolor{charliteral}{'V'}, POPT\_ARG\_NONE, 0, \textcolor{charliteral}{'V'}\},}
\DoxyCodeLine{00339         \{\textcolor{stringliteral}{"{}input-\/size"{}}, \textcolor{charliteral}{'I'}, POPT\_ARG\_INT, \&rs\_inbuflen\},}
\DoxyCodeLine{00340         \{\textcolor{stringliteral}{"{}output-\/size"{}}, \textcolor{charliteral}{'O'}, POPT\_ARG\_INT, \&rs\_outbuflen\},}
\DoxyCodeLine{00341         \{\textcolor{stringliteral}{"{}hash"{}}, \textcolor{charliteral}{'H'}, POPT\_ARG\_STRING, \&rs\_hash\_name\},}
\DoxyCodeLine{00342         \{\textcolor{stringliteral}{"{}rollsum"{}}, \textcolor{charliteral}{'R'}, POPT\_ARG\_STRING, \&rs\_rollsum\_name\},}
\DoxyCodeLine{00343         \{\textcolor{stringliteral}{"{}help"{}}, \textcolor{charliteral}{'?'}, POPT\_ARG\_NONE, 0, \textcolor{charliteral}{'h'}\},}
\DoxyCodeLine{00344         \{0, \textcolor{charliteral}{'h'}, POPT\_ARG\_NONE, 0, \textcolor{charliteral}{'h'}\},}
\DoxyCodeLine{00345         \{\textcolor{stringliteral}{"{}block-\/size"{}}, \textcolor{charliteral}{'b'}, POPT\_ARG\_INT, \&block\_len\},}
\DoxyCodeLine{00346         \{\textcolor{stringliteral}{"{}sum-\/size"{}}, \textcolor{charliteral}{'S'}, POPT\_ARG\_INT, \&strong\_len\},}
\DoxyCodeLine{00347         \{\textcolor{stringliteral}{"{}statistics"{}}, \textcolor{charliteral}{'s'}, POPT\_ARG\_NONE, \&show\_stats\},}
\DoxyCodeLine{00348         \{\textcolor{stringliteral}{"{}stats"{}}, 0, POPT\_ARG\_NONE, \&show\_stats\},}
\DoxyCodeLine{00349         \{\textcolor{stringliteral}{"{}gzip"{}}, \textcolor{charliteral}{'z'}, POPT\_ARG\_NONE, 0, OPT\_GZIP\},}
\DoxyCodeLine{00350         \{\textcolor{stringliteral}{"{}bzip2"{}}, \textcolor{charliteral}{'i'}, POPT\_ARG\_NONE, 0, OPT\_BZIP2\},}
\DoxyCodeLine{00351         \{\textcolor{stringliteral}{"{}force"{}}, \textcolor{charliteral}{'f'}, POPT\_ARG\_NONE, \&file\_force\},}
\DoxyCodeLine{00352         \{0\}}
\DoxyCodeLine{00353     \};}
\DoxyCodeLine{00354 }
\DoxyCodeLine{00355     poptContext opcon;}
\DoxyCodeLine{00356     rs\_result result;}
\DoxyCodeLine{00357 }
\DoxyCodeLine{00358     opcon = poptGetContext(\textcolor{stringliteral}{"{}rdiff"{}}, argc, argv, opts, 0);}
\DoxyCodeLine{00359     rdiff\_options(opcon);}
\DoxyCodeLine{00360     result = rdiff\_action(opcon);}
\DoxyCodeLine{00361 }
\DoxyCodeLine{00362     \textcolor{keywordflow}{if} (result != RS\_DONE)}
\DoxyCodeLine{00363         fprintf(stderr, \textcolor{stringliteral}{"{}rdiff: Failed, \%s.\(\backslash\)n"{}}, rs\_strerror(result));}
\DoxyCodeLine{00364 }
\DoxyCodeLine{00365     poptFreeContext(opcon);}
\DoxyCodeLine{00366     \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00367 \}}

\end{DoxyCode}
