\doxysection{pio.\+c}
\label{pio_8c_source}\index{src/libsphinxbase/util/pio.c@{src/libsphinxbase/util/pio.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ -\/*-\/\ c-\/basic-\/offset:\ 4;\ indent-\/tabs-\/mode:\ nil\ -\/*-\/\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1999-\/2004\ Carnegie\ Mellon\ University.\ \ All\ rights}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00027\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00028\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00029\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00030\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00031\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00032\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00033\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00034\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00035\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00036\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00037\ }
\DoxyCodeLine{00038\ \textcolor{preprocessor}{\#include\ <config.h>}}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00040\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00041\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00042\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00043\ \textcolor{preprocessor}{\#ifdef\ HAVE\_UNISTD\_H}}
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#include\ <unistd.h>}}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00046\ \textcolor{preprocessor}{\#ifdef\ HAVE\_SYS\_STAT\_H}}
\DoxyCodeLine{00047\ \textcolor{preprocessor}{\#include\ <sys/stat.h>}}
\DoxyCodeLine{00048\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00049\ \textcolor{preprocessor}{\#ifdef\ HAVE\_SYS\_TYPES\_H}}
\DoxyCodeLine{00050\ \textcolor{preprocessor}{\#include\ <sys/types.h>}}
\DoxyCodeLine{00051\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00052\ \textcolor{preprocessor}{\#include\ <assert.h>}}
\DoxyCodeLine{00053\ }
\DoxyCodeLine{00054\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/pio.h"{}}}
\DoxyCodeLine{00055\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/filename.h"{}}}
\DoxyCodeLine{00056\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/err.h"{}}}
\DoxyCodeLine{00057\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/strfuncs.h"{}}}
\DoxyCodeLine{00058\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ckd\_alloc.h"{}}}
\DoxyCodeLine{00059\ }
\DoxyCodeLine{00060\ \textcolor{preprocessor}{\#ifndef\ EXEEXT}}
\DoxyCodeLine{00061\ \textcolor{preprocessor}{\#define\ EXEEXT\ "{}"{}}}
\DoxyCodeLine{00062\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00064\ \textcolor{keyword}{enum}\ \{}
\DoxyCodeLine{00065\ \ \ \ \ COMP\_NONE,}
\DoxyCodeLine{00066\ \ \ \ \ COMP\_COMPRESS,}
\DoxyCodeLine{00067\ \ \ \ \ COMP\_GZIP,}
\DoxyCodeLine{00068\ \ \ \ \ COMP\_BZIP2}
\DoxyCodeLine{00069\ \};}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00071\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00072\ guess\_comptype(\textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *file,\ int32\ *ispipe,\ int32\ *isgz)}
\DoxyCodeLine{00073\ \{}
\DoxyCodeLine{00074\ \ \ \ \ \textcolor{keywordtype}{int}\ k;}
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00076\ \ \ \ \ k\ =\ strlen(file);}
\DoxyCodeLine{00077\ \ \ \ \ *ispipe\ =\ 0;}
\DoxyCodeLine{00078\ \ \ \ \ *isgz\ =\ COMP\_NONE;}
\DoxyCodeLine{00079\ \ \ \ \ \textcolor{keywordflow}{if}\ ((k\ >\ 2)}
\DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ \&\&\ ((strcmp(file\ +\ k\ -\/\ 2,\ \textcolor{stringliteral}{"{}.Z"{}})\ ==\ 0)}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ \ \ \ \ ||\ (strcmp(file\ +\ k\ -\/\ 2,\ \textcolor{stringliteral}{"{}.z"{}})\ ==\ 0)))\ \{}
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ *ispipe\ =\ 1;}
\DoxyCodeLine{00083\ \ \ \ \ \ \ \ \ *isgz\ =\ COMP\_COMPRESS;}
\DoxyCodeLine{00084\ \ \ \ \ \}}
\DoxyCodeLine{00085\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ ((k\ >\ 3)\ \&\&\ ((strcmp(file\ +\ k\ -\/\ 3,\ \textcolor{stringliteral}{"{}.gz"{}})\ ==\ 0)}
\DoxyCodeLine{00086\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ||\ (strcmp(file\ +\ k\ -\/\ 3,\ \textcolor{stringliteral}{"{}.GZ"{}})\ ==\ 0)))\ \{}
\DoxyCodeLine{00087\ \ \ \ \ \ \ \ \ *ispipe\ =\ 1;}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ *isgz\ =\ COMP\_GZIP;}
\DoxyCodeLine{00089\ \ \ \ \ \}}
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ ((k\ >\ 4)\ \&\&\ ((strcmp(file\ +\ k\ -\/\ 4,\ \textcolor{stringliteral}{"{}.bz2"{}})\ ==\ 0)}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ||\ (strcmp(file\ +\ k\ -\/\ 4,\ \textcolor{stringliteral}{"{}.BZ2"{}})\ ==\ 0)))\ \{}
\DoxyCodeLine{00092\ \ \ \ \ \ \ \ \ *ispipe\ =\ 1;}
\DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ *isgz\ =\ COMP\_BZIP2;}
\DoxyCodeLine{00094\ \ \ \ \ \}}
\DoxyCodeLine{00095\ \}}
\DoxyCodeLine{00096\ }
\DoxyCodeLine{00097\ FILE\ *}
\DoxyCodeLine{00098\ fopen\_comp(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *mode,\ int32\ *\ ispipe)}
\DoxyCodeLine{00099\ \{}
\DoxyCodeLine{00100\ \ \ \ \ FILE\ *fp;}
\DoxyCodeLine{00101\ }
\DoxyCodeLine{00102\ \textcolor{preprocessor}{\#ifndef\ HAVE\_POPEN}}
\DoxyCodeLine{00103\ \ \ \ \ *ispipe\ =\ 0;\ \textcolor{comment}{/*\ No\ popen()\ on\ WinCE\ */}}
\DoxyCodeLine{00104\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{/*\ HAVE\_POPEN\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00105\ \ \ \ \ int32\ isgz;}
\DoxyCodeLine{00106\ \ \ \ \ guess\_comptype(file,\ ispipe,\ \&isgz);}
\DoxyCodeLine{00107\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ HAVE\_POPEN\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00108\ }
\DoxyCodeLine{00109\ \ \ \ \ \textcolor{keywordflow}{if}\ (*ispipe)\ \{}
\DoxyCodeLine{00110\ \textcolor{preprocessor}{\#ifndef\ HAVE\_POPEN}}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Shouldn't\ get\ here,\ anyway\ */}}
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}No\ popen()\ on\ WinCE\(\backslash\)n"{}});}
\DoxyCodeLine{00113\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00114\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (strcmp(mode,\ \textcolor{stringliteral}{"{}r"{}})\ ==\ 0)\ \{}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ *command;}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{switch}\ (isgz)\ \{}
\DoxyCodeLine{00117\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_GZIP:}
\DoxyCodeLine{00118\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command\ =\ string\_join(\textcolor{stringliteral}{"{}gunzip"{}}\ EXEEXT,\ \textcolor{stringliteral}{"{}\ -\/c\ "{}},\ file,\ NULL);}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00120\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_COMPRESS:}
\DoxyCodeLine{00121\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command\ =\ string\_join(\textcolor{stringliteral}{"{}zcat"{}}\ EXEEXT,\ \textcolor{stringliteral}{"{}\ "{}},\ file,\ NULL);}
\DoxyCodeLine{00122\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00123\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_BZIP2:}
\DoxyCodeLine{00124\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command\ =\ string\_join(\textcolor{stringliteral}{"{}bunzip2"{}}\ EXEEXT,\ \textcolor{stringliteral}{"{}\ -\/c\ "{}},\ file,\ NULL);}
\DoxyCodeLine{00125\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{default}:}
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command\ =\ NULL;\ \textcolor{comment}{/*\ Make\ compiler\ happy.\ */}}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}Unknown\ \ compression\ type\ \%d\(\backslash\)n"{}},\ isgz);}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((fp\ =\ popen(command,\ mode))\ ==\ NULL)\ \{}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ a\ pipe\ for\ a\ command\ '\%s'\ mode\ '\%s'"{}},\ command,\ mode);}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(command);}
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(command);}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (strcmp(mode,\ \textcolor{stringliteral}{"{}w"{}})\ ==\ 0)\ \{}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ *command;}
\DoxyCodeLine{00139\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{switch}\ (isgz)\ \{}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_GZIP:}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command\ =\ string\_join(\textcolor{stringliteral}{"{}gzip"{}}\ EXEEXT,\ \textcolor{stringliteral}{"{}\ >\ "{}},\ file,\ NULL);}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_COMPRESS:}
\DoxyCodeLine{00144\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command\ =\ string\_join(\textcolor{stringliteral}{"{}compress"{}}\ EXEEXT,\ \textcolor{stringliteral}{"{}\ -\/c\ >\ "{}},\ file,\ NULL);}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_BZIP2:}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command\ =\ string\_join(\textcolor{stringliteral}{"{}bzip2"{}}\ EXEEXT,\ \textcolor{stringliteral}{"{}\ >\ "{}},\ file,\ NULL);}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{default}:}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command\ =\ NULL;\ \textcolor{comment}{/*\ Make\ compiler\ happy.\ */}}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}Unknown\ compression\ type\ \%d\(\backslash\)n"{}},\ isgz);}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((fp\ =\ popen(command,\ mode))\ ==\ NULL)\ \{}
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ a\ pipe\ for\ a\ command\ '\%s'\ mode\ '\%s'"{}},\ command,\ mode);}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(command);}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00157\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00158\ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(command);}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00161\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Compressed\ file\ operation\ for\ mode\ \%s\ is\ not\ supported"{}},\ mode);}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00163\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00164\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ HAVE\_POPEN\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00165\ \ \ \ \ \}}
\DoxyCodeLine{00166\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ fp\ =\ fopen(file,\ mode);}
\DoxyCodeLine{00168\ \ \ \ \ \}}
\DoxyCodeLine{00169\ }
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{keywordflow}{return}\ (fp);}
\DoxyCodeLine{00171\ \}}
\DoxyCodeLine{00172\ }
\DoxyCodeLine{00173\ }
\DoxyCodeLine{00174\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00175\ fclose\_comp(FILE\ *\ fp,\ int32\ ispipe)}
\DoxyCodeLine{00176\ \{}
\DoxyCodeLine{00177\ \ \ \ \ \textcolor{keywordflow}{if}\ (ispipe)\ \{}
\DoxyCodeLine{00178\ \textcolor{preprocessor}{\#ifdef\ HAVE\_POPEN}}
\DoxyCodeLine{00179\ \textcolor{preprocessor}{\#if\ defined(\_WIN32)\ \&\&\ (!defined(\_\_SYMBIAN32\_\_))}}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ \_pclose(fp);}
\DoxyCodeLine{00181\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ pclose(fp);}
\DoxyCodeLine{00183\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00184\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00185\ \ \ \ \ \}}
\DoxyCodeLine{00186\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00187\ \ \ \ \ \ \ \ \ fclose(fp);}
\DoxyCodeLine{00188\ \}}
\DoxyCodeLine{00189\ }
\DoxyCodeLine{00190\ }
\DoxyCodeLine{00191\ FILE\ *}
\DoxyCodeLine{00192\ fopen\_compchk(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file,\ int32\ *\ ispipe)}
\DoxyCodeLine{00193\ \{}
\DoxyCodeLine{00194\ \textcolor{preprocessor}{\#ifndef\ HAVE\_POPEN}}
\DoxyCodeLine{00195\ \ \ \ \ *ispipe\ =\ 0;\ \textcolor{comment}{/*\ No\ popen()\ on\ WinCE\ */}}
\DoxyCodeLine{00196\ \ \ \ \ \textcolor{comment}{/*\ And\ therefore\ the\ rest\ of\ this\ function\ is\ useless.\ */}}
\DoxyCodeLine{00197\ \ \ \ \ \textcolor{keywordflow}{return}\ (fopen\_comp(file,\ \textcolor{stringliteral}{"{}r"{}},\ ispipe));}
\DoxyCodeLine{00198\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{/*\ HAVE\_POPEN\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00199\ \ \ \ \ int32\ isgz;}
\DoxyCodeLine{00200\ \ \ \ \ FILE\ *fh;}
\DoxyCodeLine{00201\ }
\DoxyCodeLine{00202\ \ \ \ \ \textcolor{comment}{/*\ First\ just\ try\ to\ fopen\_comp()\ it\ */}}
\DoxyCodeLine{00203\ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ fopen\_comp(file,\ \textcolor{stringliteral}{"{}r"{}},\ ispipe))\ !=\ NULL)}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ fh;}
\DoxyCodeLine{00205\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ *tmpfile;}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ k;}
\DoxyCodeLine{00208\ }
\DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ File\ doesn't\ exist;\ try\ other\ compressed/uncompressed\ form,\ as\ appropriate\ */}}
\DoxyCodeLine{00210\ \ \ \ \ \ \ \ \ guess\_comptype(file,\ ispipe,\ \&isgz);}
\DoxyCodeLine{00211\ \ \ \ \ \ \ \ \ k\ =\ strlen(file);}
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ tmpfile\ =\ ckd\_calloc(k+5,\ 1);}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ strcpy(tmpfile,\ file);}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{switch}\ (isgz)\ \{}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_GZIP:}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ \ \ \ \ tmpfile[k\ -\/\ 3]\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{00217\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_BZIP2:}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \ \ \ \ tmpfile[k\ -\/\ 4]\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{00220\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00221\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_COMPRESS:}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \ \ \ \ tmpfile[k\ -\/\ 2]\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00224\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ COMP\_NONE:}
\DoxyCodeLine{00225\ \ \ \ \ \ \ \ \ \ \ \ \ strcpy(tmpfile\ +\ k,\ \textcolor{stringliteral}{"{}.gz"{}});}
\DoxyCodeLine{00226\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ fopen\_comp(tmpfile,\ \textcolor{stringliteral}{"{}r"{}},\ ispipe))\ !=\ NULL)\ \{}
\DoxyCodeLine{00227\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_WARN(\textcolor{stringliteral}{"{}Using\ \%s\ instead\ of\ \%s\(\backslash\)n"{}},\ tmpfile,\ file);}
\DoxyCodeLine{00228\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(tmpfile);}
\DoxyCodeLine{00229\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ fh;}
\DoxyCodeLine{00230\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00231\ \ \ \ \ \ \ \ \ \ \ \ \ strcpy(tmpfile\ +\ k,\ \textcolor{stringliteral}{"{}.bz2"{}});}
\DoxyCodeLine{00232\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ fopen\_comp(tmpfile,\ \textcolor{stringliteral}{"{}r"{}},\ ispipe))\ !=\ NULL)\ \{}
\DoxyCodeLine{00233\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_WARN(\textcolor{stringliteral}{"{}Using\ \%s\ instead\ of\ \%s\(\backslash\)n"{}},\ tmpfile,\ file);}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(tmpfile);}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ fh;}
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ \ \ \ \ strcpy(tmpfile\ +\ k,\ \textcolor{stringliteral}{"{}.Z"{}});}
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ fopen\_comp(tmpfile,\ \textcolor{stringliteral}{"{}r"{}},\ ispipe))\ !=\ NULL)\ \{}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_WARN(\textcolor{stringliteral}{"{}Using\ \%s\ instead\ of\ \%s\(\backslash\)n"{}},\ tmpfile,\ file);}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(tmpfile);}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ fh;}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(tmpfile);}
\DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00245\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ E\_WARN(\textcolor{stringliteral}{"{}Using\ \%s\ instead\ of\ \%s\(\backslash\)n"{}},\ tmpfile,\ file);}
\DoxyCodeLine{00247\ \ \ \ \ \ \ \ \ fh\ =\ fopen\_comp(tmpfile,\ \textcolor{stringliteral}{"{}r"{}},\ ispipe);}
\DoxyCodeLine{00248\ \ \ \ \ \ \ \ \ ckd\_free(tmpfile);}
\DoxyCodeLine{00249\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00250\ \ \ \ \ \}}
\DoxyCodeLine{00251\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ HAVE\_POPEN\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00252\ \}}
\DoxyCodeLine{00253\ }
\DoxyCodeLine{00254\ lineiter\_t\ *}
\DoxyCodeLine{00255\ lineiter\_start(FILE\ *fh)}
\DoxyCodeLine{00256\ \{}
\DoxyCodeLine{00257\ \ \ \ \ lineiter\_t\ *li;}
\DoxyCodeLine{00258\ }
\DoxyCodeLine{00259\ \ \ \ \ li\ =\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(*li));}
\DoxyCodeLine{00260\ \ \ \ \ li-\/>buf\ =\ ckd\_malloc(128);}
\DoxyCodeLine{00261\ \ \ \ \ li-\/>buf[0]\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{00262\ \ \ \ \ li-\/>bsiz\ =\ 128;}
\DoxyCodeLine{00263\ \ \ \ \ li-\/>len\ =\ 0;}
\DoxyCodeLine{00264\ \ \ \ \ li-\/>fh\ =\ fh;}
\DoxyCodeLine{00265\ }
\DoxyCodeLine{00266\ \ \ \ \ li\ =\ lineiter\_next(li);}
\DoxyCodeLine{00267\ \ \ \ \ }
\DoxyCodeLine{00268\ \ \ \ \ \textcolor{comment}{/*\ Strip\ the\ UTF-\/8\ BOM\ */}}
\DoxyCodeLine{00269\ \ \ \ \ }
\DoxyCodeLine{00270\ \ \ \ \ \textcolor{keywordflow}{if}\ (li\ \&\&\ 0\ ==\ strncmp(li-\/>buf,\ \textcolor{stringliteral}{"{}\(\backslash\)xef\(\backslash\)xbb\(\backslash\)xbf"{}},\ 3))\ \{}
\DoxyCodeLine{00271\ \ \ \ \ \ \ \ \ memmove(li-\/>buf,\ li-\/>buf\ +\ 3,\ strlen(li-\/>buf\ +\ 1));}
\DoxyCodeLine{00272\ \ \ \ \ \ \ \ \ li-\/>len\ -\/=\ 3;}
\DoxyCodeLine{00273\ \ \ \ \ \}}
\DoxyCodeLine{00274\ \ \ \ \ }
\DoxyCodeLine{00275\ \ \ \ \ \textcolor{keywordflow}{return}\ li;}
\DoxyCodeLine{00276\ \}}
\DoxyCodeLine{00277\ }
\DoxyCodeLine{00278\ lineiter\_t\ *}
\DoxyCodeLine{00279\ lineiter\_start\_clean(FILE\ *fh)}
\DoxyCodeLine{00280\ \{}
\DoxyCodeLine{00281\ \ \ \ \ lineiter\_t\ *li;}
\DoxyCodeLine{00282\ \ \ \ \ }
\DoxyCodeLine{00283\ \ \ \ \ li\ =\ lineiter\_start(fh);}
\DoxyCodeLine{00284\ \ \ \ \ }
\DoxyCodeLine{00285\ \ \ \ \ \textcolor{keywordflow}{if}\ (li\ ==\ NULL)}
\DoxyCodeLine{00286\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ li;}
\DoxyCodeLine{00287\ \ \ \ \ }
\DoxyCodeLine{00288\ \ \ \ \ li-\/>clean\ =\ TRUE;}
\DoxyCodeLine{00289\ \ \ \ \ }
\DoxyCodeLine{00290\ \ \ \ \ \textcolor{keywordflow}{if}\ (li-\/>buf\ \&\&\ li-\/>buf[0]\ ==\ \textcolor{charliteral}{'\#'})\ \{}
\DoxyCodeLine{00291\ \ \ \ \ \ \ \ \ li\ =\ lineiter\_next(li);}
\DoxyCodeLine{00292\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00293\ \ \ \ \ \ \ \ \ string\_trim(li-\/>buf,\ STRING\_BOTH);}
\DoxyCodeLine{00294\ \ \ \ \ \}}
\DoxyCodeLine{00295\ \ \ \ \ }
\DoxyCodeLine{00296\ \ \ \ \ \textcolor{keywordflow}{return}\ li;}
\DoxyCodeLine{00297\ \}}
\DoxyCodeLine{00298\ }
\DoxyCodeLine{00299\ }
\DoxyCodeLine{00300\ \textcolor{keyword}{static}\ lineiter\_t\ *}
\DoxyCodeLine{00301\ lineiter\_next\_plain(lineiter\_t\ *li)}
\DoxyCodeLine{00302\ \{}
\DoxyCodeLine{00303\ \ \ \ \ \textcolor{comment}{/*\ We\ are\ reading\ the\ next\ line\ */}}
\DoxyCodeLine{00304\ \ \ \ \ li-\/>lineno++;}
\DoxyCodeLine{00305\ \ \ \ \ }
\DoxyCodeLine{00306\ \ \ \ \ \textcolor{comment}{/*\ Read\ a\ line\ and\ check\ for\ EOF.\ */}}
\DoxyCodeLine{00307\ \ \ \ \ \textcolor{keywordflow}{if}\ (fgets(li-\/>buf,\ li-\/>bsiz,\ li-\/>fh)\ ==\ NULL)\ \{}
\DoxyCodeLine{00308\ \ \ \ \ \ \ \ \ lineiter\_free(li);}
\DoxyCodeLine{00309\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00310\ \ \ \ \ \}}
\DoxyCodeLine{00311\ \ \ \ \ \textcolor{comment}{/*\ If\ we\ managed\ to\ read\ the\ whole\ thing,\ then\ we\ are\ done}}
\DoxyCodeLine{00312\ \textcolor{comment}{\ \ \ \ \ *\ (this\ will\ be\ by\ far\ the\ most\ common\ result).\ */}}
\DoxyCodeLine{00313\ \ \ \ \ li-\/>len\ =\ strlen(li-\/>buf);}
\DoxyCodeLine{00314\ \ \ \ \ \textcolor{keywordflow}{if}\ (li-\/>len\ <\ li-\/>bsiz\ -\/\ 1\ ||\ li-\/>buf[li-\/>len\ -\/\ 1]\ ==\ \textcolor{charliteral}{'\(\backslash\)n'})}
\DoxyCodeLine{00315\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ li;}
\DoxyCodeLine{00316\ }
\DoxyCodeLine{00317\ \ \ \ \ \textcolor{comment}{/*\ Otherwise\ we\ have\ to\ reallocate\ and\ keep\ going.\ */}}
\DoxyCodeLine{00318\ \ \ \ \ \textcolor{keywordflow}{while}\ (1)\ \{}
\DoxyCodeLine{00319\ \ \ \ \ \ \ \ \ li-\/>bsiz\ *=\ 2;}
\DoxyCodeLine{00320\ \ \ \ \ \ \ \ \ li-\/>buf\ =\ ckd\_realloc(li-\/>buf,\ li-\/>bsiz);}
\DoxyCodeLine{00321\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ If\ we\ get\ an\ EOF,\ we\ are\ obviously\ done.\ */}}
\DoxyCodeLine{00322\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fgets(li-\/>buf\ +\ li-\/>len,\ li-\/>bsiz\ -\/\ li-\/>len,\ li-\/>fh)\ ==\ NULL)\ \{}
\DoxyCodeLine{00323\ \ \ \ \ \ \ \ \ \ \ \ \ li-\/>len\ +=\ strlen(li-\/>buf\ +\ li-\/>len);}
\DoxyCodeLine{00324\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ li;}
\DoxyCodeLine{00325\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00326\ \ \ \ \ \ \ \ \ li-\/>len\ +=\ strlen(li-\/>buf\ +\ li-\/>len);}
\DoxyCodeLine{00327\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ If\ we\ managed\ to\ read\ the\ whole\ thing,\ then\ we\ are\ done.\ */}}
\DoxyCodeLine{00328\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (li-\/>len\ <\ li-\/>bsiz\ -\/\ 1\ ||\ li-\/>buf[li-\/>len\ -\/\ 1]\ ==\ \textcolor{charliteral}{'\(\backslash\)n'})}
\DoxyCodeLine{00329\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ li;}
\DoxyCodeLine{00330\ \ \ \ \ \}}
\DoxyCodeLine{00331\ }
\DoxyCodeLine{00332\ \ \ \ \ \textcolor{comment}{/*\ Shouldn't\ get\ here.\ */}}
\DoxyCodeLine{00333\ \ \ \ \ \textcolor{keywordflow}{return}\ li;}
\DoxyCodeLine{00334\ \}}
\DoxyCodeLine{00335\ }
\DoxyCodeLine{00336\ }
\DoxyCodeLine{00337\ lineiter\_t\ *}
\DoxyCodeLine{00338\ lineiter\_next(lineiter\_t\ *li)}
\DoxyCodeLine{00339\ \{}
\DoxyCodeLine{00340\ \ \ \ \ \textcolor{keywordflow}{if}\ (!li-\/>clean)}
\DoxyCodeLine{00341\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ lineiter\_next\_plain(li);}
\DoxyCodeLine{00342\ \ \ \ \ }
\DoxyCodeLine{00343\ \ \ \ \ \textcolor{keywordflow}{for}\ (li\ =\ lineiter\_next\_plain(li);\ li;\ li\ =\ lineiter\_next\_plain(li))\ \{}
\DoxyCodeLine{00344\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (li-\/>buf\ \&\&\ li-\/>buf[0]\ !=\ \textcolor{charliteral}{'\#'})\ \{}
\DoxyCodeLine{00345\ \ \ \ \ \ \ \ \ \ \ \ \ li-\/>buf\ =\ string\_trim(li-\/>buf,\ STRING\_BOTH);}
\DoxyCodeLine{00346\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00347\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00348\ \ \ \ \ \}}
\DoxyCodeLine{00349\ \ \ \ \ \textcolor{keywordflow}{return}\ li;}
\DoxyCodeLine{00350\ \}}
\DoxyCodeLine{00351\ }
\DoxyCodeLine{00352\ \textcolor{keywordtype}{int}\ lineiter\_lineno(lineiter\_t\ *li)}
\DoxyCodeLine{00353\ \{}
\DoxyCodeLine{00354\ \ \ \ \ \textcolor{keywordflow}{return}\ li-\/>lineno;}
\DoxyCodeLine{00355\ \}}
\DoxyCodeLine{00356\ }
\DoxyCodeLine{00357\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00358\ lineiter\_free(lineiter\_t\ *li)}
\DoxyCodeLine{00359\ \{}
\DoxyCodeLine{00360\ \ \ \ \ \textcolor{keywordflow}{if}\ (li\ ==\ NULL)}
\DoxyCodeLine{00361\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00362\ \ \ \ \ ckd\_free(li-\/>buf);}
\DoxyCodeLine{00363\ \ \ \ \ ckd\_free(li);}
\DoxyCodeLine{00364\ \}}
\DoxyCodeLine{00365\ }
\DoxyCodeLine{00366\ \textcolor{keywordtype}{char}\ *}
\DoxyCodeLine{00367\ fread\_line(FILE\ *stream,\ \textcolor{keywordtype}{size\_t}\ *out\_len)}
\DoxyCodeLine{00368\ \{}
\DoxyCodeLine{00369\ \ \ \ \ \textcolor{keywordtype}{char}\ *output,\ *outptr;}
\DoxyCodeLine{00370\ \ \ \ \ \textcolor{keywordtype}{char}\ buf[128];}
\DoxyCodeLine{00371\ }
\DoxyCodeLine{00372\ \ \ \ \ output\ =\ outptr\ =\ NULL;}
\DoxyCodeLine{00373\ \ \ \ \ \textcolor{keywordflow}{while}\ (fgets(buf,\ \textcolor{keyword}{sizeof}(buf),\ stream))\ \{}
\DoxyCodeLine{00374\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ len\ =\ strlen(buf);}
\DoxyCodeLine{00375\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Append\ this\ data\ to\ the\ buffer.\ */}}
\DoxyCodeLine{00376\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (output\ ==\ NULL)\ \{}
\DoxyCodeLine{00377\ \ \ \ \ \ \ \ \ \ \ \ \ output\ =\ ckd\_malloc(len\ +\ 1);}
\DoxyCodeLine{00378\ \ \ \ \ \ \ \ \ \ \ \ \ outptr\ =\ output;}
\DoxyCodeLine{00379\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00380\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00381\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ cur\ =\ outptr\ -\/\ output;}
\DoxyCodeLine{00382\ \ \ \ \ \ \ \ \ \ \ \ \ output\ =\ ckd\_realloc(output,\ cur\ +\ len\ +\ 1);}
\DoxyCodeLine{00383\ \ \ \ \ \ \ \ \ \ \ \ \ outptr\ =\ output\ +\ cur;}
\DoxyCodeLine{00384\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00385\ \ \ \ \ \ \ \ \ memcpy(outptr,\ buf,\ len\ +\ 1);}
\DoxyCodeLine{00386\ \ \ \ \ \ \ \ \ outptr\ +=\ len;}
\DoxyCodeLine{00387\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Stop\ on\ a\ short\ read\ or\ end\ of\ line.\ */}}
\DoxyCodeLine{00388\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (len\ <\ \textcolor{keyword}{sizeof}(buf)-\/1\ ||\ buf[len-\/1]\ ==\ \textcolor{charliteral}{'\(\backslash\)n'})}
\DoxyCodeLine{00389\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00390\ \ \ \ \ \}}
\DoxyCodeLine{00391\ \ \ \ \ \textcolor{keywordflow}{if}\ (out\_len)\ *out\_len\ =\ outptr\ -\/\ output;}
\DoxyCodeLine{00392\ \ \ \ \ \textcolor{keywordflow}{return}\ output;}
\DoxyCodeLine{00393\ \}}
\DoxyCodeLine{00394\ }
\DoxyCodeLine{00395\ \textcolor{preprocessor}{\#define\ FREAD\_RETRY\_COUNT\ \ \ \ \ \ \ 60}}
\DoxyCodeLine{00396\ }
\DoxyCodeLine{00397\ int32}
\DoxyCodeLine{00398\ fread\_retry(\textcolor{keywordtype}{void}\ *pointer,\ int32\ size,\ int32\ num\_items,\ FILE\ *\ stream)}
\DoxyCodeLine{00399\ \{}
\DoxyCodeLine{00400\ \ \ \ \ \textcolor{keywordtype}{char}\ *data;}
\DoxyCodeLine{00401\ \ \ \ \ uint32\ n\_items\_read;}
\DoxyCodeLine{00402\ \ \ \ \ uint32\ n\_items\_rem;}
\DoxyCodeLine{00403\ \ \ \ \ uint32\ n\_retry\_rem;}
\DoxyCodeLine{00404\ \ \ \ \ int32\ loc;}
\DoxyCodeLine{00405\ }
\DoxyCodeLine{00406\ \ \ \ \ n\_retry\_rem\ =\ FREAD\_RETRY\_COUNT;}
\DoxyCodeLine{00407\ }
\DoxyCodeLine{00408\ \ \ \ \ data\ =\ pointer;}
\DoxyCodeLine{00409\ \ \ \ \ loc\ =\ 0;}
\DoxyCodeLine{00410\ \ \ \ \ n\_items\_rem\ =\ num\_items;}
\DoxyCodeLine{00411\ }
\DoxyCodeLine{00412\ \ \ \ \ \textcolor{keywordflow}{do}\ \{}
\DoxyCodeLine{00413\ \ \ \ \ \ \ \ \ n\_items\_read\ =\ fread(\&data[loc],\ size,\ n\_items\_rem,\ stream);}
\DoxyCodeLine{00414\ }
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ n\_items\_rem\ -\/=\ n\_items\_read;}
\DoxyCodeLine{00416\ }
\DoxyCodeLine{00417\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (n\_items\_rem\ >\ 0)\ \{}
\DoxyCodeLine{00418\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ an\ incomplete\ read\ occurred\ */}}
\DoxyCodeLine{00419\ }
\DoxyCodeLine{00420\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (n\_retry\_rem\ ==\ 0)}
\DoxyCodeLine{00421\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00422\ }
\DoxyCodeLine{00423\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (n\_retry\_rem\ ==\ FREAD\_RETRY\_COUNT)\ \{}
\DoxyCodeLine{00424\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}fread()\ failed;\ retrying...\(\backslash\)n"{}});}
\DoxyCodeLine{00425\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00426\ }
\DoxyCodeLine{00427\ \ \ \ \ \ \ \ \ \ \ \ \ -\/-\/n\_retry\_rem;}
\DoxyCodeLine{00428\ }
\DoxyCodeLine{00429\ \ \ \ \ \ \ \ \ \ \ \ \ loc\ +=\ n\_items\_read\ *\ size;}
\DoxyCodeLine{00430\ \textcolor{preprocessor}{\#ifdef\ HAVE\_UNISTD\_H}}
\DoxyCodeLine{00431\ \ \ \ \ \ \ \ \ \ \ \ \ sleep(1);}
\DoxyCodeLine{00432\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00433\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00434\ \ \ \ \ \}\ \textcolor{keywordflow}{while}\ (n\_items\_rem\ >\ 0);}
\DoxyCodeLine{00435\ }
\DoxyCodeLine{00436\ \ \ \ \ \textcolor{keywordflow}{return}\ num\_items;}
\DoxyCodeLine{00437\ \}}
\DoxyCodeLine{00438\ }
\DoxyCodeLine{00439\ }
\DoxyCodeLine{00440\ \textcolor{comment}{/*\ Silvio\ Moioli:\ updated\ to\ use\ Unicode\ */}}
\DoxyCodeLine{00441\ \textcolor{preprocessor}{\#ifdef\ \_WIN32\_WCE\ }\textcolor{comment}{/*\ No\ stat()\ on\ WinCE\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00442\ int32}
\DoxyCodeLine{00443\ stat\_retry(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file,\ \textcolor{keyword}{struct}\ stat\ *\ statbuf)}
\DoxyCodeLine{00444\ \{}
\DoxyCodeLine{00445\ \ \ \ \ WIN32\_FIND\_DATAW\ file\_data;}
\DoxyCodeLine{00446\ \ \ \ \ HANDLE\ *h;}
\DoxyCodeLine{00447\ \ \ \ \ \textcolor{keywordtype}{wchar\_t}\ *wfile;}
\DoxyCodeLine{00448\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ len;}
\DoxyCodeLine{00449\ }
\DoxyCodeLine{00450\ \ \ \ \ len\ =\ mbstowcs(NULL,\ file,\ 0)\ +\ 1;}
\DoxyCodeLine{00451\ \ \ \ \ wfile\ =\ ckd\_calloc(len,\ \textcolor{keyword}{sizeof}(*wfile));}
\DoxyCodeLine{00452\ \ \ \ \ mbstowcs(wfile,\ file,\ len);}
\DoxyCodeLine{00453\ \ \ \ \ \textcolor{keywordflow}{if}\ ((h\ =\ FindFirstFileW(wfile,\ \&file\_data))\ ==\ INVALID\_HANDLE\_VALUE)\ \{}
\DoxyCodeLine{00454\ \ \ \ \ \ \ \ \ ckd\_free(wfile);}
\DoxyCodeLine{00455\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00456\ \ \ \ \ \}}
\DoxyCodeLine{00457\ \ \ \ \ ckd\_free(wfile);}
\DoxyCodeLine{00458\ \ \ \ \ memset(statbuf,\ 0,\ \textcolor{keyword}{sizeof}(statbuf));}
\DoxyCodeLine{00459\ \ \ \ \ statbuf-\/>st\_mtime\ =\ file\_data.ftLastWriteTime.dwLowDateTime;}
\DoxyCodeLine{00460\ \ \ \ \ statbuf-\/>st\_size\ =\ file\_data.nFileSizeLow;}
\DoxyCodeLine{00461\ \ \ \ \ FindClose(h);}
\DoxyCodeLine{00462\ }
\DoxyCodeLine{00463\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00464\ \}}
\DoxyCodeLine{00465\ }
\DoxyCodeLine{00466\ }
\DoxyCodeLine{00467\ int32}
\DoxyCodeLine{00468\ stat\_mtime(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file)}
\DoxyCodeLine{00469\ \{}
\DoxyCodeLine{00470\ \ \ \ \ \textcolor{keyword}{struct\ }stat\ statbuf;}
\DoxyCodeLine{00471\ }
\DoxyCodeLine{00472\ \ \ \ \ \textcolor{keywordflow}{if}\ (stat\_retry(file,\ \&statbuf)\ !=\ 0)}
\DoxyCodeLine{00473\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00474\ }
\DoxyCodeLine{00475\ \ \ \ \ \textcolor{keywordflow}{return}\ ((int32)\ statbuf.st\_mtime);}
\DoxyCodeLine{00476\ \}}
\DoxyCodeLine{00477\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00478\ \textcolor{preprocessor}{\#define\ STAT\_RETRY\_COUNT\ \ \ \ \ \ \ \ 10}}
\DoxyCodeLine{00479\ int32}
\DoxyCodeLine{00480\ stat\_retry(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file,\ \textcolor{keyword}{struct}\ stat\ *\ statbuf)}
\DoxyCodeLine{00481\ \{}
\DoxyCodeLine{00482\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00483\ }
\DoxyCodeLine{00484\ \ \ \ \ }
\DoxyCodeLine{00485\ \ \ \ \ }
\DoxyCodeLine{00486\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ STAT\_RETRY\_COUNT;\ i++)\ \{}
\DoxyCodeLine{00487\ }
\DoxyCodeLine{00488\ \textcolor{preprocessor}{\#ifndef\ HAVE\_SYS\_STAT\_H}}
\DoxyCodeLine{00489\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ FILE\ *fp;}
\DoxyCodeLine{00490\ }
\DoxyCodeLine{00491\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((fp=(FILE\ *)fopen(file,\ \textcolor{stringliteral}{"{}r"{}}))!=\ 0)}
\DoxyCodeLine{00492\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{00493\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fseek(\ fp,\ 0,\ SEEK\_END);}
\DoxyCodeLine{00494\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ statbuf-\/>st\_size\ =\ ftell(\ fp\ );}
\DoxyCodeLine{00495\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fclose(fp);}
\DoxyCodeLine{00496\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00497\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00498\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00499\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{/*\ HAVE\_SYS\_STAT\_H\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00500\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (stat(file,\ statbuf)\ ==\ 0)}
\DoxyCodeLine{00501\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00502\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00503\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ ==\ 0)\ \{}
\DoxyCodeLine{00504\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ stat\ file\ '\%s';\ retrying..."{}},\ file);}
\DoxyCodeLine{00505\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00506\ \textcolor{preprocessor}{\#ifdef\ HAVE\_UNISTD\_H}}
\DoxyCodeLine{00507\ \ \ \ \ \ \ \ \ sleep(1);}
\DoxyCodeLine{00508\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00509\ \ \ \ \ \}}
\DoxyCodeLine{00510\ }
\DoxyCodeLine{00511\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00512\ \}}
\DoxyCodeLine{00513\ }
\DoxyCodeLine{00514\ int32}
\DoxyCodeLine{00515\ stat\_mtime(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file)}
\DoxyCodeLine{00516\ \{}
\DoxyCodeLine{00517\ \ \ \ \ \textcolor{keyword}{struct\ }stat\ statbuf;}
\DoxyCodeLine{00518\ }
\DoxyCodeLine{00519\ \textcolor{preprocessor}{\#ifdef\ HAVE\_SYS\_STAT\_H}}
\DoxyCodeLine{00520\ \ \ \ \ \textcolor{keywordflow}{if}\ (stat(file,\ \&statbuf)\ !=\ 0)}
\DoxyCodeLine{00521\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00522\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{/*\ HAVE\_SYS\_STAT\_H\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00523\ \ \ \ \ \textcolor{keywordflow}{if}\ (stat\_retry(file,\ \&statbuf)\ !=\ 0)}
\DoxyCodeLine{00524\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00525\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ HAVE\_SYS\_STAT\_H\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00526\ }
\DoxyCodeLine{00527\ \ \ \ \ \textcolor{keywordflow}{return}\ ((int32)\ statbuf.st\_mtime);}
\DoxyCodeLine{00528\ \}}
\DoxyCodeLine{00529\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ !\_WIN32\_WCE\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00530\ }
\DoxyCodeLine{00531\ \textcolor{keyword}{struct\ }bit\_encode\_s\ \{}
\DoxyCodeLine{00532\ \ \ \ \ FILE\ *fh;}
\DoxyCodeLine{00533\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{char}\ buf,\ bbits;}
\DoxyCodeLine{00534\ \ \ \ \ int16\ refcount;}
\DoxyCodeLine{00535\ \};}
\DoxyCodeLine{00536\ }
\DoxyCodeLine{00537\ bit\_encode\_t\ *}
\DoxyCodeLine{00538\ bit\_encode\_attach(FILE\ *outfh)}
\DoxyCodeLine{00539\ \{}
\DoxyCodeLine{00540\ \ \ \ \ bit\_encode\_t\ *be;}
\DoxyCodeLine{00541\ }
\DoxyCodeLine{00542\ \ \ \ \ be\ =\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(*be));}
\DoxyCodeLine{00543\ \ \ \ \ be-\/>refcount\ =\ 1;}
\DoxyCodeLine{00544\ \ \ \ \ be-\/>fh\ =\ outfh;}
\DoxyCodeLine{00545\ \ \ \ \ \textcolor{keywordflow}{return}\ be;}
\DoxyCodeLine{00546\ \}}
\DoxyCodeLine{00547\ }
\DoxyCodeLine{00548\ bit\_encode\_t\ *}
\DoxyCodeLine{00549\ bit\_encode\_retain(bit\_encode\_t\ *be)}
\DoxyCodeLine{00550\ \{}
\DoxyCodeLine{00551\ \ \ \ \ ++be-\/>refcount;}
\DoxyCodeLine{00552\ \ \ \ \ \textcolor{keywordflow}{return}\ be;}
\DoxyCodeLine{00553\ \}}
\DoxyCodeLine{00554\ }
\DoxyCodeLine{00555\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00556\ bit\_encode\_free(bit\_encode\_t\ *be)}
\DoxyCodeLine{00557\ \{}
\DoxyCodeLine{00558\ \ \ \ \ \textcolor{keywordflow}{if}\ (be\ ==\ NULL)}
\DoxyCodeLine{00559\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00560\ \ \ \ \ \textcolor{keywordflow}{if}\ (-\/-\/be-\/>refcount\ >\ 0)}
\DoxyCodeLine{00561\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ be-\/>refcount;}
\DoxyCodeLine{00562\ \ \ \ \ ckd\_free(be);}
\DoxyCodeLine{00563\ }
\DoxyCodeLine{00564\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00565\ \}}
\DoxyCodeLine{00566\ }
\DoxyCodeLine{00567\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00568\ bit\_encode\_write(bit\_encode\_t\ *be,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *bits,\ \textcolor{keywordtype}{int}\ nbits)}
\DoxyCodeLine{00569\ \{}
\DoxyCodeLine{00570\ \ \ \ \ \textcolor{keywordtype}{int}\ tbits;}
\DoxyCodeLine{00571\ }
\DoxyCodeLine{00572\ \ \ \ \ tbits\ =\ nbits\ +\ be-\/>bbits;}
\DoxyCodeLine{00573\ \ \ \ \ \textcolor{keywordflow}{if}\ (tbits\ <\ 8)\ \ \{}
\DoxyCodeLine{00574\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Append\ to\ buffer.\ */}}
\DoxyCodeLine{00575\ \ \ \ \ \ \ \ \ be-\/>buf\ |=\ ((bits[0]\ >>\ (8\ -\/\ nbits))\ <<\ (8\ -\/\ tbits));}
\DoxyCodeLine{00576\ \ \ \ \ \}}
\DoxyCodeLine{00577\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00578\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ i\ =\ 0;}
\DoxyCodeLine{00579\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (tbits\ >=\ 8)\ \{}
\DoxyCodeLine{00580\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Shift\ bits\ out\ of\ the\ buffer\ and\ splice\ with\ high-\/order\ bits\ */}}
\DoxyCodeLine{00581\ \ \ \ \ \ \ \ \ \ \ \ \ fputc(be-\/>buf\ |\ ((bits[i])\ >>\ be-\/>bbits),\ be-\/>fh);}
\DoxyCodeLine{00582\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Put\ low-\/order\ bits\ back\ into\ buffer\ */}}
\DoxyCodeLine{00583\ \ \ \ \ \ \ \ \ \ \ \ \ be-\/>buf\ =\ (bits[i]\ <<\ (8\ -\/\ be-\/>bbits))\ \&\ 0xff;}
\DoxyCodeLine{00584\ \ \ \ \ \ \ \ \ \ \ \ \ tbits\ -\/=\ 8;}
\DoxyCodeLine{00585\ \ \ \ \ \ \ \ \ \ \ \ \ ++i;}
\DoxyCodeLine{00586\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00587\ \ \ \ \ \}}
\DoxyCodeLine{00588\ \ \ \ \ \textcolor{comment}{/*\ tbits\ contains\ remaining\ number\ of\ \ bits.\ */}}
\DoxyCodeLine{00589\ \ \ \ \ be-\/>bbits\ =\ tbits;}
\DoxyCodeLine{00590\ }
\DoxyCodeLine{00591\ \ \ \ \ \textcolor{keywordflow}{return}\ nbits;}
\DoxyCodeLine{00592\ \}}
\DoxyCodeLine{00593\ }
\DoxyCodeLine{00594\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00595\ bit\_encode\_write\_cw(bit\_encode\_t\ *be,\ uint32\ codeword,\ \textcolor{keywordtype}{int}\ nbits)}
\DoxyCodeLine{00596\ \{}
\DoxyCodeLine{00597\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{char}\ bits[4];}
\DoxyCodeLine{00598\ \ \ \ \ codeword\ <<=\ (32\ -\/\ nbits);}
\DoxyCodeLine{00599\ \ \ \ \ bits[0]\ =\ (codeword\ >>\ 24)\ \&\ 0xff;}
\DoxyCodeLine{00600\ \ \ \ \ bits[1]\ =\ (codeword\ >>\ 16)\ \&\ 0xff;}
\DoxyCodeLine{00601\ \ \ \ \ bits[2]\ =\ (codeword\ >>\ 8)\ \&\ 0xff;}
\DoxyCodeLine{00602\ \ \ \ \ bits[3]\ =\ codeword\ \&\ 0xff;}
\DoxyCodeLine{00603\ \ \ \ \ \textcolor{keywordflow}{return}\ bit\_encode\_write(be,\ bits,\ nbits);}
\DoxyCodeLine{00604\ \}}
\DoxyCodeLine{00605\ }
\DoxyCodeLine{00606\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00607\ bit\_encode\_flush(bit\_encode\_t\ *be)}
\DoxyCodeLine{00608\ \{}
\DoxyCodeLine{00609\ \ \ \ \ \textcolor{keywordflow}{if}\ (be-\/>bbits)\ \{}
\DoxyCodeLine{00610\ \ \ \ \ \ \ \ \ fputc(be-\/>buf,\ be-\/>fh);}
\DoxyCodeLine{00611\ \ \ \ \ \ \ \ \ be-\/>bbits\ =\ 0;}
\DoxyCodeLine{00612\ \ \ \ \ \}}
\DoxyCodeLine{00613\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00614\ \}}
\DoxyCodeLine{00615\ }
\DoxyCodeLine{00616\ \textcolor{preprocessor}{\#if\ defined(HAVE\_SYS\_STAT\_H)\ \&\&\ !defined(\_\_MINGW32\_\_)\ }\textcolor{comment}{/*\ Unix,\ Cygwin,\ doesn't\ work\ on\ MINGW\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00617\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00618\ build\_directory(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path)}
\DoxyCodeLine{00619\ \{}
\DoxyCodeLine{00620\ \ \ \ \ \textcolor{keywordtype}{int}\ rv;}
\DoxyCodeLine{00621\ }
\DoxyCodeLine{00622\ \ \ \ \ \textcolor{comment}{/*\ Utterly\ failed...\ */}}
\DoxyCodeLine{00623\ \ \ \ \ \textcolor{keywordflow}{if}\ (strlen(path)\ ==\ 0)}
\DoxyCodeLine{00624\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00625\ \ \ \ \ \textcolor{comment}{/*\ Utterly\ succeeded...\ */}}
\DoxyCodeLine{00626\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ ((rv\ =\ mkdir(path,\ 0777))\ ==\ 0)}
\DoxyCodeLine{00627\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00628\ \ \ \ \ \textcolor{comment}{/*\ Or,\ it\ already\ exists...\ */}}
\DoxyCodeLine{00629\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (errno\ ==\ EEXIST)}
\DoxyCodeLine{00630\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00631\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (errno\ !=\ ENOENT)\ \{}
\DoxyCodeLine{00632\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ create\ \%s"{}});}
\DoxyCodeLine{00633\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00634\ \ \ \ \ \}}
\DoxyCodeLine{00635\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00636\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ *dirname\ =\ ckd\_salloc(path);}
\DoxyCodeLine{00637\ \ \ \ \ \ \ \ \ path2dirname(path,\ dirname);}
\DoxyCodeLine{00638\ \ \ \ \ \ \ \ \ build\_directory(dirname);}
\DoxyCodeLine{00639\ \ \ \ \ \ \ \ \ ckd\_free(dirname);}
\DoxyCodeLine{00640\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ mkdir(path,\ 0777);}
\DoxyCodeLine{00641\ \ \ \ \ \}}
\DoxyCodeLine{00642\ \}}
\DoxyCodeLine{00643\ \textcolor{preprocessor}{\#elif\ defined(\_WIN32)}}
\DoxyCodeLine{00644\ \textcolor{comment}{/*\ FIXME:\ Implement\ this.\ */}}
\DoxyCodeLine{00645\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00646\ build\_directory(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path)}
\DoxyCodeLine{00647\ \{}
\DoxyCodeLine{00648\ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}build\_directory()\ unimplemented\ on\ your\ platform!\(\backslash\)n"{}});}
\DoxyCodeLine{00649\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00650\ \}}
\DoxyCodeLine{00651\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00652\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00653\ build\_directory(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path)}
\DoxyCodeLine{00654\ \{}
\DoxyCodeLine{00655\ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}build\_directory()\ unimplemented\ on\ your\ platform!\(\backslash\)n"{}});}
\DoxyCodeLine{00656\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00657\ \}}
\DoxyCodeLine{00658\ \textcolor{preprocessor}{\#endif}}

\end{DoxyCode}
