~amsn-daily/amsn/amsn-packaging

1228 by ahamelin
Changed the path used to run tclsh.
1
#!/usr/bin/env tclsh
1146 by ahamelin
Added two new keys in langen and langfr_ca (readonlywarn, readonlymsgbox).
2
# Written by:   Alexandre Hamelin (ahamelin users sourceforge net)
3
# Date:         Sept 2, 2003
4
# Usage:        ./addkey.tcl
5
#
6
# Small utility to add a new message key to a language file. When the key is
7
# added, the language file is sorted before it is written back to the disk.
8
# If the key already exists in the target language file, the associated message
9
# will be replaced. In the latter case, the old message will be printed on
10
# screen first.
1593 by ahamelin
only added the $Id:$ keyword
11
#
12
# $Id$
1146 by ahamelin
Added two new keys in langen and langfr_ca (readonlywarn, readonlymsgbox).
13
14
proc prompt {msg} {
15
    puts -nonewline "$msg"
16
    flush stdout
17
    return [gets stdin]
18
}
19
20
proc die {msg} {
21
    puts "error: $msg"
22
    exit 1
23
}
24
25
set key  [prompt "Specify a key (^C to abort): "]
26
set lang [prompt "Language for this key (en, fr_ca, etc.): "]
27
28
if {[catch {open lang$lang "r"} fd]} {
29
    puts "TIP: This utility should be run from within the lang directory."
30
    die $fd
31
}
32
33
# Read the content of the language file.
34
set lines [list]
35
gets $fd version
36
while { [gets $fd line] >= 0 } {
37
    lappend lines $line
38
}
39
close $fd
40
41
# See whether the key exists or not.
42
set k [lsearch $lines "$key *"]
43
if {$k > -1} {
44
    # Print the old message if the key existed.
45
    set keytext [lindex $lines $k]
46
    puts "-- Old message: [string repeat "-" 54]"
47
    puts [string range $keytext [expr [string first " " $keytext]+1] end]
48
    puts [string repeat "-" 70]
49
}
50
51
set msg [prompt "Enter the text for this key (<Enter> to end):\n"]
52
53
if {$k > -1} {
54
    # Replace the text of an existing key.
55
    lset lines $k "$key $msg"
56
} else {
57
    # Add a new key.
58
    lappend lines "$key $msg"
59
}
60
61
# Sort the content.
62
set lines [lsort $lines]
63
64
#puts stderr "WARNING: Original language file (lang$lang) will be truncated."
65
#puts stderr "         Please press enter to continue."
66
#gets stdin
67
68
# Write the new language file.
69
if {[catch {open lang$lang "w"} fd]} {
70
    die "$fd"
71
}
72
puts $fd $version
73
puts $fd [join $lines "\n"]
74
close $fd