/*--------------------------------------------------------------------------*/ int sci_percent_XMLAttr_size(char *fname, unsigned long fname_len) { int id; SciErr err; double d[2] = { 1, 0 }; int * addr = 0; XMLAttr * attrs; int size; char * option = 0; CheckLhs(1, 1); CheckRhs(1, 2); err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (!isXMLAttr(addr, pvApiCtx)) { Scierror(999, gettext("%s: Wrong type for input argument #%d: A %s expected.\n"), fname, 1, "XMLAttr"); return 0; } id = getXMLObjectId(addr, pvApiCtx); attrs = XMLObject::getFromId<XMLAttr>(id); if (!attrs) { Scierror(999, gettext("%s: XMLList does not exist.\n"), fname); return 0; } if (Rhs == 2) { err = getVarAddressFromPosition(pvApiCtx, 2, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (!isStringType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1)) { Scierror(999, gettext("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2); return 0; } if (getAllocatedSingleString(pvApiCtx, addr, &option) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } if (strcmp(option, "r") && strcmp(option, "c") && strcmp(option, "*")) { freeAllocatedSingleString(option); Scierror(44, _("%s: Wrong value for input argument #%d: '%s', '%s' or '%s' expected.\n"), fname, 2, "r", "c", "*"); return 0; } } size = (int)(attrs->getSize()); if (Rhs == 1) { d[1] = size; if (size == 0) { d[0] = 0; } err = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 2, d); } else { if (option[0] == 'r') { if (size == 0) { d[0] = 0; } } else { d[0] = size; } freeAllocatedSingleString(option); err = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 1, d); } if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xmlName(char *fname, unsigned long fname_len) { int id; SciErr err; int *addr = 0; const char **pstStrings = 0; const char * types[] = {"XMLAttr", "XMLList", "XMLSet", "XMLElem"}; int type; int size; CheckLhs(1, 1); CheckRhs(1, 1); err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } type = isXMLObjects(types, 4, addr, pvApiCtx); if (!type) { Scierror(999, gettext("%s: Wrong type for input argument #%i: XMLSet, XMLList, XMLAttr or XMLElem expected.\n"), fname, 1); return 0; } type--; id = getXMLObjectId(addr, pvApiCtx); if (type == 1 || type == 2) { XMLList * list = XMLObject::getFromId < XMLList > (id); if (!list) { Scierror(999, gettext("%s: XMLSet or XMLList does not exist.\n"), fname); return 0; } pstStrings = list->getNameFromList(); size = list->getSize(); } else if (type == 0) { XMLAttr * attrs = XMLObject::getFromId<XMLAttr>(id); if (!attrs) { Scierror(999, gettext("%s: XMLAttr does not exist.\n"), fname); return 0; } pstStrings = attrs->getNames(); size = attrs->getSize(); } else { XMLElement * elem = XMLObject::getFromId<XMLElement>(id); if (!elem) { Scierror(999, gettext("%s: XMLElem does not exist.\n"), fname); return 0; } pstStrings = new const char *[1]; pstStrings[0] = elem->getNodeName(); size = 1; } if (size) { err = createMatrixOfString(pvApiCtx, Rhs + 1, 1, size, const_cast < const char * const *>(pstStrings)); delete[]pstStrings; if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { createEmptyMatrix(pvApiCtx, Rhs + 1); } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }