aboutsummaryrefslogtreecommitdiff
path: root/tclfile.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'tclfile.tcl')
-rw-r--r--tclfile.tcl20
1 files changed, 20 insertions, 0 deletions
diff --git a/tclfile.tcl b/tclfile.tcl
index 7700a5d..61db3f2 100644
--- a/tclfile.tcl
+++ b/tclfile.tcl
@@ -1,3 +1,4 @@
+
package require Tclpd 0.2.3
package provide tclfile 0.1
@@ -12,3 +13,22 @@ proc tclfile::make_symbol {argslist} {
}
return $output
}
+
+# expand things like ~ $HOME $ProgramFiles
+proc tclfile::expand_vars {filename} {
+ set sub $filename
+ foreach var [regexp -all -inline -- {\$\w+} $filename] {
+ regexp -- {\$(\w+)} $var -> varname
+ if {[catch {set got $::env($varname)} fid]} {
+ #puts stderr "caught $fid"
+ } else {
+ set sub [string map [list "\$$varname" $got \{ "" \} ""] $filename]
+ # TODO this should really be a regex that properly
+ # recognizes {} around the symbol as separate from just {}
+ # used in a filename. But first, Pd will need a full
+ # escaping mechanism so it can allow {}
+ #set sub [regsub "\(.+\)HOME\(.+\)" $sub "==\1==$got==\2=="]
+ }
+ }
+ return $sub
+}