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

📄 testhtml.c

📁 基于s3c2410芯片的数据采集系统 目标环境:S3C2410芯片、经裁剪后的linux2.6内核、sqlite数据库、cgi库 项目描述:节点端采集数据
💻 C
📖 第 1 页 / 共 2 页
字号:
    unsigned char output[40];    int inlen = len, outlen = 30;    htmlEncodeEntities(output, &outlen, ch, &inlen, 0);    output[outlen] = 0;    fprintf(stdout, "SAX.cdata(%s, %d)\n", output, len);}/** * referenceDebug: * @ctxt:  An XML parser context * @name:  The entity name * * called when an entity reference is detected.  */static voidreferenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name){    fprintf(stdout, "SAX.reference(%s)\n", name);}/** * ignorableWhitespaceDebug: * @ctxt:  An XML parser context * @ch:  a xmlChar string * @start: the first char in the string * @len: the number of xmlChar * * receiving some ignorable whitespaces from the parser. * Question: how much at a time ??? */static voidignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len){    char output[40];    int i;    for (i = 0;(i<len) && (i < 30);i++)	output[i] = ch[i];    output[i] = 0;    fprintf(stdout, "SAX.ignorableWhitespace(%s, %d)\n", output, len);}/** * processingInstructionDebug: * @ctxt:  An XML parser context * @target:  the target name * @data: the PI data's * @len: the number of xmlChar * * A processing instruction has been parsed. */static voidprocessingInstructionDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *target,                      const xmlChar *data){    fprintf(stdout, "SAX.processingInstruction(%s, %s)\n",            (char *) target, (char *) data);}/** * commentDebug: * @ctxt:  An XML parser context * @value:  the comment content * * A comment has been parsed. */static voidcommentDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *value){    fprintf(stdout, "SAX.comment(%s)\n", value);}/** * warningDebug: * @ctxt:  An XML parser context * @msg:  the message to display/transmit * @...:  extra parameters for the message display * * Display and format a warning messages, gives file, line, position and * extra parameters. */static void XMLCDECLwarningDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...){    va_list args;    va_start(args, msg);    fprintf(stdout, "SAX.warning: ");    vfprintf(stdout, msg, args);    va_end(args);}/** * errorDebug: * @ctxt:  An XML parser context * @msg:  the message to display/transmit * @...:  extra parameters for the message display * * Display and format a error messages, gives file, line, position and * extra parameters. */static void XMLCDECLerrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...){    va_list args;    va_start(args, msg);    fprintf(stdout, "SAX.error: ");    vfprintf(stdout, msg, args);    va_end(args);}/** * fatalErrorDebug: * @ctxt:  An XML parser context * @msg:  the message to display/transmit * @...:  extra parameters for the message display * * Display and format a fatalError messages, gives file, line, position and * extra parameters. */static void XMLCDECLfatalErrorDebug(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...){    va_list args;    va_start(args, msg);    fprintf(stdout, "SAX.fatalError: ");    vfprintf(stdout, msg, args);    va_end(args);}static xmlSAXHandler debugSAXHandlerStruct = {    internalSubsetDebug,    isStandaloneDebug,    hasInternalSubsetDebug,    hasExternalSubsetDebug,    resolveEntityDebug,    getEntityDebug,    entityDeclDebug,    notationDeclDebug,    attributeDeclDebug,    elementDeclDebug,    unparsedEntityDeclDebug,    setDocumentLocatorDebug,    startDocumentDebug,    endDocumentDebug,    startElementDebug,    endElementDebug,    referenceDebug,    charactersDebug,    ignorableWhitespaceDebug,    processingInstructionDebug,    commentDebug,    warningDebug,    errorDebug,    fatalErrorDebug,    getParameterEntityDebug,    cdataDebug,    NULL,    1,    NULL,    NULL,    NULL,    NULL};xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;/************************************************************************ *									* *				Debug					* *									* ************************************************************************/static voidparseSAXFile(char *filename) {    htmlDocPtr doc = NULL;    /*     * Empty callbacks for checking     */#ifdef LIBXML_PUSH_ENABLED    if (push) {	FILE *f;#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)	f = fopen(filename, "rb");#else	f = fopen(filename, "r");#endif	if (f != NULL) {	    int res, size = 3;	    char chars[4096];	    htmlParserCtxtPtr ctxt;	    /* if (repeat) */		size = 4096;	    res = fread(chars, 1, 4, f);	    if (res > 0) {		ctxt = htmlCreatePushParserCtxt(emptySAXHandler, NULL,			    chars, res, filename, XML_CHAR_ENCODING_NONE);		while ((res = fread(chars, 1, size, f)) > 0) {		    htmlParseChunk(ctxt, chars, res, 0);		}		htmlParseChunk(ctxt, chars, 0, 1);		doc = ctxt->myDoc;		htmlFreeParserCtxt(ctxt);	    }	    if (doc != NULL) {		fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");		xmlFreeDoc(doc);	    }	    fclose(f);	}	if (!noout) {#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)		f = fopen(filename, "rb");#else		f = fopen(filename, "r");#endif	    if (f != NULL) {		int res, size = 3;		char chars[4096];		htmlParserCtxtPtr ctxt;		/* if (repeat) */		    size = 4096;		res = fread(chars, 1, 4, f);		if (res > 0) {		    ctxt = htmlCreatePushParserCtxt(debugSAXHandler, NULL,				chars, res, filename, XML_CHAR_ENCODING_NONE);		    while ((res = fread(chars, 1, size, f)) > 0) {			htmlParseChunk(ctxt, chars, res, 0);		    }		    htmlParseChunk(ctxt, chars, 0, 1);		    doc = ctxt->myDoc;		    htmlFreeParserCtxt(ctxt);		}		if (doc != NULL) {		    fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");		    xmlFreeDoc(doc);		}		fclose(f);	    }	}    } else {	#endif /* LIBXML_PUSH_ENABLED */	doc = htmlSAXParseFile(filename, NULL, emptySAXHandler, NULL);	if (doc != NULL) {	    fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");	    xmlFreeDoc(doc);	}	if (!noout) {	    /*	     * Debug callback	     */	    doc = htmlSAXParseFile(filename, NULL, debugSAXHandler, NULL);	    if (doc != NULL) {		fprintf(stdout, "htmlSAXParseFile returned non-NULL\n");		xmlFreeDoc(doc);	    }	}#ifdef LIBXML_PUSH_ENABLED    }#endif /* LIBXML_PUSH_ENABLED */}static voidparseAndPrintFile(char *filename) {    htmlDocPtr doc = NULL;    /*     * build an HTML tree from a string;     */#ifdef LIBXML_PUSH_ENABLED    if (push) {	FILE *f;#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)	f = fopen(filename, "rb");#else	f = fopen(filename, "r");#endif	if (f != NULL) {	    int res, size = 3;	    char chars[4096];	    htmlParserCtxtPtr ctxt;	    /* if (repeat) */		size = 4096;	    res = fread(chars, 1, 4, f);	    if (res > 0) {		ctxt = htmlCreatePushParserCtxt(NULL, NULL,			    chars, res, filename, XML_CHAR_ENCODING_NONE);		while ((res = fread(chars, 1, size, f)) > 0) {		    htmlParseChunk(ctxt, chars, res, 0);		}		htmlParseChunk(ctxt, chars, 0, 1);		doc = ctxt->myDoc;		htmlFreeParserCtxt(ctxt);	    }	    fclose(f);	}    } else {		doc = htmlReadFile(filename, NULL, options);    }#else	doc = htmlReadFile(filename,NULL,options);#endif    if (doc == NULL) {        xmlGenericError(xmlGenericErrorContext,		"Could not parse %s\n", filename);    }#ifdef LIBXML_TREE_ENABLED    /*     * test intermediate copy if needed.     */    if (copy) {        htmlDocPtr tmp;        tmp = doc;	doc = xmlCopyDoc(doc, 1);	xmlFreeDoc(tmp);    }#endif#ifdef LIBXML_OUTPUT_ENABLED    /*     * print it.     */    if (!noout) { #ifdef LIBXML_DEBUG_ENABLED	if (!debug) {	    if (encoding)		htmlSaveFileEnc("-", doc, encoding);	    else		htmlDocDump(stdout, doc);	} else	    xmlDebugDumpDocument(stdout, doc);#else	if (encoding)	    htmlSaveFileEnc("-", doc, encoding);	else	    htmlDocDump(stdout, doc);#endif    }	#endif /* LIBXML_OUTPUT_ENABLED */    /*     * free it.     */    xmlFreeDoc(doc);}int main(int argc, char **argv) {    int i, count;    int files = 0;    for (i = 1; i < argc ; i++) {#ifdef LIBXML_DEBUG_ENABLED	if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))	    debug++;	else#endif	    if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))	    copy++;#ifdef LIBXML_PUSH_ENABLED	else if ((!strcmp(argv[i], "-push")) || (!strcmp(argv[i], "--push")))	    push++;#endif /* LIBXML_PUSH_ENABLED */	else if ((!strcmp(argv[i], "-sax")) || (!strcmp(argv[i], "--sax")))	    sax++;	else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout")))	    noout++;	else if ((!strcmp(argv[i], "-repeat")) ||	         (!strcmp(argv[i], "--repeat")))	    repeat++;	else if ((!strcmp(argv[i], "-encode")) ||	         (!strcmp(argv[i], "--encode"))) {	    i++;	    encoding = argv[i];        }    }    for (i = 1; i < argc ; i++) {	if ((!strcmp(argv[i], "-encode")) ||	         (!strcmp(argv[i], "--encode"))) {	    i++;	    continue;        }	if (argv[i][0] != '-') {	    if (repeat) {		for (count = 0;count < 100 * repeat;count++) {		    if (sax)			parseSAXFile(argv[i]);		    else   			parseAndPrintFile(argv[i]);		}    	    } else {		if (sax)		    parseSAXFile(argv[i]);		else   		    parseAndPrintFile(argv[i]);	    }	    files ++;	}    }    if (files == 0) {	printf("Usage : %s [--debug] [--copy] [--copy] HTMLfiles ...\n",	       argv[0]);	printf("\tParse the HTML files and output the result of the parsing\n");#ifdef LIBXML_DEBUG_ENABLED	printf("\t--debug : dump a debug tree of the in-memory document\n");#endif	printf("\t--copy : used to test the internal copy implementation\n");	printf("\t--sax : debug the sequence of SAX callbacks\n");	printf("\t--repeat : parse the file 100 times, for timing\n");	printf("\t--noout : do not print the result\n");#ifdef LIBXML_PUSH_ENABLED	printf("\t--push : use the push mode parser\n");#endif /* LIBXML_PUSH_ENABLED */	printf("\t--encode encoding : output in the given encoding\n");    }    xmlCleanupParser();    xmlMemoryDump();    return(0);}#else /* !LIBXML_HTML_ENABLED */#include <stdio.h>int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {    printf("%s : HTML support not compiled in\n", argv[0]);    return(0);}#endif

⌨️ 快捷键说明

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