\doxysection{filename.\+c}
\label{filename_8c_source}\index{src/libsphinxbase/util/filename.c@{src/libsphinxbase/util/filename.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}{\ *\ filename.c\ -\/-\/\ File\ and\ path\ name\ operations.}}
\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)\ 1999\ 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:\ filename.c,v\ \$}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ *\ Revision\ 1.5\ \ 2005/06/22\ 03:01:07\ \ arthchan2003}}
\DoxyCodeLine{00050\ \textcolor{comment}{\ *\ Added\ \ keyword}}
\DoxyCodeLine{00051\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00052\ \textcolor{comment}{\ *\ Revision\ 1.3\ \ 2005/03/30\ 01:22:48\ \ archan}}
\DoxyCodeLine{00053\ \textcolor{comment}{\ *\ Fixed\ mistakes\ in\ last\ updates.\ Add}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00055\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00056\ \textcolor{comment}{\ *\ 30-\/Oct-\/1997\ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University.}}
\DoxyCodeLine{00057\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Started.}}
\DoxyCodeLine{00058\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00059\ }
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00062\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00063\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00064\ \textcolor{preprocessor}{\#include\ <assert.h>}}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/filename.h"{}}}
\DoxyCodeLine{00067\ }
\DoxyCodeLine{00068\ \textcolor{preprocessor}{\#ifdef\ \_MSC\_VER}}
\DoxyCodeLine{00069\ \textcolor{preprocessor}{\#pragma\ warning\ (disable:\ 4996)}}
\DoxyCodeLine{00070\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ }
\DoxyCodeLine{00073\ \textcolor{comment}{/*\ Strip\ off\ all\ leading\ pathname\ components\ */}}
\DoxyCodeLine{00074\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00075\ path2basename(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keywordtype}{char}\ *base)}
\DoxyCodeLine{00076\ \{}
\DoxyCodeLine{00077\ \ \ \ \ int32\ i,\ l;}
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00079\ \ \ \ \ l\ =\ strlen(path);}
\DoxyCodeLine{00080\ \textcolor{preprocessor}{\#if\ defined(\_WIN32)\ ||\ defined(\_\_CYGWIN\_\_)}}
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ l\ -\/\ 1;\ (i\ >=\ 0)\ \&\&\ !(path[i]\ ==\ \textcolor{charliteral}{'/'}\ ||\ path[i]\ ==\ \textcolor{charliteral}{'\(\backslash\)\(\backslash\)'});\ -\/-\/i);}
\DoxyCodeLine{00082\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00083\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ l\ -\/\ 1;\ (i\ >=\ 0)\ \&\&\ !(path[i]\ ==\ \textcolor{charliteral}{'/'});\ -\/-\/i);}
\DoxyCodeLine{00084\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00085\ \ \ \ \ strcpy(base,\ path\ +\ i\ +\ 1);}
\DoxyCodeLine{00086\ \}}
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00088\ \textcolor{comment}{/*\ Return\ all\ leading\ pathname\ components\ */}}
\DoxyCodeLine{00089\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00090\ path2dirname(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keywordtype}{char}\ *dir)}
\DoxyCodeLine{00091\ \{}
\DoxyCodeLine{00092\ \ \ \ \ int32\ i,\ l;}
\DoxyCodeLine{00093\ }
\DoxyCodeLine{00094\ \ \ \ \ l\ =\ strlen(path);}
\DoxyCodeLine{00095\ \textcolor{preprocessor}{\#if\ defined(\_WIN32)\ ||\ defined(\_\_CYGWIN\_\_)}}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ l\ -\/\ 1;\ (i\ >=\ 0)\ \&\&\ !(path[i]\ ==\ \textcolor{charliteral}{'/'}\ ||\ path[i]\ ==\ \textcolor{charliteral}{'\(\backslash\)\(\backslash\)'});\ -\/-\/i);}
\DoxyCodeLine{00097\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ l\ -\/\ 1;\ (i\ >=\ 0)\ \&\&\ !(path[i]\ ==\ \textcolor{charliteral}{'/'});\ -\/-\/i);}
\DoxyCodeLine{00099\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00100\ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ <=\ 0)}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ dir[0]\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{00102\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ memcpy(dir,\ path,\ i);}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ dir[i]\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{00105\ \ \ \ \ \}}
\DoxyCodeLine{00106\ \}}
\DoxyCodeLine{00107\ }
\DoxyCodeLine{00108\ }
\DoxyCodeLine{00109\ \textcolor{comment}{/*\ Strip\ off\ the\ shortest\ trailing\ .xyz\ suffix\ */}}
\DoxyCodeLine{00110\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00111\ strip\_fileext(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keywordtype}{char}\ *root)}
\DoxyCodeLine{00112\ \{}
\DoxyCodeLine{00113\ \ \ \ \ int32\ i,\ l;}
\DoxyCodeLine{00114\ }
\DoxyCodeLine{00115\ \ \ \ \ l\ =\ strlen(path);}
\DoxyCodeLine{00116\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ l\ -\/\ 1;\ (i\ >=\ 0)\ \&\&\ (path[i]\ !=\ \textcolor{charliteral}{'.'});\ -\/-\/i);}
\DoxyCodeLine{00117\ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ <\ 0)}
\DoxyCodeLine{00118\ \ \ \ \ \ \ \ \ strcpy(root,\ path);\ \ \ \ \ \textcolor{comment}{/*\ Didn't\ find\ a\ .\ */}}
\DoxyCodeLine{00119\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00120\ \ \ \ \ \ \ \ \ strncpy(root,\ path,\ i);}
\DoxyCodeLine{00121\ \ \ \ \ \}}
\DoxyCodeLine{00122\ \}}
\DoxyCodeLine{00123\ }
\DoxyCodeLine{00124\ \textcolor{comment}{/*\ Test\ if\ this\ path\ is\ absolute.\ */}}
\DoxyCodeLine{00125\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00126\ path\_is\_absolute(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path)}
\DoxyCodeLine{00127\ \{}
\DoxyCodeLine{00128\ \textcolor{preprocessor}{\#if\ defined(\_WIN32)\ \&\&\ !defined(\_WIN32\_WCE)\ }\textcolor{comment}{/*\ FIXME:\ Also\ SymbianOS\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{comment}{/*\ Starts\ with\ drive\ letter\ :\ \(\backslash\)\ or\ /\ */}}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ (strlen(path)\ >=\ 3}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \ \&\&}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ \ ((path[0]\ >=\ \textcolor{charliteral}{'A'}\ \&\&\ path[0]\ <=\ \textcolor{charliteral}{'Z'})}
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ \ \ ||\ (path[0]\ >=\ \textcolor{charliteral}{'a'}\ \&\&\ path[0]\ <=\ \textcolor{charliteral}{'z'}))}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \ \&\&\ path[1]\ ==\ \textcolor{charliteral}{':'}}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \&\&\ (path[2]\ ==\ \textcolor{charliteral}{'/'}\ ||\ path[2]\ ==\ \textcolor{charliteral}{'\(\backslash\)\(\backslash\)'}));}
\DoxyCodeLine{00136\ \textcolor{preprocessor}{\#elif\ defined(\_WIN32\_WCE)}}
\DoxyCodeLine{00137\ \ \ \ \ \textcolor{keywordflow}{return}\ path[0]\ ==\ \textcolor{charliteral}{'\(\backslash\)\(\backslash\)'}\ ||\ path[0]\ ==\ \textcolor{charliteral}{'/'};}
\DoxyCodeLine{00138\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{/*\ Assume\ Unix\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{keywordflow}{return}\ path[0]\ ==\ \textcolor{charliteral}{'/'};}
\DoxyCodeLine{00140\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00141\ \}}

\end{DoxyCode}
