\doxysubsection{emit.\+c}
\label{emit_8c_source}\index{emit.c@{emit.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*=                    -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * librsync -\/-\/ dynamic caching and delta update in HTTP}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright (C) 2000, 2001, 2004 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}}
\DoxyCodeLine{00008 \textcolor{comment}{ * modify it under the terms of the GNU Lesser General Public License}}
\DoxyCodeLine{00009 \textcolor{comment}{ * as published by the Free Software Foundation; either version 2.1 of}}
\DoxyCodeLine{00010 \textcolor{comment}{ * the License, or (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, but}}
\DoxyCodeLine{00013 \textcolor{comment}{ * WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00014 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU}}
\DoxyCodeLine{00015 \textcolor{comment}{ * 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}}
\DoxyCodeLine{00018 \textcolor{comment}{ * License 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{preprocessor}{\#include "{}config.h"{}}             \textcolor{comment}{/* IWYU pragma: keep */}}
\DoxyCodeLine{00023 \textcolor{preprocessor}{\#include <assert.h>}}
\DoxyCodeLine{00024 \textcolor{preprocessor}{\#include "{}librsync.h"{}}}
\DoxyCodeLine{00025 \textcolor{preprocessor}{\#include "{}emit.h"{}}}
\DoxyCodeLine{00026 \textcolor{preprocessor}{\#include "{}job.h"{}}}
\DoxyCodeLine{00027 \textcolor{preprocessor}{\#include "{}netint.h"{}}}
\DoxyCodeLine{00028 \textcolor{preprocessor}{\#include "{}prototab.h"{}}}
\DoxyCodeLine{00029 \textcolor{preprocessor}{\#include "{}trace.h"{}}}
\DoxyCodeLine{00030 }
\DoxyCodeLine{00031 \textcolor{keywordtype}{void} rs\_emit\_delta\_header(rs\_job\_t *job)}
\DoxyCodeLine{00032 \{}
\DoxyCodeLine{00033     rs\_trace(\textcolor{stringliteral}{"{}emit DELTA magic"{}});}
\DoxyCodeLine{00034     rs\_squirt\_n4(job, RS\_DELTA\_MAGIC);}
\DoxyCodeLine{00035 \}}
\DoxyCodeLine{00036 }
\DoxyCodeLine{00037 \textcolor{keywordtype}{void} rs\_emit\_literal\_cmd(rs\_job\_t *job, \textcolor{keywordtype}{int} len)}
\DoxyCodeLine{00038 \{}
\DoxyCodeLine{00039     \textcolor{keywordtype}{int} cmd;}
\DoxyCodeLine{00040     \textcolor{keywordtype}{int} param\_len = len <= 64 ? 0 : rs\_int\_len(len);}
\DoxyCodeLine{00041 }
\DoxyCodeLine{00042     \textcolor{keywordflow}{if} (param\_len == 0) \{}
\DoxyCodeLine{00043         cmd = len;}
\DoxyCodeLine{00044         rs\_trace(\textcolor{stringliteral}{"{}emit LITERAL\_\%d, cmd\_byte=\%\#04x"{}}, len, cmd);}
\DoxyCodeLine{00045     \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (param\_len == 1) \{}
\DoxyCodeLine{00046         cmd = RS\_OP\_LITERAL\_N1;}
\DoxyCodeLine{00047         rs\_trace(\textcolor{stringliteral}{"{}emit LITERAL\_N1(len=\%d), cmd\_byte=\%\#04x"{}}, len, cmd);}
\DoxyCodeLine{00048     \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (param\_len == 2) \{}
\DoxyCodeLine{00049         cmd = RS\_OP\_LITERAL\_N2;}
\DoxyCodeLine{00050         rs\_trace(\textcolor{stringliteral}{"{}emit LITERAL\_N2(len=\%d), cmd\_byte=\%\#04x"{}}, len, cmd);}
\DoxyCodeLine{00051     \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{00052         assert(param\_len == 4);}
\DoxyCodeLine{00053         cmd = RS\_OP\_LITERAL\_N4;}
\DoxyCodeLine{00054         rs\_trace(\textcolor{stringliteral}{"{}emit LITERAL\_N4(len=\%d), cmd\_byte=\%\#04x"{}}, len, cmd);}
\DoxyCodeLine{00055     \}}
\DoxyCodeLine{00056 }
\DoxyCodeLine{00057     rs\_squirt\_byte(job, (rs\_byte\_t)cmd);}
\DoxyCodeLine{00058     \textcolor{keywordflow}{if} (param\_len)}
\DoxyCodeLine{00059         rs\_squirt\_netint(job, len, param\_len);}
\DoxyCodeLine{00060 }
\DoxyCodeLine{00061     job-\/>stats.lit\_cmds++;}
\DoxyCodeLine{00062     job-\/>stats.lit\_bytes += len;}
\DoxyCodeLine{00063     job-\/>stats.lit\_cmdbytes += 1 + param\_len;}
\DoxyCodeLine{00064 \}}
\DoxyCodeLine{00065 }
\DoxyCodeLine{00066 \textcolor{keywordtype}{void} rs\_emit\_copy\_cmd(rs\_job\_t *job, rs\_long\_t where, rs\_long\_t len)}
\DoxyCodeLine{00067 \{}
\DoxyCodeLine{00068     \textcolor{keywordtype}{int} cmd;}
\DoxyCodeLine{00069     rs\_stats\_t *stats = \&job-\/>stats;}
\DoxyCodeLine{00070     \textcolor{keyword}{const} \textcolor{keywordtype}{int} where\_bytes = rs\_int\_len(where);}
\DoxyCodeLine{00071     \textcolor{keyword}{const} \textcolor{keywordtype}{int} len\_bytes = rs\_int\_len(len);}
\DoxyCodeLine{00072 }
\DoxyCodeLine{00073     \textcolor{comment}{/* Commands ascend (1,1), (1,2), ... (8, 8) */}}
\DoxyCodeLine{00074     \textcolor{keywordflow}{if} (where\_bytes == 8)}
\DoxyCodeLine{00075         cmd = RS\_OP\_COPY\_N8\_N1;}
\DoxyCodeLine{00076     \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (where\_bytes == 4)}
\DoxyCodeLine{00077         cmd = RS\_OP\_COPY\_N4\_N1;}
\DoxyCodeLine{00078     \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (where\_bytes == 2)}
\DoxyCodeLine{00079         cmd = RS\_OP\_COPY\_N2\_N1;}
\DoxyCodeLine{00080     \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{00081         assert(where\_bytes == 1);}
\DoxyCodeLine{00082         cmd = RS\_OP\_COPY\_N1\_N1;}
\DoxyCodeLine{00083     \}}
\DoxyCodeLine{00084     \textcolor{keywordflow}{if} (len\_bytes == 1) ;}
\DoxyCodeLine{00085     \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (len\_bytes == 2)}
\DoxyCodeLine{00086         cmd += 1;}
\DoxyCodeLine{00087     \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (len\_bytes == 4)}
\DoxyCodeLine{00088         cmd += 2;}
\DoxyCodeLine{00089     \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{00090         assert(len\_bytes == 8);}
\DoxyCodeLine{00091         cmd += 3;}
\DoxyCodeLine{00092     \}}
\DoxyCodeLine{00093 }
\DoxyCodeLine{00094     rs\_trace(\textcolor{stringliteral}{"{}emit COPY\_N\%d\_N\%d(where="{}} FMT\_LONG \textcolor{stringliteral}{"{}, len="{}} FMT\_LONG}
\DoxyCodeLine{00095              \textcolor{stringliteral}{"{}), cmd\_byte=\%\#04x"{}}, where\_bytes, len\_bytes, where, len, cmd);}
\DoxyCodeLine{00096     rs\_squirt\_byte(job, (rs\_byte\_t)cmd);}
\DoxyCodeLine{00097     rs\_squirt\_netint(job, where, where\_bytes);}
\DoxyCodeLine{00098     rs\_squirt\_netint(job, len, len\_bytes);}
\DoxyCodeLine{00099 }
\DoxyCodeLine{00100     stats-\/>copy\_cmds++;}
\DoxyCodeLine{00101     stats-\/>copy\_bytes += len;}
\DoxyCodeLine{00102     stats-\/>copy\_cmdbytes += 1 + where\_bytes + len\_bytes;}
\DoxyCodeLine{00103 \}}
\DoxyCodeLine{00104 }
\DoxyCodeLine{00105 \textcolor{keywordtype}{void} rs\_emit\_end\_cmd(rs\_job\_t *job)}
\DoxyCodeLine{00106 \{}
\DoxyCodeLine{00107     \textcolor{keywordtype}{int} cmd = RS\_OP\_END;}
\DoxyCodeLine{00108 }
\DoxyCodeLine{00109     rs\_trace(\textcolor{stringliteral}{"{}emit END, cmd\_byte=\%\#04x"{}}, cmd);}
\DoxyCodeLine{00110     rs\_squirt\_byte(job, (rs\_byte\_t)cmd);}
\DoxyCodeLine{00111 \}}

\end{DoxyCode}
