;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "htk/htk-config")



#? *** htk_shell

;; dummy function that adds HTK C header files in C file
(eval `(de dummy_htk_shell () ,htk-cpheader-cmd ()))

#? * (dummy_htk_shell)
#? * (exithtk <exitcode>)
#? * (initshell <argc> <argv> <ver> <sccs>)
#? * (register <ver> <sccs>)
#? * (infoprinted)
#? * (printstdopts <opts>)
#? * (printconfig)
#? * (getconfig <user> <incglob> <list> <max>)
#? * (hasconfparm <list> <size> <name>)
#? * (getconfstr <list> <size> <name> <str>)
#? * (getconfbool <list> <size> <name> <b>)
#? * (getconfint <list> <size> <name> <ival>)
#? * (getconfflt <list> <size> <name> <fval>)
#? * (numargs)
#? * (nextarg)
#? * (getstrarg)
#? * (getswtarg)
#? * (getintarg)
#? * (getlongarg)
#? * (getfltarg)
#? * (getchkedint <min> <max> <swtname>)
#? * (getchkedlong <min> <max> <swtname>)
#? * (getchkedflt <min> <max> <swtname>)
#? * (getintenvvar <envvar> <value>)
#? * (getfilenameext <logfn> <actfn> <st> <en>)
#? * (fopen <fname> <filter> <ispipe>)
#? * (fclose <f> <ispipe>)
#? * (initsource <fname> <src> <filter>)
#? * (closesource <src>)
#? * (attachsource <file> <src>)
#? * (srcposition <src> <s>)
#? * (getch <src>)
#? * (ungetch <c> <src>)
#? * (readstring <src> <s>)
#? * (parsestring <src> <s>)
#? * (readrawstring <src> <s>)
#? * (writestring <f> <s> <q>)
#? * (rewritestring <s> <dst> <q>)
#? * (skipline <src>)
#? * (readline <src> <s>)
#? * (readuntilline <src> <s>)
#? * (skipwhitespace <src>)
#? * (skipcomment <src>)
#? * (readshort <src> <s> <n> <binary>)
#? * (readint <src> <i> <n> <binary>)
#? * (readfloat <src> <x> <n> <binary>)
#? * (rawreadshort <src> <s> <n> <bin> <swap>)
#? * (rawreadint <src> <i> <n> <bin> <swap>)
#? * (rawreadfloat <src> <x> <n> <bin> <swap>)
#? * (swapshort <p>)
#? * (swapint32 <p>)
#? * (keypressed <twait>)
#? * (writeshort <f> <s> <n> <binary>)
#? * (writeint <f> <i> <n> <binary>)
#? * (writefloat <f> <x> <n> <binary>)
#? * (htk-nameof <fn> <s>)
#? * (htk-baseof <fn> <s>)
#? * (htk-pathof <fn> <s>)
#? * (htk-extnof <fn> <s>)
#? * (makefn <fn> <path> <ext> <s>)
#? * (counterfn <prefix> <suffix> <count> <width> <s>)
#? * (substfname <fname> <s>)
#? * (domatch <s> <p>)
#? * (maskmatch <mask> <spkr> <str>)
#? * (retrievecommandline)

;; ********************************************************

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; 3 functions have their names change from C to lush
;;;; New -> NewObject 
;;;; Dispose -> DisposeObject
;;;; Exit -> ExitHTK


(de ExitHTK (  exitcode )
    ((-int-) exitcode)  
    #{ Exit(  $exitcode  );  #} 
    ()
)

(de InitShell ( argc  argv  ver  sccs ) 
    ((-int-) argc)
    ((-gptr- "char **") argv) 
    ((-gptr- "char *") ver) 
    ((-gptr- "char *") sccs)  
    (int   #{ InitShell(  $argc   ,$argv   ,$ver   ,$sccs  )  #} )       ;; ReturnStatus -> int
)


(de Register (  ver  sccs )
    ((-gptr- "char *") ver) 
    ((-gptr- "char *") sccs)  
    #{ Register(  $ver   ,$sccs  );  #} 
    ()
)


(de InfoPrinted (  )
    (int   #{ InfoPrinted(  )  #} )
)


(de PrintStdOpts (  opts )
    ((-gptr- "char *") opts)  
    #{ PrintStdOpts(  $opts  );  #} 
    ()
)


(de PrintConfig (  )
    #{ PrintConfig(  );  #} 
    ()
)


(de GetConfig (  user  incglob  list  max )
    ((-gptr- "char *") user) 
    ((-int-) incglob) 
    ((-gptr- "ConfParam **") list) 
    ((-int-) max)  
    (int   #{ GetConfig(  $user   ,$incglob   ,$list   ,$max  )  #} )
)


(de HasConfParm (  list  size  name )
    ((-gptr- "ConfParam **") list) 
    ((-int-) size) 
    ((-gptr- "char *") name)  
    (int   #{ HasConfParm(  $list   ,$size   ,$name  )  #} )
)


(de GetConfStr (  list  size  name  str )
    ((-gptr- "ConfParam **") list) 
    ((-int-) size) 
    ((-gptr- "char *") name) 
    ((-gptr- "char *") str)  
    (int   #{ GetConfStr(  $list   ,$size   ,$name   ,$str  )  #} )
)


(de GetConfBool (  list  size  name  b )
    ((-gptr- "ConfParam **") list) 
    ((-int-) size) 
    ((-gptr- "char *") name) 
    ((-gptr- "Boolean *") b)  
    (int   #{ GetConfBool(  $list   ,$size   ,$name   ,$b  )  #} )
)


(de GetConfInt (  list  size  name  ival )
    ((-gptr- "ConfParam **") list) 
    ((-int-) size) 
    ((-gptr- "char *") name) 
    ((-gptr- "int *") ival)  
    (int   #{ GetConfInt(  $list   ,$size   ,$name   ,$ival  )  #} )
)


(de GetConfFlt (  list  size  name  fval )
    ((-gptr- "ConfParam **") list) 
    ((-int-) size) 
    ((-gptr- "char *") name) 
    ((-gptr- "double *") fval)  
    (int   #{ GetConfFlt(  $list   ,$size   ,$name   ,$fval  )  #} )
)


(de NumArgs (  )
    (int    #{ NumArgs(  )  #} )
)


(de NextArg (  )
    (int   #{ NextArg(  )  #} )                     ;; ArgKind (enum) -> int
)


(de GetStrArg (  )
    (gptr   #{ GetStrArg(  )  #} )                   ;; char * -> gptr
)


(de GetSwtArg (  )
    (gptr   #{ GetSwtArg(  )  #} )                  ;; char * -> gptr
)


(de GetIntArg (  )
    (int      #{ GetIntArg(  )  #} )
)


(de GetLongArg (  )
    (int     #{ GetLongArg(  )  #} )        ;; long -> int
)


(de GetFltArg (  )
    (double    #{ GetFltArg(  )  #} )         ;; float -> double 
)


(de GetChkedInt (  min  max  swtname )
    ((-int-) min) 
    ((-int-) max) 
    ((-gptr- "char *") swtname)  
    (int     #{ GetChkedInt(  $min   ,$max   ,$swtname  )  #} )
)


(de GetChkedLong (  min  max  swtname )
    ((-int-) min)                   ;; long -> int
    ((-int-) max)                   ;; long -> int
    ((-gptr- "char *") swtname)  
    (int     #{ GetChkedLong(  $min   ,$max   ,$swtname  )  #} )        ;; long -> int
)


(de GetChkedFlt (  min  max  swtname )
    ((-float-) min) 
    ((-float-) max) 
    ((-gptr- "char *") swtname)  
    (double   #{ GetChkedFlt(  $min   ,$max   ,$swtname  )  #} )         ;; float -> double 
)


(de GetIntEnvVar (  envvar  value )
    ((-gptr- "char *") envvar) 
    ((-gptr- "int *") value)  
    (int   #{ GetIntEnvVar(  $envvar   ,$value  )  #} )
)


(de GetFileNameExt (  logfn  actfn  st  en )
    ((-gptr- "char *") logfn) 
    ((-gptr- "char *") actfn) 
    ((-gptr- "long *") st) 
    ((-gptr- "long *") en)  
    (int   #{ GetFileNameExt(  $logfn   ,$actfn   ,$st   ,$en  )  #} )
)


(de FOpen (  fname  filter  ispipe )
    ((-gptr- "char *") fname) 
    ((-int-) filter)               ;; IOFilter (enum ) -> int
    ((-gptr- "Boolean *") ispipe)  
    (gptr #{ FOpen(  $fname   ,$filter   ,$ispipe  )  #} )            ;; FILE *   -> gptr
)


(de FClose (  f  ispipe )
    ((-gptr- "FILE *") f) 
    ((-int-) ispipe)  
    #{ FClose(  $f   ,$ispipe  );  #} 
    ()
)


(de InitSource (  fname  src  filter )
    ((-gptr- "char *") fname) 
    ((-gptr- "Source *") src) 
    ((-int-) filter)                ;; IOFilter (enum ) -> int
    (int   #{ InitSource(  $fname   ,$src   ,$filter  )  #} )       ;; ReturnStatus -> int
)


(de CloseSource (  src )
    ((-gptr- "Source *") src)  
    #{ CloseSource(  $src  );  #} 
    ()
)


(de AttachSource (  file  src )
    ((-gptr- "FILE *") file) 
    ((-gptr- "Source *") src)  
    #{ AttachSource(  $file   ,$src  );  #} 
    ()
)


(de SrcPosition (  src  s )
    ((-gptr- "Source *") src) 
    ((-gptr- "char *") s)  
    (gptr #{ SrcPosition(  *$src   ,$s  )  #} )            ;; char *   -> gptr
)


(de GetCh (  src )
    ((-gptr- "Source *") src)  
    (int    #{ GetCh(  $src  )  #} )
)


(de UnGetCh (  c  src )
    ((-int-) c) 
    ((-gptr- "Source *") src)  
    #{ UnGetCh(  $c   ,$src  );  #} 
    ()
)


(de ReadString (  src  s )
    ((-gptr- "Source *") src) 
    ((-gptr- "char *") s)  
    (int   #{ ReadString(  $src   ,$s  )  #} )
)


(de ParseString (  src  s )
    ((-gptr- "char *") src) 
    ((-gptr- "char *") s)  
    (gptr #{ ParseString(  $src   ,$s  )  #} )            ;; char *   -> gptr
)


(de ReadRawString (  src  s )
    ((-gptr- "Source *") src) 
    ((-gptr- "char *") s)  
    (int   #{ ReadRawString(  $src   ,$s  )  #} )
)


(de WriteString (  f  s  q )
    ((-gptr- "FILE *") f) 
    ((-gptr- "char *") s) 
    ((-int-) q)                    ;; char -> int
    #{ WriteString(  $f   ,$s   ,$q  );  #} 
    ()
)


(de ReWriteString (  s  dst  q )
    ((-gptr- "char *") s) 
    ((-gptr- "char *") dst) 
    ((-int-) q)                    ;; char -> int
    (gptr #{ ReWriteString(  $s   ,$dst   ,$q  )  #} )            ;; char *   -> gptr
)


(de SkipLine (  src )
    ((-gptr- "Source *") src)  
    (int   #{ SkipLine(  $src  )  #} )
)


(de ReadLine (  src  s )
    ((-gptr- "Source *") src) 
    ((-gptr- "char *") s)  
    (int   #{ ReadLine(  $src   ,$s  )  #} )
)


(de ReadUntilLine (  src  s )
    ((-gptr- "Source *") src) 
    ((-gptr- "char *") s)  
    #{ ReadUntilLine (  $src   ,$s  );  #} 
    ()
)


(de SkipWhiteSpace (  src )
    ((-gptr- "Source *") src)  
    #{ SkipWhiteSpace(  $src  );  #} 
    ()
)


(de SkipComment (  src )
    ((-gptr- "Source *") src)  
    #{ SkipComment(  $src  );  #} 
    ()
)


(de ReadShort (  src  s  n  binary )
    ((-gptr- "Source *") src) 
    ((-gptr- "short *") s) 
    ((-int-) n) 
    ((-int-) binary)  
    (int   #{ ReadShort(  $src   ,$s   ,$n   ,$binary  )  #} )
)


(de ReadInt (  src  i  n  binary )
    ((-gptr- "Source *") src) 
    ((-gptr- "int *") i) 
    ((-int-) n) 
    ((-int-) binary)  
    (int  #{  ReadInt(  $src   ,$i   ,$n   ,$binary  )  #} )
)


(de ReadFloat (  src  x  n  binary )
    ((-gptr- "Source *") src) 
    ((-gptr- "float *") x) 
    ((-int-) n) 
    ((-int-) binary)  
    (int   #{ ReadFloat(  $src   ,$x   ,$n   ,$binary  )  #} )
)


(de RawReadShort (  src  s  n  bin  swap )
    ((-gptr- "Source *") src) 
    ((-gptr- "short *") s) 
    ((-int-) n) 
    ((-int-) bin) 
    ((-int-) swap)  
    (int   #{ RawReadShort(  $src   ,$s   ,$n   ,$bin   ,$swap  )  #} )
)


(de RawReadInt (  src  i  n  bin  swap )
    ((-gptr- "Source *") src) 
    ((-gptr- "int *") i) 
    ((-int-) n) 
    ((-int-) bin) 
    ((-int-) swap)  
    (int   #{ RawReadInt(  $src   ,$i   ,$n   ,$bin   ,$swap  )  #} )
)


(de RawReadFloat (  src  x  n  bin  swap )
    ((-gptr- "Source *") src) 
    ((-gptr- "float *") x) 
    ((-int-) n) 
    ((-int-) bin) 
    ((-int-) swap)  
    (int   #{ RawReadFloat(  $src   ,$x   ,$n   ,$bin   ,$swap  )  #} )
)


(de SwapShort (  p )
    ((-gptr- "short *") p)  
    #{ SwapShort(  $p  );  #} 
    ()
)


(de SwapInt32 (  p )
    ((-gptr- "int32 *") p)  
    #{ SwapInt32(  $p  );  #} 
    ()
)


(de KeyPressed (  twait )
    ((-int-) twait)  
    (int   #{ KeyPressed(  $twait  )  #} )
)


(de WriteShort (  f  s  n  binary )
    ((-gptr- "FILE *") f) 
    ((-gptr- "short *") s) 
    ((-int-) n) 
    ((-int-) binary)  
    #{ WriteShort(  $f   ,$s   ,$n   ,$binary  );  #} 
    ()
)


(de WriteInt (  f  i  n  binary )
    ((-gptr- "FILE *") f) 
    ((-gptr- "int *") i) 
    ((-int-) n) 
    ((-int-) binary)  
    #{ WriteInt(  $f   ,$i   ,$n   ,$binary  );  #} 
    ()
)


(de WriteFloat (  f  x  n  binary )
    ((-gptr- "FILE *") f) 
    ((-gptr- "float *") x) 
    ((-int-) n) 
    ((-int-) binary)  
    #{ WriteFloat(  $f   ,$x   ,$n   ,$binary  );  #} 
    ()
)


(de HTK-NameOf (  fn  s )
    ((-gptr- "char *") fn) 
    ((-gptr- "char *") s)  
    (gptr   #{ NameOf(  $fn   ,$s  )  #} )               ;; char * -> gptr
)


(de HTK-BaseOf (  fn  s )
    ((-gptr- "char *") fn) 
    ((-gptr- "char *") s)  
    (gptr   #{ BaseOf(  $fn   ,$s  )  #} )               ;; char * -> gptr
)


(de HTK-PathOf (  fn  s )
    ((-gptr- "char *") fn) 
    ((-gptr- "char *") s)  
    (gptr  #{ PathOf(  $fn   ,$s  )  #} )               ;; char *  -> gptr
)


(de HTK-ExtnOf (  fn  s )
    ((-gptr- "char *") fn) 
    ((-gptr- "char *") s)  
    (gptr  #{ ExtnOf(  $fn   ,$s  )  #} )               ;; char *   -> gptr
)


(de MakeFN (  fn  path  ext  s )
    ((-gptr- "char *") fn) 
    ((-gptr- "char *") path) 
    ((-gptr- "char *") ext) 
    ((-gptr- "char *") s)  
    (gptr  #{ MakeFN(  $fn   ,$path   ,$ext   ,$s  )  #} )           ;; char *  -> gptr
)


(de CounterFN (  prefix  suffix  count  width  s )
    ((-gptr- "char *") prefix) 
    ((-gptr- "char*") suffix) 
    ((-int-) count) 
    ((-int-) width) 
    ((-gptr- "char *") s)  
    (gptr   #{ CounterFN(  $prefix   ,$suffix   ,$count   ,$width   ,$s  )  #} )       ;; char * -> gptr
)


(de SubstFName (  fname  s )
    ((-gptr- "char *") fname) 
    ((-gptr- "char *") s)  
    #{ SubstFName(  $fname   ,$s  );  #} 
    ()
)


(de DoMatch (  s  p )
    ((-gptr- "char *") s) 
    ((-gptr- "char *") p)  
    (int   #{ DoMatch(  $s   ,$p  )  #} )
)


(de MaskMatch (  mask  spkr  str )
    ((-gptr- "char *") mask) 
    ((-gptr- "char *") spkr) 
    ((-gptr- "char *") str)  
    (int   #{ MaskMatch(  $mask   ,$spkr   ,$str  )  #} )
)


(de RetrieveCommandLine (  )
    (gptr #{ RetrieveCommandLine(  )  #} )            ;; char *   -> gptr
)

;; ********************************************************

(dhc-make-with-libs () (list htk-libhtk)
  dummy_htk_shell
  exithtk
  initshell
  register
  infoprinted
  printstdopts
  printconfig
  getconfig
  hasconfparm
  getconfstr
  getconfbool
  getconfint
  getconfflt
  numargs
  nextarg
  getstrarg
  getswtarg
  getintarg
  getlongarg
  getfltarg
  getchkedint
  getchkedlong
  getchkedflt
  getintenvvar
  getfilenameext
  fopen
  fclose
  initsource
  closesource
  attachsource
  srcposition
  getch
  ungetch
  readstring
  parsestring
  readrawstring
  writestring
  rewritestring
  skipline
  readline
  readuntilline
  skipwhitespace
  skipcomment
  readshort
  readint
  readfloat
  rawreadshort
  rawreadint
  rawreadfloat
  swapshort
  swapint32
  keypressed
  writeshort
  writeint
  writefloat
  htk-nameof
  htk-baseof
  htk-pathof
  htk-extnof
  makefn
  counterfn
  substfname
  domatch
  maskmatch
  retrievecommandline
)
