From 32feb537da0228c4357632fd1f325556022cf911 Mon Sep 17 00:00:00 2001 From: DevSeed Date: Sun, 5 Jun 2016 22:07:46 +0800 Subject: [PATCH] yurisizuku fix the pre processing bug that can't deal with multi line comments. --- srcCpp/pp.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 srcCpp/pp.cpp diff --git a/srcCpp/pp.cpp b/srcCpp/pp.cpp new file mode 100644 index 00000000..ba433cc1 --- /dev/null +++ b/srcCpp/pp.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +using namespace std; +/* + preprocess + remove \r\n,comments +*/ +void preprocess(char *inpath,char *outpath) +{ + ifstream fin(inpath); + ofstream fout(outpath); + string line; + string tmp; + size_t start,end; + int flag=0;//flag=1 /* comment + while(getline(fin,line)) + { + tmp=""; + start=-2; + while(1) + { + start=line.find("\r\n",start+2); + if(start!=string::npos) + line=line.replace(start,2,""); + else break; + } + if(flag==1) + { + start=line.find("*/"); + if(start!=string::npos) + flag=0; + } + else + { + start=line.find("//"); + if(start!=string::npos) + line=line.substr(0,start); + start=-2; + } + while(1) + { + start+=2; + end=line.find("/*",start); + if(flag==0) + tmp+=line.substr(start,end-start); + if(end!=string::npos) + flag=1; + else break; + start=line.find("*/",end+2); + if(start!=string::npos) + flag=0; + else break; + } + fout<