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