File: mkimage_c.tcl

package info (click to toggle)
cvstrac 1.1.5-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 824 kB
  • ctags: 680
  • sloc: ansic: 13,963; tcl: 111; makefile: 72; sh: 19
file content (35 lines) | stat: -rw-r--r-- 1,051 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
#!/usr/bin/tclsh
#
# This script reads the names of GIF files from the command line.
# It outputs C code that can be linked into CVSTrac so that the
# named GIFs are accessible by the web interface.
#
# Example usage:
#
#      tclsh mkimage_c.tcl *.gif >image.c
#

puts {/* This code is automatically generated. Do not edit. */}
puts {#include "image.h"}
foreach f $argv {
  set fd [open $f]
  fconfigure $fd -translation binary
  set data [read $fd]
  close $fd
  binary scan $data H[expr {[string length $data]*2}] hex
  puts "/*\n** WEBPAGE: /[file tail $f]\n*/"
  regsub -all {[^a-zA-Z0-9_]} [file tail $f] _ nm
  puts "void image_${nm}(void){"
  puts -nonewline "  static const char $nm\[\] = {"
  for {set i 0} {[string index $hex $i]!=""} {incr i 2} {
    if {$i%16==0} {puts -nonewline "\n   "}
    set byte [string range $hex $i [expr {$i+1}]]
    puts -nonewline " 0x$byte,"
  }
  puts "\n  };"
  puts "  cgi_set_content_type(\"image/gif\");"
  puts "  cgi_append_content($nm, sizeof($nm));"
  puts "  g.isConst = 1;"
  puts "}"
  puts ""
}