File: setversion

package info (click to toggle)
tk-html3 3.0~fossil20110109-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,656 kB
  • sloc: ansic: 48,994; tcl: 25,966; sh: 1,190; yacc: 161; makefile: 24
file content (112 lines) | stat: -rwxr-xr-x 2,449 bytes parent folder | download | duplicates (9)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@"}

# Insert version and other information into a number of files.

global trouble
set    trouble 0

# ============================================================
# Generate the substitution map.

proc mapdef {k v} {
    global map
    set map(@${k}@) $v
    return
}

proc map {} {
    global map
    set res [list]
    foreach k [lsort [array names map]] {
	lappend res $k $map($k)
    }
    return $res
}

# ============================================================

proc svfile {fname patternlist} {
    global trouble subst out
    if {![file exists $fname]} {
	puts stderr   "File $fname: Does not exist"
	set trouble 1
	return
    }

    puts "Updating file $fname ..."

    set                 fh [open $fname r]
    set contents [read $fh]
    close              $fh

    puts $out "svfile [list $fname] \{"

    foreach {pattern current} $patternlist {
	set newvalue [string map $subst $pattern]

	puts $out "    [list $pattern]"
	puts $out "    [list $newvalue]"

	set contents [string map [list $current $newvalue] $contents]
    }

    puts $out "\}"

    if {[catch {
	set              fh [open ${fname}.new w]
	puts -nonewline $fh $contents
	close           $fh
    }]} {
	file delete -force ${fname}.new
	puts stderr "Unable to write new contents of $fname"
	set trouble 1
	return
    }
    file rename -force ${fname}.new $fname
    return
}

proc extension {name data} {
    global pname
    set    pname $name
}

# ============================================================

set v [lindex $argv 0]
if {$v == {}} {
    puts stderr "Usage: $argv0 major.minor(\[abp.\]patchlevel)?"
    exit -1
}

regexp {([0-9]+)\.([0-9+])(([abp.])([0-9]+))?} $v \
	-> major minor __ detail patchlevel

source DESCRIPTION

mapdef mDate            [string toupper \
	[clock format \
	[clock seconds] -format "%b-%d-%Y"]]
mapdef mFullVersion     $v
mapdef mMajor           $major
mapdef mMinor           $minor
mapdef mShortDosVersion $major$minor
mapdef mVersion         ${major}.$minor
mapdef mName            $pname


# ============================================================

set flistfile [file join [file dirname [info script]] svfiles]
set newflist ${flistfile}.new
set out [open ${flistfile}.new w]
set subst [map]
source $flistfile
close $out

## set trouble 1 ; # enforce that new file does not overwrite old
if {!$trouble} {
    file rename -force ${flistfile}.new ${flistfile}
}