Hello Julien, On Fri, May 26, 2006 at 06:20:48PM +0200, Julien Cristau wrote: > > The attached patch modifies the po4aman-display-po script by
Thanks a lot for the patch. But, ouch, the file was already changed...a lot. > - removing useless ';' from a few lines This was done. > - making it work when /bin/sh isn't bash (the usage function definition > yields a syntax error with dash) done > - quoting a few variables should be done now (can you check?). > - using iconv -t latin1 because it's what man expects not done (see Thomas answer) > - replacing `command` with the standard $(command) form Is there a reason for doing this? > - fixing the "trap" usage done. I'm attaching the new version in case you want to check. Thanks in advance. -- Nekral
#!/bin/sh # # po4aman-display-po permits to see how a manpage translated with po4a # will be displayed, without needing to uncompress the original manpage # and call po4a-translate. # OPTIONS="" usage() { echo "Usage: $0 -p PO_FILE [-m MASTER_FILE] [-o PO4A_OPT]" return 0 } error () { echo "Error: $1" 1>&2 exit 1 } while getopts m:p:ho: option do case $option in m) MASTER="$OPTARG" ;; p) PO="$OPTARG" ;; o) OPTIONS="-o $OPTARG $OPTIONS" ;; h) usage exit 0 ;; [?]) usage 1>&2 exit 1 ;; esac done if [ -z "$PO" ] then usage 1>&2 exit 1 fi if [ ! -f "$PO" ] then error "could not find po file: $PO" fi if [ -z "$MASTER" ] then echo "No manpage specified." echo "Trying to find the manpage according to a line reference in the PO." MASTER=$(grep -m 1 "^#:" $PO | sed -e 's/^.* \(.*\):.*$/\1/') fi find_man() { section="$1" man="$2" echo -n "Looking for manpage $file" [ -n "$section" ] && echo " in section $section" || echo "" MAN_NUMBER=`man --all --where --locale=C $section "$man" 2> /dev/null | wc -l` if [ "$MAN_NUMBER" = "0" ] then return 1 elif [ "$MAN_NUMBER" != "1" ]; then error "Too many possible manpages: $(man -aw -L C $section "$man"), you must specify the manpage or the section" else MASTER=`man --where --locale=C "$section" "$man"` fi return 0 } if [ ! -f "$MASTER" ] then echo "Can't find the master man page $MASTER" file=$(basename "$MASTER") MASTER="" section="" if ! find_man "" "$file" then # Maybe $file contains a section # (in the form of file.section.extension) section=$(echo "$file" | sed -ne 's/^.*\.\([1-9].*\)$/\1/; s/\..*//; p') file=$(echo "$file" | sed -e 's/\.[1-9].*//') if ! find_man "$section" "$file" then # Maybe there is an extension at the end of the manpage (e.g. .man) file=$(echo "$file" | sed -e 's/\..*//') if ! find_man "$section" "$file" then echo "No manpage found" echo "You must provide the manpage with the -m option" MASTER="" fi fi fi if [ -n "$MASTER" ] then echo "Using: $MASTER as the original manpage" fi fi # checking mandatory options if [ -z "$MASTER" ] then usage 1>&2 exit 1 fi # checking files if [ ! -e "$MASTER" ] then error "could not find master file: $MASTER" fi if [ "${MASTER%.gz}" = "$MASTER" ] then MAINNAME="$MASTER" else MAINNAME=`mktemp` trap "rm \"$MAINNAME\"" EXIT INT gunzip -c "$MASTER" > "$MAINNAME" fi CHARSET_MASTER=`file -i "$MAINNAME" | cut -d "=" -f 2` CHARSET_PO=`file -i "$PO" | cut -d "=" -f 2` po4a-translate -f man -k 0 -m "$MAINNAME" -M "$CHARSET_MASTER" \ -p "$PO" $OPTIONS| iconv -f "$CHARSET_PO" -t // | man -l -