]> git.lyx.org Git - lyx.git/blob - development/MacOSX/lyxeditor
ctest: invert es/Intro_docbook5
[lyx.git] / development / MacOSX / lyxeditor
1 #!/bin/sh
2 # ron@18james.com, 11 Dec 2003
3 # With modifications by Angus Leeming, tweaked by Bennett Helm 21 Jan 2007
4
5 parse_serverpipe()
6 {
7         test -r "$1" || {
8                 echo "Usage: parse_serverpipe lyxrc" >&2
9                 exit 1
10         }
11
12         # The output of this sed script is output to STDOUT
13         LYXPIPE=`sed -n '/^\\\\serverpipe /{
14 # First consider that the file path may be quoted
15 s/^ *\\\\serverpipe \{1,\}\"\([^"]\{1,\}\)\" *$/\1/
16 tfound
17
18 # Now, unquoted
19 s/^ *\\\\serverpipe \{1,\}\(.*\)/\1/
20 s/ *$//
21
22 :found
23 # Change from single to double shell quoting temporarily...
24 '"
25 s@^~/@${HOME}/@
26 # Revert to single shell quotes
27 "'
28
29 p
30 q
31 }' "$1"`
32         echo "${LYXPIPE}"
33 }
34
35
36 USER_SUPPORT="${HOME}/Library/Application Support"
37 test -d "${USER_SUPPORT}" || {
38         echo "Something horrible is going on. No user support directory ${USER_SUPPORT}" >&2 
39         exit 1
40 }
41
42 # we prefer newer lyx releases here...
43 for LYXDIR in LyX-2.4 LyX-2.3 LyX-2.2 LyX-2.1 LyX-2.0 LyX-1.6 LyX-1.5 LyX-1.4 LyX
44 do
45         ABS_USER_LYXDIR="${USER_SUPPORT}/${LYXDIR}"
46         test -d "${ABS_USER_LYXDIR}" || {
47                 continue
48         }
49         PREFERENCES="${ABS_USER_LYXDIR}/preferences"
50         test -r "${PREFERENCES}" || {
51                 echo "Failed to find PREFERENCES: ${PREFERENCES}" >&2
52                 continue
53         }
54         # preferences file exists.
55         # See if it contains a \\serverpipe entry
56         LYXPIPE=$(parse_serverpipe "${PREFERENCES}")
57         # break if pipe entry and pipe detected
58         # hopefully it's the correct LyX instance...
59         if [ -n "$LYXPIPE" -a -p "$LYXPIPE".in ]; then
60                 break
61         fi
62         # now check for default pipe location
63         if [ -p "${ABS_USER_LYXDIR}"/.lyxpipe.in ]; then
64                 LYXPIPE="${ABS_USER_LYXDIR}/.lyxpipe"
65                 break
66         fi
67 done
68
69 # echo "preferences file sets lyxpipe as ${LYXPIPE}"
70
71 test -z "${LYXPIPE}" && {
72         ABS_SYSTEM_LYXDIR=$(dirname "$0")
73         ABS_SYSTEM_LYXDIR=$(dirname "${ABS_SYSTEM_LYXDIR}")"/Resources"
74         test -d "${ABS_SYSTEM_LYXDIR}" || {
75                 echo "Failed to find ABS_SYSTEM_LYXDIR: ${ABS_SYSTEM_LYXDIR}" >&2
76                 exit 1
77         }
78         LYXRC_DIST="${ABS_SYSTEM_LYXDIR}/lyxrc.dist"
79         test -r "${LYXRC_DIST}" || {
80                 echo "Failed to find LYXRC_DIST: ${LYXRC_DIST}" >&2
81                 exit 1
82         }
83
84         # lyxrc.dist exists
85         # See if it contains a \\serverpipe entry
86         LYXPIPE=$(parse_serverpipe "${LYXRC_DIST}")
87 }
88
89 if [ -n "$LYXPIPE" -a -p "$LYXPIPE".in ]; then
90         MAC_LYXPIPE_CONTENTS="LYXCMD:macdvix:server-goto-file-row:$1 $2"
91         # echo "$MAC_LYXPIPE_CONTENTS"
92         echo "$MAC_LYXPIPE_CONTENTS" > "${LYXPIPE}".in || { echo "Cannot write to lyxpipe." ; exit 2 ; }
93         while read line ; do
94                 echo LyX said: $line
95         done < "${LYXPIPE}".out || { echo "Cannot read from lyxpipe." ; exit 2 ; }
96         test -x /usr/bin/osascript && /usr/bin/osascript -e 'tell application id "org.lyx.lyx" to activate'
97 else
98         echo "Our best guess sets lyxpipe as ${LYXPIPE}"
99         echo "But the lyxpipe could not be found."
100         exit 1
101 fi
102 # The end
103