source: branches/1.3/gui/apps/encodedata.in @ 4676

Last change on this file since 4676 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

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