⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sgml.c

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 C
📖 第 1 页 / 共 2 页
字号:
			** Character reference or Entity			*/		    case S_ero:			if (c == '#')			    {				/*   &# is Char Ref Open */ 				context->state = S_cro;				break;			    }			context->state = S_entity;			/** FALL THROUGH TO S_entity !! ***/			/*			** Handle Entities			*/		    case S_entity:			if (isalnum((int) c))				HTChunk_putc(string, c);			else			    {				HTChunk_terminate(string);				handle_entity(context);				text = b;				count = 0;				if (c != ';')				    {					--text;					goto S_text;				    }				context->state = S_text;			    }			break;			/*	Character reference			 */		    case S_cro:			if (isalnum((int)c))				/* accumulate a character NUMBER */				HTChunk_putc(string, c);			else			    {				int value;				HTChunk_terminate(string);				if (sscanf(HTChunk_data(string), "%d", &value)==1)					PUTC((char)value);				else				    {					PUTB("&#", 2);					PUTB(HTChunk_data(string), HTChunk_size(string)-1);				    }				text = b;				count = 0;				if (c != ';')				    {					--text;					goto S_text;				    }				context->state = S_text;			    }			break;		    case S_tag:		/* new tag */		    handle_S_tag:			if (isalnum((int)c))				HTChunk_putc(string, c);			else { /* End of tag name */			    int i;			    if (c == '/') {				if (HTChunk_size(string) > 0)				    HTTRACE(SGML_TRACE, "`<%s/' found!\n" _ HTChunk_data(string));				context->state = S_end;				break;			    } else if (c == '!') {				if (HTChunk_size(string) > 0)				    HTTRACE(SGML_TRACE, " `<%s!' found!\n" _ HTChunk_data(string));				context->state = S_md;				break;			    }			    HTChunk_terminate(string);			    context->current_tag  = SGMLFindTag(dtd, HTChunk_data(string));			    if (context->current_tag == NULL) {				HTTRACE(SGML_TRACE, "*** Unknown element %s\n" _ HTChunk_data(string));				(*context->actions->unparsed_begin_element)				    (context->target, HTChunk_data(string), HTChunk_size(string));			    } else {				for (i=0; i<context->current_tag->number_of_attributes; i++) {				    context->present[i] = NO;				    context->value[i] = -1;				}			    }			    context->token = 0;			    HTChunk_clear(string);			    context->current_attribute_number = INVALID;			    goto S_tag_gap;			}			break;		    S_tag_gap:			context->state = S_tag_gap;		    case S_tag_gap:		/* Expecting attribute or > */			if (isspace((int) c))				break;	/* Gap between attributes */			if (c == '>')				goto got_element_open;			else				goto S_attr;		    S_attr:			/*			** Start collecting the attribute name and collect			** it in S_attr.			*/			context->state = S_attr;			HTChunk_truncate(string, context->token);		    case S_attr:			if (isspace((int) c) || c == '>' || c == '=')				goto got_attribute_name;			else				HTChunk_putc(string, c);			break;		    got_attribute_name:			/*			** This label is entered when attribute name has been			** collected. Process it and enter S_attr_gap for			** potential value or start of the next attribute.			*/			HTChunk_terminate(string) ;			handle_attribute_name				(context, HTChunk_data(string) + context->token);			HTChunk_truncate(string, context->token);			context->state = S_attr_gap;		    case S_attr_gap:	/* Expecting attribute or = or > */			if (isspace((int) c))				break;	/* Gap after attribute */			if (c == '>')				goto got_element_open;			else if (c == '=')				context->state = S_equals;			else				goto S_attr; /* Get next attribute */			break;		    case S_equals:	/* After attr = */ 			if (isspace((int) c))				break;	/* Before attribute value */			if (c == '>')			    {		/* End of tag */				HTTRACE(SGML_TRACE, "found = but no value\n");				goto got_element_open;			    }			else if (c == '\'')				context->state = S_squoted;			else if (c == '"')				context->state = S_dquoted;			else				goto S_value;			break;		    S_value:			context->state = S_value;			HTChunk_truncate(string, context->token);		    case S_value:			if (isspace((int) c) || c == '>')			    {				HTChunk_terminate(string);				handle_attribute_value(context);				context->token = HTChunk_size(string);				goto S_tag_gap;			    }			else				HTChunk_putc(string, c);			break;				    case S_squoted:	/* Quoted attribute value */			if (c == '\'')			    {				HTChunk_terminate(string);				handle_attribute_value(context);				context->token = HTChunk_size(string);				context->state = S_tag_gap;			    }			else if (c && c != '\n' && c != '\r')				HTChunk_putc(string, c);			break;			    case S_dquoted:	/* Quoted attribute value */			if (c == '"')			    {				HTChunk_terminate(string);				handle_attribute_value(context);				context->token = HTChunk_size(string);				context->state = S_tag_gap;			    }			else if (c && c != '\n' && c != '\r')				HTChunk_putc(string, c);			break;		    case S_end:	/* </ */			if (isalnum((int) c))				HTChunk_putc(string, c);			else			    {		/* End of end tag name */				HTTag *t;				char * first;				HTChunk_terminate(string);				if ((first=HTChunk_data(string))!=NULL && *first != '\0')				        t = SGMLFindTag(dtd, HTChunk_data(string));				else				    	/* Empty end tag */					/* Original code popped here one					   from the stack. If this feature					   is required, I have to put the					   stack back... -- msa */					t = NULL;				if (!t) {				    HTTRACE(SGML_TRACE, "Unknown end tag </%s>\n" _ HTChunk_data(string));				    (*context->actions->unparsed_end_element)					(context->target, HTChunk_data(string), HTChunk_size(string));				} else {				    context->current_tag = NULL;				    end_element(context, t);				}				HTChunk_clear(string);				context->current_attribute_number = INVALID;				if (c != '>')				    {					if (!isspace((int) c))					    HTTRACE(SGML_TRACE, "`</%s%c' found!\n" _ HTChunk_data(string) _ c);					context->state = S_junk_tag;				    }				else				    {					text = b;					count = 0;					context->state = S_text;				    }			    }			break;		    case S_junk_tag:			if (c == '>')			    {				text = b;				count = 0;				context->state = S_text;			    }			break;			/*			** Scanning (actually skipping) declarations			*/		    case S_md:			if (c == '-')				context->state = S_com_1;			else if (c == '"')				context->state = S_md_dqs;			else if (c == '\'')				context->state = S_md_sqs;			else if (c == '>')			    {				text = b;				count = 0;				context->state = S_text;			    }			break;		    case S_md_dqs: /* Skip double quoted string */			if (c == '"')				context->state = S_md;			else if (c == '>')			    {				text = b;				count = 0;				context->state = S_text;			    }			break;		    case S_md_sqs: /* Skip single quoted string */			if (c == '\'')				context->state = S_md;			else if (c == '>')			    {				text = b;				count = 0;				context->state = S_text;			    }			break;		    case S_com_1: /* Starting a comment? */			context->state = (c == '-') ? S_com : S_md;			if (c == '>')			    {				text = b;				count = 0;				context->state = S_text;			    }			break;		    case S_com: /* ..within comment */			if (c == '-')				context->state = S_com_2;			break;		    case S_com_2: /* Ending a comment ? */			context->state = (c == '-') ? S_com_2a : S_com;			break;		    		    case S_com_2a:			if (c == '>') {			    text = b;			    count = 0;			    context->state = S_text;			} else if (c == '-') {			    context->state = S_com_2a;			} else			    context->state = S_com;			break;		    }	    }	if (count > 0)		PUTB(text, count);	return HT_OK;    }PRIVATE int SGML_string (HTStream * context, const char* s)    {	return SGML_write(context, s, (int) strlen(s));    }PRIVATE int SGML_character (HTStream * context, char c)    {	return SGML_write(context, &c, 1);    }/*_______________________________________________________________________*//*	Structured Object Class**	-----------------------*/PRIVATE const HTStreamClass SGMLParser = {    "SGML",    SGML_flush,    SGML_free,    SGML_abort,    SGML_character,     SGML_string,    SGML_write}; /*	Create SGML Engine**	------------------**** On entry,**	dtd		represents the DTD, along with**	actions		is the sink for the data as a set of routines.***/PUBLIC HTStream *SGML_new(const SGML_dtd * dtd, HTStructured * target){    int i;    HTStream* context;    if ((context = (HTStream  *) HT_CALLOC(1, sizeof(HTStream))) == NULL)	HT_OUTOFMEM("SGML_begin");    context->isa = &SGMLParser;    context->string = HTChunk_new(128);	/* Grow by this much */    context->dtd = dtd;    context->target = target;    context->actions = (HTStructuredClass*)(((HTStream*)target)->isa);    /* Ugh: no OO */    context->state = S_text;    for(i=0; i<MAX_ATTRIBUTES; i++)	context->value[i] = 0;    return context;}PUBLIC HTTag * SGML_findTag (SGML_dtd * dtd, int element_number){    return (dtd && element_number>=0 && element_number<dtd->number_of_tags) ?	(dtd->tags+element_number) : NULL;}PUBLIC char * SGML_findTagName (SGML_dtd * dtd, int element_number){    return (dtd && element_number>=0 && element_number<dtd->number_of_tags) ?	(dtd->tags+element_number)->name : NULL;}PUBLIC SGMLContent SGML_findTagContents (SGML_dtd * dtd, int element_number){    return (dtd && element_number>=0 && element_number<dtd->number_of_tags) ?	(dtd->tags+element_number)->contents : SGML_ELEMENT;}PUBLIC int SGML_findElementNumber (SGML_dtd * dtd, char * name_element){    if (dtd && name_element) {	int i;	HTTag *ct;	for (i = 0; i< dtd->number_of_tags; i++) {	    ct = &(dtd->tags[i]);	    if (!strcasecomp(ct->name,name_element))		return i;	}    }    return -1;}PUBLIC char * HTTag_name (HTTag * tag){    return tag ? tag->name : NULL;}PUBLIC SGMLContent HTTag_content (HTTag * tag){    return tag ? tag->contents : SGML_EMPTY;}PUBLIC int HTTag_attributes (HTTag * tag){    return tag ? tag->number_of_attributes : -1;}PUBLIC char * HTTag_attributeName (HTTag * tag, int attribute_number){    return (tag && attribute_number>=0 && attribute_number<tag->number_of_attributes) ?	(tag->attributes+attribute_number)->name : NULL;}PUBLIC char * HTAttr_name (HTAttr * attr){    return attr ? attr->name : NULL;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -