(defun groom-ai-eps ()
"Groom the Adobe Illustrator EPS file in the current buffer.  The grooming is
to make the file suitable for inclusion in a groff PIC.  The grooming entails:

    (1) getting rid of the binary crap on the first line, befor the %!PS- ...
        comment 

    (2) getting rid of the entire %%BeginData ... %%EndData region

    (3) nuking everything from the line after the %%EOF comment to the end of
        the file"

    (interactive)

    ; Do step (1).
    (beginning-of-buffer)
    (setq p (point))
    (search-forward "%!PS")
    (backward-char 4)
    (kill-region p (point))

    ; Do step (2).
    (search-forward "%%BeginData")
    (backward-word 1)
    (backward-char 2)
    (setq p (point))
    (search-forward "%%EndData")
    (kill-region p (point))

    ; Do step (3).
    (search-forward "%%EOF")
    (forward-line 1)
    (beginning-of-line)
    (setq p (point))
    (end-of-buffer)
    (kill-region p (point))

    ; Save to file with a ".ps" extesion, appended to the file name sans one
    ; extension.  Following this convention, if the eps file is named X.ai.eps,
    ; its converted ps file is named X.ai.ps.  Having the .ps extesion as the
    ; last will make the file directly usable by the groff .PIC macro, per the
    ; convention that this macro expects a ".ps" and ".jpg" file with the same
    ; root name.  Per this convention, we'll export jpg files from Illustrator
    ; with the extension .ai.jpg, which is the default way that Illustrator does
    ; it for files named X.ai.eps.
    (write-file (concat (file-name-sans-extension (buffer-name)) ".ps"))
)