-
Notifications
You must be signed in to change notification settings - Fork 30
/
get-graphics.sed
93 lines (86 loc) · 3.17 KB
/
get-graphics.sed
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
#(##defaults(stem="TESTSTEM", build_target_extension="pdf")##)
# Existing graphics files look different than missing files. We still want to
# extract them, though. Also, the paragraph structure is much simpler, so we
# short-circuit paragraph logic and just get the target off the line.
/^File: \(.*\) Graphic file (type [^)]*)/{
s//\1/
# If the file has a ps extension, kill that first.
s/\.e\{0,1\}ps$//
b addtargets
}
#(##include("paragraphs.sed")##)
/^[^[:cntrl:]:]*:[[:digit:]]\{1,\}:[[:space:][:cntrl:]]*LaTeX[[:space:][:cntrl:]]*Error:[[:space:][:cntrl:]]*File `/{
# Get rid of trailing newlines for every paragraph, since LaTeX errors are
# often split at arbitrary (not word) boundaries.
s/\n//g
b needonemore
}
# We have all the paragraphs we need - so extract the file name and extensions
/^::0::.*: LaTeX Error: File `/{
# Request one more paragraph if we ended in a newline. This is a very
# strange corner case that hits us when the filename error line ends in a
# newline, and latex breaks the error line right before that newline
# (creating a double empty line, which looks like an extra empty paragraph).
# Yes, LaTeX log output is that weird.
/\n\n$/{
s/^::0:://
b needonemore
}
# Kill all newlines, since the filename information can be split across lines
s/\n\{1,\}/ /g
# Collapse spaces
s/[[:space:]]\{1,\}/ /g
# Remove information before filename
s/^.*File `//
# If we have a pdflatex-style error (specifying which extensions are
# allowed), handle that.
/extensions: /{
# Remove suffix and get extensions
s/' not found\..*extensions: \([^[:space:]]*\).*/::::\1/
b fileparsed
}
# graphic file names with extensions specified in the .tex file (bad news,
# but it happens, especially with old latex-dvi-ps pipelines) don't give the
# same error, so we generate an empty extension list.
s/' not found\..*/::::/
:fileparsed
# If there are no extensions, that typically means that an extension was
# specified. We only want stems (extensions determined dynamically), so
# remove it (but only do so for eps includes - pdf stuff is handled differently).
# Other extensions get labeled "UNKNOWN" so we can at least debug what's happening.
/\(\.e\{0,1\}ps\)::::$/{
s//::::\1/
b psext
}
s/\(\.[^.]*\)::::$/:::: UNKNOWN=\1/
:psext
# Now we have filename::::extensionlist in the pattern space
# Place in the hold buffer, add missing stem comment
h
s/\(.*\)::::\(.*\)/# MISSING stem "\1" - allowed extensions: \2/
p
# Now get the hold buffer back, get rid of extension list, and call addtargets
g
s/::::.*//
b addtargets
}
# If we didn't detect something known, trash it and go get another paragraph
d
:addtargets
# Attempt to deal with filenames that contain spaces
s/[[:space:]]/\\\\\\&/g
# Add -include .gpi.d line in case this is a gnuplot file
h
s/.*/-include &.gpi.d/
p
g
# Add graphics source files as dependencies of this file - it makes it rebuild
# when they change.
s!.*!(##stem##).d: $$(call graphics-source,&,(##stem##))!
p
s/.*//
x
# Add graphics dependencies to main document
s!.*!(##stem##).(##build_target_extension##) (##stem##)._graphics: $$(call graphics-target,&,(##stem##))!
p
d