~ubuntu-branches/ubuntu/utopic/flwm/utopic

1 by Tommi Virtanen
Import upstream version 1.00
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
	    if [llength $list]<3 continue
20
	    set tag [lindex $list 1]
21
	    set value [lrange $list 2 1000]
22
	    if [llength $value]==1 {set value [lindex $value 0]}
23
	    if {$tag=="group"} {set group $value}
24
	    if {$tag=="name"} {set name $value}
25
	    if {$tag=="exec"} {set exec $value}
26
	}
27
	close $f
28
	if {$group=="" || $name == "" || $exec == ""} {
29
	    puts "$fname is missing necessary data"
30
	    return
31
	}
32
	set dir $env(HOME)/.wmx/$group
33
	set exec [string trimright $exec "& "]
34
	catch {mkdir [list $dir]}
35
	if [llength $exec]==1 {
36
	    if [catch {set command [exec which $exec]}] {
37
		puts "$fname : can't find the program $exec"
38
		return
39
	    } else {
40
		catch {unlink [list $dir/$name]}
41
		link -sym $command $dir/$name
42
	    }
43
	} else {
44
	    set f [open $dir/$name "w"]
45
	    puts $f "#! /bin/sh"
46
	    puts $f "exec $exec"
47
	    close $f
48
	    chmod +x [list $dir/$name]
49
	}
50
	incr count
51
    }
52
}
53
54
if ![catch {set l [glob /etc/X11/wmconfig/*]}] {
55
   foreach f $l {read_wmfile $f}
56
}
57
58
if ![catch {set l [glob $env(HOME)/.wmconfig/*]}] {
59
   foreach f $l {read_wmfile $f}
60
}
61
62
if !$count {
63
   error "No files found in /etc/X11/wmconfig or ~/.wmconfig"
64
}
65