File: install.tcl

package info (click to toggle)
maxima 5.6-17
  • links: PTS
  • area: main
  • in suites: woody
  • size: 30,572 kB
  • ctags: 47,715
  • sloc: ansic: 154,079; lisp: 147,553; asm: 45,843; tcl: 16,744; sh: 11,057; makefile: 7,198; perl: 1,842; sed: 334; fortran: 24; awk: 5
file content (86 lines) | stat: -rw-r--r-- 2,006 bytes parent folder | download
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
#!/bin/sh
# comment \
exec wish "$0" "$@"
# this file extracts a bunch of files at the end of it
# and then uses these.
proc main { } {
    global argv0 argv files
    set done ""
    set fi [open $argv0 r]
    fconfigure $fi -translation binary
    set data [read $fi 2000]
    set outdir /tmp/jim
    assureExists $outdir directory
    while { [outputOneFile $fi $outdir] } { }
    if {[llength $done] > 0 } {
	puts "unpacked $done"
	exit 0
    } else {
	puts "failed"
	exit 1
    }
}

proc outputOneFile {  stream outdir } {
    upvar 1 done done
    upvar 1 data data
    set exp  "\n>>>Begin (\[^ ]*) (\[0-9]+)\r?\n"
    puts "entering:[string length $data],[string range $data 0 200]"
    if { [regexp -indices $exp $data all] } {
	regexp $exp $data junk filename filesize
	set data [string range $data [expr 1 + [lindex $all 1]] end]
    } else { return 0 }
    set outfile [file join $outdir $filename]
    assureExists [file dirname $outfile] directory
    set ff [open $outfile w]
    fconfigure $ff -translation binary
    set remains $filesize
    while { 1 } {
	if { [string length $data] >= $remains } {
	    puts -nonewline $ff [string range $data 0 [expr $remains -1]]
	    set data [string range $data $remains end]
	    lappend done [list $filename $filesize $outfile]
	    close $ff
	    return 1
	} else { puts -nonewline $ff $data
	         incr remains -[string length $data]
	          #puts "writing [string length $data]"
	         set data ""
	}
	set read [read $stream 5000]
	append data $read
	if { [string length $read] == 0 } {
	    close $ff
	    file delete $outfile
	    error "Terminates in middle of reading $filename: remains $remains"
	}
    }
}

    

proc assureExists { dir type } {
    if { [catch {file stat $dir stat} ] } {
	if { "$type" == "directory" } {
	    file mkdir $dir
	    return 1
	}
    }
    if { "$stat(type)" != "directory" }  {
	error "not a $type it is a $stat(type)"
}   }



main




>>>Begin xmcd.tgz 651163
jimmy

>>>Begin billy 8
hi there