Michael Uleysky
9 years ago
9 changed files with 163 additions and 17 deletions
@ -0,0 +1,2 @@ |
|||||||
|
/gmt_filter_headfoot.cpp |
||||||
|
/gmt_filter_headfoot.h |
@ -0,0 +1,31 @@ |
|||||||
|
#include "filters.h" |
||||||
|
#include "gmt_filter_headfoot.h" |
||||||
|
|
||||||
|
int gmt_filter_default(int fd, std::string* res, void* p) |
||||||
|
{ |
||||||
|
ssize_t br; |
||||||
|
char buffer[4096]; |
||||||
|
|
||||||
|
do |
||||||
|
{ |
||||||
|
br=read(fd,buffer,4096); |
||||||
|
res->append(buffer,br); |
||||||
|
} while(0!=br); |
||||||
|
close(fd); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int gmt_filter_headfoot(int fd, std::string* res, void* p) |
||||||
|
{ |
||||||
|
yyscan_t scanner; |
||||||
|
FILE* in; |
||||||
|
|
||||||
|
in=fdopen(fd,"r"); |
||||||
|
gmt_filter_headfootlex_init_extra(res,&scanner); |
||||||
|
gmt_filter_headfootset_in(in,scanner); |
||||||
|
gmt_filter_headfootlex(scanner); |
||||||
|
gmt_filter_headfootlex_destroy(scanner); |
||||||
|
fclose(in); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
#ifndef MODGMT_FILTERS_H |
||||||
|
#define MODGMT_FILTERS_H |
||||||
|
#include <unistd.h> |
||||||
|
#include <string> |
||||||
|
|
||||||
|
typedef int (*gmt_filter)(int, std::string*, void*); |
||||||
|
|
||||||
|
int gmt_filter_default(int, std::string*, void*); |
||||||
|
int gmt_filter_headfoot(int, std::string*, void*); |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,46 @@ |
|||||||
|
%option 8bit reentrant |
||||||
|
%option warn |
||||||
|
%option yylineno |
||||||
|
%option noyywrap |
||||||
|
%option header-file="gmt_filter_headfoot.h" |
||||||
|
%option outfile="gmt_filter_headfoot.cpp" |
||||||
|
%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; |
||||||
|
%% |
@ -1 +1,35 @@ |
|||||||
MODLIBS+=-lgmt |
MODLIBS+=-lgmt |
||||||
|
|
||||||
|
GMT_FLSOURCE=gmt_filter_headfoot.cpp |
||||||
|
GMT_FLHEADERS=$(subst .cpp,.h,$(GMT_FLSOURCE)) |
||||||
|
|
||||||
|
ifeq ($(subst ,$(GMT_FLSOURCE),$(SOURCE)),$(SOURCE)) |
||||||
|
SOURCE+=$(GMT_FLSOURCE) |
||||||
|
MODSOURCE+=modules/gmt/$(GMT_FLSOURCE) |
||||||
|
MODHEADERS+=modules/gmt/$(GMT_FLHEADERS) |
||||||
|
endif |
||||||
|
|
||||||
|
ifdef MODULE |
||||||
|
filters.d: gmt_filter_headfoot.h |
||||||
|
|
||||||
|
gmt_filter_headfoot.cpp: gmt_filter_headfoot.l |
||||||
|
flex $< |
||||||
|
[ -f gmt_filter_headfoot.h ] && touch gmt_filter_headfoot.h |
||||||
|
|
||||||
|
gmt_filter_headfoot.h: gmt_filter_headfoot.l gmt_filter_headfoot.cpp |
||||||
|
|
||||||
|
.PHONY: gmt_clean |
||||||
|
|
||||||
|
clean: gmt_clean |
||||||
|
|
||||||
|
gmt_clean: |
||||||
|
rm -f $(GMT_FLSOURCE) $(GMT_FLHEADERS) |
||||||
|
|
||||||
|
else |
||||||
|
|
||||||
|
modules/gmt/gmt_filter_headfoot.cpp: modules/gmt/gmt_filter_headfoot.l |
||||||
|
make -C modules/gmt -f ../../Makefile MODULE=gmt gmt_filter_headfoot.cpp |
||||||
|
|
||||||
|
modules/gmt/gmt_filter_headfoot.h: modules/gmt/gmt_filter_headfoot.cpp |
||||||
|
|
||||||
|
endif |
||||||
|
@ -0,0 +1,12 @@ |
|||||||
|
#include "modgmt.h" |
||||||
|
#include "object.h" |
||||||
|
|
||||||
|
ObjectBase* GMT_Header(const ObjectList* input) |
||||||
|
{ |
||||||
|
return new ObjectString(header); |
||||||
|
} |
||||||
|
|
||||||
|
ObjectBase* GMT_Footer(const ObjectList* input) |
||||||
|
{ |
||||||
|
return new ObjectString(footer); |
||||||
|
} |
Loading…
Reference in new issue