4 # this file extracts a bunch of files at the end of it
5 # files are marked by "\n>>>Begin filename length\n"
6 # if the filename is *.doeval then it is evaluated as
7 # a tcl script, at the time it is encoutered.
10 global argv0 argv files
12 set fi [open
$argv0 r
]
13 fconfigure
$fi -translation binary
14 set data
[read $fi 2000]
16 assureExists
$outdir directory
17 while { [outputOneFile
$fi $outdir] } { }
18 if {[llength
$done] > 0 } {
27 proc outputOneFile
{ stream outdir
} {
30 set exp
"\n>>>Begin (\[^ ]*) (\[0-9]+)\r?\n"
31 puts
"entering:[string length $data],[string range $data 0 200]"
32 if { [regexp
-indices $exp $data all
] } {
33 regexp
$exp $data junk filename filesize
34 set data
[string range
$data [expr 1 + [lindex
$all 1]] end
]
36 if { [regexp
{\.doeval$
} $filename] } {
40 set outfile
[file join $outdir $filename]
41 assureExists
[file dirname $outfile] directory
42 set ff
[open
$outfile w
]
43 fconfigure
$ff -translation binary
46 if { [string length
$data] >= $remains } {
47 puts
-nonewline $ff [string range
$data 0 [expr $remains -1]]
48 set data
[string range
$data $remains end
]
49 lappend
done [list
$filename $filesize $outfile]
52 } else { puts
-nonewline $ff $data
53 incr remains
-[string length
$data]
54 #puts "writing [string length $data]"
57 set read [read $stream 5000]
59 if { [string length
$read] == 0 } {
62 error
"Terminates in middle of reading $filename: remains $remains"
69 proc assureExists
{ dir
type } {
70 if { [catch
{file stat
$dir stat
} ] } {
71 if { "$type" == "directory" } {
76 if { "$stat(type)" != "directory" } {
77 error
"not a $type it is a $stat(type)"
87 >>>Begin xmcd.tgz
651163