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;
}

转载于:https://www.cnblogs.com/tmzbot/p/6540421.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值