src/server: usage/help/doc updates
[fw/openocd] / src / server / httpd / html2tcl.sh
1 #!/bin/bash
2 # restart using a Tcl shell \
3         exec sh -c 'for tclshell in tclsh tclsh83 cygtclsh80 ; do \
4                         ( echo | $tclshell ) 2> /dev/null && exec $tclshell "`( cygpath -w \"$0\" ) 2> /dev/null || echo $0`" "$@" ; \
5                 done ; \
6                 echo "file2c.tcl: cannot find Tcl shell" ; exit 1' "$0" "$@"
7
8 #===============================================================================
9 #
10 #    file2c.tcl
11 #
12 #    Convert a file into a header that can be #included from C.
13 #
14 #===============================================================================
15 #####ECOSGPLCOPYRIGHTBEGIN####
16 ## -------------------------------------------
17 ## This file is part of eCos, the Embedded Configurable Operating System.
18 ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
19 ##
20 ## eCos is free software; you can redistribute it and/or modify it under
21 ## the terms of the GNU General Public License as published by the Free
22 ## Software Foundation; either version 2 or (at your option) any later version.
23 ##
24 ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
25 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
26 ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27 ## for more details.
28 ##
29 ## You should have received a copy of the GNU General Public License along
30 ## with eCos; if not, write to the Free Software Foundation, Inc.,
31 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
32 ##
33 ## As a special exception, if other files instantiate templates or use macros
34 ## or inline functions from this file, or you compile this file and link it
35 ## with other works to produce a work based on this file, this file does not
36 ## by itself cause the resulting work to be covered by the GNU General Public
37 ## License. However the source code for this file must still be made available
38 ## in accordance with section (3) of the GNU General Public License.
39 ##
40 ## This exception does not invalidate any other reasons why a work based on
41 ## this file might be covered by the GNU General Public License.
42 ##
43 ## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
44 ## at http://sources.redhat.com/ecos/ecos-license/
45 ## -------------------------------------------
46 #####ECOSGPLCOPYRIGHTEND####
47 #===============================================================================
48 ######DESCRIPTIONBEGIN####
49 #
50 # Author(s):    jlarmour,bartv
51 # Contact(s):   
52 # Date:         2001-07-20
53 # Purpose:      
54 # Description:
55 # Usage:        file2c.tcl <file to encode> <output C header file>
56 #
57 #####DESCRIPTIONEND####
58 #===============================================================================
59
60 if { $argc != 2 } {
61         puts "Usage: html2tcl.tcl <infile> <outfile>"
62         exit 1
63 }
64 set infile [lindex $argv 0]
65 set outfile [lindex $argv 1]
66                                 
67 set infilefd [open $infile "r"]
68 set data [read $infilefd]
69 close $infilefd
70
71
72
73
74 if [string match *\.tcl $infile]==0 {
75         puts "Not .tcl file, skipping $infile"
76         exit 0
77 }
78
79 set outfilefd [ open $outfile "w" ]
80 if [regexp -start 0 {^\s*<html.*} $data]==0 {
81         puts "copy $infile"
82         puts -nonewline $outfilefd $data
83         close $outfilefd
84         exit 0
85 }
86
87 puts "converting $infile"
88
89 set result ""
90 append result "# converted to .tcl by html2tcl.tcl\n"
91 append result "set buffer \"\"\n"
92
93 set pos 0
94 set done 0
95 while {$done==0} {
96         set start [string first <tcl> $data $pos]
97         if $start==-1 {
98                 # We're done...
99                 set done 1
100                 set start [string length $data]
101                 set end $start
102         } else {
103                 set end [string first </tcl> $data $start]
104                 if $end==-1 {
105                         # uh-oh, not closed
106                         puts "<tcl> not closed!"
107                         exit 1
108                 }
109         }
110         #puts "done $done start $start end $end"
111         # Dump HTML into resulting file.
112         append result "append buffer {"
113         append result [string range $data $pos [expr $start-1]]
114         #puts [string range $data $pos $start]
115         append result "}\n"
116         
117         # Dump TCL into resulting file.
118         append result "[string range $data [expr $start+5] [expr $end-1]]\n"
119         
120         set pos [expr $end+6]
121 }
122
123 append result "start_chunked \"html\"\n"
124 append result {write_chunked $buffer} "\n"
125 append result "end_chunked\n"
126
127 puts $outfilefd $result
128 close $outfilefd