跳转到内容

用户:Antigng-bot/fix

维基百科,自由的百科全书
struct problemlist
{
	char title[100];
	struct problemlist *next;
};
struct problemlist *query(char *target,char *spacenum)
{
	FILE *f;
	char line[1000]={0},url[1000]={0},snd[1000]={0},ecd[200]={0},title[200]={0},sroffset[100]={0};
	const char *match="title=\"",*nextmatch="<continue sroffset=\"";
	const int length=strlen(match),nextlength=strlen(nextmatch);
	int i=0,j=0,k=0,next=0,count=0;
	struct problemlist *pre,*temp,*head=0;
	strcpy(url,"https://zh.wikipedia.org/w/api.php?action=query&list=search&format=xml&srlimit=500&srsearch=");
	URLEncode(target,strlen(target),ecd,200);
	strcat(url,ecd);
	strcat(url,"&srnamespace=");
	strcat(url,spacenum);
	do
	{

		strcpy(snd,url);
		if(next)
		{
		     strcat(snd,"&sroffset=");
			 strcat(snd,sroffset);
		}
        get(snd,"a.txt",1);
		f=fopen("a.txt","r+");
	  do
	  {
		  fgets(line,1000,f);
	  }while(line[0]!='<'&&!feof(f));
	  next=0;
	  do
	  {
		  i=0;
		  while(line[i])
		  {
			  for(j=0;j<nextlength;j++)
			{
				if(line[i+j]!=nextmatch[j]) break;
			}
			if(j==nextlength)
			{
				
				for(k=0;line[i+j+k]!='\"'&&line[i+j+k]!=0;k++)
				{
					sroffset[k]=line[i+j+k];
				}
				sroffset[k]=0;
				if(line[i+j+k]=='\"') next=1;
				i=i+j+k;j=0;k=0;
				continue;
				
			}
			else i=i+j;
			for(j=0;j<length;j++)
			{
				if(line[i+j]!=match[j]) break;
			}
			if(j==length)
			{
				
				for(k=0;line[i+j+k]!='\"'&&line[i+j+k]!=0;k++)
				{
					title[k]=line[i+j+k];
				}
				title[k]=0;
				if(line[i+j+k]=='\"')
				{
					if(!head)
				  {
					    pre=temp=(struct problemlist *)malloc(sizeof(struct problemlist));
					    head=temp;
				   }
				   else
			     {
					     pre=temp;
					     temp=(struct problemlist *)malloc(sizeof(struct problemlist));
					     pre->next=temp;
				   }
				   strcpy(temp->title,title);
				   temp->next=0;
				   i=i+j+k;j=0;k=0;
				   continue;
				}
			}
			i++;
		  }
		  fgets(line,1000,f);
	  }while(!feof(f));
	  fclose(f);
	  count++;
	}while(next);
	return head;
}

void show(struct problemlist *head)
{
   FILE *f;
   f=fopen("b.txt","w+");
   while(head)
   {
     fprintf(f,"%s\n",head->title);
	 head=head->next;
   } 
   fclose(f);
}

int proceed(struct problemlist* p,struct problemlist **new,int depth)
{
	struct problemlist *pre,*head;
	FILE *f;
	int i=0,j,count=0,cl,flag,status=0,todo=0;
	char c[1000],line[1000],tt[200],*newtext,ch;
	char *match=G2U("外部鏈接"),*replace=G2U("外部連結");
	int length=strlen(match),rpl=strlen(replace);
	if(!p) return -1;
	newtext=(char *)malloc(1024*1024);
	head=p;
	for(count=0;count<depth&&head;count++,pre=head,head=head->next,free(pre))
	{
		strcpy(c,"https://zh.wikipedia.org/w/index.php?action=raw&title=");
		URLEncode(head->title,strlen(head->title),tt,200);
		strcat(c,tt);
		get(c,"text.txt",0);
	 //printf("mark 1:\n");
		f=fopen("text.txt","r+");
		flag=0;
		while(!feof(f))
    {
  	  ch=fgetc(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) continue;
  status=0;todo=0;cl=0;newtext[cl]=0;
 // printf("mark 2:\n");
	while(!feof(f))
	{
		
		fgets(line,1000,f);
	//	printf("%s\n",line);
		i=0;
		while(line[i])
		{
		 	if(line[i]==match[0])
			{
			//	printf("preok\n");
				for(j=0;j<length;j++)
				{
					if(line[i+j]!=match[j]) break;
				}
				
				if(j==length) 
				{
				    newtext[cl]=0;
				//	printf("%s %d\n",replace,rpl);
				    strcat(newtext,replace);
					todo=1;
					cl+=rpl;
					i=i+j;
					j=0;
					continue;
					
				}
			}
		
			newtext[cl]=line[i];
			i++;
			cl++;newtext[cl]=0;
			
		}
	}
	newtext[cl]=0;
//	printf("mark3 %d\n",todo);

	if(todo) edit(head->title,newtext);
	fflush(f);
	fclose(f);
		
		
	}
	free(newtext);
	free(match);
	free(replace);
	*new=head;
	return 0;
}