From 1e819ac8c4ef63049299b81911ba205c76678b94 Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Thu, 22 Jun 2023 14:34:22 +1000 Subject: [PATCH] enforce loading of shipped core punk tm modules over modules elsewhere in filesystem --- src/punk86.vfs/lib/app-punk/repl.tcl | 30 ++++++++++++++++++-- src/punk86.vfs/lib/app-shellspy/shellspy.tcl | 10 +++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/punk86.vfs/lib/app-punk/repl.tcl b/src/punk86.vfs/lib/app-punk/repl.tcl index 493a74a2..a7d4fdf2 100644 --- a/src/punk86.vfs/lib/app-punk/repl.tcl +++ b/src/punk86.vfs/lib/app-punk/repl.tcl @@ -28,8 +28,26 @@ proc todo {} { } +if {[string match "*.vfs/*" [info script]]} { + #src/xxx.vfs/lib/app-punk/repl.tcl + #back 5 gives same level as src folder + #we assume if calling directly into .vfs that the user would prefer to use src/modules - so back only 4 + set modulefolder [file dirname [file dirname [file dirname [file dirname [info script]]]]]/modules -tcl::tm::add [pwd]/modules +} else { + set modulefolder [file dirname [info nameofexecutable]]/modules +} + +if {[file exists $modulefolder]} { + tcl::tm::add $modulefolder +} else { + puts stderr "Warning unable to find module folder at: $modulefolder" +} + + +if {[file exists [pwd]/modules]} { + tcl::tm::add [pwd]/modules +} if {![info exists ::env(SHELL)]} { set ::env(SHELL) punk86 @@ -48,13 +66,21 @@ if {![info exists ::env(TERM)]} { } +package require Thread #These are strong dependencies # - the repl requires Threading and punk,shellfilter,shellrun to call and display properly. +# tm list already indexed - need 'package forget' to find modules based on current tcl::tm::list + +package forget shellfilter package require shellfilter +package forget shellrun package require shellrun -package require Thread +package forget punk package require punk + + + #todo - move to less generic namespace namespace eval repl { variable screen_last_chars "" ;#a small sliding append buffer for last char of any screen output to detect \n vs string diff --git a/src/punk86.vfs/lib/app-shellspy/shellspy.tcl b/src/punk86.vfs/lib/app-shellspy/shellspy.tcl index 97a64bf2..37e2e409 100644 --- a/src/punk86.vfs/lib/app-shellspy/shellspy.tcl +++ b/src/punk86.vfs/lib/app-shellspy/shellspy.tcl @@ -74,15 +74,21 @@ if {[file extension $arg1] in [list .tCl]} { #lappend auto_path c:/tcl/lib/tcllib1.20 +package require Thread + +#NOTE: tm package index will probably already have been created so we must use 'package forget' to restrict to current tcl::tm::list path +#Review - effect on load time of wasting a previously created index? better way? #require core modules only from punk distribution (REVIEW - override option?) +package foreget flagfilter package require flagfilter +package forget shellfilter package require shellfilter -package require Thread +package foget punk package require punk #restore module paths set tm_list_now [tcl::tm::list] -foreach p [$original_tm_list] { +foreach p $original_tm_list { if {$p ni $tm_list_now} { tcl::tm::add $p }