\doxysection{bio.\+c}
\label{bio_8c_source}\index{src/libsphinxbase/util/bio.c@{src/libsphinxbase/util/bio.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\ \textcolor{comment}{/*}}
\DoxyCodeLine{00038\ \textcolor{comment}{\ *\ bio.c\ -\/-\/\ Sphinx-\/3\ binary\ file\ I/O\ functions.}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *\ **********************************************}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ CMU\ ARPA\ Speech\ Project}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1996\ Carnegie\ Mellon\ University.}}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *\ ALL\ RIGHTS\ RESERVED.}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *\ **********************************************}}
\DoxyCodeLine{00046\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00047\ \textcolor{comment}{\ *\ HISTORY}}
\DoxyCodeLine{00048\ \textcolor{comment}{\ *\ \$Log\$}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ *\ Revision\ 1.4\ \ 2005/06/21\ \ 20:40:46\ \ arthchan2003}}
\DoxyCodeLine{00050\ \textcolor{comment}{\ *\ 1,\ Fixed\ doxygen\ documentation,\ 2,\ Add\ the\ \$\ keyword.}}
\DoxyCodeLine{00051\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00052\ \textcolor{comment}{\ *\ Revision\ 1.3\ \ 2005/03/30\ 01:22:46\ \ archan}}
\DoxyCodeLine{00053\ \textcolor{comment}{\ *\ Fixed\ mistakes\ in\ last\ updates.\ Add}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00055\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00056\ \textcolor{comment}{\ *\ 02-\/Jul-\/1997\ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00057\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Bugfix:\ Added\ byteswapping\ in\ bio\_verify\_chksum().}}
\DoxyCodeLine{00058\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00059\ \textcolor{comment}{\ *\ 18-\/Dec-\/1996\ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00060\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Created.}}
\DoxyCodeLine{00061\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00062\ }
\DoxyCodeLine{00063\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00064\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00065\ \textcolor{preprocessor}{\#include\ <assert.h>}}
\DoxyCodeLine{00066\ }
\DoxyCodeLine{00067\ \textcolor{preprocessor}{\#ifdef\ \_MSC\_VER}}
\DoxyCodeLine{00068\ \textcolor{preprocessor}{\#pragma\ warning\ (disable:\ 4996)}}
\DoxyCodeLine{00069\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00071\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/bio.h"{}}}
\DoxyCodeLine{00072\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/err.h"{}}}
\DoxyCodeLine{00073\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ckd\_alloc.h"{}}}
\DoxyCodeLine{00074\ }
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00076\ \textcolor{preprocessor}{\#define\ BIO\_HDRARG\_MAX\ \ 32}}
\DoxyCodeLine{00077\ \textcolor{preprocessor}{\#define\ END\_COMMENT\ \ \ \ \ "{}*end\_comment*\(\backslash\)n"{}}}
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00079\ }
\DoxyCodeLine{00080\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00081\ bcomment\_read(FILE\ *\ fp)}
\DoxyCodeLine{00082\ \{}
\DoxyCodeLine{00083\ \ \ \ \ \_\_BIGSTACKVARIABLE\_\_\ \textcolor{keywordtype}{char}\ iline[16384];}
\DoxyCodeLine{00084\ }
\DoxyCodeLine{00085\ \ \ \ \ \textcolor{keywordflow}{while}\ (fgets(iline,\ \textcolor{keyword}{sizeof}(iline),\ fp)\ !=\ NULL)\ \{}
\DoxyCodeLine{00086\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (strcmp(iline,\ END\_COMMENT)\ ==\ 0)}
\DoxyCodeLine{00087\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00088\ \ \ \ \ \}}
\DoxyCodeLine{00089\ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}Missing\ \%s\ marker\(\backslash\)n"{}},\ END\_COMMENT);}
\DoxyCodeLine{00090\ \}}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ }
\DoxyCodeLine{00093\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00094\ swap\_check(FILE\ *\ fp)}
\DoxyCodeLine{00095\ \{}
\DoxyCodeLine{00096\ \ \ \ \ uint32\ magic;}
\DoxyCodeLine{00097\ }
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{keywordflow}{if}\ (fread(\&magic,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp)\ !=\ 1)\ \{}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Cannot\ read\ BYTEORDER\ MAGIC\ NO.\(\backslash\)n"{}});}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00101\ \ \ \ \ \}}
\DoxyCodeLine{00102\ }
\DoxyCodeLine{00103\ \ \ \ \ \textcolor{keywordflow}{if}\ (magic\ !=\ BYTE\_ORDER\_MAGIC)\ \{}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ either\ need\ to\ swap\ or\ got\ bogus\ magic\ number\ */}}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ SWAP\_INT32(\&magic);}
\DoxyCodeLine{00106\ }
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (magic\ ==\ BYTE\_ORDER\_MAGIC)}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ SWAP\_INT32(\&magic);}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Bad\ BYTEORDER\ MAGIC\ NO:\ \%08x,\ expecting\ \%08x\(\backslash\)n"{}},}
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ magic,\ BYTE\_ORDER\_MAGIC);}
\DoxyCodeLine{00113\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00114\ \ \ \ \ \}}
\DoxyCodeLine{00115\ }
\DoxyCodeLine{00116\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00117\ \}}
\DoxyCodeLine{00118\ }
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00120\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00121\ bio\_hdrarg\_free(\textcolor{keywordtype}{char}\ **argname,\ \textcolor{keywordtype}{char}\ **argval)}
\DoxyCodeLine{00122\ \{}
\DoxyCodeLine{00123\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00124\ }
\DoxyCodeLine{00125\ \ \ \ \ \textcolor{keywordflow}{if}\ (argname\ ==\ NULL)}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ argname[i];\ i++)\ \{}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ ckd\_free(argname[i]);}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ ckd\_free(argval[i]);}
\DoxyCodeLine{00130\ \ \ \ \ \}}
\DoxyCodeLine{00131\ \ \ \ \ ckd\_free(argname);}
\DoxyCodeLine{00132\ \ \ \ \ ckd\_free(argval);}
\DoxyCodeLine{00133\ \}}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ }
\DoxyCodeLine{00136\ int32}
\DoxyCodeLine{00137\ bio\_writehdr\_version(FILE\ *\ fp,\ \textcolor{keywordtype}{char}\ *version)}
\DoxyCodeLine{00138\ \{}
\DoxyCodeLine{00139\ \ \ \ \ uint32\ b;}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00141\ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}s3\(\backslash\)n"{}});}
\DoxyCodeLine{00142\ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}version\ \%s\(\backslash\)n"{}},\ version);}
\DoxyCodeLine{00143\ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}endhdr\(\backslash\)n"{}});}
\DoxyCodeLine{00144\ \ \ \ \ fflush(fp);}
\DoxyCodeLine{00145\ }
\DoxyCodeLine{00146\ \ \ \ \ b\ =\ (uint32)\ BYTE\_ORDER\_MAGIC;}
\DoxyCodeLine{00147\ \ \ \ \ fwrite(\&b,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp);}
\DoxyCodeLine{00148\ \ \ \ \ fflush(fp);}
\DoxyCodeLine{00149\ }
\DoxyCodeLine{00150\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00151\ \}}
\DoxyCodeLine{00152\ }
\DoxyCodeLine{00153\ }
\DoxyCodeLine{00154\ int32}
\DoxyCodeLine{00155\ bio\_writehdr(FILE\ *fp,\ ...)}
\DoxyCodeLine{00156\ \{}
\DoxyCodeLine{00157\ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *key;}
\DoxyCodeLine{00158\ \ \ \ \ va\_list\ args;}
\DoxyCodeLine{00159\ \ \ \ \ uint32\ b;}
\DoxyCodeLine{00160\ }
\DoxyCodeLine{00161\ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}s3\(\backslash\)n"{}});}
\DoxyCodeLine{00162\ \ \ \ \ va\_start(args,\ fp);}
\DoxyCodeLine{00163\ \ \ \ \ \textcolor{keywordflow}{while}\ ((key\ =\ va\_arg(args,\ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *))\ !=\ NULL)\ \{}
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *val\ =\ va\_arg(args,\ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *);}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (val\ ==\ NULL)\ \{}
\DoxyCodeLine{00166\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Wrong\ number\ of\ arguments\(\backslash\)n"{}});}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ \ \ \ \ va\_end(args);}
\DoxyCodeLine{00168\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00169\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00170\ \ \ \ \ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}\%s\ \%s\(\backslash\)n"{}},\ key,\ val);}
\DoxyCodeLine{00171\ \ \ \ \ \}}
\DoxyCodeLine{00172\ \ \ \ \ va\_end(args);}
\DoxyCodeLine{00173\ }
\DoxyCodeLine{00174\ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}endhdr\(\backslash\)n"{}});}
\DoxyCodeLine{00175\ \ \ \ \ fflush(fp);}
\DoxyCodeLine{00176\ }
\DoxyCodeLine{00177\ \ \ \ \ b\ =\ (uint32)\ BYTE\_ORDER\_MAGIC;}
\DoxyCodeLine{00178\ \ \ \ \ \textcolor{keywordflow}{if}\ (fwrite(\&b,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp)\ !=\ 1)}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00180\ \ \ \ \ fflush(fp);}
\DoxyCodeLine{00181\ }
\DoxyCodeLine{00182\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00183\ \}}
\DoxyCodeLine{00184\ }
\DoxyCodeLine{00185\ }
\DoxyCodeLine{00186\ int32}
\DoxyCodeLine{00187\ bio\_readhdr(FILE\ *\ fp,\ \textcolor{keywordtype}{char}\ ***argname,\ \textcolor{keywordtype}{char}\ ***argval,\ int32\ *\ swap)}
\DoxyCodeLine{00188\ \{}
\DoxyCodeLine{00189\ \ \ \ \ \_\_BIGSTACKVARIABLE\_\_\ \textcolor{keywordtype}{char}\ line[16384],\ word[4096];}
\DoxyCodeLine{00190\ \ \ \ \ int32\ i,\ l;}
\DoxyCodeLine{00191\ \ \ \ \ int32\ lineno;}
\DoxyCodeLine{00192\ }
\DoxyCodeLine{00193\ \ \ \ \ *argname\ =\ (\textcolor{keywordtype}{char}\ **)\ ckd\_calloc(BIO\_HDRARG\_MAX\ +\ 1,\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}\ *));}
\DoxyCodeLine{00194\ \ \ \ \ *argval\ =\ (\textcolor{keywordtype}{char}\ **)\ ckd\_calloc(BIO\_HDRARG\_MAX,\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}\ *));}
\DoxyCodeLine{00195\ }
\DoxyCodeLine{00196\ \ \ \ \ lineno\ =\ 0;}
\DoxyCodeLine{00197\ \ \ \ \ \textcolor{keywordflow}{if}\ (fgets(line,\ \textcolor{keyword}{sizeof}(line),\ fp)\ ==\ NULL)\{}
\DoxyCodeLine{00198\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Premature\ EOF,\ line\ \%d\(\backslash\)n"{}},\ lineno);}
\DoxyCodeLine{00199\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00200\ \ \ \ \ \}}
\DoxyCodeLine{00201\ \ \ \ \ lineno++;}
\DoxyCodeLine{00202\ }
\DoxyCodeLine{00203\ \ \ \ \ \textcolor{keywordflow}{if}\ ((line[0]\ ==\ \textcolor{charliteral}{'s'})\ \&\&\ (line[1]\ ==\ \textcolor{charliteral}{'3'})\ \&\&\ (line[2]\ ==\ \textcolor{charliteral}{'\(\backslash\)n'}))\ \{}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ New\ format\ (post\ Dec-\/1996,\ including\ checksums);\ read\ argument-\/value\ pairs\ */}}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;;)\ \{}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fgets(line,\ \textcolor{keyword}{sizeof}(line),\ fp)\ ==\ NULL)\ \{}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Premature\ EOF,\ line\ \%d\(\backslash\)n"{}},\ lineno);}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00210\ \ \ \ \ \ \ \ \ \ \ \ \ lineno++;}
\DoxyCodeLine{00211\ }
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (sscanf(line,\ \textcolor{stringliteral}{"{}\%s\%n"{}},\ word,\ \&l)\ !=\ 1)\ \{}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Header\ format\ error,\ line\ \%d\(\backslash\)n"{}},\ lineno);}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (strcmp(word,\ \textcolor{stringliteral}{"{}endhdr"{}})\ ==\ 0)}
\DoxyCodeLine{00217\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (word[0]\ ==\ \textcolor{charliteral}{'\#'})\ \textcolor{comment}{/*\ Skip\ comments\ */}}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{continue};}
\DoxyCodeLine{00220\ }
\DoxyCodeLine{00221\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ >=\ BIO\_HDRARG\_MAX)\ \{}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{stringliteral}{"{}Max\ arg-\/value\ limit(\%d)\ exceeded;\ increase\ BIO\_HDRARG\_MAX\(\backslash\)n"{}},}
\DoxyCodeLine{00224\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ BIO\_HDRARG\_MAX);}
\DoxyCodeLine{00225\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00226\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00227\ }
\DoxyCodeLine{00228\ \ \ \ \ \ \ \ \ \ \ \ \ (*argname)[i]\ =\ ckd\_salloc(word);}
\DoxyCodeLine{00229\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (sscanf(line\ +\ l,\ \textcolor{stringliteral}{"{}\%s"{}},\ word)\ !=\ 1)\ \{\ \ \ \ \ \ \textcolor{comment}{/*\ Multi-\/word\ values\ not\ allowed\ */}}
\DoxyCodeLine{00230\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Header\ format\ error,\ line\ \%d\(\backslash\)n"{}},\ lineno);}
\DoxyCodeLine{00231\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00232\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00233\ \ \ \ \ \ \ \ \ \ \ \ \ (*argval)[i]\ =\ ckd\_salloc(word);}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ \ \ \ \ i++;}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00236\ \ \ \ \ \}}
\DoxyCodeLine{00237\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Old\ format\ (without\ checksums);\ the\ first\ entry\ must\ be\ the\ version\#\ */}}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (sscanf(line,\ \textcolor{stringliteral}{"{}\%s"{}},\ word)\ !=\ 1)\ \{}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Header\ format\ error,\ line\ \%d\(\backslash\)n"{}},\ lineno);}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00243\ }
\DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ (*argname)[0]\ =\ ckd\_salloc(\textcolor{stringliteral}{"{}version"{}});}
\DoxyCodeLine{00245\ \ \ \ \ \ \ \ \ (*argval)[0]\ =\ ckd\_salloc(word);}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ i\ =\ 1;}
\DoxyCodeLine{00247\ }
\DoxyCodeLine{00248\ \ \ \ \ \ \ \ \ bcomment\_read(fp);}
\DoxyCodeLine{00249\ \ \ \ \ \}}
\DoxyCodeLine{00250\ \ \ \ \ (*argname)[i]\ =\ NULL;}
\DoxyCodeLine{00251\ }
\DoxyCodeLine{00252\ \ \ \ \ \textcolor{keywordflow}{if}\ ((*swap\ =\ swap\_check(fp))\ <\ 0)\ \{}
\DoxyCodeLine{00253\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}swap\_check\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00254\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00255\ \ \ \ \ \}}
\DoxyCodeLine{00256\ }
\DoxyCodeLine{00257\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00258\ error\_out:}
\DoxyCodeLine{00259\ \ \ \ \ bio\_hdrarg\_free(*argname,\ *argval);}
\DoxyCodeLine{00260\ \ \ \ \ *argname\ =\ *argval\ =\ NULL;}
\DoxyCodeLine{00261\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00262\ \}}
\DoxyCodeLine{00263\ }
\DoxyCodeLine{00264\ }
\DoxyCodeLine{00265\ \textcolor{keyword}{static}\ uint32}
\DoxyCodeLine{00266\ chksum\_accum(\textcolor{keywordtype}{void}\ *buf,\ int32\ el\_sz,\ int32\ n\_el,\ uint32\ sum)}
\DoxyCodeLine{00267\ \{}
\DoxyCodeLine{00268\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00269\ \ \ \ \ uint8\ *i8;}
\DoxyCodeLine{00270\ \ \ \ \ uint16\ *i16;}
\DoxyCodeLine{00271\ \ \ \ \ uint32\ *i32;}
\DoxyCodeLine{00272\ }
\DoxyCodeLine{00273\ \ \ \ \ \textcolor{keywordflow}{switch}\ (el\_sz)\ \{}
\DoxyCodeLine{00274\ \ \ \ \ \textcolor{keywordflow}{case}\ 1:}
\DoxyCodeLine{00275\ \ \ \ \ \ \ \ \ i8\ =\ (uint8\ *)\ buf;}
\DoxyCodeLine{00276\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n\_el;\ i++)}
\DoxyCodeLine{00277\ \ \ \ \ \ \ \ \ \ \ \ \ sum\ =\ (sum\ <<\ 5\ |\ sum\ >>\ 27)\ +\ i8[i];}
\DoxyCodeLine{00278\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00279\ \ \ \ \ \textcolor{keywordflow}{case}\ 2:}
\DoxyCodeLine{00280\ \ \ \ \ \ \ \ \ i16\ =\ (uint16\ *)\ buf;}
\DoxyCodeLine{00281\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n\_el;\ i++)}
\DoxyCodeLine{00282\ \ \ \ \ \ \ \ \ \ \ \ \ sum\ =\ (sum\ <<\ 10\ |\ sum\ >>\ 22)\ +\ i16[i];}
\DoxyCodeLine{00283\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00284\ \ \ \ \ \textcolor{keywordflow}{case}\ 4:}
\DoxyCodeLine{00285\ \ \ \ \ \ \ \ \ i32\ =\ (uint32\ *)\ buf;}
\DoxyCodeLine{00286\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n\_el;\ i++)}
\DoxyCodeLine{00287\ \ \ \ \ \ \ \ \ \ \ \ \ sum\ =\ (sum\ <<\ 20\ |\ sum\ >>\ 12)\ +\ i32[i];}
\DoxyCodeLine{00288\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00289\ \ \ \ \ \textcolor{keywordflow}{default}:}
\DoxyCodeLine{00290\ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}Unsupported\ elemsize\ for\ checksum:\ \%d\(\backslash\)n"{}},\ el\_sz);}
\DoxyCodeLine{00291\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00292\ \ \ \ \ \}}
\DoxyCodeLine{00293\ }
\DoxyCodeLine{00294\ \ \ \ \ \textcolor{keywordflow}{return}\ sum;}
\DoxyCodeLine{00295\ \}}
\DoxyCodeLine{00296\ }
\DoxyCodeLine{00297\ }
\DoxyCodeLine{00298\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00299\ swap\_buf(\textcolor{keywordtype}{void}\ *buf,\ int32\ el\_sz,\ int32\ n\_el)}
\DoxyCodeLine{00300\ \{}
\DoxyCodeLine{00301\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00302\ \ \ \ \ uint16\ *buf16;}
\DoxyCodeLine{00303\ \ \ \ \ uint32\ *buf32;}
\DoxyCodeLine{00304\ }
\DoxyCodeLine{00305\ \ \ \ \ \textcolor{keywordflow}{switch}\ (el\_sz)\ \{}
\DoxyCodeLine{00306\ \ \ \ \ \textcolor{keywordflow}{case}\ 1:}
\DoxyCodeLine{00307\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00308\ \ \ \ \ \textcolor{keywordflow}{case}\ 2:}
\DoxyCodeLine{00309\ \ \ \ \ \ \ \ \ buf16\ =\ (uint16\ *)\ buf;}
\DoxyCodeLine{00310\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n\_el;\ i++)}
\DoxyCodeLine{00311\ \ \ \ \ \ \ \ \ \ \ \ \ SWAP\_INT16(buf16\ +\ i);}
\DoxyCodeLine{00312\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00313\ \ \ \ \ \textcolor{keywordflow}{case}\ 4:}
\DoxyCodeLine{00314\ \ \ \ \ \ \ \ \ buf32\ =\ (uint32\ *)\ buf;}
\DoxyCodeLine{00315\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n\_el;\ i++)}
\DoxyCodeLine{00316\ \ \ \ \ \ \ \ \ \ \ \ \ SWAP\_INT32(buf32\ +\ i);}
\DoxyCodeLine{00317\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00318\ \ \ \ \ \textcolor{keywordflow}{default}:}
\DoxyCodeLine{00319\ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}Unsupported\ elemsize\ for\ byteswapping:\ \%d\(\backslash\)n"{}},\ el\_sz);}
\DoxyCodeLine{00320\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00321\ \ \ \ \ \}}
\DoxyCodeLine{00322\ \}}
\DoxyCodeLine{00323\ }
\DoxyCodeLine{00324\ }
\DoxyCodeLine{00325\ int32}
\DoxyCodeLine{00326\ bio\_fread(\textcolor{keywordtype}{void}\ *buf,\ int32\ el\_sz,\ int32\ n\_el,\ FILE\ *\ fp,\ int32\ swap,}
\DoxyCodeLine{00327\ \ \ \ \ \ \ \ \ \ \ uint32\ *\ chksum)}
\DoxyCodeLine{00328\ \{}
\DoxyCodeLine{00329\ \ \ \ \ \textcolor{keywordflow}{if}\ (fread(buf,\ el\_sz,\ n\_el,\ fp)\ !=\ (\textcolor{keywordtype}{size\_t})\ n\_el)}
\DoxyCodeLine{00330\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00331\ }
\DoxyCodeLine{00332\ \ \ \ \ \textcolor{keywordflow}{if}\ (swap)}
\DoxyCodeLine{00333\ \ \ \ \ \ \ \ \ swap\_buf(buf,\ el\_sz,\ n\_el);}
\DoxyCodeLine{00334\ }
\DoxyCodeLine{00335\ \ \ \ \ \textcolor{keywordflow}{if}\ (chksum)}
\DoxyCodeLine{00336\ \ \ \ \ \ \ \ \ *chksum\ =\ chksum\_accum(buf,\ el\_sz,\ n\_el,\ *chksum);}
\DoxyCodeLine{00337\ }
\DoxyCodeLine{00338\ \ \ \ \ \textcolor{keywordflow}{return}\ n\_el;}
\DoxyCodeLine{00339\ \}}
\DoxyCodeLine{00340\ }
\DoxyCodeLine{00341\ int32}
\DoxyCodeLine{00342\ bio\_fwrite(\textcolor{keywordtype}{void}\ *buf,\ int32\ el\_sz,\ int32\ n\_el,\ FILE\ *fp,}
\DoxyCodeLine{00343\ \ \ \ \ \ \ \ \ \ \ \ int32\ swap,\ uint32\ *chksum)}
\DoxyCodeLine{00344\ \{}
\DoxyCodeLine{00345\ \ \ \ \ \textcolor{keywordflow}{if}\ (chksum)}
\DoxyCodeLine{00346\ \ \ \ \ \ \ \ \ *chksum\ =\ chksum\_accum(buf,\ el\_sz,\ n\_el,\ *chksum);}
\DoxyCodeLine{00347\ \ \ \ \ \textcolor{keywordflow}{if}\ (swap)\ \{}
\DoxyCodeLine{00348\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ *nbuf;}
\DoxyCodeLine{00349\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ rv;}
\DoxyCodeLine{00350\ }
\DoxyCodeLine{00351\ \ \ \ \ \ \ \ \ nbuf\ =\ ckd\_calloc(n\_el,\ el\_sz);}
\DoxyCodeLine{00352\ \ \ \ \ \ \ \ \ memcpy(nbuf,\ buf,\ n\_el\ *\ el\_sz);}
\DoxyCodeLine{00353\ \ \ \ \ \ \ \ \ swap\_buf(nbuf,\ el\_sz,\ n\_el);}
\DoxyCodeLine{00354\ \ \ \ \ \ \ \ \ rv\ =\ fwrite(nbuf,\ el\_sz,\ n\_el,\ fp);}
\DoxyCodeLine{00355\ \ \ \ \ \ \ \ \ ckd\_free(nbuf);}
\DoxyCodeLine{00356\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ rv;}
\DoxyCodeLine{00357\ \ \ \ \ \}}
\DoxyCodeLine{00358\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00359\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ fwrite(buf,\ el\_sz,\ n\_el,\ fp);}
\DoxyCodeLine{00360\ \ \ \ \ \}}
\DoxyCodeLine{00361\ \}}
\DoxyCodeLine{00362\ }
\DoxyCodeLine{00363\ int32}
\DoxyCodeLine{00364\ bio\_fread\_1d(\textcolor{keywordtype}{void}\ **buf,\ \textcolor{keywordtype}{size\_t}\ el\_sz,\ uint32\ *\ n\_el,\ FILE\ *\ fp,}
\DoxyCodeLine{00365\ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ sw,\ uint32\ *\ ck)}
\DoxyCodeLine{00366\ \{}
\DoxyCodeLine{00367\ \ \ \ \ \textcolor{comment}{/*\ Read\ 1-\/d\ array\ size\ */}}
\DoxyCodeLine{00368\ \ \ \ \ \textcolor{keywordflow}{if}\ (bio\_fread(n\_el,\ \textcolor{keyword}{sizeof}(int32),\ 1,\ fp,\ sw,\ ck)\ !=\ 1)}
\DoxyCodeLine{00369\ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}fread(arraysize)\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00370\ \ \ \ \ \textcolor{keywordflow}{if}\ (*n\_el\ <=\ 0)}
\DoxyCodeLine{00371\ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}Bad\ arraysize:\ \%d\(\backslash\)n"{}},\ *n\_el);}
\DoxyCodeLine{00372\ }
\DoxyCodeLine{00373\ \ \ \ \ \textcolor{comment}{/*\ Allocate\ memory\ for\ array\ data\ */}}
\DoxyCodeLine{00374\ \ \ \ \ *buf\ =\ (\textcolor{keywordtype}{void}\ *)\ ckd\_calloc(*n\_el,\ el\_sz);}
\DoxyCodeLine{00375\ }
\DoxyCodeLine{00376\ \ \ \ \ \textcolor{comment}{/*\ Read\ array\ data\ */}}
\DoxyCodeLine{00377\ \ \ \ \ \textcolor{keywordflow}{if}\ (bio\_fread(*buf,\ el\_sz,\ *n\_el,\ fp,\ sw,\ ck)\ !=\ *n\_el)}
\DoxyCodeLine{00378\ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}fread(arraydata)\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00379\ }
\DoxyCodeLine{00380\ \ \ \ \ \textcolor{keywordflow}{return}\ *n\_el;}
\DoxyCodeLine{00381\ \}}
\DoxyCodeLine{00382\ }
\DoxyCodeLine{00383\ int32}
\DoxyCodeLine{00384\ bio\_fread\_2d(\textcolor{keywordtype}{void}\ ***arr,}
\DoxyCodeLine{00385\ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ e\_sz,}
\DoxyCodeLine{00386\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ *d1,}
\DoxyCodeLine{00387\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ *d2,}
\DoxyCodeLine{00388\ \ \ \ \ \ \ \ \ \ \ \ \ \ FILE\ *fp,}
\DoxyCodeLine{00389\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ swap,}
\DoxyCodeLine{00390\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ *chksum)}
\DoxyCodeLine{00391\ \{}
\DoxyCodeLine{00392\ \ \ \ \ uint32\ l\_d1,\ l\_d2;}
\DoxyCodeLine{00393\ \ \ \ \ uint32\ n;}
\DoxyCodeLine{00394\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ ret;}
\DoxyCodeLine{00395\ \ \ \ \ \textcolor{keywordtype}{void}\ *raw;}
\DoxyCodeLine{00396\ \ \ \ \ }
\DoxyCodeLine{00397\ \ \ \ \ ret\ =\ bio\_fread(\&l\_d1,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp,\ swap,\ chksum);}
\DoxyCodeLine{00398\ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ !=\ 1)\ \{}
\DoxyCodeLine{00399\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ ==\ 0)\ \{}
\DoxyCodeLine{00400\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Unable\ to\ read\ complete\ data"{}});}
\DoxyCodeLine{00401\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00402\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00403\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}OS\ error\ in\ bio\_fread\_2d"{}});}
\DoxyCodeLine{00404\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00405\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00406\ \ \ \ \ \}}
\DoxyCodeLine{00407\ \ \ \ \ ret\ =\ bio\_fread(\&l\_d2,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp,\ swap,\ chksum);}
\DoxyCodeLine{00408\ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ !=\ 1)\ \{}
\DoxyCodeLine{00409\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ ==\ 0)\ \{}
\DoxyCodeLine{00410\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Unable\ to\ read\ complete\ data"{}});}
\DoxyCodeLine{00411\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00412\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00413\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}OS\ error\ in\ bio\_fread\_2d"{}});}
\DoxyCodeLine{00414\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00416\ \ \ \ \ \}}
\DoxyCodeLine{00417\ \ \ \ \ \textcolor{keywordflow}{if}\ (bio\_fread\_1d(\&raw,\ e\_sz,\ \&n,\ fp,\ swap,\ chksum)\ !=\ n)}
\DoxyCodeLine{00418\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00419\ }
\DoxyCodeLine{00420\ \ \ \ \ assert(n\ ==\ l\_d1*l\_d2);}
\DoxyCodeLine{00421\ }
\DoxyCodeLine{00422\ \ \ \ \ *d1\ =\ l\_d1;}
\DoxyCodeLine{00423\ \ \ \ \ *d2\ =\ l\_d2;}
\DoxyCodeLine{00424\ \ \ \ \ *arr\ =\ ckd\_alloc\_2d\_ptr(l\_d1,\ l\_d2,\ raw,\ e\_sz);}
\DoxyCodeLine{00425\ }
\DoxyCodeLine{00426\ \ \ \ \ \textcolor{keywordflow}{return}\ n;}
\DoxyCodeLine{00427\ \}}
\DoxyCodeLine{00428\ }
\DoxyCodeLine{00429\ int32}
\DoxyCodeLine{00430\ bio\_fread\_3d(\textcolor{keywordtype}{void}\ ****arr,}
\DoxyCodeLine{00431\ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ e\_sz,}
\DoxyCodeLine{00432\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ *d1,}
\DoxyCodeLine{00433\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ *d2,}
\DoxyCodeLine{00434\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ *d3,}
\DoxyCodeLine{00435\ \ \ \ \ \ \ \ \ \ \ \ \ \ FILE\ *fp,}
\DoxyCodeLine{00436\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ swap,}
\DoxyCodeLine{00437\ \ \ \ \ \ \ \ \ \ \ \ \ \ uint32\ *chksum)}
\DoxyCodeLine{00438\ \{}
\DoxyCodeLine{00439\ \ \ \ \ uint32\ l\_d1;}
\DoxyCodeLine{00440\ \ \ \ \ uint32\ l\_d2;}
\DoxyCodeLine{00441\ \ \ \ \ uint32\ l\_d3;}
\DoxyCodeLine{00442\ \ \ \ \ uint32\ n;}
\DoxyCodeLine{00443\ \ \ \ \ \textcolor{keywordtype}{void}\ *raw;}
\DoxyCodeLine{00444\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ ret;}
\DoxyCodeLine{00445\ }
\DoxyCodeLine{00446\ \ \ \ \ ret\ =\ bio\_fread(\&l\_d1,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp,\ swap,\ chksum);}
\DoxyCodeLine{00447\ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ !=\ 1)\ \{}
\DoxyCodeLine{00448\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ ==\ 0)\ \{}
\DoxyCodeLine{00449\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Unable\ to\ read\ complete\ data"{}});}
\DoxyCodeLine{00450\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00451\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00452\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}OS\ error\ in\ bio\_fread\_3d"{}});}
\DoxyCodeLine{00453\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00454\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00455\ \ \ \ \ \}}
\DoxyCodeLine{00456\ \ \ \ \ ret\ =\ bio\_fread(\&l\_d2,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp,\ swap,\ chksum);}
\DoxyCodeLine{00457\ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ !=\ 1)\ \{}
\DoxyCodeLine{00458\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ ==\ 0)\ \{}
\DoxyCodeLine{00459\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Unable\ to\ read\ complete\ data"{}});}
\DoxyCodeLine{00460\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00461\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00462\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}OS\ error\ in\ bio\_fread\_3d"{}});}
\DoxyCodeLine{00463\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00464\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00465\ \ \ \ \ \}}
\DoxyCodeLine{00466\ \ \ \ \ ret\ =\ bio\_fread(\&l\_d3,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp,\ swap,\ chksum);}
\DoxyCodeLine{00467\ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ !=\ 1)\ \{}
\DoxyCodeLine{00468\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ret\ ==\ 0)\ \{}
\DoxyCodeLine{00469\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Unable\ to\ read\ complete\ data"{}});}
\DoxyCodeLine{00470\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00471\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00472\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}OS\ error\ in\ bio\_fread\_3d"{}});}
\DoxyCodeLine{00473\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00474\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00475\ \ \ \ \ \}}
\DoxyCodeLine{00476\ }
\DoxyCodeLine{00477\ \ \ \ \ \textcolor{keywordflow}{if}\ (bio\_fread\_1d(\&raw,\ e\_sz,\ \&n,\ fp,\ swap,\ chksum)\ !=\ n)\ \{}
\DoxyCodeLine{00478\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00479\ \ \ \ \ \}}
\DoxyCodeLine{00480\ }
\DoxyCodeLine{00481\ \ \ \ \ assert(n\ ==\ l\_d1\ *\ l\_d2\ *\ l\_d3);}
\DoxyCodeLine{00482\ }
\DoxyCodeLine{00483\ \ \ \ \ *arr\ =\ ckd\_alloc\_3d\_ptr(l\_d1,\ l\_d2,\ l\_d3,\ raw,\ e\_sz);}
\DoxyCodeLine{00484\ \ \ \ \ *d1\ =\ l\_d1;}
\DoxyCodeLine{00485\ \ \ \ \ *d2\ =\ l\_d2;}
\DoxyCodeLine{00486\ \ \ \ \ *d3\ =\ l\_d3;}
\DoxyCodeLine{00487\ \ \ \ \ }
\DoxyCodeLine{00488\ \ \ \ \ \textcolor{keywordflow}{return}\ n;}
\DoxyCodeLine{00489\ \}}
\DoxyCodeLine{00490\ }
\DoxyCodeLine{00491\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00492\ bio\_verify\_chksum(FILE\ *\ fp,\ int32\ byteswap,\ uint32\ chksum)}
\DoxyCodeLine{00493\ \{}
\DoxyCodeLine{00494\ \ \ \ \ uint32\ file\_chksum;}
\DoxyCodeLine{00495\ }
\DoxyCodeLine{00496\ \ \ \ \ \textcolor{keywordflow}{if}\ (fread(\&file\_chksum,\ \textcolor{keyword}{sizeof}(uint32),\ 1,\ fp)\ !=\ 1)}
\DoxyCodeLine{00497\ \ \ \ \ \ \ \ \ E\_FATAL(\textcolor{stringliteral}{"{}fread(chksum)\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00498\ \ \ \ \ \textcolor{keywordflow}{if}\ (byteswap)}
\DoxyCodeLine{00499\ \ \ \ \ \ \ \ \ SWAP\_INT32(\&file\_chksum);}
\DoxyCodeLine{00500\ \ \ \ \ \textcolor{keywordflow}{if}\ (file\_chksum\ !=\ chksum)}
\DoxyCodeLine{00501\ \ \ \ \ \ \ \ \ E\_FATAL}
\DoxyCodeLine{00502\ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{stringliteral}{"{}Checksum\ error;\ file-\/checksum\ \%08x,\ computed\ \%08x\(\backslash\)n"{}},}
\DoxyCodeLine{00503\ \ \ \ \ \ \ \ \ \ \ \ \ \ file\_chksum,\ chksum);}
\DoxyCodeLine{00504\ \}}
\DoxyCodeLine{00505\ }
\DoxyCodeLine{00506\ int16*}
\DoxyCodeLine{00507\ bio\_read\_wavfile(\textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *directory,}
\DoxyCodeLine{00508\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *filename,}
\DoxyCodeLine{00509\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *extension,}
\DoxyCodeLine{00510\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ header,}
\DoxyCodeLine{00511\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ endian,}
\DoxyCodeLine{00512\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *nsamps)}
\DoxyCodeLine{00513\ \{}
\DoxyCodeLine{00514\ \ \ \ \ FILE\ *uttfp;}
\DoxyCodeLine{00515\ \ \ \ \ \textcolor{keywordtype}{char}\ *inputfile;}
\DoxyCodeLine{00516\ \ \ \ \ int32\ n,\ l;}
\DoxyCodeLine{00517\ \ \ \ \ int16\ *data;}
\DoxyCodeLine{00518\ }
\DoxyCodeLine{00519\ \ \ \ \ n\ =\ strlen(extension);}
\DoxyCodeLine{00520\ \ \ \ \ l\ =\ strlen(filename);}
\DoxyCodeLine{00521\ \ \ \ \ \textcolor{keywordflow}{if}\ ((n\ <=\ l)\ \&\&\ (0\ ==\ strcmp(filename\ +\ l\ -\/\ n,\ extension)))}
\DoxyCodeLine{00522\ \ \ \ \ \ \ \ \ extension\ =\ \textcolor{stringliteral}{"{}"{}};}
\DoxyCodeLine{00523\ \ \ \ \ inputfile\ =\ ckd\_calloc(strlen(directory)\ +\ l\ +\ n\ +\ 2,\ 1);}
\DoxyCodeLine{00524\ \ \ \ \ \textcolor{keywordflow}{if}\ (directory)\ \{}
\DoxyCodeLine{00525\ \ \ \ \ \ \ \ \ sprintf(inputfile,\ \textcolor{stringliteral}{"{}\%s/\%s\%s"{}},\ directory,\ filename,\ extension);}
\DoxyCodeLine{00526\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00527\ \ \ \ \ \ \ \ \ sprintf(inputfile,\ \textcolor{stringliteral}{"{}\%s\%s"{}},\ filename,\ extension);}
\DoxyCodeLine{00528\ \ \ \ \ \}}
\DoxyCodeLine{00529\ }
\DoxyCodeLine{00530\ \ \ \ \ \textcolor{keywordflow}{if}\ ((uttfp\ =\ fopen(inputfile,\ \textcolor{stringliteral}{"{}rb"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{00531\ \ \ \ \ \ \ \ \ E\_FATAL\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ file\ '\%s'\ for\ reading"{}},\ inputfile);}
\DoxyCodeLine{00532\ \ \ \ \ \}}
\DoxyCodeLine{00533\ \ \ \ \ fseek(uttfp,\ 0,\ SEEK\_END);}
\DoxyCodeLine{00534\ \ \ \ \ n\ =\ ftell(uttfp);}
\DoxyCodeLine{00535\ \ \ \ \ fseek(uttfp,\ 0,\ SEEK\_SET);}
\DoxyCodeLine{00536\ \ \ \ \ \textcolor{keywordflow}{if}\ (header\ >\ 0)\ \{}
\DoxyCodeLine{00537\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fseek(uttfp,\ header,\ SEEK\_SET)\ <\ 0)\ \{}
\DoxyCodeLine{00538\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ move\ to\ an\ offset\ \%d\ in\ a\ file\ '\%s'"{}},\ header,\ inputfile);}
\DoxyCodeLine{00539\ \ \ \ \ \ \ \ \ \ \ \ \ fclose(uttfp);}
\DoxyCodeLine{00540\ \ \ \ \ \ \ \ \ \ \ \ \ ckd\_free(inputfile);}
\DoxyCodeLine{00541\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00542\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00543\ \ \ \ \ \ \ \ \ n\ -\/=\ header;}
\DoxyCodeLine{00544\ \ \ \ \ \}}
\DoxyCodeLine{00545\ \ \ \ \ n\ /=\ \textcolor{keyword}{sizeof}(int16);}
\DoxyCodeLine{00546\ \ \ \ \ data\ =\ ckd\_calloc(n,\ \textcolor{keyword}{sizeof}(*data));}
\DoxyCodeLine{00547\ \ \ \ \ \textcolor{keywordflow}{if}\ ((l\ =\ fread(data,\ \textcolor{keyword}{sizeof}(int16),\ n,\ uttfp))\ <\ n)\ \{}
\DoxyCodeLine{00548\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ read\ \%d\ samples\ from\ \%s:\ \%d"{}},\ n,\ inputfile,\ l);}
\DoxyCodeLine{00549\ \ \ \ \ \ \ \ \ ckd\_free(data);}
\DoxyCodeLine{00550\ \ \ \ \ \ \ \ \ ckd\_free(inputfile);}
\DoxyCodeLine{00551\ \ \ \ \ \ \ \ \ fclose(uttfp);}
\DoxyCodeLine{00552\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00553\ \ \ \ \ \}}
\DoxyCodeLine{00554\ \ \ \ \ ckd\_free(inputfile);}
\DoxyCodeLine{00555\ \ \ \ \ fclose(uttfp);}
\DoxyCodeLine{00556\ \ \ \ \ \textcolor{keywordflow}{if}\ (nsamps)\ *nsamps\ =\ n;}
\DoxyCodeLine{00557\ }
\DoxyCodeLine{00558\ \ \ \ \ \textcolor{keywordflow}{return}\ data;}
\DoxyCodeLine{00559\ \}}

\end{DoxyCode}
