SQLite cominbed source file splitter

SQLite cominbed source file splitter,第1张

概述This program splits the combined version of SQLite source code. See http://www.sqlite.org/ or http://www.sqlite.org/download.html for more of SQLite. #include <stdio.h> typedef enum {     Error = -1,


This program splits the combined version of sqlite source code. See http://www.sqlite.org/ or http://www.sqlite.org/download.html for more of sqlite.


#include <stdio.h>

typedef enum
{
Error = -1,
None = 0,
Common,
BeginInc,
EndInc,
Beginfile,
Endfile,
} lineType;

typedef int Bool;

typedef struct
{
file *file;
char *fname;
} Writer;

voID writetoCur (Writer *cur,char *line)
{
fprintf(cur->file,"%s",line);
}

voID writeIncToCur (Writer *cur,char *chbuf)
{
fprintf(cur->file,"#include /"%s/"",chbuf);
}

Bool nextEq (char **s,const char *t)
{
Bool res = strncmp((*s),(t),strlen(t))==0;
if (res)
{
*s += strlen(t);
}
return res;
}

voID getfilename (char *fname,const char *p)
{
while (*p != '*' && *p != ' ' && *p != 0)
{
*fname++ = *p++;
}
*fname = 0;
}

#define lineBufSize 1024

lineType readline (file *file,char *line,char *fname)
{
int lenline;
lineType type;
if (!fgets(line,lineBufSize - 1,file))
{
return None;
}
if (strlen(line) == lineBufSize - 1)
{ // possibly error
return Error;
}
lenline = strlen(line);
if (lenline > 20 && line[0] == '/' && line[1] == '*')
{
char *pEnd = line + lenline;
char *p = line + 2;
for ( ; (*p == '*' || *p == ' ') && *p != 0; p++);
if (p - line < 10)
{
return Common;
}
if (nextEq(&p,"Begin file "))
{
getfilename(fname,p);
return Beginfile;
}
else if (nextEq(&p,"End of "))
{
getfilename(fname,p);
return Endfile;
}
else if (nextEq(&p,"Include pager.h in the mIDdle of "))
{
getfilename(fname,p);
return BeginInc;
}
else if (nextEq(&p,"Continuing where we left off in "))
{
getfilename(fname,p);
return EndInc;
}
}
return Common;
}

voID parse (char *sfname)
{
#define StackSize 32
char chbuf[128];
char fnbuf[256];
char line[lineBufSize];
Writer stack[StackSize];
Writer *cur;
int depth = 0;
file *srcfile = fopen(sfname,"r");

cur = stack + depth;
sprintf(fnbuf,"out/%s",sfname);
cur->file = fopen(fnbuf,"w");

while (1)
{
lineType type = readline(srcfile,line,chbuf);
if (type == Error)
{
printf("An error has occurred during parsing./n");
break;
}
else if (type == None)
{
break;
}
switch (type)
{
case Common:
writetoCur(cur,line);
break;
case BeginInc:
writeIncToCur(cur,chbuf);
break;
case EndInc:
break;
case Beginfile:
printf("Found file embedded %s/n",chbuf);
depth++;
cur = stack + depth;
sprintf(fnbuf,chbuf);
cur->file = fopen(fnbuf,"w");
writetoCur(cur,line);
break;
case Endfile:
writetoCur(cur,line);
fclose(cur->file);
depth--;
cur = stack + depth;
break;
}
if (depth < 0)
{
break;
}
}
for ( ; depth >= 0; depth--)
{
cur = stack + depth;
fclose(cur->file);
}
}

int main (voID)
{
parse("sqlite3.c");
return 0;
} 总结

以上是内存溢出为你收集整理的SQLite cominbed source file splitter全部内容,希望文章能够帮你解决SQLite cominbed source file splitter所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1178461.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存