tufte layout files:
[lyx.git] / development / tools / lyxeditor
blobbffc3fb2a5db7a9c817173ddc280dd4c841449bc
1 #!/bin/sh
2 # file lyxeditor
3 # This file is part of LyX, the document processor.
4 # Licence details can be found in the file COPYING.
6 # author Ronald Florence
7 # author Angus Leeming
8 # author Bennett Helm
9 # author Enrico Forestieri
11 # Full author contact details are available in file CREDITS
13 # This script passes filename and line number of a latex file to the lyxpipe
14 # of a running instance of LyX. If the filename is an absolute path pointing
15 # to an already existing latex file in the temp dir (produced by a preview,
16 # for example), LyX will jump to the corresponding line in the .lyx file.
17 # It may also be invoked by a viewer for performing a reverse DVI/PDF search.
19 parse_serverpipe()
21 # The output of this sed script is output to STDOUT
22 LYXPIPE=`sed -n '/^\\\\serverpipe /{
23 # First consider that the file path may be quoted
24 s/^ *\\\\serverpipe \{1,\}\"\([^"]\{1,\}\)\" *$/\1/
25 tfound
27 # Now, unquoted
28 s/^ *\\\\serverpipe \{1,\}\(.*\)/\1/
29 s/ *$//
31 :found
32 # Change from single to double shell quoting temporarily...
34 s@^~/@${HOME}/@
35 # Revert to single shell quotes
40 }' "$1"`
42 echo "${LYXPIPE}"
43 unset LYXPIPE
46 if [ $# != 2 ]; then
47 echo "Usage: $0 <latexfile> <lineno>"
48 exit 1
51 LYXPIPE=""
53 case $OSTYPE in
54 *darwin*) OSTYPE=macosx ;;
55 esac
57 if [ "$OSTYPE" = "macosx" ]; then
58 LYXSYSDIRS="/Applications/LyX.app/Contents/Resources"
59 LYXBASEDIR=LyX
60 pushd "${HOME}/Library/Application Support" > /dev/null
61 else
62 LYXSYSDIRS="/usr/share/lyx /usr/local/share/lyx /opt/share/lyx"
63 LYXBASEDIR=.lyx
64 pushd "${HOME}" > /dev/null
67 for LYXDIR in ${LYXBASEDIR}*
69 PREFERENCES="${LYXDIR}/preferences"
70 test -r "${PREFERENCES}" || continue
71 # See if preferences file contains a \serverpipe entry
72 LYXPIPE=`parse_serverpipe "${PREFERENCES}"`
73 # If it does and $LYXPIPE.in exists, break out of the loop
74 test -n "${LYXPIPE}" -a -r "${LYXPIPE}".in && break || LYXPIPE=""
75 done
77 popd > /dev/null
79 if [ -z "${LYXPIPE}" ]; then
80 # The preferences file does not set lyxpipe, so check lyxrc.dist
81 for SUBDIR in ${LYXSYSDIRS}
83 for LYXSYSDIR in ${SUBDIR}*
85 LYXRC_DIST=${LYXSYSDIR}/lyxrc.dist
86 test -r "${LYXRC_DIST}" || continue
87 # See if lyxrc.dist contains a \serverpipe entry
88 LYXPIPE=`parse_serverpipe "${LYXRC_DIST}"`
89 # If it does and $LYXPIPE.in exists, break out of the loop
90 test -n "${LYXPIPE}" -a -r "${LYXPIPE}".in && break || LYXPIPE=""
91 done
92 test -n "${LYXPIPE}" && break
93 done
96 if [ -z "${LYXPIPE}" ]; then
97 echo "Unable to find the lyxpipe!"
98 exit
101 # Let's do the job
103 if [ "${OSTYPE}" = "macosx" ]; then
104 file=`echo "$1" | sed 's|^/private||'`
105 elif [ "${OSTYPE}" = "cygwin" ]; then
106 file=`cygpath -a "$1"`
107 else
108 file=$1
111 echo "Using the lyxpipe ${LYXPIPE}"
112 COMMAND="LYXCMD:revdvi:server-goto-file-row:$file $2"
113 echo "$COMMAND"
114 echo "$COMMAND" > "${LYXPIPE}".in || exit
115 read < "${LYXPIPE}".out || exit