Commit | Line | Data |
---|---|---|
53e5116e TG |
1 | #! /bin/sed -nf |
2 | ||
3 | # Copyright (C) 2011, 2012, 2016 Free Software Foundation, Inc. | |
4 | ||
5 | # This file is part of GNUnited Nations. | |
6 | ||
7 | # GNUnited Nations is free software: you can redistribute it and/or | |
8 | # modify it under the terms of the GNU General Public License as | |
9 | # published by the Free Software Foundation, either version 3 of the | |
10 | # License, or (at your option) any later version. | |
11 | ||
12 | # GNUnited Nations is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | ||
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with GNUnited Nations. If not, see <https://www.gnu.org/licenses/>. | |
19 | ||
20 | # Prepend fuzzy translations with wdiff from the previous msgid | |
21 | # to current msgid. The difference is put in comment lines beginning | |
22 | # with `# | '; if such comments are present in the PO file, they are | |
23 | # removed by the script. | |
24 | ||
25 | # Remove old difference. | |
26 | /^# |[| ]/d; | |
27 | # Add new difference. | |
28 | /^#, fuzzy\>/{ | |
29 | # Read previous and current msgids. | |
30 | N; /\n#| msgid "/! b obsolete; | |
31 | :read-previous; | |
32 | N; /\n#| [^\n]*$/ b read-previous; | |
33 | /\nmsgid "[^\n]*$/! b obsolete; | |
34 | :read-current; | |
35 | N; /\nmsgstr "/ b create-file; | |
36 | /\n"[^\n]*$/b read-current; b obsolete; | |
37 | # Create a temporary file. Its name shall be kept in the last line | |
38 | # of both pattern and hold space. | |
39 | :create-file; | |
40 | # It seems to be considerably faster to create a new file than | |
41 | # to rewrite an existing one on fencepost (?) | |
42 | x; s%.*%/bin/mktemp -t addiff.XXXXXXXXXXXXX%e; | |
43 | H; g; | |
44 | # Cut out the lines with current msgid. | |
45 | s/\nmsgid ".*\(\n[^\n]*\)$/\1/; | |
46 | # Extract previous msgid. | |
47 | s/^#, fuzzy\>[^\n]*\n//; s/^#| msgid "\([^\n]*\)"[^\n]*\n/\1\n/; | |
48 | s/\nmsgid [^\n]*\n/\n/; | |
49 | s/\(" *\)\?\n#| "//g; | |
50 | s/" *\n/\n/; s/^\n*//; | |
51 | # Escape single quotes to workaround command line. | |
52 | s/'/'"'"'/g; | |
53 | # Escape `\n's to workaround wdiff. | |
54 | s/\\n/\\\\n/g; | |
55 | # Output previous msgid to temporary file. | |
56 | s%^\(.*\)\n%echo '\1' > %e; | |
57 | # Extract current msgid. | |
58 | g; s/\nmsgstr ".*\n/\n/; s/^.*\nmsgid "\([^\n]*\)"/\1/; | |
59 | s/\(" *\)\?\n"//g; s/" *\n/\n/; s/^\n*//; s/'/'"'"'/g; s/\\n/\\\\n/g; | |
60 | # Invoke diff program and remove the temporary file. | |
61 | s%\(.*\)\n\([^\n]*\)$%echo '\1' | /usr/bin/wdiff \2 -; rm \2%e; | |
62 | s/\n//g; t rm-duplicates; | |
63 | # A little bit of postprocessing. | |
64 | :rm-duplicates; s/\[-\(.*\)-\] *{+\1+}/\1/; t rm-duplicates; | |
65 | :merge-tails; | |
66 | s/\[-\(.\)\?\(.\+\)-\] *{+\(.\)\?\2+}/\[-\1-\]{+\3+}\2/; | |
67 | t merge-tails; | |
68 | :merge-heads; | |
69 | s/\[-\(.\+\)\(.\)\?-\] *{+\1\(.\)\?+}/\1\[-\2-\]{+\3+}/; | |
70 | t merge-heads; | |
71 | :merge-wings; | |
72 | s/\[-\(.\+\)\(.\)\?\(.\+\)-\] *{+\1\(.\)\?\3+}/\1\[-\2-\]{+\4+}\3/; | |
73 | t merge-wings; | |
74 | s/\[--\]//g; s/{++}//g; | |
75 | /{+.*+}/ b format; /\[-.*-\]/ b format; | |
76 | s/.*/# || No change detected. The change might only be in amounts of spaces./ | |
77 | b output-diff; | |
78 | :format; | |
79 | # fmt -w 75 the result. | |
80 | # Remove possible long word beginning the string | |
81 | s/^\([^ ]\{75,\}\) \(.*\)$/\1\n\2/; | |
82 | :fmt; | |
83 | # Long word; leave on the line. | |
84 | s/\(\n[^\n ]\{75,\}\) \([^\n]*\)$/\1\n\2/; t fmt; | |
85 | # There is a space: split the line. | |
86 | s/\([^\n]\{75\}\)\([^\n]\+\)$/\1\n\2/; t proceed; | |
87 | # No more characters. | |
88 | b fmt-done; | |
89 | :proceed; | |
90 | # Move the newline to the last space in the line. | |
91 | s/ \([^\n ]*\)\n\([^\n]*\)$/\n\1\2/; b fmt; | |
92 | :fmt-done; | |
93 | # Prepend every line with `# | '. | |
94 | s/\(^\|\n\)/\1# | /g; | |
95 | :output-diff; p; | |
96 | # Pass original content to output. | |
97 | g; s/\n\([^\n]*\)$// | |
98 | :obsolete | |
99 | # We've got something different, e.g. obsolete msg or no previous msgid; | |
100 | # just pass what we have. | |
101 | } | |
102 | # Otherwise, just print the input. | |
103 | p |