#!/bin/sh
# Script for editing, proccesing and viewing LaTeX documents

while [ 0 ]; do
dialog --title "Dialog menu box" \
       --menu "Choose one of the following or press <Cancel> to exit" \ 
	  11 40 3 \
       "1" "Edit a text file" \
	  "2" "Compile a latex file" \
	  "3" "View a .dvi file" 2>/tmp/ans
if [ $? = 1 ]; then
   rm -f /tmp/ans
   clear
   exit 0
fi
R="`cat /tmp/ans`"
if [ $R = "1" ]; then
   dialog --title "Dialog input box" \
          --inputbox "    Please input file name:" \
          8 40 $F 2>/tmp/ans 
   if [ $? = 1 ]; then
      continue
   fi
   F="`cat /tmp/ans`"
   if [ -f $F ]; then
      jed $F
   else # if the file does not exist...
      dialog --title "Dialog yesno box" \
	        --yesno "\n        Is this a new file ?" 6 40 
	 if [ $? = 0 ]; then
	    jed $F
	 else
	    continue
	 fi   
   fi
elif [ $R = "2" ]; then   
   dialog --title "Choose file" \
          --inputbox "    Please input file name:" \
          8 40 $F 2>/tmp/ans 
   if [ $? = 1 ]; then
      continue
   fi
   F="`cat /tmp/ans`"
   if [ -e $F ]; then
      clear
      latex $F 
   else  # if the file does not exist...
      dialog --title "Dialog message box" \
	        --msgbox "\n     File not found" 6 30 
	 continue
   fi
elif [ $R = "3" ]; then
   dialog --title "Dialog input box" \
          --inputbox "    Please input file name:" \
          8 40 $F 2>/tmp/ans 
   if [ $? = 1 ]; then
      continue
   fi
   F="`cat /tmp/ans`"
   if [ -f $F ]; then
      clear
	 tmview $F
   else  # daca fisierul nu exista...
      dialog --title "Dialog message box" \
	        --msgbox "\n     File not found" 6 30
	 continue
   fi
fi   
done
