#!/bin/sh
#
# Configure 0.3
# configuration program for dosemu
# WARNIG : This program is alpha !
#
# If you have any problems or bugs with this program, 
# please let me know.
#
# This script needs dialog 0.4
# 
# (c) 1994 Jan 'TWP' VANDENBERGHE
#          jvdbergh@wins.uia.ac.be
#

# tempory file
TEMP=/tmp/dosconfig.answers

# config file
CONFIG_BACK=/tmp/dosemu.backup


# checks status of dialog
check_status() {

if [ "$?" != 0 ]
then
   clear
   echo -e "\nDosconfig canceled! Exiting to shell \n"
   cp $CONFIG_BACK $CONFIG
   exit
fi
}

# deleteds part of config. file
delete_part() {

if test -f $CONFIG
then
  awk  -v dummy="$1" '{ if ( match($0,dummy) ) \
  { do { getline } while ( (match($0,"##") == 0 ) && ( $0 != "" )) } print }'\
  < $CONFIG > $TEMP
  mv $TEMP $CONFIG 
fi 
}

select_debug() {

delete_part "## DEBUG ##"
echo "## DEBUG ##" >> $CONFIG

dialog  --title "DEBUG" --checklist "choose one or more options" 24 60 17 \
   1 config   on \
   2 disk     off \
   3 warning  off \
   4 hardware off \
   5 port     off \
   6 read     off \
   7 general  off \
   8 IPC      off \
   9 video    off \
   a write    off \
   b xms      off \
   c ems      off \
   d serial   off \
   e keyb     off \
   f dpmi     off \
   g printer  off \
   h mouse    off 2>$TEMP

check_status

choice=`cat $TEMP`
echo "debug {" >> $CONFIG

for option in $choice
do
   case $option in
     \"1\") echo  "   config on" >> $CONFIG;;
     \"2\") echo  "   disk on" >> $CONFIG;;
     \"3\") echo  "   warning on" >> $CONFIG;;
     \"4\") echo  "   hardware on" >> $CONFIG;;   
     \"5\") echo  "   port on" >> $CONFIG;;
     \"6\") echo  "   read on" >> $CONFIG;;
     \"7\") echo  "   general on" >> $CONFIG;;
     \"8\") echo  "   IPC on" >> $CONFIG;;
     \"9\") echo  "   video on" >> $CONFIG;;
     \"a\") echo  "   write on" >> $CONFIG;;
     \"b\") echo  "   xms on" >> $CONFIG;;
     \"c\") echo  "   ems on" >> $CONFIG;;
     \"d\") echo  "   serial on" >> $CONFIG;;
     \"e\") echo  "   keyb on" >> $CONFIG;;
     \"f\") echo  "   dpmi on" >> $CONFIG;;
     \"g\") echo  "   printer on" >> $CONFIG;;
     \"h\") echo  "   mouse on" >> $CONFIG;;
esac  
done

echo "}" >> $CONFIG
echo "" >> $CONFIG
}


select_miscellaneous() {

delete_part "## MISCELLANEOUS ##"
echo "## MISCELLANEOUS ##" >> $CONFIG

dialog  --title "MISCELLANEOUS" --checklist "DOSBANNER : Want startup DOSEMU \
banner messages?  Of course :-)\nTIMEINT   : is necessary for many programs to \
work." 10 70 2\
   1 dosbanner on \
   2 timint on 2> $TEMP

check_status

choice=`cat $TEMP`

for option in $choice
do
   case $option in
   \"1\") echo "dosbanner on" >> $CONFIG;;
   \"2\") echo "timint on" >> $CONFIG;;
   esac
done

dialog  --title "MISCELLANEOUS" --radiolist "select cpu-type to emulate" 10 40 3\
   1 80286 off\
   2 80386 off \
   3 80486 on 2>$TEMP

check_status

choice=`cat $TEMP`
case $choice in
   1) echo "cpu 80286" >> $CONFIG;;
   2) echo "cpu 80386" >> $CONFIG;;
   3) echo "cpu 80486" >> $CONFIG;;
esac

dialog  --title "MISCELLANEOUS" --checklist "mathcoprocessor on during DOSEMU\
? : " 8 50 1 \
   1 "mathcoprocessor on" on 2> $TEMP

check_status

choice=`cut -c -3 $TEMP`
case $choice in
   \"1\") echo "mathco on" >> $CONFIG;;
   "") echo "mathco off" >> $CONFIG;;
esac

dialog  --title "MISCELLANEOUS" --radiolist "boot from" 9 30 2\
   1 "boot from A" off\
   2 "boot from C" on 2> $TEMP

check_status

choice=`cat $TEMP`
case $choice in
   1) echo "bootA" >> $CONFIG;;
   2) echo "bootC" >> $CONFIG;;
esac

echo "" >> $CONFIG
}


select_keyboard() {

delete_part "## KEYBOARD ##"
echo "## KEYBOARD ##" >> $CONFIG

dialog --title "KEYBOARD" --radiolist "select a keyboard layout" 24 60 17 \
  1 us off \
  2 uk off \
  3 dvorak off \
  4 sf off \
  5 sf_latin1 off \
  6 finnish off \
  7 finnish_latin1 off \
  8 sg off \
  9 sg_latin1 off \
  a de off \
  b de_latin1 off \
  c dk off \
  d dk_latin1 off \
  e es off \
  f es_latin1 off \
  g fr off \
  h fr_latin1 off \
  i be on \
  j no off 2> $TEMP

check_status

echo -n "keyboard {  " >> $CONFIG

choice=`cat $TEMP`
case $choice in 
     1) echo -n "layout us  " >> $CONFIG;;
     2) echo -n "layout uk  " >> $CONFIG;;
     3) echo -n "layout dvorak  " >> $CONFIG;;
     4) echo -n "layout sf  " >> $CONFIG;;
     5) echo -n "layout sf_latin1  " >> $CONFIG;;
     6) echo -n "layout finnish  " >> $CONFIG;;
     7) echo -n "layout finnish-latin1  " >> $CONFIG;;
     8) echo -n "layout sg  " >> $CONFIG;;
     9) echo -n "layout sg_latin1  " >> $CONFIG;;
     a) echo -n "layout de  " >> $CONFIG;;
     b) echo -n "layout de_latin1  " >> $CONFIG;;
     c) echo -n "layout dk  " >> $CONFIG;;
     d) echo -n "layout dk_latin1  " >> $CONFIG;;
     e) echo -n "layout es  " >> $CONFIG;;
     f) echo -n "layout es_latin1  " >> $CONFIG;;
     g) echo -n "layout fr  " >> $CONFIG;;
     h) echo -n "layout fr_latin1  " >> $CONFIG;;
     i) echo -n "layout be  " >> $CONFIG;;
     j) echo -n"layout no  " >> $CONFIG;;
esac  

dialog  --title "KEYBOARD" --checklist "KEYBINT : allows more accurate of \
keyboard interrupts.\nIt is a bit unstable, but makes keyboard work better \
when set to \"on\".\nRAWKEYBOARD : allows for accurate keyboard emulation for \
DOS programs." 11 75 2\
   1 keybint on \
   2 rawkeyboard off 2> $TEMP

check_status

choice=`cat $TEMP`
for option in $choice
do
   case $option in
   \"1\") echo -n "keybint on  " >> $CONFIG;;
   \"2\") echo -n "rawkeyboard on  " >> $CONFIG;;
   esac
done

echo "}" >> $CONFIG

dialog --title "HOGTHRESHOLD" --inputbox "If DOSEMU speed is unimportant, \
and CPU time is very valuable to you,\n\
you may want to set HogThreshold to a non-zero value.  This means\n\
the number of keypress requests in a row before CPU time is given\n\
away from DOSEMU.  A good value to use could be 10.\n\
A zero disables CPU hogging detection via keyboard requests." 12 75 2>$TEMP

check_status

choice=`cat $TEMP`

echo "HogThreshold $choice" >> $CONFIG
echo "" >> $CONFIG
}


select_memory() {

delete_part "## MEMORY ##"
echo "## MEMORY ##" >> $CONFIG

dialog --title "MEMORY" --inputbox "give size 'XMS' in Kb or type 'off'\
to disable memory." 8 70 2>$TEMP
check_status
choice=`cat $TEMP`
echo "xms $choice" >> $CONFIG

dialog --title "MEMORY" --inputbox "give size 'EMS' in Kb or type 'off'\
to disable memory." 8 70 2>$TEMP
check_status
choice=`cat $TEMP`
echo "ems $choice" >> $CONFIG

dialog --title "MEMORY" --inputbox "give size 'DPMI' in Kb or type 'off'\
to disable memory.\nDPMI is still unstable, \
so be careful with DPMI paramters." 9 70 2>$TEMP
check_status
choice=`cat $TEMP`
echo "dpmi $choice" >> $CONFIG

echo "" >> $CONFIG
}


select_speaker() {

delete_part "## SPEAKER ##"
echo "## SPEAKER ##" >> $CONFIG

dialog  --title "SPEAKER" --radiolist "select an option :\n\
  native      Enable DOSEMU direct access to the speaker ports.\n\
  emulated    Enable simple beeps at the terminal.\n\
  off         Disable speaker emulation." 13 70 3\
   1 "native" on\
   2 "emulated" off \
   3 "off" off  2> $TEMP

check_status

choice=`cat $TEMP`
case $choice in
  1) echo "speaker native" >> $CONFIG;;
  2) echo "speaker emulated" >> $CONFIG;;
  3) echo "speaker off" >> $CONFIG;;
esac

echo "" >> $CONFIG
}


select_mouse() {

dialog  --title "MOUSE" --radiolist "select mouseport" 11 30 4 \
   1 "com 1" on\
   2 "com 2" off \
   3 "com 3" off \
   4 "com 4" off 2> $TEMP

check_status

echo -n "serial { mouse  " >> $CONFIG

choice=`cat $TEMP`
case $choice in
  1) echo -n "com 1  " >> $CONFIG;;
  2) echo -n "com 2  " >> $CONFIG;;
  3) echo -n "com 3  " >> $CONFIG;;
  4) echo -n "com 4  " >> $CONFIG;;
esac

echo  "device /dev/mouse }" >> $CONFIG

dialog  --title "MOUSE" --radiolist "select mousetype" 15 30 8 \
   1 "microsoft" on\
   2 "logitech" off \
   3 "mmseries" off \
   4 "mouseman" off \
   5 "hitachi" off \
   6 "mousesystems" off \
   7 "busmouse" off \
   8 "ps2" off  2> $TEMP


check_status
echo -n "mouse { " >> $CONFIG

choice=`cat $TEMP`

case $choice in
  1) echo -n "microsoft" >> $CONFIG;;
  2) echo -n "logitech" >> $CONFIG;;
  3) echo -n "mmseries" >> $CONFIG;;
  4) echo -n "mouseman" >> $CONFIG;;
  5) echo -n "hitachi" >> $CONFIG;;
  6) echo -n "mousesystems " >> $CONFIG;;
  7) echo -n "busmouse  device /dev/mouse internaldriver" >> $CONFIG;;
  8) echo -n "ps2 device /dev/mouse internaldriver" >> $CONFIG;;
esac

echo " }" >> $CONFIG

}


select_modem() {

dialog  --title "MODEM" --radiolist "select modemport" 11 30 4 \
   1 "com 1" on\
   2 "com 2" off \
   3 "com 3" off \
   4 "com 4" off 2> $TEMP

check_status
echo -n "serial { " >> $CONFIG

choice=`cat $TEMP`
case $choice in
  1) echo -n "com 1  " >> $CONFIG;;
  2) echo -n "com 2  " >> $CONFIG;;
  3) echo -n "com 3  " >> $CONFIG;;
  4) echo -n "com 4  " >> $CONFIG;;
esac

echo  "device /dev/modem }" >> $CONFIG

}


select_serial() {

delete_part "## SERIAL ##"
echo "## SERIAL ##" >> $CONFIG

dialog --title "SERIAL" --yesno "Do you want to install a mouse ?" 5 40

if [ "$?" = "0" ]
then 
   select_mouse
fi

dialog --title "SERIAL" --yesno "Do you want to install a modem ?" 5 40

if [ "$?" = "0" ]
then 
   select_modem
fi

echo "" >> $CONFIG

}


select_network() {

delete_part "## NETWORKING SUPPORT ##"
echo "## NETWORKING SUPPORT ##" >> $CONFIG

dialog  --title "NETWORK" --checklist "Turn the following option 'on' \
if you require IPX/SPX emulation.\n\
Therefore, there is no need to load IPX.COM within the DOS session.\n\
The following option does not emulate LSL.COM, IPXODI.COM, etc.\n\
NOTE: MUST HAVE IPX PROTOCOL ENABLED IN KERNEL !!" 12 72 1\
   1 "IPX on" off 2> $TEMP

check_status
choice=`cut -c -3 $TEMP`

case $choice in
   \"1\") echo  "ipxsupport on" >> $CONFIG;;
      "") echo  "ipxsupport off " >> $CONFIG;;
esac

dialog  --title "NETWORK" --checklist "Enable Novell 8137->raw 802.3\
translation hack in new packet driver." 8 72 1\
   1 "Novell hack on" off 2> $TEMP


check_status
choice=`cut -c -3 $TEMP`

case $choice in 
   \"1\") echo  "pktdriver novell_hack" >> $CONFIG;;
esac

echo "" >> $CONFIG 
}

select_video() {

delete_part "## VIDEO ##"
echo "## VIDEO ##" >> $CONFIG

dialog  --title "VIDEO" --radiolist "select videomode" 11 30 4\
   1 "vga" on\
   2 "ega" off \
   3 "cga" off \
   4 "mda" off  2> $TEMP


check_status
echo -n "video { " >> $CONFIG

choice=`cat $TEMP`

case $choice in
  1) echo -n "vga  " >> $CONFIG;;
  2) echo -n "ega  " >> $CONFIG;;
  3) echo -n "cga  " >> $CONFIG;;
  4) echo -n "mda  " >> $CONFIG;;
esac

echo -n "console  "  >> $CONFIG

dialog  --title "VIDEO" --checklist "graphics ?" 8 30 1\
   1 "graphics off" off 2> $TEMP


check_status
choice=`cut -c -3 $TEMP`
case $choice in
   \"1\") echo -n "graphics " >> $CONFIG;;
esac

dialog  --title "VIDEO" --radiolist "select chipset" 12 30 5\
   1 "standard" on\
   2 "trident" off \
   3 "diamond" off \
   4 "ET4000" off  \
   5 "S3" off 2> $TEMP


check_status
choice=`cat $TEMP`

case $choice in
  2) echo -n "chipset trident  " >> $CONFIG;;
  3) echo -n "chipset diamond  " >> $CONFIG;;
  4) echo -n "chipset et4000  " >> $CONFIG;;
  5) echo -n "chipset s3  " >> $CONFIG;;
esac

dialog --title "VIDEO" --inputbox "give videomemory in Kb :" 8 40 2> $TEMP

check_status
choice=`cat $TEMP`
echo -n "memsize $choice  " >> $CONFIG

dialog --title "VIDEO" --yesno "Do you want to use a videobios file ?" 5 45\
  2> $TEMP

if [ "$?" = "0" ]
then
   dialog --title "VIDEO" --infobox "       Please wait ...
   Configure is making the videobios file " 5 50
   /usr/lib/dosemu/getrom  > /usr/lib/dosemu/vbios 2> $TEMP
   echo -n "vbios_file /usr/lib/dosemu/vbios  " >> $CONFIG 
fi

echo " }" >> $CONFIG

dialog  --title "VIDEO" --checklist "allow videoport access on ?" 8 35 1\
   1 "port access on" on 2> $TEMP

check_status
choice=`cut -c -3 $TEMP`
case $choice in 
   \"1\") echo  "allowvideoportaccess on " >> $CONFIG;;
esac


echo "" >> $CONFIG

}

select_floppy() {

delete_part "## FLOPPY DISKS ##"
echo "## FLOPPY DISKS ##" >> $CONFIG

dialog  --title "FLOPPY DISKS" --radiolist "                 floppy drive A:\n\
FOR SAFETY, UNMOUNT ALL FLOPPY DRIVES FROM YOUR FILESYSTEM BEFORE\n\
STARTING UP DOSEMU!  DAMAGE TO THE FLOPPY MAY RESULT OTHERWISE!" 12 70 3\
   1 "three inch" on \
   2 "five inch" off \
   3 "no floppy drive" off 2> $TEMP

check_status
choice=`cat $TEMP`

if [ $choice != "3" ]
then
   echo -n "floppy { device /dev/fd0 " >> $CONFIG
   case $choice in
     1) echo  "threeinch }" >> $CONFIG;;
     2) echo  "fiveinch }" >> $CONFIG;;
   esac
fi

dialog  --title "FLOPPY DISKS" --radiolist "                 floppy drive B:\n\
FOR SAFETY, UNMOUNT ALL FLOPPY DRIVES FROM YOUR FILESYSTEM BEFORE\n\
STARTING UP DOSEMU!  DAMAGE TO THE FLOPPY MAY RESULT OTHERWISE!" 12 70 3\
   1 "three inch" off \
   2 "five inch" off \
   3 "no floppy drive" on 2> $TEMP

check_status
choice=`cat $TEMP`
if [ $choice != "3" ]
then
   echo -n "floppy { device /dev/fd1 " >> $CONFIG
   case $choice in
     1) echo  "threeinch }" >> $CONFIG;;
     2) echo  "fiveinch }" >> $CONFIG;;
   esac
fi

dialog  --title "FLOPPY DISKS" --checklist "If floppy disk speed is very \
important, set this option 'ON'\n\
However, this makes the floppy drive a bit unstable.  This \n\
is best used if the floppies are write-protected." 10 70 1\
   1 "fast access on" off 2> $TEMP

check_status
choice=`cut -c -3 $TEMP`
case $choice in 
   \"1\") echo "FastFloppy on" >> $CONFIG;;
esac

echo "" >> $CONFIG
}


select_partition() {

dialog --title "HARD DISKS"  --inputbox "which disk ?" 8 40 2> $TEMP

choice=`cat $TEMP`
echo -n "partition \"$choice\" " >> $CONFIG
dialog --title "HARD DISKS"  --inputbox "which partition ?" 8 40 2> $TEMP  
choice=`cat $TEMP`
echo -n "$choice "  >> $CONFIG

dialog --title "HARD DISKS" --yesno "readonly ?" 5 50 
if [ "$?" = "0" ]
then
   echo "readonly }" >> $CONFIG
else
   echo "}" >> $CONFIG
fi 

}

select_wholedisk()  {

dialog --title "HARD DISKS"  --inputbox "which disk ?" 8 40 2> $TEMP

choice=`cat $TEMP`
echo  "wholedisk \"$choice\" }" >> $CONFIG

}


select_image() {

dialog --title "HARD DISKS" --yesno "Do you have a DOS bootable disk ?" 5 50

if [ "$?" = "1" ]
then 
   dialog --title "HARD DISKS" --msgbox "- Boot DOS on a system. 
      That's the real DOS, not DOSEMU.
   - Format a diskette with 'FORMAT A: /S'
   - Copy C:\DOS\FDISK.EXE to the diskette.
   - Copy C:\DOS\SYS.COM to the diskette." 10 50
   clear
   exit
else
   dialog --title "HARD DISKS" --msgbox "Please insert the DOS disk in drive
   A: (/dev/fd0)" 5 50
   dialog --title "HARD DISKS" --infobox "Configure will now copy some files
   This could take a while ..." 4 50
   mkdir /temp_dosemu
   mount -t msdos /dev/fd0 /temp_dosemu
   cp commands/exitemu.com /temp_dosemu
   echo -e "FDISK /MBR\r\nSYS C:\r\nEXITEMU\n\r" > /temp_dosemu/autoexec.bat
   umountfloppy /dev/fd0
   rmdir /temp_dosemu
   cp -i hdimage.dist /var/lib/dosemu/hdimage
   echo -n "disk { " >> $CONFIG
   echo "image \"/var/lib/dosemu/hdimage\" } " >> $CONFIG
   dialog --title "HARD DISKS" --msgbox "Configure will now start DOSEMU !
It then will execute some commands,
and exit DOSEMU ... " 7 50 
   dos -A 
fi

}

select_harddisk() {

delete_part "## HARD DISK ##"
echo "## HARD DISK ##" >> $CONFIG

dialog --title "HARD DISKS" --yesno "Do you want to use a DISKIMAGE file ?"\
 5 50 

if [ "$?" = "0" ]
then
   select_image
else
   echo -n "disk { " >> $CONFIG
   dialog --title "HARD DISKS" --radiolist "Do you want to use a partion \
or a whole disk ?"  9 55 2 \
     1 "partition" on\
     2 "while disk" off 2> $TEMP
   check_status
   choice=`cat $TEMP`
   case $choice in
      1) select_partition;;
      2) select_wholedisk;;
   esac
fi
 
echo "" >> $CONFIG

}


select_terminals() {

delete_part "## TERMINAL ##"
echo "## TERMINAL ##" >> $CONFIG

echo -n "terminal { " >> $CONFIG

dialog --title "TERMINAL" --radiolist "Select the character set to use with \
DOSEMU." 9 50 2 \
  1 "latin" on \
  2 "IBM" off 2> $TEMP

#check_status
choice=`cat $TEMP`
case $choice in
   1) echo -n "charset latin  " >> $CONFIG;;
   2) echo -n "charset ibm  " >> $CONFIG;;
esac

dialog --title "TERMINAL" --radiolist "Enable or disable color terminal \
support.  "normal" means to use the normal color set, \
and "xterm" uses the color set enhanced for use on terminals that \
can only display 8 colors instead of 16 colors." 14 50 3\
  1 "off" off \
  2 "normal" on \
  3 "xterm" off 2> $TEMP

check_status
choice=`cat $TEMP`
case $choice in
  1) echo -n "color off  " >> $CONFIG;;
  2) echo -n "color normal  " >> $CONFIG;;
  3) echo -n "color xterm  " >> $CONFIG;;
esac
  
dialog --title "TERMINALS" --inputbox "A number indicating the frequency \
of terminal updates of the 
screen. The smaller the number, the more frequent. 
A value of 20 gives a frequency of about one per second, 
which is very slow. However, more CPU time is to DOS applications 
when updates are less frequent. 
A value of 2 is recommended in most cases, but if you have a fast 
system or link, you can decrease this to 0. ( default = 2 )" 14 70 2> $TEMP

check_status
choice=`cat $TEMP`
echo -n "updatefreq $choice  " >> $CONFIG

dialog --title "TERMINALS" --inputbox "The size of each screen update in 
number of lines.  This is extremely useful for modem users 
to improve typing and interactive response.
The smaller this number, the better the typing response, 
but the slower the update becomes. A value of 1 is good for 
2400bps  modem links, and a value of 5 is good for 14400bps 
modem links. ( default = 25 )" 14 65 2> $TEMP

check_status
choice=`cat $TEMP`
echo -n "updatelines $choice  " >> $CONFIG

dialog --title "TERMINAL" --radiolist "This selects the screen-update engine\
to use.  It is highly recommended that you select the "fast" update system, \
unless you are running on a nonstandard terminal that does not support ANSI \
or VT100 sequences.  In this case, use "ncurses"." 13 60 2\
   1 "fast" on \
   2 "ncurses" off 2> $TEMP

 check_status
 choice=`cat $TEMP`
 case $choice in
   1) echo -n "method fast  " >> $CONFIG;;
   2) echo -n "method ncurses  " >> $CONFIG;;
 esac

 dialog --title "TERMINAL" --radiolist "Enable/disable printing of the\
character at the bottom-right corner of the screen.  Some terminals, \
especially DOS based ones, scroll the screen when something is printed \
in the corner. " 12 60 2\
   1 "on" on \
   2 "off" off 2> $TEMP

 check_status
 choice=`cat $TEMP`
 case $choice in
   1) echo -n "corner on  " >> $CONFIG;;
   2) echo -n "corner off  " >> $CONFIG;;
 esac
 echo "}" >> $CONFIG

echo "" >> $CONFIG

}


select_printers() {

delete_part "## PRINTERS ##"
echo "## PRINTERS ##" >> $CONFIG

echo -n "printer { " >> $CONFIG

dialog --title "PRINTERS" --yesno "Do you want DOSEMU to 'lpr' ?" 5 50

if [ "$?" = "0" ]
then
   echo  "options \"-p %s\"  command \"lpr\"  timeout 10 }" >> $CONFIG
else   
   echo "file \"lpt3\" }" >> $CONFIG
fi

echo "" >> $CONFIG

}


select_X() {

delete_part "## X SUPPORT ##"
echo "## X SUPPORT ##" >> $CONFIG

echo -n "X { " >> $CONFIG

dialog --title "X SUPPORT" --inputbox "A number indicating the frequency of \
X updates of the screen. 
The smaller the number, the more frequent. A value of 20 
gives a frequency of about one per second, which is very 
slow.
However, more CPU time is given to DOS  applications 
when updates are less frequent. (default = 8):" 13 66 2> $TEMP
  
check_status
choice=`cat $TEMP`
echo -n "updatefreq $choice  " >> $CONFIG

dialog --title "X SUPPORT" --inputbox "The size of each screen update in
number of lines. The smaller this number, the better 
the typing response, but the slower the update becomes. 
(default = 25):" 11 60 2> $TEMP

check_status
choice=`cat $TEMP`
echo -n "updatelines $choice  " >> $CONFIG

dialog --title "X SUPPORT" --inputbox "The X server to use. If this is not
specified, dosemu will use the DISPLAY 
environment variable.
(This is the normal case) (def = :0):" 11 45 2> $TEMP
  
check_status
choice=`cat $TEMP`
echo -n "display \"$choice\"  " >> $CONFIG

dialog --title "X SUPPORT" --inputbox "What you want dosemu to display in \
the title bar 
of its window. (def = dosemu):" 9 55 2> $TEMP
  
check_status
choice=`cat $TEMP`
echo -n "title \"$choice\"  " >> $CONFIG

dialog --title "X SUPPORT" --inputbox "Used when the dosemu window is \
iconified.
(def = dosemu):"  9 46 2> $TEMP
  
check_status
choice=`cat $TEMP`
echo -n "icon_name \"$choice\"  " >> $CONFIG

echo "}" >> $CONFIG
 
echo "" >> $CONFIG

}

main_menu() {


dialog --title "DosEmu configuration program" \
   --menu "Select function" 21 60 13 \
  1 "Debug " \
  2 "Miscellaneous" \
  3 "Keyboard" \
  4 "Memory" \
  5 "Speaker" \
  6 "Serial" \
  7 "Network" \
  8 "Video" \
  9 "Terminals" \
  a "X" \
  b "Floppy disk" \
  c "Printers" \
  d "Harddisk" 2> $TEMP

if [ $? != 0 ]
then tput sgr0
     clear
     echo -e "configuration finished\n\n"
     exit
fi

choice=`cat $TEMP`
case $choice in
   1) select_debug;;
   2) select_miscellaneous;;
   3) select_keyboard;;
   4) select_memory;;
   5) select_speaker;;
   6) select_serial;;
   7) select_network;;
   8) select_video;;
   9) select_terminals;;
   a) select_X;;
   b) select_floppy;;
   c) select_printers;;
   d) select_harddisk;;

esac	 

}


dialog --title "DosEmu configuration program" \
   --menu "Select function" 9 50 2 \
  1 "global configuration file" \
  2 "local configuration file" 2> $TEMP

check_status
choice=`cat $TEMP`
if [ $choice = 1 ]
then 
   CONFIG="/etc/dosemu.conf"
else
   CONFIG="$HOME/.dosrc"
fi
if test -f $CONFIG
then echo "" 
else 
    cp -b $CONFIG $CONFIG_BACK
    echo  "## configuration file for DOSEMU created by dosconfig 0.3 ##" > $CONFIG
    echo -e "##                 please do not edit                     ##\n" >> $CONFIG
fi

while true
do 
  main_menu
done
