gv changed its command line options in version 3.6.1 so that it no longer 
recognizes `gv -swap`. Instead we need `gv --swap`. (An extra '-').

The function GV_SWAP below outputs '-swap' or '--swap' to stdout, 
depending. I use this to initialize the PS_VIEWER variable.

It works perfectly here, but I'm unsure whether to commit the change. Is 
it just too cute?

Angus (with beer in hand)

Index: lib/configure.m4
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/configure.m4,v
retrieving revision 1.91
diff -u -p -r1.91 configure.m4
--- lib/configure.m4    20 Jan 2005 15:02:15 -0000      1.91
+++ lib/configure.m4    1 Feb 2005 18:09:32 -0000
@@ -292,10 +292,45 @@ test "$sxw_to_latex_command" = "w2l" &&
 SEARCH_PROG([for an Latex -> OpenOffice.org 
converter],latex_to_sxw_command,oolatex oolatex.sh)
 test "$latex_to_sxw_command" != "none" && 
latex_to_sxw_command="$latex_to_sxw_command \$\$i"

+GV_SWAP() {
+  # The gv syntax changed at version 3.6.1 from `gv -swap` to `gv --swap`
+
+  # `gv --version` should return 'gv 3.6.1' or similar.
+  # If gv is not in the PATH, the '--version' option is not recognized
+  # or if the string is not of the expected form, then
+  # gv_version_str will be empty.
+  gv_digits='[0-9]\{1,\}'
+  gv_version_str=`gv --version 2>&1 | \
+    sed -n "s/gv *\($gv_digits\.$gv_digits\.$gv_digits\)/\1/p; 1q"`
+  unset gv_digits
+
+  # If the string is empty then output '-swap' to stdout and return
+  test "$gv_version_str" = "" && {
+    unset gv_version_str
+    echo "-swap"
+    return
+  }
+
+  # Extract the major, minor, patchlevel values
+  gv_major=`echo "$gv_version_str" | cut -d'.' -f1`
+  gv_minor=`echo "$gv_version_str" | cut -d'.' -f2`
+  gv_patch=`echo "$gv_version_str" | cut -d'.' -f3`
+
+  # Build a single version number
+  # 3.6.1 becomes 300601
+  gv_version=`echo "(${gv_major}*100000)+(${gv_minor}*100)+${gv_patch}" | 
bc -l`
+
+  test $gv_version -ge 300601 && echo "--swap" || echo "-swap"
+
+  unset gv_version_str gv_major gv_minor gv_patch gv_version
+}
+
+
 # Search something to preview postscript
 SEARCH_PROG([for a Postscript previewer],GHOSTVIEW,gsview32 gv ghostview 
kghostview)
 case $GHOSTVIEW in
-  gv|ghostview) PS_VIEWER="$GHOSTVIEW -swap" ;;
+  ghostview) PS_VIEWER="ghostview -swap" ;;
+  gv) PS_VIEWER='gv '`GV_SWAP` ;;
   *) PS_VIEWER="$GHOSTVIEW";;
 esac
 EPS_VIEWER=$GHOSTVIEW


Reply via email to