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.
 
 
 
 
 
 

46 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
// struct yyguts_t defined in each flex output file, this emits warning at linking stage
#define yyguts_t gmt_filter_headfootguts_t
#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>%%Page:.*\n
<NOTCOMMENTS>%%BeginPageSetup.*\n
<NOTCOMMENTS>%%EndPageSetup.*\n BEGIN(ENDHEAD);
<NOTCOMMENTS>%%BeginSetup.*\n BEGIN(SETUP);
<NOTCOMMENTS,ENDFOOTER>.*\n yyextra->append(yytext,yyleng);
<SETUP>%%EndSetup.*\n BEGIN(NOTCOMMENTS);
<INITIAL,SETUP,ENDHEAD>.*\n
<*><<EOF>> yyterminate;
%%