From 53e5116e3b3912f92576e8fb1e7e9f29c7057f15 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Th=C3=A9r=C3=A8se=20Godefroy?= Date: Sun, 17 Sep 2017 22:33:56 +0200 Subject: [PATCH] Add local version of add-fuzzy-diff; tweak gnun-add-fuzzy-diff to use it. --- add-fuzzy-diff | 103 ++++++++++++++++++++++++++++++++++++++++++++ gnun-add-fuzzy-diff | 3 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100755 add-fuzzy-diff diff --git a/add-fuzzy-diff b/add-fuzzy-diff new file mode 100755 index 00000000..7567c3f2 --- /dev/null +++ b/add-fuzzy-diff @@ -0,0 +1,103 @@ +#! /bin/sed -nf + +# Copyright (C) 2011, 2012, 2016 Free Software Foundation, Inc. + +# This file is part of GNUnited Nations. + +# GNUnited Nations is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# GNUnited Nations is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with GNUnited Nations. If not, see . + +# Prepend fuzzy translations with wdiff from the previous msgid +# to current msgid. The difference is put in comment lines beginning +# with `# | '; if such comments are present in the PO file, they are +# removed by the script. + +# Remove old difference. +/^# |[| ]/d; +# Add new difference. +/^#, fuzzy\>/{ +# Read previous and current msgids. + N; /\n#| msgid "/! b obsolete; + :read-previous; + N; /\n#| [^\n]*$/ b read-previous; + /\nmsgid "[^\n]*$/! b obsolete; + :read-current; + N; /\nmsgstr "/ b create-file; + /\n"[^\n]*$/b read-current; b obsolete; +# Create a temporary file. Its name shall be kept in the last line +# of both pattern and hold space. + :create-file; +# It seems to be considerably faster to create a new file than +# to rewrite an existing one on fencepost (?) + x; s%.*%/bin/mktemp -t addiff.XXXXXXXXXXXXX%e; + H; g; +# Cut out the lines with current msgid. + s/\nmsgid ".*\(\n[^\n]*\)$/\1/; +# Extract previous msgid. + s/^#, fuzzy\>[^\n]*\n//; s/^#| msgid "\([^\n]*\)"[^\n]*\n/\1\n/; + s/\nmsgid [^\n]*\n/\n/; + s/\(" *\)\?\n#| "//g; + s/" *\n/\n/; s/^\n*//; +# Escape single quotes to workaround command line. + s/'/'"'"'/g; +# Escape `\n's to workaround wdiff. + s/\\n/\\\\n/g; +# Output previous msgid to temporary file. + s%^\(.*\)\n%echo '\1' > %e; +# Extract current msgid. + g; s/\nmsgstr ".*\n/\n/; s/^.*\nmsgid "\([^\n]*\)"/\1/; + s/\(" *\)\?\n"//g; s/" *\n/\n/; s/^\n*//; s/'/'"'"'/g; s/\\n/\\\\n/g; +# Invoke diff program and remove the temporary file. + s%\(.*\)\n\([^\n]*\)$%echo '\1' | /usr/bin/wdiff \2 -; rm \2%e; + s/\n//g; t rm-duplicates; +# A little bit of postprocessing. + :rm-duplicates; s/\[-\(.*\)-\] *{+\1+}/\1/; t rm-duplicates; + :merge-tails; + s/\[-\(.\)\?\(.\+\)-\] *{+\(.\)\?\2+}/\[-\1-\]{+\3+}\2/; + t merge-tails; + :merge-heads; + s/\[-\(.\+\)\(.\)\?-\] *{+\1\(.\)\?+}/\1\[-\2-\]{+\3+}/; + t merge-heads; + :merge-wings; + s/\[-\(.\+\)\(.\)\?\(.\+\)-\] *{+\1\(.\)\?\3+}/\1\[-\2-\]{+\4+}\3/; + t merge-wings; + s/\[--\]//g; s/{++}//g; + /{+.*+}/ b format; /\[-.*-\]/ b format; + s/.*/# || No change detected. The change might only be in amounts of spaces./ + b output-diff; + :format; +# fmt -w 75 the result. +# Remove possible long word beginning the string + s/^\([^ ]\{75,\}\) \(.*\)$/\1\n\2/; + :fmt; +# Long word; leave on the line. + s/\(\n[^\n ]\{75,\}\) \([^\n]*\)$/\1\n\2/; t fmt; +# There is a space: split the line. + s/\([^\n]\{75\}\)\([^\n]\+\)$/\1\n\2/; t proceed; +# No more characters. + b fmt-done; + :proceed; +# Move the newline to the last space in the line. + s/ \([^\n ]*\)\n\([^\n]*\)$/\n\1\2/; b fmt; + :fmt-done; +# Prepend every line with `# | '. + s/\(^\|\n\)/\1# | /g; + :output-diff; p; +# Pass original content to output. + g; s/\n\([^\n]*\)$// + :obsolete +# We've got something different, e.g. obsolete msg or no previous msgid; +# just pass what we have. +} +# Otherwise, just print the input. +p diff --git a/gnun-add-fuzzy-diff b/gnun-add-fuzzy-diff index 212c195f..83ae35e4 100755 --- a/gnun-add-fuzzy-diff +++ b/gnun-add-fuzzy-diff @@ -53,6 +53,7 @@ function single_file_needed () { exit 1 } +ADD_FUZZY_DIFF=./add-fuzzy-diff in_place= file= @@ -100,6 +101,6 @@ if test $# -gt 0; then single_file_needed fi -/usr/local/libexec/gnun/add-fuzzy-diff $in_place "$file" +$ADD_FUZZY_DIFF $in_place "$file" exit $? -- 2.25.1