You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.3 KiB

%option 8bit reentrant
%option warn
%option yylineno
%option noyywrap
%option prefix="gmt_filter_headfoot"
%option extra-type="std::string*"
%option nounput
%x NOTCOMMENTS
%x SETUP
%x ENDHEAD
%x ENDFOOTER
%{
#include <string>
// flex use register keyword, but it deprecated in C++11.
#define register
// Get rid of warning on unused function
#define YY_NO_INPUT
#define yyterminate {return 0;}
%}
/*
For header:
1. Remove all comments from begin to %%EndComments inclusively
2. Remove %%Page, %%BeginPageSetup, %%EndPageSetup DSC comments
3. Remove all content between %%BeginSetup and %%EndSetup (skip setpagedevice)
4. Skip code after %%EndPageSetup (draw code)
For footer:
1. Remove all before %%PageTrailer, but not %%PageTrailer itself
*/
%%
<INITIAL>%%EndComments\n BEGIN(NOTCOMMENTS);
<INITIAL>%%PageTrailer\n yyextra->append(yytext,yyleng); BEGIN(ENDFOOTER);
<NOTCOMMENTS>\n%%Page:.*\n yyextra->append("\n",1);
<NOTCOMMENTS>\n%%BeginPageSetup.*\n yyextra->append("\n",1);
<NOTCOMMENTS>\n%%EndPageSetup.*\n yyextra->append("\n",1); BEGIN(ENDHEAD);
<NOTCOMMENTS>\n%%BeginSetup.*\n yyextra->append("\n",1); BEGIN(SETUP);
<NOTCOMMENTS,ENDFOOTER>.*\n yyextra->append(yytext,yyleng);
<SETUP>\n%%EndSetup.*\n yyextra->append("\n",1); BEGIN(NOTCOMMENTS);
<INITIAL,SETUP,ENDHEAD>.*\n
<*><<EOF>> yyterminate;
%%