| 1 |
#! /usr/bin/tcl |
| 2 |
|
| 3 |
# flwm_wmconfig reads the RedHat "/etc/X11/wmconfig" directory (and |
| 4 |
# the ~/.wmconfig directory) and builds a ~/.wmx directory from it so |
| 5 |
# that you have a big complex menu in flwm! |
| 6 |
|
| 7 |
set count 0 |
| 8 |
|
| 9 |
proc read_wmfile {fname} { |
| 10 |
global count |
| 11 |
global env |
| 12 |
if [catch {set f [open $fname]} message] { |
| 13 |
puts $message |
| 14 |
} else { |
| 15 |
set group "" |
| 16 |
set name "" |
| 17 |
set exec "" |
| 18 |
while {[gets $f list]>=0} { |
| 19 |
set n 0 |
| 20 |
catch {set n [llength $list]} |
| 21 |
if $n<3 continue |
| 22 |
set tag [lindex $list 1] |
| 23 |
set value [lrange $list 2 1000] |
| 24 |
if [llength $value]==1 {set value [lindex $value 0]} |
| 25 |
if {$tag=="group"} {set group $value} |
| 26 |
if {$tag=="name"} {set name $value} |
| 27 |
if {$tag=="exec"} {set exec $value} |
| 28 |
} |
| 29 |
close $f |
| 30 |
if {$group=="" || $name == "" || $exec == ""} { |
| 31 |
puts "$fname is missing necessary data" |
| 32 |
return |
| 33 |
} |
| 34 |
set dir $env(HOME)/.wmx/$group |
| 35 |
set exec [string trimright $exec "& "] |
| 36 |
catch {mkdir [list $dir]} |
| 37 |
if [llength $exec]==1 { |
| 38 |
if [catch {set command [exec which $exec]}] { |
| 39 |
puts "$fname : can't find the program $exec" |
| 40 |
return |
| 41 |
} else { |
| 42 |
catch {unlink [list $dir/$name]} |
| 43 |
link -sym $command $dir/$name |
| 44 |
} |
| 45 |
} else { |
| 46 |
set f [open $dir/$name "w"] |
| 47 |
puts $f "#! /bin/sh" |
| 48 |
puts $f "exec $exec" |
| 49 |
close $f |
| 50 |
chmod +x [list $dir/$name] |
| 51 |
} |
| 52 |
incr count |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if ![catch {set l [glob /etc/X11/wmconfig/*]}] { |
| 57 |
foreach f $l {read_wmfile $f} |
| 58 |
} |
| 59 |
|
| 60 |
if ![catch {set l [glob $env(HOME)/.wmconfig/*]}] { |
| 61 |
foreach f $l {read_wmfile $f} |
| 62 |
} |
| 63 |
|
| 64 |
if !$count { |
| 65 |
error "No files found in /etc/X11/wmconfig or ~/.wmconfig" |
| 66 |
} |
| 67 |
|