]> git.lyx.org Git - lyx.git/blob - development/tools/lyxeditor
Set \origin correctly when upgrading docs
[lyx.git] / development / tools / lyxeditor
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.
5
6 # author Ronald Florence
7 # author Angus Leeming
8 # author Bennett Helm
9 # author Enrico Forestieri
10
11 # Full author contact details are available in file CREDITS
12
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.
18
19 parse_serverpipe()
20 {
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
26
27 # Now, unquoted
28 s/^ *\\\\serverpipe \{1,\}\(.*\)/\1/
29 s/ *$//
30
31 :found
32 # Change from single to double shell quoting temporarily...
33 '"
34 s@^~/@${HOME}/@
35 # Revert to single shell quotes
36 "'
37
38 p
39 q
40 }' "$1"`
41
42     echo "${LYXPIPE}"
43     unset LYXPIPE
44 }
45
46 if [ $# != 2 ]; then
47     echo "Usage: $0 <latexfile> <lineno>"
48     exit 1
49 fi
50
51 LYXPIPE=""
52
53 case $OSTYPE in
54     *darwin*) OSTYPE=macosx ;;
55 esac
56
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
65 fi
66
67 for LYXDIR in ${LYXBASEDIR}*
68 do
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
76
77 popd > /dev/null
78
79 if [ -z "${LYXPIPE}" ]; then
80     # The preferences file does not set lyxpipe, so check lyxrc.dist
81     for SUBDIR in ${LYXSYSDIRS}
82     do
83         for LYXSYSDIR in ${SUBDIR}*
84         do
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
94 fi
95
96 if [ -z "${LYXPIPE}" ]; then
97     echo "Unable to find the lyxpipe!"
98     exit
99 fi
100
101 # Let's do the job
102
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
109 fi
110
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