PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/get-graphics.sed

https://code.google.com/p/latex-makefile/
sed | 87 lines | 45 code | 7 blank | 35 comment | 2 complexity | 94fc5df3b4247822a7702fad9c2b1bb9 MD5 | raw file
 1#(##defaults(stem="TESTSTEM", build_target_extension="pdf")##)
 2
 3# Existing graphics files look different than missing files.  We still want to
 4# extract them, though.  Also, the paragraph structure is much simpler, so we
 5# short-circuit paragraph logic and just get the target off the line.
 6/^File: \(.*\) Graphic file (type [^)]*)/{
 7  s//\1/
 8  # If the file has a ps extension, kill that first.
 9  s/\.e\{0,1\}ps$//
10  b addtargets
11}
12
13#(##include("paragraphs.sed")##)
14
15/^[^[:cntrl:]:]*:[[:digit:]]\{1,\}:[[:space:][:cntrl:]]*LaTeX[[:space:][:cntrl:]]*Error:[[:space:][:cntrl:]]*File `/{
16  # Get rid of trailing newlines for every paragraph, since LaTeX errors are
17  # often split at arbitrary (not word) boundaries.
18  s/\n//g
19  b needonemore
20}
21# We have all the paragraphs we need - so extract the file name and extensions
22/^::0::.*: LaTeX Error: File `/{
23  # Request one more paragraph if we ended in a newline.  This is a very
24  # strange corner case that hits us when the filename error line ends in a
25  # newline, and latex breaks the error line right before that newline
26  # (creating a double empty line, which looks like an extra empty paragraph).
27  # Yes, LaTeX log output is that weird.
28  /\n\n$/{
29    s/^::0:://
30    b needonemore
31  }
32  # Kill all newlines, since the filename information can be split across lines
33  s/\n\{1,\}/ /g
34  # Collapse spaces
35  s/[[:space:]]\{1,\}/ /g
36  # Remove information before filename
37  s/^.*File `//
38  # If we have a pdflatex-style error (specifying which extensions are
39  # allowed), handle that.
40  /extensions: /{
41    # Remove suffix and get extensions
42    s/' not found\..*extensions: \([^[:space:]]*\).*/::::\1/
43    b fileparsed
44  }
45  # graphic file names with extensions specified in the .tex file (bad news,
46  # but it happens, especially with old latex-dvi-ps pipelines) don't give the
47  # same error, so we generate an empty extension list.
48  s/' not found\..*/::::/
49  :fileparsed
50
51  # If there are no extensions, that typically means that an extension was
52  # specified.  We only want stems (extensions determined dynamically), so
53  # remove it (but only do so for eps includes - pdf stuff is handled differently).
54  s/\.e\{0,1\}ps::::$/::::/
55  # Now we have filename::::extensionlist in the pattern space
56  # Place in the hold buffer, add missing stem comment
57  h
58  s/\(.*\)::::\(.*\)/# MISSING stem "\1" - allowed extensions are "\2" - leave comment here - it affects the build/
59  p
60  # Now get the hold buffer back, get rid of extension list, and call addtargets
61  g
62  s/::::.*//
63  b addtargets
64}
65
66# If we didn't detect something known, trash it and go get another paragraph
67d
68
69:addtargets
70# Attempt to deal with filenames that contain spaces
71s/[[:space:]]/\\\\\\&/g
72# Add -include .gpi.d line in case this is a gnuplot file
73h
74s/.*/-include &.gpi.d/
75p
76g
77
78# Add graphics source files as dependencies of this file - it makes it rebuild
79# when they change.
80s!.*!(##stem##).d: $$(call graphics-source,&)!
81p
82s/.*//
83x
84# Add graphics dependencies to main document
85s!.*!(##stem##).(##build_target_extension##) (##stem##)._graphics: $$(call graphics-target,&)!
86p
87d