# RPM macros for font packages.
#
# Copyright © 2008-2019 Nicolas Mailhot <nim@fedoraproject.org>
# SPDX-License-Identifier: GPL-3.0-or-later
# adapted for ALTLinux by Igor Vlasenko <viy>

# Fix text files produced on other systems. Arguments
# -e <encoding>       source OS encoding
# -n                  do not recode files, only adjust folding and end of lines
%linuxtext(e:n) \
for textfile in %* ; do\
  %{!-n:\
    iconv -f %{-e*}%{!-e:$(uchardet "${textfile}")} -t UTF-8 -o "${textfile}.tmp" "${textfile}"\
    touch -r "${textfile}" "${textfile}.tmp"\
    mv "${textfile}.tmp" "${textfile}"\
  }\
  fold -s "${textfile}" > "${textfile}.tmp"\
  LANG=C LC_ALL=C sed -e 's/\\r$// ; 1 s/^\\xef\\xbb\\xbf//' -i "${textfile}.tmp"\
  touch -r "${textfile}" "${textfile}.tmp"\
  mv "${textfile}.tmp" "${textfile}"\
  chmod 0644 "${textfile}"\
done

