aboutsummaryrefslogtreecommitdiff
path: root/tclfile.tcl
blob: 61db3f22df7f841062879287c1903ef55efec6aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

package require Tclpd 0.2.3

package provide tclfile 0.1
namespace eval ::tclfile {
}

proc tclfile::make_symbol {argslist} {
    set output [pd::strip_selectors $argslist]
    set selector [lindex $output 0]
    if {$selector eq "list" || $selector eq "float"} {
        set output [lrange $output 1 end]
    }
    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
}