#! /bin/sh
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
#   2017, 2018, 2019, 2020,
#   2021, 2022, 2023, 2024 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 <http://www.gnu.org/licenses/>.

# Test gnun-preconvert and gnun-merge-preconverted.

date_mask='....-..-.. ..:.\{5,7\}'
timestamp='1983-09-27 12:36-0500'
substitute_notices='2,3d;
1a# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,\
#   2017, 2018, 2019, 2020,\
#   2021, 2022, 2023, 2024 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 <http://www.gnu.org/licenses/>.'

# The lines beginning with `#: ' will depend on $(bulddir).
# The POT-Creation-Date will depend on the time of checking.
# The Language and Content-Transfer-Encoding fields depend on gettext version.
cat "${srcdir}/conv.pr.html" > conv.pr.html || exit 1
"${bindir}/gnun-preconvert" conv.pr.html "${srcdir}/conv.html" \
  || exit 1

"${MSGCAT}" conv.pr.po \
| "${SED}" -e "$substitute_notices" -e '/^#: /d' \
    -e '/^"Language: .*\\n"$/d' -e \
    's/^\("Content-Type:.*charset=\).*\\n"$/\1UTF-8\\n"/' -e \
    's/^\("Content-Transfer-Encoding:\) .*\\n"$/\1 ENCODING"/' -e \
    's/^\("POT-Creation-Date:\) '"$date_mask"'\\n"$/\1 '"$timestamp"'\\n"/' \
    > conv1.pr.po
"${MSGCAT}" "${srcdir}/preconv.pr.po" > preconv.pr.po
mv conv1.pr.po conv.pr.po
diff preconv.pr.po conv.pr.po || exit 1
"${bindir}/gnun-preconvert" -e utf-8 conv.pr.html -- "${srcdir}/conv.html" \
  || exit 1
"${MSGCAT}" conv.pr.po > conv1.pr.po
"${SED}" -e "$substitute_notices" -e '/^#: /d' -e '/^"Language: .*\\n"$/d' -e \
  's/^\("Content-Type:.*charset=\).*\\n"$/\1UTF-8\\n"/' -e \
  's/^\("Content-Transfer-Encoding:\) .*\\n"$/\1 ENCODING"/' -e \
  's/^\("POT-Creation-Date:\) '"$date_mask"'\\n"$/\1 '"$timestamp"'\\n"/' \
  < conv1.pr.po > conv.pr.po
diff preconv.pr.po conv.pr.po || exit 1

cp conv.pr.po conv2.pr.po

"${bindir}/gnun-merge-preconverted" conv.pr.po "${srcdir}/conv.pot"
"${MSGCAT}" conv.pr.po \
  | "${SED}" -e '/^"Language: .*\\n"$/d' -e \
      's/^\("POT-Creation-Date:\) '"$date_mask"'\\n"$/\1 '"$timestamp"'\\n"/' \
       > conv1.pr.po

case "x$WDIFF" in
  x ) file=conv-no-diffs.pr.po ;;
  * ) file=conv.pr.po ;;
esac

"${MSGCAT}" "${srcdir}/$file" > conv0.pr.po

diff conv0.pr.po conv1.pr.po || exit 1
rm conv.pr.html

mv conv2.pr.po conv.pr.po

"${bindir}/gnun-merge-preconverted" -d conv.pr.po "${srcdir}/conv.pot"

"${MSGCAT}" conv.pr.po \
  | "${SED}" -e '/^"Language: .*\\n"$/d' -e \
      's/^\("POT-Creation-Date:\) '"$date_mask"'\\n"$/\1 '"$timestamp"'\\n"/' \
      > conv1.pr.po
"${MSGCAT}" "${srcdir}/conv-no-diffs.pr.po" > conv0.pr.po
diff conv0.pr.po conv1.pr.po || exit 1

rm conv0.pr.po conv1.pr.po conv.pr.po preconv.pr.po
exit 0
