#!/bin/sh
# the next line restarts using wish\
exec wish "$0" "$@"
# TigerGraphics TRAFFIC Version 1.0 Copyright(C) 2026 Cora Kohlmeier, Frank Hamberg

# 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 3 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, see <http://www.gnu.org/licenses/>.

global GUI
global pwd
global home
global allbuts log pady
global colorscheme
global lfont sfont
global command
global c2
global editor
global traffichome
global toolflag
global trafficversion init
global workdir
global DOS 
set trafficversion 1.0
set GUI 1
set compile 1

# Environment ermitteln
set home $env(HOME)

# so ist es für Linuxe und MacOS
set DOS 0
set traffichome [file dir [info script]]
# Betriebssystem ermitteln
set arch [lindex $tcl_platform(os) 0]

# Settings für Windows
if {[string match Windows* $arch]==1} {
	set DOS 1
}
# Settings für MacOS
if {[string match Darwin* $arch]==1} {
	set DOS 2
# auf MacOS Mojave prüfen	
	if {[string match 18* [lindex $tcl_platform(osVersion) 0]]} {set DOS 3}
}

# Arbeitsverzeichnis festlegen
if {$DOS==1} {
	set workdir $home/traffic
	set traffichome .
} else {
	set workdir $home/.local/traffic
}
# Arbeitsverzeichnis anlegen -- ist unschädlich falls es schon existiert
file mkdir $workdir
# Grundeinstellungen sicherstellen
if ![file exist $workdir/.trafficdefaults] {
	file copy -force $traffichome/trafficdefaults $workdir/.trafficdefaults
}

set toolflag trafficgui

set dirlist "util travizutil"
foreach item $dirlist {
  if {$compile==1} {auto_mkindex $traffichome/$item *.tcl}
  lappend autopath $traffichome/$item
  set dir $traffichome/$item
  set unit [open $traffichome/$item/tclIndex]
  eval [read $unit]
  close $unit
}

set init 1
readdefaultchanges
main
# Für Windows
if {$DOS==1} {console hide}
