############################################################################################### # File: autoexec.tcl # Author: M Shaw # Purpose: Autoexec startup test file # Language: Ticol Tcl v1.19..v1.26+ # # Versions: # 1.00 09/Jun/2015 First version (autoexec.tcl implemented) # 1.01 09/Dec/2015 Slight modifications # 1.02 15/Mar/2016 Banner changes # 1.03 26/Sep/2016 Remove -nonewline from rainbow call # 1.05 19/Jan/2017 Add scrolling regions # 1.05 23/Jan/2017 Add threading info # 1.06 26/Jan/2017 Add every-clock for multi-threaded version # 1.07 28/Jan/2017 Improve code for threading with [after] # 1.08 06/Jul/2017 Remove [lmap] proc def now a native command, show free/total memory # 1.09 23/Dec/2017 Added optional calendar using calendar.tcl # 1.10 01/Aug/2018 Unset logo -const on exit # 1.11 29/Jul/2019 Change [eval file] to [source file] # 1.12 22/Aug/2019 Change title block layout # 1.13 09/Oct/2019 Removed $logo() var usage now we have the [logo] command # 1.14 22/Feb/2021 Update calendar loading # 1.15 15/May/2023 Minor updates ############################################################################################### # Notes: # NOTE: option expression is ON in this script. Commands in [if] etc. must be wrapped in [] # NOTE autoexec.tcl must NOT be encrypted/obfuscated (for the most obvious reasons) # NOTE Encryption of autoexec.tcl is unsupported by design ############################################################################################### option expression push on halt unset ONE_GIGABYTE ONE_MEGABYTE -const -nocomplain const ONE_GIGABYTE 1073741824.0 const ONE_MEGABYTE 1048576.0 set cursor_yloc 0 #set sw [console width] # Requires that we can buffer and crop the text also set sw 80 set y 2 set done $false # Ensure we can found our own components... set working_path [addslash [file dirname [info executablename]]] # Uses EXENAME #set working_path [addslash [file dirname [array item argv 0 -nocomplain]]] # Uses Script name #set working_path [file dirname [info script]] #puts "[info script] is Working in $working_path [info scriptpath] argv0 [array item argv 0]" ############################################################################################### undef rainbow -nocomplain if { ! [defined rainbow] } { proc rainbow {s} { # Port to a built-in command with CRLF handling? set q [split $s ""] # FIX Split not passing \n set i [rndseq 6 15] # Changed from [rnd] to [rndseq] 09/Oct/2019 foreach x $q { # Not passing \n textcolor $i # if {[eq $x {}] } { # OK # puts " " -nonewline # } elseif { [asc $x] == 10 } { # \n is 0x0a # newline # } else { puts $x -nonewline # } ++ i if {$i > 15} { set i 9 } # Reset colour } textcolor } } else { puts "Error: proc \[rainbow\] already defined" stop } ############################################################################################### # FIX cannot see globals/level -1 if { ! [defined scroll_titles] } { proc scroll_titles {cursor_yloc} { #vars * -level 0 #option echo on #upvar cursor_yloc #puts "cursor_yloc is '$cursor_yloc'" option expression push off draw_logo blue $cursor_yloc sleep 1000 /* for {set i 5} {> $i 0} {-- i} { console scroll 4 2 20 5 -1 sleep 50 } sleep 1000 # */ for {set i 0} {< $i 5} {++ i} { console scroll 26 3 50 4 sleep 50 } #gotoxy 3 2 /* sleep 200 for {set i 20} {> $i 0} {-- i} { console scroll 1 1 80 20 -1 sleep 50 } gotoxy 1 1 # */ set x 26 gotoxy $x 3 puts "For help, type:\t\thelp help" gotoxy $x 4 puts "To search topics type:\t\tfind topic" gotoxy $x 5 puts "To run as script type:\t\trun scriptname" gotoxy $x 6 puts "To show option settings type:\toption" #puts "For the FAQ type:\t\thelp faq" # Dummy console prompt ##################################### set s "[info username]@[info hostname] [info cmdcount]>" gotoxy 1 $cursor_yloc puts "$s " -nonewline gotoxy [+ [string length $s] 2] $cursor_yloc option expression pop } } if { ! [defined draw_logo] } { proc draw_logo {colour cursor_yloc} { logo $colour - 3 2 -shade red # Dummy console prompt ##################################### set s "[info username]@[info hostname] [info cmdcount]>" gotoxy 1 $cursor_yloc puts "$s " -nonewline gotoxy [+ [string length $s] 2] $cursor_yloc set ::done $::true } } cls textcolor yellow gotoxy 3 $y logo -shade darkyellow # Logo is now built-in ############################################################################################### textcolor incr y ###################################### # Describe the product # ###################################### set x 26 set y 2 # Tcl version and copyright info gotoxy $x [incr y] textcolor cyan rainbow "Ticol " textcolor puts "Tcl v[info tclversion] Copyright (C) M Shaw 2010-[date -year]" -nonewline # Build date info gotoxy $x [incr y] puts "Build date: $tcl_date" # Windows version #gotoxy 3 [incr y] gotoxy $x [incr y] puts "[info winver]" -nonewline gotoxy $x [incr y] set mem_total [info memtotal] if {< $mem_total $ONE_GIGABYTE} { puts "[comma [round [/ [info memavail] $ONE_MEGABYTE] 1]]Mb of [comma [round [/ $mem_total $ONE_MEGABYTE] 1]]Mb available memory ([info mempercentfree]% free)" -nonewline } else { puts "[comma [/ [info memavail] $ONE_GIGABYTE]] Gb of [comma [/ $mem_total $ONE_GIGABYTE]] Gb available memory ([info mempercentfree]% free)" -nonewline } unset mem_total ONE_GIGABYTE ONE_MEGABYTE -nocomplain textcolor #gotoxy 3 [incr y] incr y gotoxy $x [incr y] puts "[lcount [commands]] commands are available" gotoxy $x [incr y] puts "Use: help for detailed info" incr y #scroll_titles if {$tcl_threaded} { textcolor yellow gotoxy $x [- $y 3] puts "Multi-threaded release (Alpha quality)" -nonewline textcolor } ############################################################################################### # Draw Title Box ############################################################################################### box 1 1 $sw [incr y 1] blue blue -nofill option echo on #gotoxy $x [incr y] #[incr y] set cursor_yloc [+ $y 1] # /* ############################################################################################### # Optional calendar ############################################################################################### gotoxy 1 [incr y] if {[file exists "${working_path}calendar.tcl"]} { source ${working_path}calendar.tcl # Include } else { puts "Can't find calendar iin ${working_path}" } #puts "DEBUG calendar '${working_path}calendar.tcl' defined?: '[bool [defined calendar]]'" # undef calendar -nocomplain if [defined calendar] { calendar [date -month] [date -year] += cursor_yloc 8 undef calendar } # */ ############################################################################################### gotoxy 3 [incr y] option echo off gotoxy 1 [incr y] undef rainbow -nocomplain unset x y sw -nocomplain ############################################################################################### ################################################# # Run some threaded events for demo # Applies only to experimental threaded compile ################################################# option echo push on if {$tcl_threaded} { after 1500 {set vret1 [scroll_titles $cursor_yloc]} # Code arg must be braced after 2200 {set vret2 [draw_logo yellow $cursor_yloc]} # Code arg must be braced #after 10000 {set vret3 [source screensave.tcl]} # No keyboard or mouse input polling vwait vret1 vwait vret2 #vwait vret3 500 unset done -nocomplain source every-clock.tcl # Use [source] as [run] will clear vars vwait _clock_running puts "Use: every cancel to stop the RTC clock" } else { #sleep 1000 #scroll_titles $cursor_yloc /* sleep 1000 for {set i 0} {< $i 5} {++ i} { console scroll 26 3 50 4 sleep 50 } # */ } gotoxy 1 $cursor_yloc # Restore the cursor for the CLI prompt ############################################################################################### #stop # Enter the CLI if desired unset cursor_yloc -nocomplain # unset x ############################################################################################### option echo pop array unset logo -const -nocomplain # We don't need the built-in logo array after autoexec unset done -nocomplain # Logo is defined internally in Ticol.exe - Once logo is undefined it can't be redefined undef draw_logo scroll_titles -nocomplain option expression off # Tip of the day (TOTD) # newline if {file exists ${working_path}totd.tcl} { source ${working_path}totd.tcl } unset working_path return 0 -code ok # Ensure we return to the CLI # EOF #