Menu

[r3]: / cmp / View / IView.tcl  Maximize  Restore  History

Download this file

216 lines (165 with data), 4.5 kB

  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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
##
## Compiler2 - IView
##
## (C) IPN - Ingenieurbuero fuer Praezisionsnumerik
##
## Dipl.-Ing. Andreas Otto
## Ulmenstrasse 3
## D-34289 Zierenberg
## mailto:aotto@t-online.de
## http://tclcompiler.sourceforge.net
##
## Alle Rechte vorbehalten
##
package require StdLib
package require FileLib
PkgProvide IView
##
## -----------------------------------------------------------------
##
namespace eval ::IView {
variable VDIR [ file join [::Env::COMPILER_HOME] exe [::Env::COMPILER_ARCH] var View ]
variable SDIR [ file join [::Env::COMPILER_HOME] var View ]
variable FMIME [ file join $VDIR .mime ]
variable MVIEW ; ## mime -> viewer
variable MDESC ; ## mime -> desc
variable MREGE ; ## mime -> rege
variable MARGS ; ## mime -> args
}
proc ::IView::Init {} {
variable FMIME
variable MVIEW
variable MDESC
variable MREGE
variable MARGS
if {[info exists MVIEW] || ![ file exists $FMIME ]} return
set _D {}
set _V {}
set _R {}
set _A {}
foreach { M R D V A } [ ReadFile $FMIME ] {
lappend _V $M $V
lappend _D $M $D
lappend _R $M $R
lappend _A $M $A
}
array set MVIEW $_V
array set MDESC $_D
array set MREGE $_R
array set MARGS $_A
}
::IView::Init
proc ::IView::ErrorN { args } {
::StdLib::ErrorN {VIEWER ERROR} $args
}
##
## --------------------------------------------------------------
## public
##
proc ::IView::Exec { Typ File } {
variable MVIEW
variable MREGE
variable MARGS
::FileLib::Check { exist readable file } $File
if {![ info exists MREGE($Typ) ]} {
ErrorN "mime type \"$Typ\" was not defined"
}
if {![ regexp $MREGE($Typ) $File ]} {
ErrorN "file \"$File\"" "does not fit regular expression \"$MREGE($Typ)\""
}
::StdLib::Exec "$MVIEW($Typ) $MARGS($Typ) $File"
}
proc ::IView::ExecN { File } {
variable MVIEW
variable MREGE
::FileLib::Check { exist readable file } $File
foreach { M R } [ array get MREGE ] {
if {![ regexp $R $File ]} continue
set C "$MVIEW($M) $File"
::StdLib::Push ERROR ERROR
if {[catch {::StdLib::Exec $C} ERR ]} {
ErrorN "the exec of \"$C\" failed" "$ERR" \
"please use \"cct view --add ...\" to add the right mime-handler"
}
::StdLib::Pop ERROR
return
}
ErrorN "can not file mime type for" $File
}
##
## --------------------------------------------------------------
## Mime interface
##
proc ::IView::List {} {
variable MVIEW
variable MDESC
variable MREGE
variable MARGS
set RET {}
foreach {M V} [ array get MVIEW ] {
lappend RET $M $V $MARGS($M) $MREGE($M) $MDESC($M)]
}
return $RET
}
proc ::IView::MimeList {} {
puts ""
puts [ format {%5s : %-10s : %-5s : %-15s : %s} mime viewer args regexp description ]
puts ""
foreach {M V A R D} [ List ] {
puts [ format {%5s : %-10s : %-5s : %-15s : %s} $M $V $A $R $D]
}
puts ""
}
proc ::IView::MimeAdd { List } {
variable FMIME
::FileLib::Append $FMIME $List
}
##
## --------------------------------------------------------------
## Doc interface
##
proc ::IView::DocAdd { PKG List {DIR žNOž}} {
if {$DIR == "žNOž"} {
set DIR [ file join [::Env::COMPILER_HOME] var View $PKG ]
} else {
set DIR [ file join $DIR var View $PKG ]
}
file mkdir [ file dirname $DIR ]
WriteFile $DIR $List
}
proc ::IView::DocDel { PKG {DIR žNOž} } {
if {$DIR == "žNOž"} {
set DIR [ file join [::Env::COMPILER_HOME] var View $PKG ]
} else {
set DIR [ file join $DIR var View $PKG ]
}
file delete -force $DIR
}
proc ::IView::DocList { PKG } {
variable SDIR
foreach F [ glob -nocomplain -directory $SDIR $PKG ] {
::FileLib::Check { exist readable file } $F
puts "\nPACKAGE [file tail $F]\n"
set I 0
foreach { M F } [ ReadFile $F ] {
puts [ format { %2i) %-5s : %s} $I $M [ file tail $F ] ]
incr I
}
}
}
proc ::IView::DocExec { PKG NUM} {
variable SDIR
set D [ file join $SDIR ]
set F [ glob -nocomplain -directory $D $PKG ]
if {$F == ""} {
::StdLib::Error "(BUG) can resolve package name \"PKG\""
}
if {![ string is integer $NUM ]} {
::StdLib::Error "expect integer but got \"$NUM\""
}
if {[ llength $F ] > 1} {
ErrorN "get more than one package \"$F\""
}
foreach { M D } [ lrange [ ReadFile $F ] [expr {$NUM*2}] end ] break
Exec $M [ file join [::Env::COMPILER_HOME] $D ]
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.