IDZEBRA  2.1.3
mk_version.tcl
Go to the documentation of this file.
1 #!/usr/bin/tclsh
2 
3 proc usage {} {
4  puts {mk_version.tcl [-v] IDMETA infile ..}
5  exit 1
6 }
7 
8 set verbose 0
9 set l [llength $argv]
10 set i 0
11 while {$i < $l} {
12  set arg [lindex $argv $i]
13  switch -glob -- $arg {
14  -v {
15  incr verbose
16  }
17  default {
18  if {![info exists conffile]} {
19  set conffile $arg
20  } else {
21  lappend infiles $arg
22  }
23  }
24  }
25  incr i
26 }
27 if {![info exists infiles]} {
28  puts "mk_version.tcl: missing input file(s)"
29  usage
30 }
31 
32 set f [open $conffile r]
33 while {1} {
34  set cnt [gets $f line]
35  if {$cnt < 0} {
36  break
37  }
38  regexp {VERSION=([0-9.]+)} $line s version
39 }
40 close $f
41 
42 set maps(VERSION) $version
43 
44 set c [split $version .]
45 
46 set versionl [expr ([lindex $c 0] * 256 + [lindex $c 1]) * 256 + [lindex $c 2]]
47 set maps(VERSION_HEX) [format %x $versionl]
48 
49 if {[llength $c] == 3} {
50  lappend c 1
51 }
52 set maps(WIN_FILEVERSION) [join $c ,]
53 
54 set maps(VERSION_SHA1) {}
55 
56 foreach x [array names maps] {
57  puts "$x=$maps($x)"
58 }
59 
60 foreach ifile $infiles {
61  set if [open "${ifile}.in" r]
62  set of [open "${ifile}" w]
63 
64  while {1} {
65  set cnt [gets $if line]
66  if {$cnt < 0} {
67  break
68  }
69  foreach x [array names maps] {
70  regsub -all "@$x@" $line $maps($x) line
71  }
72  puts $of $line
73  }
74  close $if
75  close $of
76 }