1 | #!/bin/sh |
---|
2 | # ====================================================================== |
---|
3 | # AUTHOR: Derrick S. Kearney, Purdue University |
---|
4 | # Copyright (c) 2004-2009 Purdue Research Foundation |
---|
5 | # |
---|
6 | # See the file "license.terms" for information on usage and |
---|
7 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
8 | # ====================================================================== |
---|
9 | #\ |
---|
10 | exec wish "$0" $* |
---|
11 | |
---|
12 | package require Rappture |
---|
13 | |
---|
14 | proc printHelp {} { |
---|
15 | set help { |
---|
16 | encodedata [OPTIONS] <infile> <outfile> |
---|
17 | |
---|
18 | simulator simulator - simulate simulation |
---|
19 | |
---|
20 | OPTIONS: |
---|
21 | -as z|b64|zb64 - how to encode the file |
---|
22 | -no-header - don't include the header |
---|
23 | } |
---|
24 | puts $help |
---|
25 | exit 0 |
---|
26 | } |
---|
27 | |
---|
28 | |
---|
29 | proc parseOptions {listVar returnVar} { |
---|
30 | upvar $listVar argv |
---|
31 | upvar $returnVar params |
---|
32 | |
---|
33 | set argc [llength $argv] |
---|
34 | for {set i 0} {$i < $argc} {incr i} { |
---|
35 | set opt [lindex $argv $i] |
---|
36 | if {("-as" == $opt)} { |
---|
37 | if {[expr {$i+1}] < $argc} { |
---|
38 | incr i |
---|
39 | set params(-as) [lindex $argv $i] |
---|
40 | } else { |
---|
41 | printHelp |
---|
42 | } |
---|
43 | } elseif {("-no-header" == $opt)} { |
---|
44 | set params(-no-header) "-no-header" |
---|
45 | } else { |
---|
46 | # place all extra params in the params array |
---|
47 | lappend params(oParams) $opt |
---|
48 | } |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | proc main {argv} { |
---|
53 | array set params { |
---|
54 | -as "zb64" |
---|
55 | -no-header "" |
---|
56 | oParams {} |
---|
57 | } |
---|
58 | |
---|
59 | parseOptions argv params |
---|
60 | |
---|
61 | if {[llength $params(oParams)] < 2} { |
---|
62 | printHelp |
---|
63 | return |
---|
64 | } |
---|
65 | set infile [lindex $params(oParams) 0] |
---|
66 | set outfile [lindex $params(oParams) 1] |
---|
67 | |
---|
68 | if {[catch { |
---|
69 | set fid [open $infile r] |
---|
70 | fconfigure $fid -translation binary |
---|
71 | set info [read $fid] |
---|
72 | close $fid |
---|
73 | }] != 0 } { |
---|
74 | puts "could not open $infile for reading" |
---|
75 | return |
---|
76 | } |
---|
77 | |
---|
78 | puts "as = $params(-as)" |
---|
79 | puts "header = $params(-no-header)" |
---|
80 | |
---|
81 | # FIXME: i hate this |
---|
82 | if {"" != $params(-no-header)} { |
---|
83 | set encdata [Rappture::encoding::encode -as $params(-as) $params(-no-header) -- $info] |
---|
84 | } else { |
---|
85 | set encdata [Rappture::encoding::encode -as $params(-as) -- $info] |
---|
86 | } |
---|
87 | |
---|
88 | if {[catch { |
---|
89 | set fid [open $outfile w] |
---|
90 | fconfigure $fid -translation binary |
---|
91 | puts $fid $encdata |
---|
92 | close $fid |
---|
93 | }] != 0 } { |
---|
94 | puts "could not open $outfile for writing" |
---|
95 | return |
---|
96 | } |
---|
97 | |
---|
98 | } |
---|
99 | |
---|
100 | main $argv |
---|
101 | exit 0 |
---|