The gs DSC parser has two problems. First, it does not respect BeginData/EndData. If a page contains an embedded EPS and the embedded EPS has page setup comments, gs parses the comments in the embedded EPS instead of ignoring them. Second, the parser should take the first version of each comment instead of continuing to scan for other copies. This second problem makes it impossible to work-around the first problem by adding more comments at the top. This is causing me problems where a landscape page with an embedded EPS that wants to be portrait is causing ps2pdf to write a portrait pdf. Refer to the parsing rules on page 28 of section 4.4 of Adobe document 5001.DSC_Spec (25 Sep 92).
Created attachment 3931 [details] sample.ps Sample page that ps2pdf sets the wrong orientation because it looks at comments inside an embedded eps.
Created attachment 3932 [details] dsc.pat Patch to zdscpars.c to ignore comments between begin and end pairs in the bad list. This fixes my problem, but there is probably a better way to do it. Unpaired begins will cause problems.
Assigning to Alex to review (and hopefully commit) the patch.
Created attachment 3952 [details] improved patch This patch keeps the nesting counter in the dsc_data_t structure instead of the static variable.
The improved patch is committed as a rev. 8653. Regression testing shows no differences.
The DSC parser does pay attention to %%BeginData and %%BeginDocument, and skips over the embedded files. Ghostscript doesn't make use of this information, but could be made to ignore DSC comments from embedded files. The CDSC structure contains the following semi-private variables which could be used by Ghostscript to determine if the DSC parser is currently skipping DSC comments. int skip_document; /* recursion level of %%BeginDocument: */ int skip_bytes; /* #bytes to ignore from BeginData: */ /* or DOSEPS preview section */ Using these would probably result in a more robust fix.
The comment in zdscpars.c above the declaration of BadCmdlist says "If we send the data block type comments, Russell's parser will want to skip the specified block of data. This is not appropriate for our situation." Will passing comments with data length parameters cause problems?