Mon May 6 13:20:07 2013 UTC ()
Insert a dummy SPACE before the first "msgstr" start with "\n", if "msgid"
is also start with "\n", but msgctxt is inserted before it, to avoid msgfmt(1)'s
format mismatch check (`msgid' and `msgstr' entries do not both begin with '\n')


(obache)
diff -r1.5 -r1.6 pkgsrc/mk/tools/msgfmt-msgctxt.awk

cvs diff -r1.5 -r1.6 pkgsrc/mk/tools/msgfmt-msgctxt.awk (expand / switch to unified diff)

--- pkgsrc/mk/tools/msgfmt-msgctxt.awk 2013/05/05 00:34:22 1.5
+++ pkgsrc/mk/tools/msgfmt-msgctxt.awk 2013/05/06 13:20:07 1.6
@@ -1,34 +1,35 @@ @@ -1,34 +1,35 @@
1# $NetBSD: msgfmt-msgctxt.awk,v 1.5 2013/05/05 00:34:22 obache Exp $ 1# $NetBSD: msgfmt-msgctxt.awk,v 1.6 2013/05/06 13:20:07 obache Exp $
2# 2#
3# Simple awk script to strip out .po entries with msgctxt and "#~|", so the 3# Simple awk script to strip out .po entries with msgctxt and "#~|", so the
4# resultant file can be handled by the msgfmt<0.15. 4# resultant file can be handled by the msgfmt<0.15.
5# Additionally, normalize EOL style by stripping \r. 5# Additionally, normalize EOL style by stripping \r.
6 6
7BEGIN { 7BEGIN {
8 EMPTY = "^$" 8 EMPTY = "^$"
9 SPACE = "[ ]*" 9 SPACE = "[ ]*"
10 KEYWORD_SEP = "([ ]+|[ ]*\"|$)" 10 KEYWORD_SEP = "([ ]+|[ ]*\"|$)"
11 OBSOLETE = "#~ " 11 OBSOLETE = "#~ "
12 OBSOLETE_RE = "^(#~[ ]+)?[ ]*" 12 OBSOLETE_RE = "^(#~[ ]+)?[ ]*"
13 OBSOLETE_RE_MATCH = "^#~[ ]+" 13 OBSOLETE_RE_MATCH = "^#~[ ]+"
14 MSG_CONTINUATION_RE = OBSOLETE_RE "\"" 14 MSG_CONTINUATION_RE = OBSOLETE_RE "\""
15 15
16 result = getline 16 result = getline
17 if (result < 1) exit result 17 if (result < 1) exit result
18 18
19 s = 0 19 s = 0
20 p = 0 20 p = 0
21 obsolete = "" 21 obsolete = ""
 22 msgid_begin_with_nl = 0
22 23
23 while (result == 1) { 24 while (result == 1) {
24 25
25 # Buffer any "msgctxt" statements into the singular array. 26 # Buffer any "msgctxt" statements into the singular array.
26 # Strip all trailing empty strings that have no effect on 27 # Strip all trailing empty strings that have no effect on
27 # the output. 28 # the output.
28 # 29 #
29 MSGCTXT_RE = OBSOLETE_RE "msgctxt" 30 MSGCTXT_RE = OBSOLETE_RE "msgctxt"
30 if ($0 ~ MSGCTXT_RE KEYWORD_SEP) { 31 if ($0 ~ MSGCTXT_RE KEYWORD_SEP) {
31 obsolete = "" 32 obsolete = ""
32 if ($0 ~ OBSOLETE_RE_MATCH) obsolete = OBSOLETE 33 if ($0 ~ OBSOLETE_RE_MATCH) obsolete = OBSOLETE
33 sub(MSGCTXT_RE SPACE, ""); 34 sub(MSGCTXT_RE SPACE, "");
34 s = 0 35 s = 0
@@ -48,60 +49,107 @@ BEGIN { @@ -48,60 +49,107 @@ BEGIN {
48 } 49 }
49 50
50 # If we see "msgid", then we are outputting the 51 # If we see "msgid", then we are outputting the
51 # context of a singular form of a message, so dump 52 # context of a singular form of a message, so dump
52 # the contents of the singular array as "msgid" 53 # the contents of the singular array as "msgid"
53 # and output magic word "\004" then continue to output 54 # and output magic word "\004" then continue to output
54 # subsequent "msgid". Strip all trailing empty strings 55 # subsequent "msgid". Strip all trailing empty strings
55 # that have no effect on the output, and handle "\n" 56 # that have no effect on the output, and handle "\n"
56 # pickiness between msgctxt and msgid. 57 # pickiness between msgctxt and msgid.
57 # 58 #
58 MSGID_RE = OBSOLETE_RE "msgid" 59 MSGID_RE = OBSOLETE_RE "msgid"
59 if ($0 ~ MSGID_RE KEYWORD_SEP) { 60 if ($0 ~ MSGID_RE KEYWORD_SEP) {
60 obsolete = "" 61 obsolete = ""
 62 msgid_begin_with_nl = 0
 63 msgid_find_first_str = 0
61 if ($0 ~ OBSOLETE_RE_MATCH) obsolete = OBSOLETE 64 if ($0 ~ OBSOLETE_RE_MATCH) obsolete = OBSOLETE
62 if (s > 0) { 65 if (s > 0) {
 66 msgid_find_first_str = 1
63 print obsolete "msgid " singular[0] 67 print obsolete "msgid " singular[0]
64 for (i = 1; i < s; i++) 68 for (i = 1; i < s; i++)
65 print obsolete singular[i] 69 print obsolete singular[i]
66 print obsolete "\"\\004\"" 70 print obsolete "\"\\004\""
67 } 71 }
68 sub(MSGID_RE SPACE, "") 72 sub(MSGID_RE SPACE, "")
69 t = 0 73 t = 0
70 if ($0 ~ EMPTY) $0 = "\"\"" 74 if ($0 ~ EMPTY) $0 = "\"\""
71 sub(/\r$/, "") 75 sub(/\r$/, "")
72 msgid[t++] = $0 76 msgid[t++] = $0
73 while (result = getline) { 77 while (result = getline) {
74 if ($0 !~ MSG_CONTINUATION_RE) break 78 if ($0 !~ MSG_CONTINUATION_RE) break
75 sub(OBSOLETE_RE, "") 79 sub(OBSOLETE_RE, "")
76 sub(/\r$/, "") 80 sub(/\r$/, "")
77 msgid[t++] = $0 81 msgid[t++] = $0
78 } 82 }
79 if (result < 0) break 83 if (result < 0) break
80 while ((t > 1) && (msgid[t-1] ~ /^""$/)) t-- 84 while ((t > 1) && (msgid[t-1] ~ /^""$/)) t--
81 if ((singular[s-1] ~ /\\n"$/) && 85 if ((singular[s-1] ~ /\\n"$/) &&
82 (msgid[t-1] !~ /\\n"$/)) { 86 (msgid[t-1] !~ /\\n"$/)) {
83 if (msgid[t-1] !~ /""/) 87 if (msgid[t-1] !~ /""/)
84 sub("\"$", "\\n\"", msgid[t-1]) 88 sub("\"$", "\\n\"", msgid[t-1])
85 } 89 }
86 if (t > 0) { 90 if (t > 0) {
87 if (s > 0) { 91 if (s > 0) {
88 print obsolete msgid[0] 92 print obsolete msgid[0]
 93 if (msgid[0] !~ /^""$/) {
 94 msgid_find_first_str = 0
 95 if (msgid[0] ~ /^"\\n/) {
 96 msgid_begin_with_nl = 1
 97 }
 98 }
89 } else { 99 } else {
90 print obsolete "msgid " msgid[0] 100 print obsolete "msgid " msgid[0]
91 } 101 }
92 for (i = 1; i < t; i++) 102 for (i = 1; i < t; i++) {
93 print obsolete msgid[i] 103 print obsolete msgid[i]
 104 if (msgid_find_first_str && (msgid[i] !~ /^""$/)) {
 105 msgid_find_first_str = 0
 106 if (msgid[i] ~ /^"\\n/) {
 107 msgid_begin_with_nl = 1
 108 }
 109 }
 110 }
94 } 111 }
95 s = 0 112 s = 0
96 continue 113 continue
97 } 114 }
98 115
 116 # insert a SPACE before "msgstr" if "msgid" is start with "\n"
 117 # but msgctx is inserted before it to avoid msgfmt(1)'s format
 118 # mismatch check.
 119 #
 120 if (msgid_begin_with_nl) {
 121 MSGSTR_RE = OBSOLETE_RE "msgstr"
 122 if ($0 ~ MSGSTR_RE KEYWORD_SEP) {
 123 if ($0 ~ OBSOLETE_RE_MATCH) obsolete = OBSOLETE
 124 sub(MSGSTR_RE SPACE, "")
 125 if ($0 ~ EMPTY) $0 = "\"\""
 126 sub(/\r$/, "")
 127 if ($0 ~ /\"\\n/) {
 128 sub(/\\n/, " \\n")
 129 }
 130 print obsolete "msgstr " $0
 131 while (result = getline) {
 132 if ($0 !~ MSG_CONTINUATION_RE) break
 133 sub(OBSOLETE_RE, "")
 134 $sub(/\r$/,"")
 135 if (msgid_begin_with_nl && $0 ~ /^"\\n/) {
 136 sub(/^"\\n/, "\" \\n")
 137 msgid_begin_with_nl = 0
 138
 139 }
 140 print obsolete $0
 141 }
 142 }
 143 msgid_begin_with_nl = 0
 144 continue
 145 }
 146
99 # Pass everything else verbatim. 147 # Pass everything else verbatim.
100 if ($0 !~ /^#~\|/) { 148 if ($0 !~ /^#~\|/) {
101 sub(/\r$/, "") 149 sub(/\r$/, "")
102 print $0 150 print $0
103 } 151 }
104 result = getline 152 result = getline
105 if (result < 0) break 153 if (result < 0) break
106 } 154 }
107} 155}