用户:Antigng-bot/date

#define updatedatevalue(value_for_check,name_fixed,groomed) \
{\
	if(checkCS1format(value_for_check,name_fixed)==1)\
	{\
		int yy=0,mm=0,dd=0,issue=0;\
		if(!splitYMD(value_for_check,1,&yy,&mm,&dd,&issue))\
		{\
			if((!issue)&&(yy>1950)&&(mm>=1)&&(mm<=12)&&(dd>=1)&&(dd<=31))\
			{\
				sprintf(value_for_check,"%d-%02d-%02d",yy,mm,dd);\
				groomed=1;\
			}\
		}\
	}\
}
static int tempgroom(struct _templatehead *temp)
{
	int groomed=0;
	int archivetodo=0;
	int accesstodo=0;
	int datetodo=0;
	int hasyear=0;
	int hasmonth=0;
	struct _template *cur_content=temp->content;
	char *check_archive_value=NULL,*check_access_value=NULL,*check_date_value=NULL;
	char *name_fixed=NULL;
	while(cur_content)
	{
		if(cur_content->nameflag)
		{
			struct _value *cur_value=cur_content->name;
			while(cur_value)
			{
				if(cur_value->type)
				{
					if(tempgroom(cur_value->elem.temp)) groomed=1;
				}
				cur_value=cur_value->next;
			}
		}
		if(cur_content->valueflag)
		{
			struct _value *cur_value=cur_content->value;
			while(cur_value)
			{
				if(cur_value->type)
				{
					if(tempgroom(cur_value->elem.temp)) groomed=1;
				}
				cur_value=cur_value->next;
			}
		}
		cur_content=cur_content->next;
	}
	if(temp->rot)
	{
		return groomed;
	}
	name_fixed=s_calloc(sizeof(char)*8192,1);
	if(!checktempname(temp->tempname,name_fixed))
	{
		s_free(name_fixed);
		return groomed;
	}
	cur_content=temp->content;
	while(cur_content)
	{
		if(!(cur_content->nameflag)&&!(cur_content->valueflag))
		{
			fix_name(cur_content->name->elem.ch,name_fixed);
			if(!strcmp("archivedate",name_fixed)||!strcmp("archive-date",name_fixed))
			{
				if(cur_content->value)
				{
					check_archive_value=cur_content->value->elem.ch;
					archivetodo++;
				}
			}
			else if(!strcmp("accessdate",name_fixed)||!strcmp("access-date",name_fixed))
			{
				if(cur_content->value)
				{
					check_access_value=cur_content->value->elem.ch;
					accesstodo++;
				}
			}
			else if(!strcmp("year",name_fixed))
			{
				hasyear=1;
			}
			else if(!strcmp("month",name_fixed))
			{
				hasmonth=1;
			}
			else if(!strcmp("date",name_fixed)||!strcmp("airdate",name_fixed)||!strcmp("air-date",name_fixed))
			{
				if(cur_content->value)
				{
					check_date_value=cur_content->value->elem.ch;
					datetodo++;
				}
			}
		}
		cur_content=cur_content->next;
	}
	if(accesstodo==1)
	{
		updatedatevalue(check_access_value,name_fixed,groomed);
	}
	if(archivetodo==1)
	{
		updatedatevalue(check_archive_value,name_fixed,groomed);
	}
	if(datetodo==1)
	{
		if(!hasyear&&!hasmonth)
		{
			if(dodate)
			{
				updatedatevalue(check_date_value,name_fixed,groomed);
			}
		}
		else
		{
			/*
			todo
			*/
		}
	}
	s_free(name_fixed);
	return groomed;
}