No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / src / msgunfmt.tcl
blob1bd3edf5e4d59874d539e117fd9bd3a1d7dc7018
1 # Reading tcl/msgcat .msg files.
2 # Copyright (C) 2002 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 namespace eval msgcat {
19 namespace export mcset mcdump
20 variable header ""
23 proc msgcat::puts_po_string {str} {
24 # Replace " with \"
25 regsub -all "\"" $str "\\\"" str
26 # Replace \ with \\
27 regsub -all "\\\\" $str "\\\\\\" str
28 # Replace newline with \n
29 regsub -all [subst "\n"] $str "\\n" str
30 regsub -all [subst "\a"] $str "\\a" str
31 regsub -all [subst "\b"] $str "\\b" str
32 regsub -all [subst "\f"] $str "\\f" str
33 regsub -all [subst "\r"] $str "\\r" str
34 regsub -all [subst "\t"] $str "\\t" str
35 regsub -all [subst "\v"] $str "\\v" str
36 # Output it.
37 puts -nonewline "\"$str\""
40 proc msgcat::write_po_message {msgid msgstr} {
41 puts -nonewline "msgid "
42 puts_po_string $msgid
43 puts ""
44 puts -nonewline "msgstr "
45 puts_po_string $msgstr
46 puts ""
47 puts ""
50 # This gets called once for each message in the .msg catalog.
51 proc msgcat::mcset {locale src {dest ""}} {
52 msgcat::write_po_message $src $dest
55 # Main function.
56 proc msgcat::mcdump {langfile} {
57 if {[file exists $langfile]} {
58 # msgunfmt expects the output in UTF-8 encoding.
59 fconfigure stdout -encoding utf-8
61 set msgcat::header ""
63 set fd [open $langfile r]
64 # In newer tcl versions, the .msg files are in UTF-8 encoding.
65 fconfigure $fd -encoding utf-8
66 eval [read $fd]
67 close $fd
69 if {$msgcat::header == ""} {
70 # Provide a minimal header.
71 set msgcat::header [subst "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n"]
73 msgcat::write_po_message "" $msgcat::header
74 } else {
75 # Tell msgunfmt to emit an internationalized error message.
76 exit 2
80 # Main code: call the main function on the first and only argument.
81 msgcat::mcdump [lindex $argv 0]
83 exit 0