📄 parser.c.svn-base
字号:
ctxt->nsNr--; ctxt->nsTab[ctxt->nsNr] = NULL; } return(nr);}#endifstatic intxmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, int nr) { const xmlChar **atts; int *attallocs; int maxatts; if (ctxt->atts == NULL) { maxatts = 55; /* allow for 10 attrs by default */ atts = (const xmlChar **) xmlMalloc(maxatts * sizeof(xmlChar *)); if (atts == NULL) goto mem_error; ctxt->atts = atts; attallocs = (int *) xmlMalloc((maxatts / 5) * sizeof(int)); if (attallocs == NULL) goto mem_error; ctxt->attallocs = attallocs; ctxt->maxatts = maxatts; } else if (nr + 5 > ctxt->maxatts) { maxatts = (nr + 5) * 2; atts = (const xmlChar **) xmlRealloc((void *) ctxt->atts, maxatts * sizeof(const xmlChar *)); if (atts == NULL) goto mem_error; ctxt->atts = atts; attallocs = (int *) xmlRealloc((void *) ctxt->attallocs, (maxatts / 5) * sizeof(int)); if (attallocs == NULL) goto mem_error; ctxt->attallocs = attallocs; ctxt->maxatts = maxatts; } return(ctxt->maxatts);mem_error: xmlErrMemory(ctxt, NULL); return(-1);}/** * inputPush: * @ctxt: an XML parser context * @value: the parser input * * Pushes a new parser input on top of the input stack * * Returns 0 in case of error, the index in the stack otherwise */extern intinputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value){ if (ctxt->inputNr >= ctxt->inputMax) { ctxt->inputMax *= 2; ctxt->inputTab = (xmlParserInputPtr *) xmlRealloc(ctxt->inputTab, ctxt->inputMax * sizeof(ctxt->inputTab[0])); if (ctxt->inputTab == NULL) { xmlErrMemory(ctxt, NULL); return (0); } } ctxt->inputTab[ctxt->inputNr] = value; ctxt->input = value; return (ctxt->inputNr++);}/** * inputPop: * @ctxt: an XML parser context * * Pops the top parser input from the input stack * * Returns the input just removed */extern xmlParserInputPtrinputPop(xmlParserCtxtPtr ctxt){ xmlParserInputPtr ret; if (ctxt->inputNr <= 0) return (0); ctxt->inputNr--; if (ctxt->inputNr > 0) ctxt->input = ctxt->inputTab[ctxt->inputNr - 1]; else ctxt->input = NULL; ret = ctxt->inputTab[ctxt->inputNr]; ctxt->inputTab[ctxt->inputNr] = 0; return (ret);}/** * nodePush: * @ctxt: an XML parser context * @value: the element node * * Pushes a new element node on top of the node stack * * Returns 0 in case of error, the index in the stack otherwise */extern intnodePush(xmlParserCtxtPtr ctxt, xmlNodePtr value){ if (ctxt->nodeNr >= ctxt->nodeMax) { ctxt->nodeMax *= 2; ctxt->nodeTab = (xmlNodePtr *) xmlRealloc(ctxt->nodeTab, ctxt->nodeMax * sizeof(ctxt->nodeTab[0])); if (ctxt->nodeTab == NULL) { xmlErrMemory(ctxt, NULL); return (0); } } if (((unsigned int) ctxt->nodeNr) > xmlParserMaxDepth) { xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR, "Excessive depth in document: change xmlParserMaxDepth = %d\n", xmlParserMaxDepth); ctxt->instate = XML_PARSER_EOF; return(0); } ctxt->nodeTab[ctxt->nodeNr] = value; ctxt->node = value; return (ctxt->nodeNr++);}/** * nodePop: * @ctxt: an XML parser context * * Pops the top element node from the node stack * * Returns the node just removed */extern xmlNodePtrnodePop(xmlParserCtxtPtr ctxt){ xmlNodePtr ret; if (ctxt->nodeNr <= 0) return (0); ctxt->nodeNr--; if (ctxt->nodeNr > 0) ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1]; else ctxt->node = NULL; ret = ctxt->nodeTab[ctxt->nodeNr]; ctxt->nodeTab[ctxt->nodeNr] = 0; return (ret);}/** * nameNsPush: * @ctxt: an XML parser context * @value: the element name * @prefix: the element prefix * @URI: the element namespace name * * Pushes a new element name/prefix/URL on top of the name stack * * Returns -1 in case of error, the index in the stack otherwise */static intnameNsPush(xmlParserCtxtPtr ctxt, const xmlChar * value, const xmlChar *prefix, const xmlChar *URI, int nsNr){ if (ctxt->nameNr >= ctxt->nameMax) { const xmlChar * *tmp; void **tmp2; ctxt->nameMax *= 2; tmp = (const xmlChar * *) xmlRealloc((xmlChar * *)ctxt->nameTab, ctxt->nameMax * sizeof(ctxt->nameTab[0])); if (tmp == NULL) { ctxt->nameMax /= 2; goto mem_error; } ctxt->nameTab = tmp; tmp2 = (void **) xmlRealloc((void * *)ctxt->pushTab, ctxt->nameMax * 3 * sizeof(ctxt->pushTab[0])); if (tmp2 == NULL) { ctxt->nameMax /= 2; goto mem_error; } ctxt->pushTab = tmp2; } ctxt->nameTab[ctxt->nameNr] = value; ctxt->name = value; ctxt->pushTab[ctxt->nameNr * 3] = (void *) prefix; ctxt->pushTab[ctxt->nameNr * 3 + 1] = (void *) URI; ctxt->pushTab[ctxt->nameNr * 3 + 2] = (void *) (long) nsNr; return (ctxt->nameNr++);mem_error: xmlErrMemory(ctxt, NULL); return (-1);}/** * nameNsPop: * @ctxt: an XML parser context * * Pops the top element/prefix/URI name from the name stack * * Returns the name just removed */static const xmlChar *nameNsPop(xmlParserCtxtPtr ctxt){ const xmlChar *ret; if (ctxt->nameNr <= 0) return (0); ctxt->nameNr--; if (ctxt->nameNr > 0) ctxt->name = ctxt->nameTab[ctxt->nameNr - 1]; else ctxt->name = NULL; ret = ctxt->nameTab[ctxt->nameNr]; ctxt->nameTab[ctxt->nameNr] = NULL; return (ret);}/** * namePush: * @ctxt: an XML parser context * @value: the element name * * Pushes a new element name on top of the name stack * * Returns -1 in case of error, the index in the stack otherwise */extern intnamePush(xmlParserCtxtPtr ctxt, const xmlChar * value){ if (ctxt->nameNr >= ctxt->nameMax) { const xmlChar * *tmp; ctxt->nameMax *= 2; tmp = (const xmlChar * *) xmlRealloc((xmlChar * *)ctxt->nameTab, ctxt->nameMax * sizeof(ctxt->nameTab[0])); if (tmp == NULL) { ctxt->nameMax /= 2; goto mem_error; } ctxt->nameTab = tmp; } ctxt->nameTab[ctxt->nameNr] = value; ctxt->name = value; return (ctxt->nameNr++);mem_error: xmlErrMemory(ctxt, NULL); return (-1);}/** * namePop: * @ctxt: an XML parser context * * Pops the top element name from the name stack * * Returns the name just removed */extern const xmlChar *namePop(xmlParserCtxtPtr ctxt){ const xmlChar *ret; if (ctxt->nameNr <= 0) return (0); ctxt->nameNr--; if (ctxt->nameNr > 0) ctxt->name = ctxt->nameTab[ctxt->nameNr - 1]; else ctxt->name = NULL; ret = ctxt->nameTab[ctxt->nameNr]; ctxt->nameTab[ctxt->nameNr] = 0; return (ret);}static int spacePush(xmlParserCtxtPtr ctxt, int val) { if (ctxt->spaceNr >= ctxt->spaceMax) { ctxt->spaceMax *= 2; ctxt->spaceTab = (int *) xmlRealloc(ctxt->spaceTab, ctxt->spaceMax * sizeof(ctxt->spaceTab[0])); if (ctxt->spaceTab == NULL) { xmlErrMemory(ctxt, NULL); return(0); } } ctxt->spaceTab[ctxt->spaceNr] = val; ctxt->space = &ctxt->spaceTab[ctxt->spaceNr]; return(ctxt->spaceNr++);}static int spacePop(xmlParserCtxtPtr ctxt) { int ret; if (ctxt->spaceNr <= 0) return(0); ctxt->spaceNr--; if (ctxt->spaceNr > 0) ctxt->space = &ctxt->spaceTab[ctxt->spaceNr - 1]; else ctxt->space = NULL; ret = ctxt->spaceTab[ctxt->spaceNr]; ctxt->spaceTab[ctxt->spaceNr] = -1; return(ret);}/* * Macros for accessing the content. Those should be used only by the parser, * and not exported. * * Dirty macros, i.e. one often need to make assumption on the context to * use them * * CUR_PTR return the current pointer to the xmlChar to be parsed. * To be used with extreme caution since operations consuming * characters may move the input buffer to a different location ! * CUR returns the current xmlChar value, i.e. a 8 bit value if compiled * This should be used internally by the parser * only to compare to ASCII values otherwise it would break when * running with UTF-8 encoding. * RAW same as CUR but in the input buffer, bypass any token * extraction that may have been done * NXT(n) returns the n'th next xmlChar. Same as CUR is should be used only * to compare on ASCII based substring. * SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined * strings without newlines within the parser. * NEXT1(l) Skip 1 xmlChar, and must also be used only to skip 1 non-newline ASCII * defined char within the parser. * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding * * NEXT Skip to the next character, this does the proper decoding * in UTF-8 mode. It also pop-up unfinished entities on the fly. * NEXTL(l) Skip the current unicode character of l xmlChars long. * CUR_CHAR(l) returns the current unicode character (int), set l * to the number of xmlChars used for the encoding [0-5]. * CUR_SCHAR same but operate on a string instead of the context * COPY_BUF copy the current unicode char to the target buffer, increment * the index * GROW, SHRINK handling of input buffers */#define RAW (*ctxt->input->cur)#define CUR (*ctxt->input->cur)#define NXT(val) ctxt->input->cur[(val)]#define CUR_PTR ctxt->input->cur#define CMP4( s, c1, c2, c3, c4 ) \ ( ((unsigned char *) s)[ 0 ] == c1 && ((unsigned char *) s)[ 1 ] == c2 && \ ((unsigned char *) s)[ 2 ] == c3 && ((unsigned char *) s)[ 3 ] == c4 )#define CMP5( s, c1, c2, c3, c4, c5 ) \ ( CMP4( s, c1, c2, c3, c4 ) && ((unsigned char *) s)[ 4 ] == c5 )#define CMP6( s, c1, c2, c3, c4, c5, c6 ) \ ( CMP5( s, c1, c2, c3, c4, c5 ) && ((unsigned char *) s)[ 5 ] == c6 )#define CMP7( s, c1, c2, c3, c4, c5, c6, c7 ) \ ( CMP6( s, c1, c2, c3, c4, c5, c6 ) && ((unsigned char *) s)[ 6 ] == c7 )#define CMP8( s, c1, c2, c3, c4, c5, c6, c7, c8 ) \ ( CMP7( s, c1, c2, c3, c4, c5, c6, c7 ) && ((unsigned char *) s)[ 7 ] == c8 )#define CMP9( s, c1, c2, c3, c4, c5, c6, c7, c8, c9 ) \ ( CMP8( s, c1, c2, c3, c4, c5, c6, c7, c8 ) && \ ((unsigned char *) s)[ 8 ] == c9 )#define CMP10( s, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 ) \ ( CMP9( s, c1, c2, c3, c4, c5, c6, c7, c8, c9 ) && \ ((unsigned char *) s)[ 9 ] == c10 )#define SKIP(val) do { \ ctxt->nbChars += (val),ctxt->input->cur += (val),ctxt->input->col+=(val); \ if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ if ((*ctxt->input->cur == 0) && \ (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ xmlPopInput(ctxt); \ } while (0)#define SKIPL(val) do { \ int skipl; \ for(skipl=0; skipl<val; skipl++) { \ if (*(ctxt->input->cur) == '\n') { \ ctxt->input->line++; ctxt->input->col = 1; \ } else ctxt->input->col++; \ ctxt->nbChars++; \ ctxt->input->cur++; \ } \ if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ if ((*ctxt->input->cur == 0) && \ (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ xmlPopInput(ctxt); \ } while (0)#define SHRINK if ((ctxt->progressive == 0) && \ (ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \ (ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \ xmlSHRINK (ctxt);static void xmlSHRINK (xmlParserCtxtPtr ctxt) { xmlParserInputShrink(ctxt->input); if ((*ctxt->input->cur == 0) && (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) xmlPopInput(ctxt); }#define GROW if ((ctxt->progressive == 0) && \ (ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \ xmlGROW (ctxt);static void xmlGROW (xmlParserCtxtPtr ctxt) { xmlParserInputGrow(ctxt->input, INPUT_CHUNK); if ((*ctxt->input->cur == 0) && (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) xmlPopInput(ctxt);}#define SKIP_BLANKS xmlSkipBlankChars(ctxt)#define NEXT xmlNextChar(ctxt)#define NEXT1 { \ ctxt->input->col++; \ ctxt->input->cur++; \ ctxt->nbChars++; \ if (*ctxt->input->cur == 0) \ xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \ }#define NEXTL(l) do { \ if (*(ctxt->input->cur) == '\n') { \ ctxt->input->line++; ctxt->input->col = 1; \ } else ctxt->input->col++; \ ctxt->input->cur += l; \ if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ } while (0)#define CUR_CHAR(l) xmlCurrentChar(ctxt, &l)#define CUR_SCHAR(s, l) xmlStringCurrentChar(ctxt, s, &l)#define COPY_BUF(l,b,i,v) \ if (l == 1) b[i++] = (xmlChar) v; \ else i += xmlCopyCharMultiByte(&b[i],v)/** * xmlSkipBlankChars: * @ctxt: the XML parser context * * skip all blanks character found at that point in the input streams. * It pops up finished entities in the process if allowable at that point. * * Returns the number of space chars skipped */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -