static void XSLPattern_end(xmlXPathParserContextPtr pctx, int nargs) { double pos, last; XSLPATTERN_CHECK_ARGS(0); xmlXPathPositionFunction(pctx, 0); pos = xmlXPathPopNumber(pctx); xmlXPathLastFunction(pctx, 0); last = xmlXPathPopNumber(pctx); xmlXPathReturnBoolean(pctx, pos == last); }
static void XSLPattern_index(xmlXPathParserContextPtr pctx, int nargs) { XSLPATTERN_CHECK_ARGS(0); xmlXPathPositionFunction(pctx, 0); xmlXPathReturnNumber(pctx, xmlXPathPopNumber(pctx) - 1.0); }
/** * exsltMathAtan2Function: * @ctxt: an XPath parser context * @nargs: the number of arguments * * Wraps #exsltMathAtan2 for use by the XPath processor. */ static void exsltMathAtan2Function (xmlXPathParserContextPtr ctxt, int nargs) { double ret, y; if (nargs != 2) { xmlXPathSetArityError(ctxt); return; } y = xmlXPathPopNumber(ctxt); if (xmlXPathCheckError(ctxt)) return; /* x */ ret = xmlXPathPopNumber(ctxt); if (xmlXPathCheckError(ctxt)) return; ret = exsltMathAtan2(y, ret); xmlXPathReturnNumber(ctxt, ret); }
/** * exsltMathPower: * @ctxt: an XPath parser context * @nargs: the number of arguments * * Wraps #exsltMathPower for use by the XPath processor. */ static void exsltMathPowerFunction (xmlXPathParserContextPtr ctxt, int nargs) { double ret, base; if (nargs != 2) { xmlXPathSetArityError(ctxt); return; } ret = xmlXPathPopNumber(ctxt); if (xmlXPathCheckError(ctxt)) return; /* power */ base = xmlXPathPopNumber(ctxt); if (xmlXPathCheckError(ctxt)) return; ret = exsltMathPower(base, ret); xmlXPathReturnNumber(ctxt, ret); }
static void extBitFromHex (xmlXPathParserContextPtr ctxt, int nargs) { xmlChar *res; int maxw = 0, width = 0, i; unsigned long long val, v2; if (nargs != 1 && nargs != 2) { xmlXPathSetArityError(ctxt); return; } /* Pop args in reverse order */ if (nargs == 2) { maxw = xmlXPathPopNumber(ctxt); if (maxw < 0 || xmlXPathCheckError(ctxt)) return; } res = xmlXPathPopString(ctxt); if (res == NULL || xmlXPathCheckError(ctxt)) return; val = strtoull((char *) res, 0, 0x10); for (width = 0, v2 = val; v2; width++, v2 /= 2) continue; if (width == 0) /* Gotta have one zero */ width = 1; if (maxw < width) maxw = width; res = xmlRealloc(res, maxw + 1); if (res) { res[maxw] = '\0'; for (i = maxw - 1, v2 = val; i >= 0; i--) { if (width-- <= 0) res[i] = '0'; else { res[i] = (v2 & 1) ? '1' : '0'; v2 /= 2; } } } xmlXPathReturnString(ctxt, res); }
static void extBitMask (xmlXPathParserContextPtr ctxt, int nargs) { xmlChar *res; int width, maxw = 0; if (nargs != 1 && nargs != 2) { xmlXPathSetArityError(ctxt); return; } /* Pop args in reverse order */ if (nargs == 2) { maxw = xmlXPathPopNumber(ctxt); if (maxw < 0 || xmlXPathCheckError(ctxt)) return; } width = xmlXPathPopNumber(ctxt); if (width < 0 || xmlXPathCheckError(ctxt)) return; if (maxw < width) /* maxw cannot be < width */ maxw = width; if (maxw < 1) /* At least make one zero */ maxw = 1; res = xmlMalloc(maxw + 1); if (res) { res[maxw] = '\0'; if (maxw > width) memset(res, '0', maxw - width); memset(res + maxw - width, '1', width); } xmlXPathReturnString(ctxt, res); }
/** * exsltMathAcosFunction: * @ctxt: an XPath parser context * @nargs: the number of arguments * * Wraps #exsltMathAcos for use by the XPath processor. */ static void exsltMathAcosFunction (xmlXPathParserContextPtr ctxt, int nargs) { double ret; if (nargs != 1) { xmlXPathSetArityError(ctxt); return; } ret = xmlXPathPopNumber(ctxt); if (xmlXPathCheckError(ctxt)) return; ret = exsltMathAcos(ret); xmlXPathReturnNumber(ctxt, ret); }
static void extBitClearOrSet (xmlXPathParserContextPtr ctxt, int nargs, xmlChar value) { xmlChar *res; int width, bitnum = 0, delta; xmlXPathObjectPtr xop; if (nargs != 1 && nargs != 2) { xmlXPathSetArityError(ctxt); return; } /* Pop args in reverse order */ if (nargs == 2) { bitnum = xmlXPathPopNumber(ctxt); if (bitnum < 0 || xmlXPathCheckError(ctxt)) return; } xop = valuePop(ctxt); if (xop == NULL || xmlXPathCheckError(ctxt)) return; res = extBitStringVal(ctxt, xop); if (res == NULL) return; width = xmlStrlen(res); delta = width - bitnum - 1; if (delta < 0) { xmlChar *newp = xmlRealloc(res, bitnum + 2); if (newp == NULL) return; delta = -delta; memmove(newp + delta, newp, width + 1); newp[0] = value; memset(newp + 1, '0', delta - 1); res = newp; } else { res[delta] = value; } xmlXPathReturnString(ctxt, res); }
/** * exsltStrPaddingFunction: * @ctxt: an XPath parser context * @nargs: the number of arguments * * Creates a padding string of a certain length. */ static void exsltStrPaddingFunction (xmlXPathParserContextPtr ctxt, int nargs) { int number, str_len = 0, str_size = 0; xmlChar *str = NULL, *ret = NULL; if ((nargs < 1) || (nargs > 2)) { xmlXPathSetArityError(ctxt); return; } if (nargs == 2) { str = xmlXPathPopString(ctxt); str_len = xmlUTF8Strlen(str); str_size = xmlStrlen(str); } if (str_len == 0) { if (str != NULL) xmlFree(str); str = xmlStrdup((const xmlChar *) " "); str_len = 1; str_size = 1; } number = (int) xmlXPathPopNumber(ctxt); if (number <= 0) { xmlXPathReturnEmptyString(ctxt); xmlFree(str); return; } while (number >= str_len) { ret = xmlStrncat(ret, str, str_size); number -= str_len; } if (number > 0) { str_size = xmlUTF8Strsize(str, number); ret = xmlStrncat(ret, str, str_size); } xmlXPathReturnString(ctxt, ret); if (str != NULL) xmlFree(str); }
/** * exsltMathConstantFunction: * @ctxt: an XPath parser context * @nargs: the number of arguments * * Wraps #exsltMathConstant for use by the XPath processor. */ static void exsltMathConstantFunction (xmlXPathParserContextPtr ctxt, int nargs) { double ret; xmlChar *name; if (nargs != 2) { xmlXPathSetArityError(ctxt); return; } ret = xmlXPathPopNumber(ctxt); if (xmlXPathCheckError(ctxt)) return; name = xmlXPathPopString(ctxt); if (xmlXPathCheckError(ctxt)) return; ret = exsltMathConstant(name, ret); xmlXPathReturnNumber(ctxt, ret); }
static void extBitFromInt (xmlXPathParserContextPtr ctxt, int nargs) { xmlChar *res; xmlXPathObjectPtr xop; int width = 0, len; if (nargs != 1 && nargs != 2) { xmlXPathSetArityError(ctxt); return; } /* Pop args in reverse order */ if (nargs == 2) { width = xmlXPathPopNumber(ctxt); if (width < 0 || xmlXPathCheckError(ctxt)) return; } xop = valuePop(ctxt); if (xop == NULL || xmlXPathCheckError(ctxt)) return; res = extBitStringVal(ctxt, xop); if (res == NULL) return; len = xmlStrlen(res); if (width > len) { res = xmlRealloc(res, width + 1); if (res) { int count = width - len; memmove(res + count, res, len + 1); memset(res, '0', count); } } xmlXPathReturnString(ctxt, res); }