User:Antigng-bot/infobox

维基百科,自由的百科全书

<source lang="c"> char *detect[]={"imagename","width","job","birthname","dateofbirth","placeofbirth","dateofdeath","placeofdeath","languages","educate","award"}; char *replace[]={"image","box_width","occupation","birth_name","birth_date","birth_place","death_date","death_place","language","education","awards"}; int judge(char *n) {

  char *name;
  int i,j;
  i=0;j=0;length=0;
  name=(char *)calloc(strlen(n)+2,1);
 /*
  我们首先除去所有的空格
 */
  while(n[i])
  {
     if(n[i]&&n[i]!=' '&&n[i]!='\n'&&n[i]!='-'&&n[i]!='|') 

{ name[j]=n[i];j++; } i++;

  }
  name[j]=0;
 /*
  朴素的模式匹配
  */
  for(i=0;i<sizeof(detect)/sizeof(char *);i++)
  {
      length=strlen(detect[i);
     for(j=0;j<length;j++)

{ if(name[j]!=detect[i][j]) break; } if(j==length) { free(name); return i; } } free(name);

return -1; }


int proceedchild(char *title) {

   struct template

{ int flag; char *name; char *value; struct template *next; int eq; } *cite,*pre,*cur,*tail;

     /*
     模板存储在以上的结构构成的单链表中,变量cite(链表头),pre(先前的位置),cur(当前位置),tail(链表尾)
     flag代表参数的值,如果是平凡的(如name,不需要转换),则置位-1,反之,则置为一个大于等于0的数,由judge函数返回
     name是参数名,value是参数值
     next是下一个节点
     */
       HTTP f,g;
     /*
       f,g是两个可变长的数组,f存储从http服务器返回的所有内容(包括响应头);g存储修改后的新页面
     */

int i=0,j=0,k=0,flag=0,status=0,todo=0,div=0,mark=0,perr=0,effect=0,done=1,idone=1,bra=0,ready=0,comment=0,eq=0,tag=0,rcl=0; char c[5000],name[500],value[10000],errmsg[10000],record[100];

      /*
        字符数组c用于存储页面的URL,不会超过5000字节的;name,value用于存储模板参数名和参数值;errmsg是分析模板过程中产生的错误信心;record在匹配模板时用到,rcl是它   的长度*/

char ch,cht,chet;

      /*
         从f中取来的字符存在ch,cht是ch之前的一个字符,chet是ch之前的一个非' '非'\n'字符
      */

const char *match="infobox_people",*MATCH="INFOBOX PEOPLE";

      /*
         匹配infobox_people,INFOBOX PEOPLE模板
       */

const int length=strlen(match);

       /*
           match的长度
       */

struct neditargv point,source;

      /*
           这两个变量现在不用,等将来需要提交编辑了再用
         */

strcpy(c,"https://zh.wikipedia.org/w/index.php?action=raw&title=");

strcat(c,title);

f=hopen(); if(get(c,0,f)) { hclose(f);

return -5; } /*

            从服务器获取页面,如果失败,直接返回
          */

flag=0; while(!heof(f))

   {
 	  ch=hgetc(f);
 
 	  if(ch=='\r')
 	  {
 	  	if(flag==0) flag=1;
 	  	 else if(flag==2) flag=3;
 	  	

}

if(ch=='\n') { if(flag==1) flag=2; else if(flag==3) { flag=4; break; } } if(ch!='\n'&&ch!='\r') flag=0; } if(flag!=4) {


hclose(f); return -1; } /*

          找\r\n\r\n去除响应头,如果响应头后面无内容,直接返回
        */
 status=0;todo=0;div=0;cite=0;pre=0;i=0;j=0;name[0]=0;value[0]=0;perr=0;mark=-2;comment=0;eq=0;tag=0;
 g=hopen();
 cht=ch;
 if(ch!=' '&&ch!='\n') chet=ch;
     ch=hgetc(f);


 while(!heof(f))
 {
     

if(perr==2&&bra==0&&chet=='}'&&ch!='}') { strcat(errmsg,"-->"); k=0; while(errmsg[k]) { if(showerr) smartURLEncode(errmsg[k],g); k++; } perr=0; errmsg[0]=0; }

          /*
               在第三种模式下,选取合适的位置以注释的形式加入错误信息
           */

if(status<length) { if(((!status&&chet=='{')||status)&&(ch==match[status]||ch==MATCH[status])) { status++; record[rcl]=ch; rcl++; record[rcl]=0; } else { status=0; if(rcl) { for(i=0;i<rcl;i++) { smartURLEncode(record[i],g); } } rcl=0; record[0]=0; smartURLEncode(ch,g); }

                 /*
                    匹配模板
                  */

} else { if(mark==-2) { perr=0;comment=0;eq=0;tag=0;errmsg[0]=0;bra=0; cite=(struct template *)calloc(sizeof(struct template),1); cite->next=0; pre=cur=cite; strcpy(errmsg,"