-
Notifications
You must be signed in to change notification settings - Fork 0
/
cg
executable file
·108 lines (102 loc) · 3.07 KB
/
cg
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
# the next line restarts using wish \
exec tclsh "$0" ${1+"$@"}
#
# Copyright (c) by Peter De Rijk (VIB - University of Antwerp)
# See the file "license.txt" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# see where we are, add the lib dir in the original location to auto_path, load extension
set script [file join [pwd] [info script]]
set scriptname [file tail $script]
while 1 {
if {[catch {set script [file join [file dir $script] [file readlink $script]]}]} break
}
set appdir [file dir $script]
if {[lrange [file split $script] end-2 end] eq {apps cg cg.tcl}} {
set appbasedir [file dir [file dir $appdir]]
set auto_path [list $appbasedir/lib $appbasedir/lib/tcl8.5 $appbasedir/lib/tk8.5]
}
lappend auto_path $appdir/lib $appdir/lib-exp
source $appdir/lib/file.tcl
package require Extral
package require genomecomb
genomecombenv
# generic help on no args
if {[llength $argv] < 1} {
cg_help
}
proc parse_generic_args {subcmd argslist} {
if {[llength $argslist] == 1 && [inlist {-h -help --help} $argslist]} {
if {[catch {help $subcmd} msg]} {
puts stderr $msg
exit 1
}
exit 0
}
set ::stacktraceonerror 0
set remove {}
set pos 0
foreach {key value} $argslist {
if {[string index $key 0] ne "-"} {
break
} elseif {$key eq "--"} {
break
}
regsub ^-- $key - key
if {$key in "-verbose -v"} {
if {![isint $value]} {error "$value is not a number, only numbers are accepted as value for -v (--verbose)"}
logverbose $value
lappend remove $pos [expr {$pos + 1}]
} elseif {$key eq "-stack"} {
if {$value in {0 1}} {
set ::stacktraceonerror $value
lappend remove $pos [expr {$pos + 1}]
} else {
error "$value is not 0 or 1, the only accepted values for --stack"
}
} elseif {$key eq "-compressionlevel"} {
setdefcompressionlevel $value
lappend remove $pos [expr {$pos + 1}]
} elseif {$key eq "-compressionthreads"} {
setdefcompressionthreads $value
lappend remove $pos [expr {$pos + 1}]
} elseif {$key eq "-shadowdir"} {
set ::env(SHADOWDIR) $value
lappend remove $pos [expr {$pos + 1}]
} elseif {$key eq "-scratchdir"} {
set ::env(SCRATCHDIR) $value
lappend remove $pos [expr {$pos + 1}]
}
incr pos 2
}
if {[llength $remove]} {set argslist [list_sub $argslist -exclude $remove]}
return $argslist
}
set action [list_shift argv]
set args $argv
unset -nocomplain argv
if {[auto_load cg_$action]} {
set args [parse_generic_args $action $args]
set ::base "cg $action"
if {[catch {cg_$action {*}$args} msg]} {
if {!$stacktraceonerror} {
puts stderr $msg
exit 1
} else {
puts stderr "$::errorInfo\n invoked from within\ncg $action [list {*}$args]\n"
exit 1
}
}
} elseif {[file executable $::appdir/plugins/cg_$action]} {
if {[llength $args] == 1 && [inlist {-h --help} $args]} {
help $action
exit 0
}
exec $::appdir/plugins/cg_$action {*}$args <@ stdin >@ stdout 2>@ stderr
} else {
puts stderr "ERROR: unkown action $action"
puts stderr "must be one of: [join [help_actions] ", "], ..."
puts stderr "For more help use:\ncg help"
exit 1
}