#!/bin/sh -e # # find-lang - generate list of language specific files. # Inspired by tool with same name from W. L. Estes . # # Copyright (C) 2000-2013 Dmitry V. Levin # # 2012-05-23 Igor Vlasenko # * added PLD/fedora compatible all-name option (mkochano,pascalek@PLD) # # This program 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 2 of the License, or # (at your option) any later version. # # This program 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 this program; if not, see . # : ${RPMCONFIGDIR:=@RPMCONFIGDIR@} . "$RPMCONFIGDIR/functions" [ -n "${RPM_DATADIR-}" ] || RPM_DATADIR="$(rpm --eval %_datadir)" Usage() { [ "$1" = 0 ] || exec >&2 cat < This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Dmitry V. Levin EOF exit 0 } TEMP=`getopt -n "$PROG" -o h -l without-mo,with-man,with-gnome,with-kde,with-qt,all-name,custom-dir-script:,custom-file-script:,custom-link-script:,append,output:,topdir:,help,version -- "$@"` || Usage eval set -- "$TEMP" : ${TOPDIR:=$RPM_BUILD_ROOT} FIND_MO=1 FIND_MAN= FIND_GNOME= FIND_KDE= FIND_QT= ALL_NAME= CUSTOM_DIR_SCRIPT= CUSTOM_FILE_SCRIPT= CUSTOM_LINK_SCRIPT= APPEND= OUTPUT= NAME= while :; do case "$1" in --without-mo) FIND_MO= ;; --with-man) FIND_MAN=1 ;; --with-gnome) FIND_GNOME=1 ;; --with-kde) FIND_KDE=1 ;; --with-qt) FIND_QT=1 ;; --append) APPEND=1 ;; --all-name) ALL_NAME=1 ;; --custom-dir-script) shift CUSTOM_DIR_SCRIPT="$1" ;; --custom-file-script) shift CUSTOM_FILE_SCRIPT="$1" ;; --custom-link-script) shift CUSTOM_LINK_SCRIPT="$1" ;; --output) shift OUTPUT="$1" ;; --topdir) shift TOPDIR="$1" ;; -h|--help) Usage 0 ;; --version) print_version ;; --) shift break ;; *) Fatal "unrecognized option: $1" ;; esac shift done # At least one argument, please. [ "$#" -ge 1 ] || Usage cd "$TOPDIR" cd "$OLDPWD" TOPDIR="$(printf %s "$TOPDIR" |sed -e ' s:/\(\./\)\+:/:g s:/\+:/:g s:/$:: ')" [ -n "$TOPDIR" ] || Fatal "invalid TOPDIR" FindLang() { local RLOCALE='\([a-z]\{2,3\}\)\(_[A-Z]\{2\}\)\?\(@[a-z]\{3,\}\)\?\(\.[A-Z][a-zA-Z0-9]\+\(-[A-Z0-9]\)\?\)\?' local RCLOCALE='\(C\|[a-z]\{2,3\}\)\(_[A-Z]\{2\}\)\?\(@[a-z]\{3,\}\)\?\(\.[A-Z][a-zA-Z0-9]\+\(-[A-Z0-9]\)\?\)\?' if [ -n "$ALL_NAME" ]; then PATTERN='[a-zA-Z0-9][a-zA-Z0-9._+-]*' else PATTERN="$NAME" fi # truncate if required [ -n "$APPEND" ] || :>"$OUTFILE" echo '%defattr(644,root,root,755)' >>"$OUTFILE" if [ -n "$FIND_MO" ]; then find "$TOPDIR" -type f |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:\(.*/locale/'"$RLOCALE"'/\([^/]\+/\)*'"$PATTERN"'\.mo\)$:%lang(\2) \1: s:^[^%].*:: s:^%lang(en) :: /^$/d ' find "$TOPDIR" -type l |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:\(.*/locale/'"$RLOCALE"'/\([^/]\+/\)*'"$PATTERN"'\.mo\)$:%lang(\2) %attr(-,root,root) \1: s:^[^%].*:: s:^%lang(en) :: /^$/d ' fi >> "$OUTFILE" if [ -n "$FIND_MAN" ]; then find "$TOPDIR" -type f |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:\(.*/share/man/'"$RLOCALE"'/[^/]\+/'"$PATTERN"'\.[0-9a-z]\+\)\(\.[^/]\+\)\?$:%lang(\2) \1*: s:^[^%].*:: s:^%lang(en) :: /^$/d ' find "$TOPDIR" -type l |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:\(.*/share/man/'"$RLOCALE"'/[^/]\+/'"$PATTERN"'\.[0-9a-z]\+\)\(\.[^/]\+\)\?$:%lang(\2) %attr(-,root,root) \1*: s:^[^%].*:: s:^%lang(en) :: /^$/d ' fi >> "$OUTFILE" if [ -n "$FIND_GNOME" ]; then # GNOME starting with version 3.2 stores its help files in $RPM_DATADIR/help/%lang/$NAME find $TOPDIR -type d |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:^\('"$RPM_DATADIR"'/help/'"$RCLOCALE"'/'"$PATTERN"'\(/.*\)\?\)$:%lang(\2) %dir \1: s:\(.*/gnome/help/'"$PATTERN"'\)$:%dir \1: s:\(.*/gnome/help/'"$PATTERN"'/'"$RCLOCALE"'\(/.*\)\?\)$:%lang(\2) %dir \1: s:\(.*/share/omf/'"$PATTERN"'\)$:%dir \1: s:^[^%].*:: s:^%lang(\(en\|C\)) :: /^$/d ' find "$TOPDIR" -type f |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:^\('"$RPM_DATADIR"'/help/'"$RCLOCALE"'/'"$PATTERN"'/\):%lang(\2) \1: s:\(.*/gnome/help/'"$PATTERN"'/'"$RCLOCALE"'\(/.*\)\?\)$:%lang(\2) \1: s:\(.*/share/omf/'"$PATTERN"'/[^/]*-'"$RCLOCALE"'\.omf\)$:%lang(\2) \1: s:^[^%].*:: s:^%lang(\(en\|C\)) :: /^$/d ' find "$TOPDIR" -type l |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:^\('"$RPM_DATADIR"'/help/'"$RCLOCALE"'/'"$PATTERN"'/\):%lang(\2) %attr(-,root,root) \1: s:\(.*/gnome/help/'"$PATTERN"'/'"$RCLOCALE"'\(/.*\)\?\)$:%lang(\2) %attr(-,root,root) \1: s:\(.*/share/omf/'"$PATTERN"'/[^/]*-'"$RCLOCALE"'\.omf\)$:%lang(\2) %attr(-,root,root) \1: s:^[^%].*:: s:^%lang(\(en\|C\)) :: /^$/d ' fi >> "$OUTFILE" if [ -n "$FIND_KDE" ]; then find $TOPDIR -type d |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:\(.*/share/\([^/]\+/\)\?doc/HTML/'"$RLOCALE"'/'"$PATTERN"'\(/.*\)\?\)$:%lang(\3) %dir \1: s:^[^%].*:: s:^%lang(en) :: /^$/d ' find "$TOPDIR" -type f |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:\(.*/share/\([^/]\+/\)\?doc/HTML/'"$RLOCALE"'/'"$PATTERN"'/\):%lang(\3) \1: s:^[^%].*:: s:^%lang(en) :: /^$/d ' find "$TOPDIR" -type l |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:\(.*/share/\([^/]\+/\)\?doc/HTML/'"$RLOCALE"'/'"$PATTERN"'/\):%lang(\3) %attr(-,root,root) \1: s:^[^%].*:: s:^%lang(en) :: /^$/d ' fi >> "$OUTFILE" if [ -n "$FIND_QT" ]; then find "$TOPDIR" -type f |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:^\(/.*/'"$PATTERN"'/.\+/'"$RLOCALE"'/[a-z][a-z0-9]*\.qm\)$:%lang(\2) \1: s:^\(/.*/'"$PATTERN"'[_./-]'"$RLOCALE"'\.qm\)$:%lang(\2) \1: s:^\(/.*/'"$PATTERN"'/.\+/\([a-zA-Z0-9][a-zA-Z0-9._+-]*[_.-]\)\?'"$RLOCALE"'\.qm\)$:%lang(\3) \1: s:^[^%].*:: s:^%lang(en) :: /^$/d ' find "$TOPDIR" -type l |sed -e ' s:'"$TOPDIR"':: s:^[^/].*:: s:^\(/.*/'"$PATTERN"'/.\+/'"$RLOCALE"'/[a-z][a-z0-9]*\.qm\)$:%lang(\2) %attr(-,root,root) \1: s:^\(/.*/'"$PATTERN"'[_./-]'"$RLOCALE"'\.qm\)$:%lang(\2) %attr(-,root,root) \1: s:^\(/.*/'"$PATTERN"'/.\+/\([a-zA-Z0-9][a-zA-Z0-9._+-]*[_.-]\)\?'"$RLOCALE"'\.qm\)$:%lang(\3) %attr(-,root,root) \1: s:^[^%].*:: s:^%lang(en) :: /^$/d ' fi >> "$OUTFILE" if [ -n "$CUSTOM_DIR_SCRIPT" ]; then [ -r "$CUSTOM_DIR_SCRIPT" ] && custom_opt=f || custom_opt=e find $TOPDIR -type d | sed -e "s:$TOPDIR::" -$custom_opt "$CUSTOM_DIR_SCRIPT" | grep -v '^$' >> "$OUTFILE" ||: fi if [ -n "$CUSTOM_FILE_SCRIPT" ]; then [ -r "$CUSTOM_FILE_SCRIPT" ] && custom_opt=f || custom_opt=e find "$TOPDIR" -type f | sed -e "s:$TOPDIR::" -$custom_opt "$CUSTOM_FILE_SCRIPT" | grep -v '^$' >> "$OUTFILE" ||: fi if [ -n "$CUSTOM_LINK_SCRIPT" ]; then [ -r "$CUSTOM_LINK_SCRIPT" ] && custom_opt=f || custom_opt=e find "$TOPDIR" -type l | sed -e "s:$TOPDIR::" -$custom_opt "$CUSTOM_LINK_SCRIPT" | grep -v '^$' >> "$OUTFILE" ||: fi } for NAME in "$@"; do if [ -n "$OUTPUT" ]; then OUTFILE="$OUTPUT" [ "$NAME" = "$1" ] || APPEND=1 else OUTFILE="$NAME.lang" fi FindLang done