File: lyxeditor

package info (click to toggle)
lyx 2.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 96,552 kB
  • sloc: cpp: 388,556; python: 19,985; ansic: 9,725; sh: 5,696; makefile: 3,907; pascal: 1,388; objc: 985; perl: 319; yacc: 289; tcl: 163; xml: 23; sed: 16
file content (115 lines) | stat: -rwxr-xr-x 3,017 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
# file lyxeditor
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.

# author Ronald Florence
# author Angus Leeming
# author Bennett Helm
# author Enrico Forestieri

# Full author contact details are available in file CREDITS

# This script passes filename and line number of a latex file to the lyxpipe
# of a running instance of LyX. If the filename is an absolute path pointing
# to an already existing latex file in the temp dir (produced by a preview,
# for example), LyX will jump to the corresponding line in the .lyx file.
# It may also be invoked by a viewer for performing a reverse DVI/PDF search.

parse_serverpipe()
{
    # The output of this sed script is output to STDOUT
    LYXPIPE=`sed -n '/^\\\\serverpipe /{
# First consider that the file path may be quoted
s/^ *\\\\serverpipe \{1,\}\"\([^"]\{1,\}\)\" *$/\1/
tfound

# Now, unquoted
s/^ *\\\\serverpipe \{1,\}\(.*\)/\1/
s/ *$//

:found
# Change from single to double shell quoting temporarily...
'"
s@^~/@${HOME}/@
# Revert to single shell quotes
"'

p
q
}' "$1"`

    echo "${LYXPIPE}"
    unset LYXPIPE
}

if [ $# != 2 ]; then
    echo "Usage: $0 <latexfile> <lineno>"
    exit 1
fi

LYXPIPE=""

case $OSTYPE in
    *darwin*) OSTYPE=macosx ;;
esac

if [ "$OSTYPE" = "macosx" ]; then
    LYXSYSDIRS="/Applications/LyX.app/Contents/Resources"
    LYXBASEDIR=LyX
    pushd "${HOME}/Library/Application Support" > /dev/null
else
    LYXSYSDIRS="/usr/share/lyx /usr/local/share/lyx /opt/share/lyx"
    LYXBASEDIR=.lyx
    pushd "${HOME}" > /dev/null
fi

for LYXDIR in ${LYXBASEDIR}*
do
    PREFERENCES="${LYXDIR}/preferences"
    test -r "${PREFERENCES}" || continue
    # See if preferences file contains a \serverpipe entry
    LYXPIPE=`parse_serverpipe "${PREFERENCES}"`
    # If it does and $LYXPIPE.in exists, break out of the loop
    test -n "${LYXPIPE}" -a -r "${LYXPIPE}".in && break || LYXPIPE=""
done

popd > /dev/null

if [ -z "${LYXPIPE}" ]; then
    # The preferences file does not set lyxpipe, so check lyxrc.dist
    for SUBDIR in ${LYXSYSDIRS}
    do
        for LYXSYSDIR in ${SUBDIR}*
        do
            LYXRC_DIST=${LYXSYSDIR}/lyxrc.dist
            test -r "${LYXRC_DIST}" || continue
            # See if lyxrc.dist contains a \serverpipe entry
            LYXPIPE=`parse_serverpipe "${LYXRC_DIST}"`
            # If it does and $LYXPIPE.in exists, break out of the loop
            test -n "${LYXPIPE}" -a -r "${LYXPIPE}".in && break || LYXPIPE=""
        done
        test -n "${LYXPIPE}" && break
    done
fi

if [ -z "${LYXPIPE}" ]; then
    echo "Unable to find the lyxpipe!"
    exit
fi

# Let's do the job

if [ "${OSTYPE}" = "macosx" ]; then
    file=`echo "$1" | sed 's|^/private||'`
elif [ "${OSTYPE}" = "cygwin" ]; then
    file=`cygpath -a "$1"`
else
    file=$1
fi

echo "Using the lyxpipe ${LYXPIPE}"
COMMAND="LYXCMD:revdvi:server-goto-file-row:$file $2"
echo "$COMMAND"
echo "$COMMAND" > "${LYXPIPE}".in || exit
read < "${LYXPIPE}".out || exit