##############################################################################
# This file is global.conf, it is _allways_ executed as part of the inititial
# configuration.
#
# Linux dosemu  configuration  for parser versions >= 3 (dosemu-0.97.0.1)
#
# ./doc/README-tech.txt (chapter 2.) contains a description of the syntax
# and the usage. However, you normal won't edit this file !!
#
# NOTES:
#
# 1. The file dosemu.conf (and optionally ~/.dosemurc) contains variable
#    settings, that are included by global.conf for doing the
#    most reasonable configuration.
#    The file dosemu.conf (and optionally ~/.dosemurc) is what gets
#    updated by the menu driven 'setup-dosemu' tool.
#
# 2. We strongly recommend you to edit ONLY dosemu.conf.
#    If you change global.conf, you are at your own and could break
#    'setup-dosemu'.  You really need to know a lot of DOSEMU
#    internals before you fiddle with editing global.conf.
#    However, some very special cases can only be handled in global.conf.
#    
# 3. The file global.conf (this one) must either
#      - be in DOSEMU_LIB_DIR (the default, changeable via dosemu.users
#        or --Flibdir)
#      - or given via -F option (from root login, else only on
#        non-suid-root DOSEMU)
#      - or be in $HOME/.dosemu/lib.
#
#    For the latter there must be given the following conditions:
#      - in dosemu.users give the keyword 'private_setup' for this user
#      - DOSEMU _must_ be non-suid-root, except for user root or if you
#        give the keyword 'unrestricted' in addition to 'private_setup'.
#
# 4. The only compiled-in path is /etc/dosemu.users (or if not found
#    /etc/dosemu/dosemu.users), however, this can be overridden by
#    --Fusers, if not running suid-root. All other pathes are configurable
#    and the dosemu binaries can reside everywhere in the system.
#
# This file (global.conf) may also serve as an example file for
#      .dosrc            ( old style user configuration file )
#      option -I         ( configuration via commandline, see man/dos.1 )
#
# Access rights for suid-root running DOSEMU sessions are defined in
#
#      /etc/dosemu.users
#
##############################################################################

ifdef u_forceold
  undef parser_version_3
  define version_3_style_used
endif

ifndef parser_version_3
  # normally won't come here, because older DOSEMUs don't use this file
  # ... but if using -F option ...
  include "/etc/dosemu/dosemu.conf"
else
  # we are on version 3 parser

  # for security reason we restrict the PATH and restore it later
  # to its original value
  $_DOSEMU_ORIG_PATH = $PATH
  $PATH = "/usr/local/bin:/usr/bin:/bin"

  ## we set some vital variable

  if (!strlen($DOSEMU_LIB_DIR))
    # be sure, because older DOSEMU won't set this
    $DOSEMU_LIB_DIR = "/usr/lib/dosemu";
    $DOSEMU_CONF_DIR = "/etc/dosemu";
    $DOSEMU_HDIMAGE_DIR = "/var/lib/dosemu";
  else
    if (!strlen($DOSEMU_HDIMAGE_DIR))
      $DOSEMU_HDIMAGE_DIR = "/var/lib/dosemu";
    endif
    # make sure we have absolute paths
    $DOSEMU_LIB_DIR = shell("cd ", $DOSEMU_LIB_DIR, "; pwd -P");
    $DOSEMU_LIB_DIR = strdel($DOSEMU_LIB_DIR, strlen($DOSEMU_LIB_DIR)-1, 1);
    $DOSEMU_HDIMAGE_DIR = shell("cd ", $DOSEMU_HDIMAGE_DIR, "; pwd -P");
    $DOSEMU_HDIMAGE_DIR = strdel($DOSEMU_HDIMAGE_DIR, strlen($DOSEMU_HDIMAGE_DIR)-1, 1);
  endif

  $CONFIG_VERSION = ( (0 << 24) | (97 << 16) | (2 << 8) | 0)
  #                    ^           ^^           ^         ^
  if ( $DOSEMU_VERSION_CODE < $CONFIG_VERSION )
    abort "
*** sorry, your ", $DOSEMU_LIB_DIR, "/global.conf doesn't match this dosemu version
"
  endif

  $DOSEMU_VERSION = ($DOSEMU_VERSION_CODE >> 24), '.',
                    (($DOSEMU_VERSION_CODE >> 16) & 255), '.',
                    (($DOSEMU_VERSION_CODE >> 8) & 255), '.',
                    ($DOSEMU_VERSION_CODE & 255);

  $LIST_DELIM = " ,	"	#delimiters for lists <tab>, blank, comma


  # we include the global settings from /etc/dosemu.conf
  shell("test -f ", $DOSEMU_CONF_DIR, "/dosemu.conf")
  if ( $DOSEMU_SHELL_RETURN)
    abort "
*** error: ", $DOSEMU_CONF_DIR, "/dosemu.conf not accessable
    ... giving up.
"
  endif

  undef version_3_style_used    # unset it to have a valid check below
  $xxx = 'include "', $DOSEMU_CONF_DIR, '/dosemu.conf"';
  $$xxx;
  ifndef version_3_style_used
    abort "
*** Your ", $DOSEMU_CONF_DIR, "/dosemu.conf is obviously an old style or a too simple one.
    Please read Quickstart and README.txt on how to upgrade.
"
  endif

  ## we check if we have an ${HOME}/.dosemurc (given by $DOSEMU_RC),
  ## if yes, we include it here 'under user scope', which means it has
  ## all c_* classes undefined and can only change enviroment variables in
  ## its own isolated name space (prefixed with 'dosemu_').
  ## We later take over only such variables, that we allow.

  $_dosemurc = $DOSEMU_RC         # we get that passed from 'parse_config()'
  shell("test -f ", $_dosemurc)
  if ( (!$DOSEMU_SHELL_RETURN) && ($DOSEMU_VERSION_CODE >= ( ((97 << 16) | (4 << 8) | 3))))
    # we have a .dosemurc and can include
    $_dosemurc = ' include "', $_dosemurc, '"';
    enter_user_scope;
    $$_dosemurc;
    leave_user_scope;
    define skip_dosrc;

    ## now we take over the allowed variables, only those which exist
    ## with 'dosemu_' prefixed will overwrite those without the prefix.

    checkuservar $_debug,
      $_features, $_mapping,
      $_timint, $_mathco, $_cpu, $_pci, $_xms, $_ems, $_ems_frame,
      $_emusys, $_emubat, $_emuini
    checkuservar
      $_term_char_set, $_term_color, $_term_updfreq, $_escchar, $_layout,
      $_keybint
    checkuservar
      $_X_updfreq, $_X_title, $_X_icon_name, $_X_keycode, $_X_blinkrate,
      $_X_font, $_X_mitshm, $_X_sharecmap, $_X_fixed_aspect, $_X_aspect_43,
      $_X_lin_filt, $_X_bilin_filt, $_X_mode13fact, $_X_winsize, $_X_gamma,
      $_X_vgaemu_memsize, $_X_lfb, $_X_pm_interface, $_X_mgrab_key, $_X_vesamode
    ifdef guest
      define restricted
    else
      checkuservar
        $_speaker,
        $_com1, $_com2, $_com3, $_com4, $_mouse, $_mouse_dev, $_mouse_flags, $_mouse_baud,
        $_printer, $_printer_timeout, $_ports,
        $_ipxsupport, $_novell_hack, $_vnet,
        $_sound, $_sb_base, $_sb_irq, $_sb_dma, $_sb_dsp, $_sb_mixer, $_mpu_base
    endif
    ifndef restricted
      checkuservar  $_hogthreshold, $_dpmi, $_vbootfloppy, $_aspi, $_ttylocks
      $xxx = $_hdimage	# remember the contents for later check
      checkuservar  $_hdimage
      if ($xxx ne $_hdimage)
        # the user changed it in .dosemurc, have to check
        if (strlen($_hdimage) && ($DOSEMU_UID != $DOSEMU_EUID) )
          # we are running suid-root as user, don't allow partition access
          $yyy = $_hdimage
          foreach $xxx ($LIST_DELIM, $yyy)
            if (!strncmp($xxx, "/dev/", 4))
              abort "
*** sorry, your are not allowed to use ", $xxx, " in .dosemurc
"
            endif
          done
        endif
      endif
    endif
  endif
  ## end of .dosemurc inclusion

  if ( $DOSEMU_VERSION_CODE >=  ( (99 << 16) | (13 << 8) | 2) )
    if (strlen($_mapping))
      mappingdriver $_mapping;
    endif
  endif

  if (strlen($_debug))
    debug $_debug ;
  else
    debug { off }
  endif

  if ($_cpuspeed) cpuspeed $_cpuspeed endif
  if ($_rdtsc) rdtsc on else rdtsc off endif
  pci $_pci

  dosbanner on
  timint $_timint
  mathco $_mathco
  if (strlen($_cpu))
    $_cpu = "cpu ", $_cpu;
    $$_cpu
  else
    cpu 80386
  endif
  xms $_xms
  if ($_ems) ems { ems_size $_ems ems_frame $_ems_frame } else ems off endif
  dosmem $_dosmem

  if ($_emusys ne "") emusys $_emusys endif
  if ($_emubat ne "") emubat $_emubat endif
  if ($_emuini ne "") emuini $_emuini endif

  $DISABLE_MOUSE = (0)
  $DISABLE_SERIAL = (0)

  ## terminal stuff, we check a lot to insure proper operation

  $BEING_ON = ""
  $USING_X = (0)
  $REMOTE_HOST = ""

  ## Note GNU sh-utils >= 2.0 changed the default behaviour such
  #       that it doesn't display the peer for remote connections anymore.
  #       We need -l option to get this. As GNU sh-utils 1.16 doesn't
  #       have this option, we detect this case via shell return value.
  $xxx = shell("who -l am i 2>/dev/null")
  if ($DOSEMU_SHELL_RETURN)
    # we have GNU sh-utils < 2.0
    $xxx = shell("who am i")
  endif
  if ($DOSEMU_STDIN_IS_CONSOLE eq "1")
    $BEING_ON = "console"
  else
    if ((strstr($xxx, "(:") < 0) && (strchr($xxx, "(") >= 0))
      $BEING_ON = "remote"
      $REMOTE_HOST = strsplit($xxx, strchr($xxx,"(")+1,99)
      $REMOTE_HOST = strdel($REMOTE_HOST, strchr($REMOTE_HOST,")"),99)
    else
      $BEING_ON = ""
    endif
    if ( (strchr($DOSEMU_OPTIONS,"X") >=0) && ($DISPLAY ne "") )
      $USING_X = (1)
    endif
    if (strstr("xterm dtterm", $TERM) >= 0)
      $BEING_ON = $BEING_ON, "_xterm"
    else
      if (strstr("linux console", $TERM) < 0)
        # remote side must be some type of real terminal
        $BEING_ON = $BEING_ON, "_terminal"
      else
        # remote side is a Linux console
        $BEING_ON = $BEING_ON, "_console"
      endif
    endif
  endif

  warn "dosemu running on ", $BEING_ON;

  $xxx = $_term_char_set
  if ($xxx eq "")
     $xxx = "latin"
     if (strstr($BEING_ON, "_console") >= 0)
       $xxx = "ibm"
     endif
  endif
  if ( ($BEING_ON ne "console") && (!$USING_X) )
    $DISABLE_MOUSE = (1)
    if ($_term_color) $_term_color = "on" else $_term_color = "off" endif
    terminal { charset $$xxx updatefreq $_term_updfreq  escchar $_escchar
               color $$_term_color }
  endif
  if ( $DOSEMU_VERSION_CODE >= ( (97 << 16) | (10 << 8) | 5) )
    charset $$xxx
  endif

  ## host checking. Naah, we won't let all in ;-)

  ## first: logged in hosts
  if (strlen($REMOTE_HOST) && strlen($_odd_hosts))
    foreach $xxx ($LIST_DELIM,$_odd_hosts)
      if ( ! strncmp($xxx, $REMOTE_HOST, strlen($REMOTE_HOST)))
        abort "Sorry, your host is on the blacklist"
      endif
    done
  endif
  ## second: hosts on diskless machines, that aren't allowed
  if (strlen($_diskless_hosts))
    foreach $xxx ($LIST_DELIM, $_diskless_hosts)
      if ( ! strncmp($xxx, $DOSEMU_HOST, strlen($DOSEMU_HOST)))
        abort "Sorry, your host is on the blacklist"
      endif
    done
  endif

  ## X param settings

  if ( $USING_X || (strchr($DOSEMU_OPTIONS,"L") >0) )
    # running as xdos or DEXE (which may force X later)
    if ($_X_keycode == -1) # we do not test for 'auto', because older
                           # DOSEMU don't know it and we want older
                           # versions also running with this global.conf
      $_X_keycode = "keycode_auto"
    else
      if ($_X_keycode) $_X_keycode = "keycode" else $_X_keycode = "" endif
    endif
    if ($_X_sharecmap) $_X_sharecmap = "sharecmap" else $_X_sharecmap = "" endif
    if ($_X_aspect_43) $_X_aspect_43 = "aspect_43" else $_X_aspect_43 = "" endif
    if ($_X_lin_filt) $_X_lin_filt = "lin_filt" else $_X_lin_filt = "" endif
    if ($_X_bilin_filt) $_X_bilin_filt = "bilin_filt" else $_X_bilin_filt = "" endif
    if ($_X_mode13fact != 2)
      $_X_mode13fact = "mode13fact ", $_X_mode13fact
    else
      $_X_mode13fact = ""
    endif
    $_X_gamma = "gamma ", (int($_X_gamma * 100))
    if (strlen($_X_font)) $_X_font = 'font "', $_X_font, '"'; endif

    if (strlen($_X_winsize))
      $xxx = (strstr($_X_winsize,","))
      $_X_winsize = "winsize (", strdel($_X_winsize,$xxx,999), ") , (",
                    strsplit($_X_winsize,$xxx+1,999), ")"
    endif

    $xxx = $_X_vesamode
    $_X_vesamode = ""
    if (strlen($xxx))
      foreach $yyy (" 	", $xxx)
        $zzz = (strchr($yyy,","))
        $_X_vesamode = "vesamode (", strdel($yyy,$zzz,999), "),(",
                      strsplit($yyy,$zzz+1,999), ") "
      done
    endif
    if (strlen($_X_mgrab_key))
      $_X_mgrab_key = 'mgrab_key "', $_X_mgrab_key, '"'
    endif
    X { 
      title $_X_title icon_name $_X_icon_name
      updatefreq $_X_updfreq blinkrate $_X_blinkrate
      fixed_aspect $_X_fixed_aspect vgaemu_memsize $_X_vgaemu_memsize
      lfb $_X_lfb  pm_interface $_X_pm_interface mitshm $_X_mitshm
      $$_X_keycode $$_X_sharecmap $$_X_aspect_43 $$_X_lin_filt $$_X_bilin_filt
      $$_X_font $$_X_winsize $$_X_gamma
      $$_X_vesamode $$_X_mode13fact $$_X_mgrab_key
    };
  endif

  ifdef guest
    ## /etc/dosemu.users defined 'guest' for this login
    define restricted		# force restricted setting
    $_hogthreshold = (1)	# force 'nice'
    $_rawkeyboard = (off)	# force normal keyboard
    if ($BEING_ON eq "console") video { vga } endif
    sound_emu off
    $DISABLE_MOUSE = (1)
    $DISABLE_SERIAL = (1)
  else
    ## other then guest
    # video settings
    if ($BEING_ON eq "console")
      if (!strlen($_video)) $_video = "plainvga" endif
      if ($_console) $_console = "console" else $_console = "" endif
      if ($_graphics)
        $_graphics = "graphics"
        $_console = "console"
        $_vbios_seg = "vbios_seg ", ($_vbios_seg)
        $_vbios_size = "vbios_size ", ($_vbios_size)
        $_vmemsize = "memsize ", ($_vmemsize)
        if ($_videoportaccess) allowvideoportaccess on endif
      else
        $_graphics = ""; $_vbios_seg = ""; $_vbios_size = ""; $_vmemsize = ""
      endif
      if (strlen($_chipset)) $_chipset = "chipset ",$_chipset endif
      if ($_dualmon) $_dualmon = "dualmon" else $_dualmon = "" endif
      video {
        $$_video $$_console $$_graphics $$_chipset
        $$_vbios_seg  $$_vbios_size $$_vmemsize $$_dualmon
      }
    else
      if ($_dualmon) video {dualmon} endif
    endif

    ## sound settings
    if ($_sound)
      sound_emu { sb_base $_sb_base  sb_irq $_sb_irq  sb_dma $_sb_dma
                  sb_mixer $_sb_mixer  mpu_base $_mpu_base }
    else
      sound_emu off
    endif

    ## serial
    if ((!$DISABLE_SERIAL) && strlen($_ttylocks))
      ttylocks { directory $_ttylocks }
    endif
    if ((!$DISABLE_SERIAL) && strlen($_com1))
      if ($_mouse_dev eq "com1")
        if (!$DISABLE_MOUSE) serial { mouse com 1 device $$_com1 } endif
        $_mouse = ""
      else
        if ($_com1 eq "virtual")
          serial { com 1 virtual }
        else
          serial { com 1 device $$_com1 }
        endif
      endif
    endif
    if ((!$DISABLE_SERIAL) && strlen($_com2))
      if ($_mouse_dev eq "com2")
        if (!$DISABLE_MOUSE) serial { mouse com 2 device $$_com2 } endif
        $_mouse = ""
      else
        if ($_com2 eq "virtual")
          serial { com 2 virtual }
        else
          serial { com 2 device $$_com2 }
        endif
      endif
    endif
    if ((!$DISABLE_SERIAL) && strlen($_com3))
      if ($_mouse_dev eq "com3")
        if (!$DISABLE_MOUSE) serial { mouse com 3 device $$_com3 } endif
        $_mouse = ""
      else
        if ($_com3 eq "virtual")
          serial { com 3 virtual }
        else
          serial { com 3 device $$_com3 }
        endif
      endif
    endif
    if ((!$DISABLE_SERIAL) && strlen($_com4))
      if ($_mouse_dev eq "com4")
        if (!$DISABLE_MOUSE) serial { mouse com 4 device $$_com4 } endif
        $_mouse = ""
      else
        if ($_com4 eq "virtual")
          serial { com 4 virtual }
        else
          serial { com 4 device $$_com4 }
        endif
      endif
    endif


    ## mouse settings
    if ((!$DISABLE_MOUSE) && strlen($_mouse) && (strstr($_mouse_dev,"com")<0))
      if ($_mouse_baud)
        $_mouse_baud = "baudrate ", $_mouse_baud
      else
        $_mouse_baud = ""
      endif
      if (strlen($_mouse_dev))
        $_mouse_dev = "device ", $_mouse_dev, " internaldriver"
      endif
      mouse { $$_mouse $$_mouse_dev $$_mouse_flags $$_mouse_baud }
    endif

  endif # end 'not guest'

  hogthreshold $_hogthreshold

  ## keyboard setting
  if ($BEING_ON ne "console") $_rawkeyboard = (off) endif
  if ($_layout eq "auto")
    keyboard { layout auto keybint $_keybint  rawkeyboard $_rawkeyboard }
  else
    if ( strstr($_layout, "load") <0 )
      # we use the builtin keytables
      if (strlen($_layout)) $_layout = "layout ",$_layout
      else $_layout = "layout us"  endif
      keyboard {  $$_layout  keybint $_keybint  rawkeyboard $_rawkeyboard }
    else
      # we have to load a keytable
      $yyy = ""
      foreach $xxx ($LIST_DELIM, $_layout)
        if ($xxx ne "load")
          $yyy = $xxx
        endif
      done
      if (!strlen($yyy))
        abort "no keytable name in $_layout"
      endif
      shell("test -f ", $DOSEMU_LIB_DIR, "/keymap/", $yyy)
      if ( $DOSEMU_SHELL_RETURN)
        abort "keytable ",$yyy, "not found in ", $DOSEMU_LIB_DIR, "/keymap/*"
      endif
      $_layout = 'include "keymap/', $yyy, '"' ;
      $$_layout
      keyboard { keybint $_keybint  rawkeyboard $_rawkeyboard }
    endif
  endif

  secure off
  $_disks = ""
  ifdef restricted
    ## /etc/dosemu.users defined 'restricted' for this login
    if (!strlen($_secure)) secure on endif
    define c_normal
    if (strchr($_secure,"d")>=0) dexe { secure } endif
    ifdef guest
      if (strchr($_secure,"g")>=0) secure on  endif
    else
      if (strchr($_secure,"n")>=0) secure on  endif
      $_disks = $_hdimage_r
    endif
    if (strchr($_secure,"0")>=0) secure off endif
    dpmi off
    speaker emulated
    ipxsupport off
    # printer { options "%s"  command "lpr"  timeout 20 }
  else
    ## /etc/dosemu.users does allow full access for this login
    dexe { allowdisk }
    $_disks = $_hdimage
    if (!strlen($_vbootfloppy))
      bootC                      # default boot mode is 'from C:'
    else
      bootA                      # default boot mode is 'from A:'
      $yyy = ""; $zzz = "";
      foreach $xxx ($LIST_DELIM, $_vbootfloppy)
        if (strlen($yyy))
          $zzz = $xxx
        else
          $yyy = $xxx
        endif
      done
      $_vbootfloppy = $DOSEMU_HDIMAGE_DIR, "/", $yyy
      bootdisk { heads 2  sectors 18  tracks 80 threeinch  file $_vbootfloppy }
      if (strlen($zzz))
        $_disks = $_hdimage
      endif
    endif
    if (strlen($_floppy_a))
      $zzz = strsplit($_floppy_a, strstr($_floppy_a, ":"), 999);
      if (strlen($zzz))
        $zzz = strsplit($zzz, 1, 999)
        $_floppy_a = strdel($_floppy_a, strstr($_floppy_a, ":"), 999);
      else
        $zzz = "/dev/fd0"
      endif
      $xxx = shell("test -r ", $zzz);
      if ($DOSEMU_SHELL_RETURN)
        warn "**** Warning: floppy ", $zzz, " not accessable, disabled";
      else
        floppy { device $$zzz $$_floppy_a }
      endif
    endif
    if (strlen($_floppy_b))
      $zzz = strsplit($_floppy_b, strstr($_floppy_b, ":"), 999);
      if (strlen($zzz))
        $zzz = strsplit($zzz, 1, 999)
        $_floppy_b = strdel($_floppy_b, strstr($_floppy_b, ":"), 999);
      else
        $zzz = "/dev/fd1"
      endif
      $xxx = shell("test -r ", $zzz);
      if ($DOSEMU_SHELL_RETURN)
        warn "**** Warning: floppy ", $zzz, " not accessable, disabled";
      else
        floppy { device $$zzz $$_floppy_b }
      endif
    endif

    # misc stuff
    dpmi $_dpmi
    if (strlen($_irqpassing))
      $yyy = "irqpassing { "
      foreach $xxx (" ", $_irqpassing)
        $yyy = $yyy, "use_sigio ", $xxx
      done
      $yyy = $yyy, " }";
      $$yyy
    else
      irqpassing off
    endif
    if (strlen($_hardware_ram))
      hardware_ram { $$_hardware_ram }
    endif
    if (strlen($_speaker))
      $_speaker = "speaker ", $_speaker;
      $$_speaker
    else
      speaker off
    endif
    ipxsupport $_ipxsupport
    if ($_novell_hack) pktdriver novell_hack  endif
    vnet $_vnet
    if (strlen($_printer))
      foreach $xxx ($LIST_DELIM, $_printer)
        $xxx = "'-P", $xxx, " %s'";
        printer { options $$xxx  command "lpr"  timeout $_printer_timeout }
      done
    endif
    if (strlen($_ports)) ports { $$_ports } endif
  endif

  ## setting up hdimages
  $_mounted_devices = ""
  if (strlen($_disks) && (!defined(c_dexerun)))
    $yyy = strsplit($_disks, 0, strpbrk($_disks, $LIST_DELIM) + 1)
    if ($DOSDRIVE_D ne "")
      $_disks = strcat($yyy, $_disks)
    endif
    if ($DOSTMP ne "")
      $_disks = strcat($yyy, $_disks)
    endif
    foreach $xxxx ($LIST_DELIM, $_disks)
      $xxx_pref = ""
      if ((strchr($xxxx, "*") + 1) && (strlen($xxxx) == strchr($xxxx, "*") + 1))
        $xxx_pref = strdel($xxxx, strlen($xxxx) - 1, 1);
        $xxxx = shell("cd '", $DOSEMU_HDIMAGE_DIR, "/", $xxx_pref, "' 2>/dev/null && echo -n *")
        if ($DOSEMU_SHELL_RETURN)
          $xxxx = strcat($xxx_pref, "*")
          $xxx_pref = ""
        endif
      endif
     foreach $xxx ($LIST_DELIM, $xxxx)
      $xxx = strcat($xxx_pref, $xxx)
      if (!strncmp($xxx, "/dev/", 4))
        if (!strlen($_mounted_devices))
            # we first get all mounted devices
          $_mounted_devices = shell(" df | awk '/\dev\//{print $1}' | tr '\n' ' '");
            # we try to get the swap device too
          $_mounted_devices = $_mounted_devices, shell("awk '!/^\#/ && /\/dev/ && /swap/{print $1}' /etc/fstab | tr '\n' ' '");
        endif
        $yyy = strdel($xxx, strstr($xxx, ":ro"), 999);
        $zzz = strsplit($xxx, strstr($xxx, ":ro"), 999);
        $yyyy = strcat($yyy, ' ');
        if (strstr($_mounted_devices, $yyyy) <0)
            # device not in use
          if (strlen($zzz))
            disk { partition $yyy readonly };
          else
            disk { partition $yyy };
          endif
        else
          abort "
*** device ", $yyy, " in use, cannot do partition access
"
        endif
      else
        $yyy = strdel($xxx, strstr($xxx, ":ro"), 999);
        $zzz = strsplit($xxx, strstr($xxx, ":ro"), 999);
        $yyy = $DOSEMU_HDIMAGE_DIR, "/", $yyy
        shell("test -d '", $yyy, "'")
        if (!$DOSEMU_SHELL_RETURN)
          if (strlen($zzz))
            disk { directory $yyy readonly };
          else
            disk { directory $yyy };
          endif
        else
          disk { image $yyy }
        endif
      endif
     done
    done
  endif

  ## setting up ASPI devices
  ifndef restricted
    if (strlen($_aspi))
      foreach $xxx ($LIST_DELIM, $_aspi)
        $zz = (1);
        $yy2 = ""; $yy3 = (-1);
        foreach $yyy (":", $xxx)
          $zzz = "$yy", $zz, " = $yyy";
          $zz = ($zz + 1);
          $$zzz
        done;
        aspi { $yy1 devicetype $yy2 target $yy3 };
      done
    endif
  endif

  ## setting up the features list
  if ( (  ($DOSEMU_VERSION_CODE >= ((98 << 16) | (3 << 8) | 3))
             && ($DOSEMU_VERSION_CODE < (99 << 16)) )
       || ($DOSEMU_VERSION_CODE > ((99 << 16) | (5 << 8))) )
    if (strlen($_features))
      foreach $xxx ($LIST_DELIM, $_features)
        $yyy = strdel($xxx, strstr($xxx, ":"), 999);
        $zzz = strsplit($xxx, strstr($xxx, ":"), 999);
        if (strlen($zzz))
          $zzz = strsplit($zzz, 1, 999);
        else
          $zzz = (0);
        endif
        feature { $yyy = $zzz };
      done
    endif
  endif

  # ... here we are and need disallow 'shell' any further
  # so we can restore PATH
  $PATH = $_DOSEMU_ORIG_PATH

  ## define the allowed classes for subsequent .dosrc and -I parsing
  ifdef restricted
    undef c_all
    ifdef guest
      undef c_normal
      define c_dexe
      define c_nice
      define c_x
    endif
  endif

endif
#############################################################################
