4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
9 # Full author contact details are available in file CREDITS
12 # fig_copy.sh <from file> <to file>
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.
20 echo "Usage: fig_copy.sh <from file> <to file>" >&2
26 echo "Unable to read $1" >&2
31 # The work is trivial if "to" and "from" are in the same directory.
34 cd `dirname "$1"` || exit $?
36 cd "$PRESENT_DIR" || exit $?
38 cd `dirname "$2"` || exit $?
40 cd "$PRESENT_DIR" || exit $?
42 test "$FROM_DIR" = "$TO_DIR" && {
48 # Ok, they're in different directories. The .fig file must be modified.
50 # WS is a space and a tab character.
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\}/{
60 # If we're not on the last line, get the next line.
61 # It's this that defines the file itself.
65 # Does the new line contain any data?
69 # Does the new line contain only a comment?
71 /\n[${WS}]*#[^\n]*$/bloop
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@
81 sed "${TRANSFORMATION}" "$1" > "$2"