File: lyxeditor

package info (click to toggle)
lyx 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 138,444 kB
  • sloc: cpp: 244,268; ansic: 106,398; xml: 72,791; python: 39,384; sh: 7,666; makefile: 6,584; pascal: 2,143; perl: 2,101; objc: 1,084; tcl: 163; sed: 16
file content (103 lines) | stat: -rwxr-xr-x 2,728 bytes parent folder | download | duplicates (3)
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
#!/bin/sh
# ron@18james.com, 11 Dec 2003
# With modifications by Angus Leeming, tweaked by Bennett Helm 21 Jan 2007

parse_serverpipe()
{
	test -r "$1" || {
		echo "Usage: parse_serverpipe lyxrc" >&2
		exit 1
	}

	# 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}"
}


USER_SUPPORT="${HOME}/Library/Application Support"
test -d "${USER_SUPPORT}" || {
	echo "Something horrible is going on. No user support directory ${USER_SUPPORT}" >&2 
	exit 1
}

# we prefer newer lyx releases here...
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
do
	ABS_USER_LYXDIR="${USER_SUPPORT}/${LYXDIR}"
	test -d "${ABS_USER_LYXDIR}" || {
		continue
	}
	PREFERENCES="${ABS_USER_LYXDIR}/preferences"
	test -r "${PREFERENCES}" || {
		echo "Failed to find PREFERENCES: ${PREFERENCES}" >&2
		continue
	}
	# preferences file exists.
	# See if it contains a \\serverpipe entry
	LYXPIPE=$(parse_serverpipe "${PREFERENCES}")
	# break if pipe entry and pipe detected
	# hopefully it's the correct LyX instance...
	if [ -n "$LYXPIPE" -a -p "$LYXPIPE".in ]; then
		break
	fi
	# now check for default pipe location
	if [ -p "${ABS_USER_LYXDIR}"/.lyxpipe.in ]; then
		LYXPIPE="${ABS_USER_LYXDIR}/.lyxpipe"
		break
	fi
done

# echo "preferences file sets lyxpipe as ${LYXPIPE}"

test -z "${LYXPIPE}" && {
	ABS_SYSTEM_LYXDIR=$(dirname "$0")
	ABS_SYSTEM_LYXDIR=$(dirname "${ABS_SYSTEM_LYXDIR}")"/Resources"
	test -d "${ABS_SYSTEM_LYXDIR}" || {
		echo "Failed to find ABS_SYSTEM_LYXDIR: ${ABS_SYSTEM_LYXDIR}" >&2
		exit 1
	}
	LYXRC_DIST="${ABS_SYSTEM_LYXDIR}/lyxrc.dist"
	test -r "${LYXRC_DIST}" || {
		echo "Failed to find LYXRC_DIST: ${LYXRC_DIST}" >&2
		exit 1
	}

	# lyxrc.dist exists
	# See if it contains a \\serverpipe entry
	LYXPIPE=$(parse_serverpipe "${LYXRC_DIST}")
}

if [ -n "$LYXPIPE" -a -p "$LYXPIPE".in ]; then
	MAC_LYXPIPE_CONTENTS="LYXCMD:macdvix:server-goto-file-row:$1 $2"
	# echo "$MAC_LYXPIPE_CONTENTS"
	echo "$MAC_LYXPIPE_CONTENTS" > "${LYXPIPE}".in || { echo "Cannot write to lyxpipe." ; exit 2 ; }
	while read line ; do
		echo LyX said: $line
	done < "${LYXPIPE}".out || { echo "Cannot read from lyxpipe." ; exit 2 ; }
	test -x /usr/bin/osascript && /usr/bin/osascript -e 'tell application id "org.lyx.lyx" to activate'
else
	echo "Our best guess sets lyxpipe as ${LYXPIPE}"
	echo "But the lyxpipe could not be found."
	exit 1
fi
# The end