]> git.lyx.org Git - lyx.git/blob - lib/scripts/fig_copy.sh
clean up french language handling
[lyx.git] / lib / scripts / fig_copy.sh
1 #! /bin/sh
2
3 # file fig_copy.sh
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
6 #
7 # author Angus Leeming
8 #
9 # Full author contact details are available in file CREDITS
10
11 # Usage:
12 # fig_copy.sh <from file> <to file>
13
14 # This script will copy an XFIG .fig file "$1" to "$2". In the process,
15 # it will modify the contents of the .fig file so that the names of any
16 # picture files that are stored as relative paths are replaced
17 # with the absolute path.
18
19 test $# -eq 2 || {
20     echo "Usage: fig_copy.sh <from file> <to file>" >&2
21     exit 1
22 }
23
24
25 test -r "$1" || {
26     echo "Unable to read $1" >&2
27     exit 1
28 }
29
30
31 # The work is trivial if "to" and "from" are in the same directory.
32 PRESENT_DIR=$PWD
33
34 cd `dirname "$1"` || exit $?
35 FROM_DIR=$PWD
36 cd "$PRESENT_DIR" || exit $?
37
38 cd `dirname "$2"` || exit $?
39 TO_DIR=$PWD
40 cd "$PRESENT_DIR" || exit $?
41
42 test "$FROM_DIR" = "$TO_DIR" && {
43     'cp' -f "$1" "$2"
44     exit $?
45 }
46
47
48 # Ok, they're in different directories. The .fig file must be modified.
49
50 # WS is a space and a tab character.
51 WS='    '
52
53 TRANSFORMATION="
54 # We're looking for a line of text that defines an entry of
55 # type '2' (a polyline), subtype '5' (an external picture file).
56 # The line has 14 other data fields.
57 /^[${WS}]*2[${WS}]\{1,\}5\([${WS}]\{1,\}[^${WS}]\{1,\}\)\{14\}/{
58
59 :loop
60 # If we're not on the last line, get the next line.
61 # It's this that defines the file itself.
62 $!{
63 N
64
65 # Does the new line contain any data?
66 # If not, loop
67 /\n[${WS}]*$/bloop
68
69 # Does the new line contain only a comment?
70 # If so, loop
71 /\n[${WS}]*#[^\n]*$/bloop
72
73 # The contents of the final line containing the file name
74 # are ' X <file name>', where X = 0 or 1.
75 # If the file name does not begin with '/', then insert the absolute path.
76 # Note that this test will work even if the file name contains spaces.
77 s@\(.*\n[${WS}]*[01][${WS}]\{1,\}\)\([^/]\)@\1${FROM_DIR}/\2@
78 }
79 }"
80
81 sed "${TRANSFORMATION}" "$1" > "$2"
82 exit $?