#!/bin/sh
#-*- tcl -*- \
PATH=/usr/bin:$PATH ;#\
exec tkdesksh "$0" "$@"

set tkdesk(library) "/usr/lib/TkDesk"
set tkdesk(in_development) 0
set tkdesk(debug) 0

#    TkDesk - a file manager for Unix and the X Window System
#    Copyright (C) 1996, 1997  Christian Bolik
#
#    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., 675 Mass Ave, Cambridge, MA 02139, USA.
#    See the file "COPYING" in the base directory of this distribution
#    for more.

#
# =============================================================================
#
#                           START FILE FOR TKDESK
#
# =============================================================================
#

wm withdraw .
wm group . .
wm command . "$argv0 $argv"

#
# ==== Init ===================================================================
#

set tkdesk(version) "1.0b5"
set tkdesk(date) "4.12.97"

global env
if ![info exists env(DISPLAY)] {
    puts ""
    puts "TkDesk requires the X Window System to run and the DISPLAY"
    puts "environment variable to be set.  If X is already running you"
    puts "can set the DISPLAY variable for instance like this:"
    puts ""
    puts "export DISPLAY=:0.0"
    puts ""
    exit 1
}

if [info exists env(TKDESK_LIBRARY)] {
    set tkdesk(library) $env(TKDESK_LIBRARY)
}

if ![file exists $tkdesk(library)] {
    puts ""
    puts "Can't find the TkDesk run-time library.  Please either edit"
    puts "the first lines of the tkdesk script to point to where you"
    puts "installed the library, or set the environment variable"
    puts "TKDESK_LIBRARY accordingly.  Also please check that the"
    puts "correct tkdesksh is being used by the script."
    puts ""
    exit 2
}

if {![info exists dskC_version] || $dskC_version != $tkdesk(version)} {
    puts ""
    puts "The tkdesk script seems to be using an older version of tkdesksh."
    puts "Please edit the third line of this script to point to the absolute"
    puts "path and file name of tkdesksh.  Both are usually located in the"
    puts "same directory."
    puts ""
    puts "An alternative is also to modify your PATH environment variable to"
    puts "list the directory where you installed Tkdesk $tkdesk(version) before"
    puts "the one that contains the older tkdesksh."
    puts ""
    puts "The easiest method is of course to simply delete the old tkdesksh."
    puts ""
    exit 3
}
   
# -------------------------------------------------------
# Following is the bitmap used by dsk_welcome:

set tkdesk(welcome_bm) {
#define tkdesk_width 253
#define tkdesk_height 66
static char tkdesk_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0xf8,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x1f,0x00,0x00,0xe0,0x00,0x00,0x00,
 0x00,0x00,0x00,0xc0,0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xff,0x0f,0x00,0x00,0xe0,0x00,
 0x00,0x00,0x00,0x00,0x00,0xc0,0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xff,0x0f,0x00,0x00,
 0xe0,0x00,0xfe,0xff,0xff,0xff,0xff,0x0f,0xfc,0x07,0x00,0x00,0x00,0xff,0xff,
 0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x0f,
 0x00,0x00,0xe0,0x00,0xfe,0xff,0xff,0xff,0xff,0x07,0xf0,0x07,0x00,0x00,0x00,
 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0xe0,0x0f,0x00,0x00,0xe0,0x00,0xfe,0xff,0xff,0xff,0xff,0x07,0xf0,0x03,0x00,
 0x00,0x00,0xff,0xff,0xff,0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0xe0,0x07,0x00,0x00,0xe0,0x00,0xff,0x00,0xfc,0x01,0xf8,0x07,0xf0,
 0x03,0x00,0x00,0x00,0xc0,0x3f,0x00,0xfc,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0xe0,0x07,0x00,0x00,0xe0,0x00,0x3f,0x00,0xfc,0x01,0xe0,
 0x07,0xf8,0x03,0x00,0x00,0x00,0xc0,0x1f,0x00,0xc0,0x3f,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0x00,0x0f,0x00,0xfc,
 0x01,0xc0,0x07,0xf8,0x03,0x00,0x00,0x00,0xc0,0x1f,0x00,0x00,0xff,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0x00,0x07,
 0x00,0xfe,0x00,0x80,0x03,0xf8,0x01,0x00,0x00,0x00,0xc0,0x1f,0x00,0x00,0xfe,
 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x03,0x00,0x00,0xe0,
 0x80,0x07,0x00,0xfe,0x00,0x80,0x03,0xf8,0x01,0x00,0x00,0x00,0xe0,0x1f,0x00,
 0x00,0xfc,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x03,0x00,
 0x00,0xe0,0x80,0x03,0x00,0xfe,0x00,0x80,0x03,0xfc,0x01,0x00,0x00,0x00,0xe0,
 0x0f,0x00,0x00,0xf8,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,
 0x03,0x00,0x00,0xe0,0x80,0x03,0x00,0xfe,0x00,0x80,0x03,0xfc,0x01,0x00,0x00,
 0x00,0xe0,0x0f,0x00,0x00,0xf0,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0xf8,0x03,0x00,0x00,0xe0,0x80,0x01,0x00,0xfe,0x00,0x80,0x01,0xfc,0x01,
 0x00,0x00,0x00,0xe0,0x0f,0x00,0x00,0xf0,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0xf8,0x03,0x00,0x00,0xe0,0x80,0x01,0x00,0x7f,0x00,0x80,0x01,
 0xfc,0x00,0x00,0x00,0x00,0xe0,0x0f,0x00,0x00,0xe0,0x0f,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0xf8,0x01,0x00,0x00,0xe0,0xc0,0x01,0x00,0x7f,0x00,
 0x80,0x01,0xfc,0x00,0x00,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0x0f,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x01,0x00,0x00,0xe0,0x00,0x00,0x00,
 0x7f,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0x1f,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x01,0x00,0x00,0xe0,0x00,
 0x00,0x00,0x7f,0x00,0x00,0x00,0xfe,0x00,0x80,0x0f,0x00,0xf0,0x07,0x00,0x00,
 0xc0,0x1f,0x00,0x00,0xf0,0x07,0x00,0x00,0x7f,0x00,0x00,0xfc,0x01,0x00,0x1f,
 0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x7e,0x00,0xe0,0x1f,0x00,0xf0,0x07,
 0x00,0x00,0xc0,0x1f,0x00,0x00,0xfe,0x3f,0x00,0xe0,0xff,0x03,0x00,0xfc,0x00,
 0xc0,0x3f,0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x7e,0x00,0xf0,0x3f,0x00,
 0xf8,0x07,0x00,0x00,0xc0,0x3f,0x00,0xc0,0xff,0x7f,0x00,0xf0,0xff,0x07,0x00,
 0xfc,0x00,0xe0,0x7f,0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x7f,0x00,0xfc,
 0x3f,0x00,0xf8,0x03,0x00,0x00,0xc0,0x3f,0x00,0xe0,0x07,0xff,0x00,0xf8,0xf0,
 0x0f,0x00,0xfe,0x00,0xf8,0x7f,0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x7f,
 0x00,0xfe,0x3f,0x00,0xf8,0x03,0x00,0x00,0xc0,0x3f,0x00,0xf8,0x01,0xfe,0x00,
 0x3c,0xe0,0x1f,0x00,0xfe,0x00,0xfc,0x7f,0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,
 0x00,0x3f,0x00,0xff,0x3f,0x00,0xf8,0x03,0x00,0x00,0xc0,0x3f,0x00,0xfc,0x00,
 0xfc,0x01,0x3e,0xc0,0x1f,0x00,0x7e,0x00,0xfe,0x7f,0xe0,0x00,0x00,0xc0,0x1f,
 0x00,0x00,0x00,0x3f,0x80,0xc7,0x1f,0x00,0xf8,0x03,0x00,0x00,0xc0,0x3f,0x00,
 0x7e,0x00,0xfc,0x01,0x1e,0x80,0x1f,0x00,0x7e,0x00,0x8f,0x3f,0xe0,0x00,0x00,
 0xc0,0x1f,0x00,0x00,0x80,0x3f,0xc0,0x01,0x0f,0x00,0xfc,0x01,0x00,0x00,0xc0,
 0x3f,0x00,0x3f,0x00,0xfc,0x01,0x1e,0x80,0x1f,0x00,0x7f,0x80,0x03,0x1e,0xe0,
 0x00,0x00,0xc0,0x1f,0x00,0x00,0x80,0x3f,0xe0,0x00,0x00,0x00,0xfc,0x01,0x00,
 0x00,0xc0,0x3f,0x80,0x1f,0x00,0xfc,0x01,0x1f,0x00,0x1f,0x00,0x7f,0xc0,0x01,
 0x00,0xe0,0x00,0x00,0xc0,0x1f,0x00,0x00,0x80,0x3f,0x70,0x00,0x00,0x00,0xfc,
 0x01,0x00,0x00,0xc0,0x3f,0xc0,0x1f,0x00,0xfc,0x01,0x1f,0x00,0x06,0x00,0x7f,
 0xe0,0x00,0x00,0xe0,0x00,0x00,0xe0,0x0f,0x00,0x00,0x80,0x1f,0x38,0x00,0x00,
 0x00,0xfc,0x01,0x00,0x00,0xc0,0x3f,0xc0,0x0f,0x00,0xfe,0x01,0x3f,0x00,0x00,
 0x00,0x3f,0x70,0x00,0x00,0xe0,0x00,0x00,0xe0,0x0f,0x00,0x00,0xc0,0x1f,0x1c,
 0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xc0,0x3f,0xe0,0x0f,0x00,0xfe,0x00,0x3f,
 0x00,0x00,0x80,0x3f,0x38,0x00,0x00,0xe0,0x00,0x00,0xe0,0x0f,0x00,0x00,0xc0,
 0x1f,0x0e,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xe0,0x3f,0xf0,0x07,0x00,0xff,
 0x00,0x7f,0x00,0x00,0x80,0x3f,0x1c,0x00,0x00,0xe0,0x00,0x00,0xe0,0x0f,0x00,
 0x00,0xc0,0x1f,0x07,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xe0,0x1f,0xf0,0x07,
 0x00,0x7f,0x00,0xff,0x00,0x00,0x80,0x3f,0x0e,0x00,0x00,0xe0,0x00,0x00,0xf0,
 0x07,0x00,0x00,0xc0,0x8f,0x03,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xe0,0x1f,
 0xf8,0x03,0x80,0x3f,0x00,0xff,0x01,0x00,0x80,0x1f,0x07,0x00,0x00,0xe0,0x00,
 0x00,0xf0,0x07,0x00,0x00,0xc0,0xcf,0x03,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
 0xe0,0x1f,0xf8,0x03,0xc0,0x1f,0x00,0xfe,0x03,0x00,0x80,0x9f,0x07,0x00,0x00,
 0xe0,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0xef,0x07,0x00,0x00,0x00,0x7f,0x00,
 0x00,0x00,0xf0,0x1f,0xf8,0x03,0xf0,0x0f,0x00,0xfe,0x07,0x00,0xc0,0xdf,0x0f,
 0x00,0x00,0xe0,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0xef,0x07,0x00,0x00,0x00,
 0x7f,0x00,0x00,0x00,0xf0,0x0f,0xfc,0x01,0xf8,0x03,0x00,0xfc,0x0f,0x00,0xc0,
 0xdf,0x0f,0x00,0x00,0xe0,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0xf7,0x07,0x00,
 0x00,0x00,0x7f,0x00,0x00,0x00,0xf0,0x0f,0xfc,0x01,0xfe,0x01,0x00,0xf8,0x1f,
 0x00,0xc0,0xef,0x0f,0x00,0x00,0xe0,0x00,0x00,0xf8,0x03,0x00,0x00,0xe0,0xe7,
 0x0f,0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0xf8,0x0f,0xfc,0xc1,0x3f,0x00,0x00,
 0xf0,0x3f,0x00,0xc0,0xcf,0x1f,0x00,0x00,0xe0,0x00,0x00,0xf8,0x03,0x00,0x00,
 0xf0,0xe7,0x0f,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0xf8,0x07,0xfc,0xf9,0x0f,
 0x00,0x00,0xe0,0x7f,0x00,0xe0,0xcf,0x1f,0x00,0x00,0xe0,0x00,0x00,0xf8,0x03,
 0x00,0x00,0xf0,0xe7,0x0f,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0xfc,0x07,0xfe,
 0xff,0x01,0x00,0x00,0xc0,0x7f,0x00,0xe0,0xcf,0x1f,0x00,0x00,0xe0,0x00,0x00,
 0xf8,0x03,0x00,0x00,0xf0,0xc7,0x1f,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0xfc,
 0x03,0xfe,0x1f,0x00,0x00,0x00,0x80,0xff,0x00,0xe0,0x8f,0x3f,0x00,0x00,0xe0,
 0x00,0x00,0xfc,0x01,0x00,0x00,0xf0,0xc3,0x1f,0x00,0x00,0x80,0x3f,0x00,0x00,
 0x00,0xfe,0x03,0xfe,0x01,0x00,0x00,0x00,0x00,0xff,0x00,0xe0,0x87,0x3f,0x00,
 0x00,0xe0,0x00,0x00,0xfc,0x01,0x00,0x00,0xf8,0xc3,0x1f,0x00,0x00,0xc0,0x3f,
 0x00,0x00,0x00,0xfe,0x01,0xfe,0x00,0x00,0x00,0x00,0x00,0xfe,0x01,0xf0,0x87,
 0x3f,0x00,0x00,0xe0,0x00,0x00,0xfc,0x01,0x00,0x00,0xf8,0x83,0x3f,0x00,0x00,
 0xc0,0x1f,0x00,0x00,0x00,0xff,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0xfc,0x01,
 0xf0,0x07,0x7f,0x00,0x00,0xe0,0x00,0x00,0xfc,0x01,0x00,0x00,0xf8,0x83,0x3f,
 0x00,0x00,0xc0,0x1f,0x00,0x00,0x80,0xff,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,
 0xfc,0x01,0xf0,0x07,0x7f,0x00,0x00,0xe0,0x00,0x00,0xfc,0x01,0x00,0x00,0xf8,
 0x01,0x7f,0x00,0x00,0xc0,0x1f,0x00,0x00,0xc0,0x7f,0x00,0xfe,0x00,0x00,0x18,
 0x00,0x00,0xfc,0x01,0xf0,0x03,0xfe,0x00,0x00,0xe0,0x00,0x00,0xfe,0x00,0x00,
 0x00,0xfc,0x01,0x7f,0x00,0x06,0xe0,0x1f,0x00,0x00,0xc0,0x3f,0x00,0xfe,0x00,
 0x00,0x1c,0x78,0x00,0xf8,0x01,0xf8,0x03,0xfe,0x00,0x0c,0xe0,0x00,0x00,0xfe,
 0x00,0x00,0x00,0xfc,0x01,0xff,0x00,0x06,0xe0,0x0f,0x00,0x00,0xf0,0x1f,0x00,
 0xfe,0x01,0x00,0x1e,0x7c,0x00,0xf8,0x01,0xf8,0x03,0xfe,0x01,0x0c,0xe0,0x00,
 0x00,0xfe,0x00,0x00,0x00,0xfc,0x01,0xfe,0x00,0x07,0xe0,0x0f,0x00,0x00,0xf8,
 0x0f,0x00,0xfe,0x01,0x00,0x0e,0x7e,0x00,0xf8,0x01,0xf8,0x03,0xfc,0x01,0x0e,
 0xe0,0x00,0x00,0xfe,0x00,0x00,0x00,0xfc,0x00,0xfe,0x01,0x03,0xe0,0x0f,0x00,
 0x00,0xfc,0x07,0x00,0xfc,0x01,0x80,0x07,0xfe,0x00,0xf8,0x00,0xf8,0x01,0xfc,
 0x03,0x06,0xe0,0x00,0x00,0x7f,0x00,0x00,0x00,0xfc,0x00,0xfc,0x81,0x03,0xe0,
 0x0f,0x00,0x00,0xff,0x01,0x00,0xfc,0x03,0xc0,0x03,0xfe,0x00,0xf8,0x00,0xf8,
 0x01,0xf8,0x03,0x07,0xe0,0x00,0x00,0x7f,0x00,0x00,0x00,0xfe,0x00,0xfc,0xc3,
 0x01,0xf0,0x0f,0x00,0xe0,0xff,0x00,0x00,0xfc,0x07,0xe0,0x01,0xfe,0x01,0x7c,
 0x00,0xfc,0x01,0xf8,0x87,0x03,0xe0,0x00,0x80,0xff,0x00,0x00,0x00,0xfe,0x00,
 0xf8,0xe7,0x00,0xf0,0x1f,0x00,0xfe,0x3f,0x00,0x00,0xf8,0x0f,0xfc,0x00,0xfc,
 0x03,0x7c,0x00,0xfc,0x01,0xf0,0xcf,0x01,0xe0,0x00,0xe0,0xff,0x03,0x00,0x00,
 0xfe,0x00,0xf8,0xff,0xe0,0xff,0xff,0xff,0xff,0x07,0x00,0x00,0xf0,0xff,0x7f,
 0x00,0xf8,0x0f,0x3e,0x00,0xfc,0x01,0xf0,0xff,0x01,0xe0,0x00,0xff,0xff,0x7f,
 0x00,0x00,0x7e,0x00,0xf0,0x7f,0xe0,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xe0,
 0xff,0x1f,0x00,0xf0,0xff,0x1f,0x00,0xfc,0x00,0xe0,0xff,0x00,0xe0,0x00,0xff,
 0xff,0x7f,0x00,0x00,0x7f,0x00,0xe0,0x3f,0xe0,0xff,0xff,0xff,0x07,0x00,0x00,
 0x00,0xc0,0xff,0x07,0x00,0xe0,0xff,0x07,0x00,0xfe,0x00,0xc0,0x7f,0x00,0xe0,
 0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x80,0x0f,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xff,0x00,0x00,0x1e,0x00,0x00,0x1f,
 0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0};
}

#
# -----------------------------------------------------------------------------
#
# Proc:    dsk_welcome
# Desc:    Shows an informational "welcome" window when starting up.
# In:      cmd: "show" or "hide"
# Out:     ""
# Side FX: none
#

proc dsk_welcome {cmd} {
    global tkdesk

    #set bgcol gray
    set bgcol gray82
    set t .dsk_welcome

    if {$cmd == "hide"} {
	catch "destroy $t"
	return ""
    }
    
    toplevel $t -bg $bgcol
    wm withdraw $t
    wm group $t .
    wm command $t
    
    frame $t.f -bd 2 -relief raised -bg $bgcol
    pack $t.f

    frame $t.f1 -bd 2 -relief groove -bg $bgcol
    pack $t.f1 -in $t.f -padx 8 -pady 8

    label $t.lLabel -text "Welcome to..." -anchor center -fg black -bg $bgcol
    catch {$t.lLabel config -font -*-helvetica-medium-r-*-*-14-*}
    pack $t.lLabel -in $t.f1 -padx 8 -pady 8 -fill x -expand yes

    image create bitmap welcome_bm -data $tkdesk(welcome_bm) -foreground blue3
    label $t.lTkDesk -image welcome_bm -bg $bgcol
    pack $t.lTkDesk -in $t.f1 -padx 6 -pady 2 -fill x -expand yes

    message $t.lVersion -text "Version $tkdesk(version), dated $tkdesk(date)\nCopyright (C) 1996, 1997 Christian Bolik\n\nTkDesk comes with ABSOLUTELY NO WARRANTY.\nSee menu entry Help/License for details." \
	    -bg $bgcol -fg black \
	    -aspect 1000 -justify center
    catch {$t.lVersion config -font -*-helvetica-medium-r-*-*-14-*}
    pack $t.lVersion -in $t.f1 -padx 8 -pady 8 -fill x -expand yes

    if $tkdesk(in_development) {
	label $t.lDevel -text "...in Development..." \
		-bg $bgcol -fg black
	catch {$t.lDevel config -font -*-helvetica-bold-o-*-*-14-*}
	pack $t.lDevel -in $t.f1 -padx 8 -pady 8 -fill x -expand yes
    }

    frame $t.f2 -bd 2 -relief groove -bg $bgcol
    pack $t.f2 -in $t.f -fill x -padx 8 -pady 8
    
    label $t.lProgress -text "Loading..." -anchor w \
	    -bg $bgcol -fg black -width 25
    pack $t.lProgress -in $t.f2 -fill x -anchor w -padx 8

    update idletasks
    set x [expr [winfo screenwidth $t]/2 - [winfo reqwidth $t]/2 \
	    - [winfo vrootx [winfo parent $t]]]
    set y [expr [winfo screenheight $t]/2 - [winfo reqheight $t]/2 \
	    - [winfo vrooty [winfo parent $t]]]
    wm geom $t +$x+$y
    wm title $t "Starting..."
    wm deiconify $t
    update

    return ""
}

proc dsk_progress {string} {
    if ![winfo exists .dsk_welcome] return
    
    .dsk_welcome.lProgress config -text $string
    update idletasks
}

set tkdesk(error_source) ""
proc tkerror {err} {
    global tkdesk errorCode errorInfo tk_patchLevel tcl_patchLevel

    set code $errorCode
    set info $errorInfo
    
    if [winfo exists .dsk_tkerror] return
    
    cd ~
    dsk_lazy "" 1
    dsk_sound dsk_bug
    
    if {$tkdesk(error_source) == ""} {
	set ans [tk_dialog [toplevel .dsk_tkerror] \
		"Oh no, an error!" \
		"Sorry, but you have just found an error in TkDesk. You can ignore it or choose one of the actions below." \
		@$tkdesk(library)/images/xbm/bomb.xbm \
		0 " Ignore " " Inspect " " Mail Author "]
    } else {
	set ans [tk_dialog [toplevel .dsk_tkerror] \
		"Configuration Error" \
		"Error while executing action from \"$tkdesk(error_source)\":\n$err" \
		error 0 "   OK   " " Inspect "]
	set tkdesk(error_source) ""
    }

    switch $ans {
	1 {dsk_editor string "Error: $err\n\nerrorCode: $code\n\nerrorInfo: $info"}
	2 {
	    set subject "Error in TkDesk $tkdesk(version)"
	    set msg "What did you try to do when this bug occured:\n"
	    append msg "\n\n-----------------------------------------------"
	    append msg "\nError in TkDesk $tkdesk(version), using "
	    append msg "Tcl [set tcl_patchLevel] and "
	    append msg "Tk [set tk_patchLevel].\nPlatform: "
	    catch {append msg "[exec uname -a]\n"}
	    append msg "\n"
	    append msg "Error: $err\n"
	    append msg "errorCode: $code\n"
	    append msg "errorInfo: $info"

	    dsk_mailbug $subject $msg
	}
    }
    
    return ""
}

proc dsk_mailbug {subject msg} {
    global tkdesk dsk_mailbug

    catch {destroy .dsk_mailbug}
    toplevel [set t .dsk_mailbug]
    wm withdraw $t

    frame $t.f1 -bd 1 -relief raised
    pack $t.f1 -fill x
    label $t.ls -text "Subject:"
    pack $t.ls -in $t.f1 -side left -padx 4 -pady 4
    entry $t.es -width 10 -bd 2 -relief sunken
    $t.es insert end $subject
    pack $t.es -in $t.f1 -side left -fill x -expand yes \
	    -padx 4 -pady 4 -ipady 2

    frame $t.f2 -bd 1 -relief raised
    pack $t.f2 -fill both -expand yes
    frame $t.f2a
    pack $t.f2a -in $t.f2 -fill both -expand yes -padx 4 -pady 4
    text $t.tm -width 10 -height 4 -bd 2 -relief sunken -setgrid 1 \
	    -yscroll "$t.sb set"
    $t.tm insert end "$msg"
    $t.tm mark set insert 2.0
    pack $t.tm -in $t.f2a -side left -fill both -expand yes
    scrollbar $t.sb -orient vertical -command "$t.tm yview"
    pack $t.sb -in $t.f2a -side left -fill y

    frame $t.f3 -bd 1 -relief raised
    pack $t.f3 -fill x
    button $t.bc -text "Cancel" \
	    -command "set dsk_mailbug(mail) 0"
    button $t.bm -text "Send Mail to $tkdesk(authormail)" \
	    -command "set dsk_mailbug(mail) 1"
    pack $t.bc $t.bm -in $t.f3 -side left -padx 4 -pady 4 -ipady 1

    wm protocol $t WM_DELETE_WINDOW "set dsk_mailbug(mail) 0"
    if {$msg != ""} {
	wm title $t "Mail Bug Report to Author"
    } else {
	wm title $t "Send Mail to Author"
    }
    wm geometry $t 38x15
    cb_centerToplevel $t
    wm deiconify $t

    focus $t.tm
    grab $t
    set dsk_mailbug(mail) ""
    tkwait variable dsk_mailbug(mail)

    if $dsk_mailbug(mail) {
	catch {set fd [open "|mail -s \"$subject\" $tkdesk(authormail)" w]} em
	if ![info exists fd] {
	    catch {set fd [open "|mail $tkdesk(authormail)" w]} em
	}
	if ![info exists fd] {
	    cb_error "Couldn't execute: mail $tkdesk(authormail). Please send your bug report manually."
	    tkwait variable dsk_mailbug(mail)
	} else {
	    set msg [$t.tm get 1.0 end]
	    puts -nonewline $fd $msg
	    close $fd
	}
    }
    destroy $t
}

#
# -----------------------------------------------------------------------------
#

if ![info exists tkdesk(library)] {
    set tkdesk(library) "./tcldesk"
}
if {$tkdesk(library) == "./tcldesk"} {
    # need an absolute library path
    set tkdesk(library) [pwd]/tcldesk
}

# See if the user just wants to learn TkDesk's command line arguments:
if {$argv == "-?" || $argv == "--help"} {
    puts -nonewline \
"TkDesk - A Graphical Desktop and File Manager for UNIX and X11
Version $tkdesk(version), dated $tkdesk(date)
Copyright (C) 1996, 1997 Christian Bolik

Usage: tkdesk \[options\]

Options may be any combination of the following:

    -configdir <dir>       Read user configuration from <dir>.
    -debug                 Enable so-called debug mode.
    -default               Use default user configuration found in:
                           $tkdesk(library)/configs
    -develop               Enable development mode.
    -iconic                Iconify all windows of TkDesk on start-up.
    -startdir <dir>        Display <dir> in first file browser.
    -twm                   Disable use of colored icon windows.
"
exit 0
}

dsk_welcome show

# "Uglify" ;-) namespaced BLT:
if {[info command bgexec] != ""} {
    rename bgexec blt_bgexec
}
if {[info command busy] != ""} {
    rename busy blt_busy
}
if {[info command drag&drop] != ""} {
    # this must be handled differently due to internal bindings:
    proc blt_drag&drop {args} {
	eval drag&drop $args
    }
}


#
# Init cb_tools
#

dsk_progress "Initializing cb_tools..."
set cb_tools(path) "$tkdesk(library)/cb_tools"
source $cb_tools(path)/tools.tcl
cb_tools_init $cb_tools(path)

#cb_debug trace wm
#cb_debug trace update
#cb_debug trace cb_image

#
# Init tcldesk
#

if {[info command grab-orig] == ""} {
    rename grab grab-orig
    proc grab {args} {
	set ret ""
	catch {set ret [eval grab-orig $args]}
	return $ret
    }
}

if {[info command itcl_class-orig] == ""} {
    rename itcl_class itcl_class-orig
    proc itcl_class {name def} {
	catch {rename $name {}}
	uplevel 1 itcl_class-orig $name [list $def]
    }
}

# Give options set in tk_setPalette higher priority (to override weird
# CDE resources, for instance):
catch {tk_setPalette}
if [regsub {widgetDefault} [info body tk_setPalette] {interactive} nb] {
    proc tk_setPalette [info args tk_setPalette] $nb
    unset nb
}

dsk_progress "Initializing tcldesk..."
foreach c [itcl_info classes dsk_*] {
    catch {rename $c {}}
}
# use lsort to have a defined sequence of files sourced:
#foreach f [lsort [glob $tkdesk(library)/*.tcl]] {
#    #puts $f
#    source $f
#}
if {[info tclversion] < 8.0} {
    source $tkdesk(library)/tkpatches.tcl
}
set auto_path "$tkdesk(library) $auto_path"
    
if $tkdesk(in_development) {
    blt_drag&drop errors tkerror
} else {
    blt_drag&drop errors ""
}

#
# ====  Set misc. global variables ============================================
#

set tkdesk(authormail) "Christian.Bolik@mainz.netsurf.de"
set tkdesk(startdir) [pwd]
set tkdesk(initdir) $tkdesk(startdir)
set tkdesk(menu,control) 0	;# used to track <control> in menu invocations
set tkdesk(file_lb,control) 0	;# used to track <control> in file LBs
set tkdesk(active_viewer) ""	;# contains name of window last entered
set tkdesk(button_bar) ""	;# list for the button bar
set tkdesk(xmaster) 0		;# X "master" app
set tkdesk(status) lazy         ;# busy or lazy
set tkdesk(_dd_x) 0
set tkdesk(_dd_y) 0
set tkdesk_filelb_cmd ""
set tkdesk(systype) ""
catch {set tkdesk(systype) [exec uname]}
set tkdesk(_max_menu_entries) [expr [winfo screenheight .] / 21]

set tkPriv(x) 0
set tkPriv(y) 0

# use icon windows by default
set tkdesk(fvwm) 1

# Overwrite cb_tools' busy and lazy commands:
set cb_tools(busy_cmd) dsk_busy
set cb_tools(lazy_cmd) dsk_lazy

# cd to user's home dir cause this is unlikely to be moved/deleted
cd $env(HOME)

#
# ==== Process command line arguments =========================================
#

dsk_busy
dsk_progress "Processing command line options..."
dsk_debug "Processing cmdline arguments"
set tkdesk(iconic) 0
if {$argc > 0} {
    for {set i 0} {$i < [llength $argv]} {incr i} {
	set o [lindex $argv $i]
	switch -glob -- $o {
	    -conf* {
		incr i
		set tkdesk(configdir) [lindex $argv $i]
		if {[string index $tkdesk(configdir) 0] != "/" && \
		    [string index $tkdesk(configdir) 0] != "~"} {
		    set tkdesk(configdir) $tkdesk(startdir)/$tkdesk(configdir)
		}
	    }
	    -deb* {
		set tkdesk(debug) 1
		dsk_debug "Debugging enabled (hopefully :-))"
	    }
	    -def* {
		set tkdesk(configdir) $tkdesk(library)/configs
		dsk_debug "Reading default configuration."
	    }
	    -dev* {
		set tkdesk(in_development) 1
		dsk_debug "Development mode."
	    }
	    -fvwm {
		set tkdesk(fvwm) 1
		dsk_debug "Fvwm mode forced."
	    }
	    -ic* {
		set tkdesk(iconic) 1
		dsk_debug "Iconic startup."
	    }
	    -sta* {
		incr i
		set tkdesk(user,startdir) [lindex $argv $i]
	    }
	    -twm {
		set tkdesk(fvwm) 0
		dsk_debug "Fvwm mode switched off."
	    }
	    -xm* {
		set tkdesk(xmaster) 1
	    }
	    default {
		if {[string index $o 0] == "-"} {
		    puts "Don't know what $o means. Proceding anyway."
		} else {
		    set tkdesk(initdir) $o
		    dsk_debug " tkdesk(initdir) = $tkdesk(initdir)"
		}
	    }
	}
    }
}

#
# ==== Read config files: =====================================================
#

dsk_progress "Reading configuration..."
dsk_read_config

if {[winfo depth .] == 1} {
    set tkdesk(append_type_char) 1
    dsk_FileListbox :: typechar $tkdesk(append_type_char)
}

#
# ==== Start-up ===============================================================
#

dsk_debug "Now starting up"
if ![info exists tkdesk(restarted)] {
    dsk_sound dsk_welcome_begin
}

#
# ---- Enable history management:
#
dsk_progress "Enabling history..."
# path history:
dsk_history history -size $tkdesk(history_size)
# interactive command history:
dsk_history cmd_history -size $tkdesk(history_size)
# periodic execution history
dsk_history pcmd_history -size $tkdesk(history_size) \
	-callback dsk_periodic_cb
# hypersearch history:
dsk_history hsearch_history -size $tkdesk(history_size) \
	-callback dsk_editor_hsearch_cb
# opened file history:
dsk_history file_history -size $tkdesk(history_size) \
	-command "dsk_open .fv0"
# executed commands history:
dsk_history exec_history -size $tkdesk(history_size) \
	-command "eval dsk_exec"
# read strings history:
dsk_history string_history -size $tkdesk(history_size)
# print command history:
dsk_history printer_history -size $tkdesk(history_size)
# file mask history:
dsk_history mask_history -size $tkdesk(history_size)
# "execute here" history:
dsk_history xhere_history -size $tkdesk(history_size)
# mail history:
dsk_history mail_history -size $tkdesk(history_size)
# search history:
dsk_history search_history -size $tkdesk(history_size)
# replace history:
dsk_history replace_history -size $tkdesk(history_size)

set histlist {history cmd_history pcmd_history hsearch_history \
	file_history exec_history string_history printer_history \
        mask_history xhere_history mail_history search_history \
        replace_history}
set hi 0

if [info exists tkdesk(history_list)] {
    set hlist [lindex $histlist 0]
    set i 0
    foreach h $tkdesk(history_list) {
	if {[string index [lindex $h 0] 0] != "#"} {
	    $hlist add $h
	} elseif {$i > 0} {
	    incr hi
	    set hlist [lindex $histlist $hi]
	}
	incr i
    }
}

set tkdesk(histlist) $histlist
unset histlist hi

#
# ---- Possibly restore the window layout of the last session:
#
dsk_progress "Restoring layout..."
dsk_restore_layout

#
# ---- Open the initial file viewer window:
#

if {![info exists tkdesk(layout)] || !$tkdesk(have_window)} {
    # disable at_pointer placement for initial window:
    set ap $tkdesk(at_pointer)
    set tkdesk(at_pointer) 0
    
    dsk_progress "Creating a file browser..."
    set dir [history get]
    if {$dir != ""} {
	set dir [lindex $dir end]
    } else {
	if [info exists tkdesk(user,startdir)] {
	    set dir $tkdesk(user,startdir)
	} else {
	    set dir $tkdesk(initdir)
	}
    }
    set tkdesk(geometry,fbrowser) \
	    $tkdesk(file_lb,width)x$tkdesk(file_lb,height)+100+50
    dsk_FileViewer .fv[dsk_FileViewer :: id] \
	    -dir $dir -num_lbs $tkdesk(num_lbs)
    set tkdesk(geometry,fbrowser) ""

    # create the Trash window:
    #set twin .dfl[dsk_FileList :: id]
    #dsk_progress "Creating the trash window..."
    #dsk_FileList $twin -dir $tkdesk(configdir)/.trash -dontmap 1
    #update
    #wm iconify $twin
    #unset twin

    # and the app bar
    dsk_progress "Creating the Application Bar..."
    dsk_appbar

    set tkdesk(at_pointer) $ap
}

if ![info exists tkdesk(restarted)] {
    #
    # ---- Start the periodic update of the file listboxes:
    #
    dsk_progress "Starting background procs..."
    after [expr $tkdesk(update,file_lists) * 1000] dsk_update_flbs

    # ... and the periodic config-save:
    if !$tkdesk(xmaster) {
	after [expr $tkdesk(update,config) * 60000] dsk_persave_config
    }
}

dsk_progress "Ready."
if ![info exists tkdesk(restarted)] {
    dsk_sound dsk_welcome_end
}
dsk_welcome hide
dsk_lazy

if [info exists tkdesk(first_time_user)] {
    dsk_help quick
}

if [info exists tkdesk(after_startup)] {
    set tkdesk(error_source) "System"
    eval $tkdesk(after_startup)
    set tkdesk(error_source) ""
}

#
# ==== Misc. Procs ============================================================
#

#
# -----------------------------------------------------------------------------
#
# Proc:		dsk_exit
# Args:		ask	(opt.) set to 1 if it should ask by all means
# Returns: 	""
# Desc:		Exits TkDesk.
# Side-FX:	May lead to the termination of tkdesk.
#

proc dsk_exit {{ask 0}} {
    global tkdesk

    if {($tkdesk(ask_on_exit) && !$tkdesk(in_development)) || $ask} {
	if !$tkdesk(xmaster) {
	    set msg "Are you sure you want to exit TkDesk?"
	} else {
	    set msg "This will end your X Session! Is this o.k.?"
	}
    	if {[cb_yesno $msg] != 0} {
	    return
	}
    }

    foreach obj [itcl_info objects -class dsk_Editor] {
	if [winfo exists $obj] {
	    if {[$obj close_win] == "cancel"} {
		return
	    }
	}
    }
    if [info exists tkdesk(at_exit)] {
	set tkdesk(error_source) "System"
	eval $tkdesk(at_exit)
	set tkdesk(error_source) ""
    }
    dsk_sound dsk_quit_tkdesk
    dsk_save_config
    catch {dsk_shutdown_server}
    exit 0
}

#
# -----------------------------------------------------------------------------
#
# Proc:		dsk_restart
# Args:		-
# Returns: 	""
# Desc:		Restarts TkDesk.
# Side-FX:	none
#

proc dsk_restart {} {
   global argv0 tkdesk

    dsk_save_config

    # clean up
    cb_image !reset
    foreach obj [itcl_info objects -class dsk_Editor] {
	if {[$obj close_win] == "cancel"} {
	    return
	}
    }
    catch {eval itcl_unload [itcl_info classes]}
    foreach w [winfo children .] {destroy $w}

    # and now restart
    set tkdesk(restarted) 1
    uplevel #0 "cd $tkdesk(startdir)"
    uplevel #0 "source $argv0"
}

# -----------------------------------------------------------------------------
# _dsk_server_connect:
# Gets invoked when a client connects to our server port.
#
