C++ Contest Code preprocessor
大概可以拿来方便拉模板
变量名、语法都是瞎整的你感觉有用随便用好了..
#include<bits/stdc++.h>
using namespace std;
map<string,int>fp;
inline bool is_space(char c){return c==' '||c=='\t';}
bool Strike(char*t,int len,const char*strpat){
for(int i=0;i<len;++i)
if(t[i]!=strpat[i])
return 0;
return 1;
}
void Copy_File(const char*filename,char*intd){
FILE*inFile=fopen(filename,"r");
char*Line_Buffer=new char[1<<20];
while(!feof(inFile)&&fgets(Line_Buffer,1<<20,inFile)){
// process line
printf("%s%s",intd,Line_Buffer);
}puts("");
}
void Process_File(const char*filename){
int len=strlen(filename);
string filename_string(filename,len);
if(fp[filename])return;
fp[filename]=1;
FILE*inFile=fopen(filename,"r");
char*Line_Buffer=new char[1<<20];
char*Intend_Buffer=new char[1<<20];
while(!feof(inFile)&&fgets(Line_Buffer,1<<20,inFile)){
// process line
int len=strlen(Line_Buffer),int_siz=0,i=0;
for(;i<len;++i)
if(is_space(Line_Buffer[i]))
Intend_Buffer[int_siz++]=Line_Buffer[i];
else break;
if(Strike(Line_Buffer+i,5,"//cp_")){
// cp detected
if(Strike(Line_Buffer+i+5,8,"REQUIRE<")){
int t=i+13,z=0;
while(t<len&&Line_Buffer[t]!='>')++t,++z;
char*FileName=new char[z+2];
memcpy(FileName,Line_Buffer+i+13,z);
FileName[z]=0;
Process_File(FileName);
}else if(Strike(Line_Buffer+i+5,7,"INJECT<")){
int t=i+12,z=0;
while(t<len&&Line_Buffer[t]!='>')++t,++z;
char*FileName=new char[z+2];
memcpy(FileName,Line_Buffer+i+12,z);
FileName[z]=0;
Copy_File(FileName,Intend_Buffer);
}else printf("%s",Line_Buffer);
}else printf("%s",Line_Buffer);
}puts("");
}
int main(int argc,const char**argv){
if(argc<=1)
return puts("Usage: [exec_name] \"FileName\""),0;
Process_File(argv[1]);
// Process_File("cppptest1.cpp");
return 0;
}