| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: msgfmt-msgctxt.awk,v 1.4 2013/05/03 12:31:43 obache Exp $ | | 1 | # $NetBSD: msgfmt-msgctxt.awk,v 1.5 2013/05/05 00:34:22 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 | |
7 | BEGIN { | | 7 | BEGIN { |
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 "\"" |
| @@ -47,33 +47,34 @@ BEGIN { | | | @@ -47,33 +47,34 @@ BEGIN { |
47 | continue | | 47 | continue |
48 | } | | 48 | } |
49 | | | 49 | |
50 | # If we see "msgid", then we are outputting the | | 50 | # If we see "msgid", then we are outputting the |
51 | # context of a singular form of a message, so dump | | 51 | # context of a singular form of a message, so dump |
52 | # the contents of the singular array as "msgid" | | 52 | # the contents of the singular array as "msgid" |
53 | # and output magic word "\004" then continue to output | | 53 | # and output magic word "\004" then continue to output |
54 | # subsequent "msgid". Strip all trailing empty strings | | 54 | # subsequent "msgid". Strip all trailing empty strings |
55 | # that have no effect on the output, and handle "\n" | | 55 | # that have no effect on the output, and handle "\n" |
56 | # pickiness between msgctxt and msgid. | | 56 | # pickiness between msgctxt and msgid. |
57 | # | | 57 | # |
58 | MSGID_RE = OBSOLETE_RE "msgid" | | 58 | MSGID_RE = OBSOLETE_RE "msgid" |
59 | if ($0 ~ MSGID_RE KEYWORD_SEP) { | | 59 | if ($0 ~ MSGID_RE KEYWORD_SEP) { |
| | | 60 | obsolete = "" |
| | | 61 | if ($0 ~ OBSOLETE_RE_MATCH) obsolete = OBSOLETE |
60 | if (s > 0) { | | 62 | if (s > 0) { |
61 | print obsolete "msgid " singular[0] | | 63 | print obsolete "msgid " singular[0] |
62 | for (i = 1; i < s; i++) | | 64 | for (i = 1; i < s; i++) |
63 | print obsolete singular[i] | | 65 | print obsolete singular[i] |
64 | print obsolete "\"\\004\"" | | 66 | print obsolete "\"\\004\"" |
65 | } | | 67 | } |
66 | if ($0 ~ OBSOLETE_RE_MATCH) obsolete = OBSOLETE | | | |
67 | sub(MSGID_RE SPACE, "") | | 68 | sub(MSGID_RE SPACE, "") |
68 | t = 0 | | 69 | t = 0 |
69 | if ($0 ~ EMPTY) $0 = "\"\"" | | 70 | if ($0 ~ EMPTY) $0 = "\"\"" |
70 | sub(/\r$/, "") | | 71 | sub(/\r$/, "") |
71 | msgid[t++] = $0 | | 72 | msgid[t++] = $0 |
72 | while (result = getline) { | | 73 | while (result = getline) { |
73 | if ($0 !~ MSG_CONTINUATION_RE) break | | 74 | if ($0 !~ MSG_CONTINUATION_RE) break |
74 | sub(OBSOLETE_RE, "") | | 75 | sub(OBSOLETE_RE, "") |
75 | sub(/\r$/, "") | | 76 | sub(/\r$/, "") |
76 | msgid[t++] = $0 | | 77 | msgid[t++] = $0 |
77 | } | | 78 | } |
78 | if (result < 0) break | | 79 | if (result < 0) break |
79 | while ((t > 1) && (msgid[t-1] ~ /^""$/)) t-- | | 80 | while ((t > 1) && (msgid[t-1] ~ /^""$/)) t-- |