source: trunk/gui/apps/encodedata.in @ 1796

Last change on this file since 1796 was 1796, checked in by gah, 14 years ago
  • Property svn:executable set to *
File size: 2.5 KB
Line 
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#\
10bindir=`dirname $0` ; \
11. $bindir/rappture.env ; \
12exec wish "$0" $*
13
14package require Rappture
15
16proc printHelp {} {
17    set help {
18encodedata [OPTIONS] <infile> <outfile>
19
20simulator simulator - simulate simulation
21
22OPTIONS:
23 -as z|b64|zb64      - how to encode the file
24 -no-header          - don't include the header
25}
26    puts $help
27    exit 0
28}
29
30
31proc parseOptions {listVar returnVar} {
32    upvar $listVar argv
33    upvar $returnVar params
34
35    set argc [llength $argv]
36    for {set i 0} {$i < $argc} {incr i} {
37        set opt [lindex $argv $i]
38        if {("-as" == $opt)} {
39            if {[expr {$i+1}] < $argc} {
40                incr i
41                set params(-as) [lindex $argv $i]
42            } else {
43                printHelp
44            }
45        } elseif {("-no-header" == $opt)} {
46            set params(-no-header) "-no-header"
47        } else {
48            # place all extra params in the params array
49            lappend params(oParams) $opt
50        }
51    }
52}
53
54proc main {argv} {
55    array set params {
56        -as "zb64"
57        -no-header ""
58        oParams {}
59    }
60
61    parseOptions argv params
62
63    if {[llength $params(oParams)] < 2} {
64        printHelp
65        return
66    }
67    set infile [lindex $params(oParams) 0]
68    set outfile [lindex $params(oParams) 1]
69
70    if {[catch {
71            set fid [open $infile r]
72            fconfigure $fid -translation binary
73            set info [read $fid]
74            close $fid
75         }] != 0 } {
76        puts "could not open $infile for reading"
77        return
78    }
79
80    puts "as = $params(-as)"
81    puts "header = $params(-no-header)"
82
83    # FIXME: i hate this
84    if {"" != $params(-no-header)} {
85        set encdata [Rappture::encoding::encode -as $params(-as) $params(-no-header) -- $info]
86    } else {
87        set encdata [Rappture::encoding::encode -as $params(-as) -- $info]
88    }
89
90    if {[catch {
91            set fid [open $outfile w]
92            fconfigure $fid -translation binary
93            puts $fid $encdata
94            close $fid
95         }] != 0 } {
96        puts "could not open $outfile for writing"
97        return
98    }
99
100}
101
102main $argv
103exit 0
Note: See TracBrowser for help on using the repository browser.