#!/bin/csh -f

if ( $#argv < 2 ) then
  echo "Error: provide the binary directory as first argument,"
  echo "and the location of programs.txt as the second."
  echo "Proglist.tex will be written in the current directory."
  exit
endif

set GMXBINDIR   = $1
set PROGFILE	= $2

set dir = $cwd

set VER		= 3.3
set TEXIDX	= proglist.tex

set GENERAL 	= "getting_started:Getting_Started flow:Flow_Chart files:File_Formats mdp_opt:mdp_options"

cd $GMXBINDIR
set PROGRAMS = [a-z]*
cd $dir

echo ""
echo "generating latex page $TEXIDX"
echo "--------------------------------"

if ( -f $TEXIDX ) \rm $TEXIDX
touch $TEXIDX

echo "\\begin{description}" >> $TEXIDX
awk -F '|' -v longest="mk\\_angndx" '{\
  gsub("_","\\_",$0);\
  gsub("%","\\%",$0);\
  if (NF) {\
    if ( $1 == "LONGEST" ) {\
      longest = $2;\
    } else if ( $1 == "HEAD" ) {\
      printf("\\item {\\large\\bf %s}\n",$2);\
      printf("\\vspace{-2ex}\\begin{tabbing}\n");\
      printf("{\\bf %s} \\= \\kill\n",longest);\
    } else if ( $1 == "END" ) {\
      printf("\\end{tabbing}\\vspace{-2ex}\n\n");\
    } else {\
      printf("{\\bf %s} \\> %s \\\\\n",$1,$2);\
    }\
  }\
}' $PROGFILE | sed -e 's/e\.g\./{\\eg}/g' >> $TEXIDX
echo "\\end{description}" >> $TEXIDX

#last line
