void execute_one_byte() { unsigned char temp; switch (cur_inst) { case 0x00: // CLRA A = 0; break; case 0x01: // SKMBZ 0 skmbz(0x0); break; case 0x02: // XOR A = (A ^ copram[Br][Bd]) & 0xf; break; case 0x03: // SKMBZ 2 skmbz(0x2); break; case 0x04: // XIS 0 xis(0x0); break; case 0x05: // LD 0 ld(0x0); break; case 0x06: // X 0 x(0x0); break; case 0x07: // XDS 0 xds(0x0); break; case 0x08: // LBI 0,9 lbi(0, 9); break; case 0x09: // LBI 0,10 lbi(0, 10); break; case 0x0a: // LBI 0,11 lbi(0, 11); break; case 0x0b: // LBI 0,12 lbi(0, 12); break; case 0x0c: // LBI 0,13 lbi(0, 13); break; case 0x0d: // LBI 0,14 lbi(0, 14); break; case 0x0e: // LBI 0,15 lbi(0, 15); break; case 0x0f: // LBI 0,0 lbi(0, 0); break; case 0x10: // CASC A = ((~A & 0x0f) + copram[Br][Bd] + C); C = (A & 0xF0)?1:0; A &= 0x0F; if (C) { g_skip = 1; } break; case 0x11: // SKMBZ 1 skmbz(0x1); break; case 0x12: // XABR temp = A; A = Br; Br = temp & 0x3; break; case 0x13: // SKMBZ 3 skmbz(0x3); break; case 0x14: // XIS 1 xis(0x1); break; case 0x15: // LD 1 ld(0x1); break; case 0x16: // X 1 x(0x1); break; case 0x17: // XDS 1 xds(0x1); break; case 0x18: // LBI 1,9 lbi(1, 9); break; case 0x19: // LBI 1,10 lbi(1, 10); break; case 0x1a: // LBI 1,11 lbi(1, 11); break; case 0x1b: // LBI 1,12 lbi(1, 12); break; case 0x1c: // LBI 1,13 lbi(1, 13); break; case 0x1d: // LBI 1,14 lbi(1, 14); break; case 0x1e: // LBI 1,15 lbi(1, 15); break; case 0x1f: // LBI 1,0 lbi(1, 0); break; case 0x20: // SKC if (C) { g_skip = 1; } break; case 0x21: // SKE if (A == copram[Br][Bd]) { g_skip = 1; } break; case 0x22: // SC C = 1; break; case 0x24: // XIS 2 xis(0x2); break; case 0x25: // LD 2 ld(0x2); break; case 0x26: // X 2 x(0x2); break; case 0x27: // XDS 2 xds(0x2); break; case 0x28: // LBI 2,9 lbi(2, 9); break; case 0x29: // LBI 2,10 lbi(2, 10); break; case 0x2a: // LBI 2,11 lbi(2, 11); break; case 0x2b: // LBI 2,12 lbi(2, 12); break; case 0x2c: // LBI 2,13 lbi(2, 13); break; case 0x2d: // LBI 2,14 lbi(2, 14); break; case 0x2e: // LBI 2,15 lbi(2, 15); break; case 0x2f: // LBI 2,0 lbi(2, 0); break; case 0x30: // ASC A = (A + copram[Br][Bd] + C); C = (A & 0xF0)?1:0; A = A & 0x0F; if (C) { g_skip = 1; } break; case 0x31: // ADD A = (A + copram[Br][Bd]) & 0x0F; break; case 0x32: // RC C = 0; break; case 0x34: // XIS 3 xis(0x3); break; case 0x35: // LD 3 ld(0x3); break; case 0x36: // X 3 x(0x3); break; case 0x37: // XDS 3 xds(0x3); break; case 0x38: // LBI 3,9 lbi(3, 9); break; case 0x39: // LBI 3,10 lbi(3, 10); break; case 0x3a: // LBI 3,11 lbi(3, 11); break; case 0x3b: // LBI 3,12 lbi(3, 12); break; case 0x3c: // LBI 3,13 lbi(3, 13); break; case 0x3d: // LBI 3,14 lbi(3, 14); break; case 0x3e: // LBI 3,15 lbi(3, 15); break; case 0x3f: // LBI 3,0 lbi(3, 0); break; case 0x40: // COMP A = (~A) & 0xf; break; case 0x41: // SKT if (COUNT_CARRY) { g_skip = 1; COUNT_CARRY = 0; } break; case 0x42: // RMB 2 rmb(2); break; case 0x43: // RMB 3 rmb(3); break; case 0x44: // NOP break; case 0x45: // RMB 1 rmb(1); break; case 0x46: // SMB 2 smb(2); break; case 0x47: // SMB 1 smb(1); break; case 0x48: // RET pop_stack(); break; case 0x49: // RETSK pop_stack(); g_skip = 1; break; case 0x4a: // ADT A = (A + 10) & 0xf; break; case 0x4b: // SMB 3 smb(3); break; case 0x4c: // RMB 0 rmb(0); break; case 0x4d: // SMB 0 smb(0); break; case 0x4e: // CBA A = Bd; break; case 0x4f: // XAS temp = A; A = SIO; SIO = temp; break; case 0x50: // CAB Bd = A; break; case 0x51: // AISC case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: A = A + (cur_inst & 0xf); if (A & 0xf0) { g_skip = 1; } A &= 0xf; break; case 0x70: // STII case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: copram[Br][Bd] = cur_inst & 0x0f; Bd++; if (Bd > 0xf) { Bd = 0; } break; case 0xbf: // LQID Q = coprom[(PC & 0x300) | ((A << 4) & 0xf0) | (copram[Br][Bd] & 0xf)]; SC = SB; break; case 0xff: // JID PC = coprom[(PC & 0x300) | ((A << 4) & 0xf0) | (copram[Br][Bd] & 0xf)]; break; default: if (cur_inst >= 0x80 && cur_inst < 0xbf) { if (PC >= 0x080 && PC < 0x100) // JP within SRP { PC = (PC & 0x380) | (cur_inst & 0x7f); } else // JSRP { push_stack(); PC = 0x080 | (cur_inst & 0x3f); } } else if (cur_inst >= 0xc0 && cur_inst < 0xff) { PC = (PC & 0x3c0) | (cur_inst & 0x3f); } else { // MATT : commented this stuff out for reasons explained at top of file // cout.setf(ios::hex); // cout.setf(ios::right, ios::adjustfield); // cout << "Invalid Instruction: " << setw(2) << setfill( '0' ) << static_cast<int>(cur_inst) << " at PC: " << setw(3) << setfill( '0' ) << static_cast<int>(inst_pc) << endl; break; } } }
void TXFMXPath::evaluateExpr(DOMNode *h, safeBuffer inexpr) { // Temporarily add any necessary name spaces into the document XSECXPathNodeList addedNodes; setXPathNS(document, XPathAtts, addedNodes, formatter, mp_nse); XPathProcessorImpl xppi; // The processor XercesParserLiaison xpl; #if XALAN_VERSION_MAJOR == 1 && XALAN_VERSION_MINOR > 10 XercesDOMSupport xds(xpl); #else XercesDOMSupport xds; #endif XPathEvaluator xpe; XPathFactoryDefault xpf; XPathConstructionContextDefault xpcc; XalanDocument * xd; XalanNode * contextNode; // Xalan can throw exceptions in all functions, so do one broad catch point. try { // Map to Xalan xd = xpl.createDocument(document); // For performing mapping XercesDocumentWrapper *xdw = xpl.mapDocumentToWrapper(xd); XercesWrapperNavigator xwn(xdw); // Map the "here" node - but only if part of current document XalanNode * hereNode = NULL; if (h->getOwnerDocument() == document) { hereNode = xwn.mapNode(h); if (hereNode == NULL) { hereNode = findHereNodeFromXalan(&xwn, xd, h); if (hereNode == NULL) { throw XSECException(XSECException::XPathError, "Unable to find here node in Xalan Wrapper map"); } } } // Now work out what we have to set up in the new processing TXFMBase::nodeType inputType = input->getNodeType(); XalanDOMString cd; // For the moment assume the root is the context const XalanDOMChar * cexpr; safeBuffer contextExpr; switch (inputType) { case DOM_NODE_DOCUMENT : case DOM_NODE_XPATH_NODESET : // do XPath over the whole document and, if the input was an // XPath Nodeset, then later intersect the result with the input nodelist cd = XalanDOMString("/"); // Root node cexpr = cd.c_str(); // The context node is the "root" node contextNode = xpe.selectSingleNode( xds, xd, cexpr, xd->getDocumentElement()); break; case DOM_NODE_DOCUMENT_FRAGMENT : { // Need to map the DOM_Node that we are given from the input to the appropriate XalanNode // Create the XPath expression to find the node if (input->getFragmentId() != NULL) { contextExpr.sbTranscodeIn("//descendant-or-self::node()[attribute::Id='"); contextExpr.sbXMLChCat(input->getFragmentId()); contextExpr.sbXMLChCat("']"); // Map the node contextNode = xpe.selectSingleNode( xds, xd, contextExpr.rawXMLChBuffer(), //XalanDOMString((char *) contextExpr.rawBuffer()).c_str(), xd->getDocumentElement()); if (contextNode == NULL) { // Last Ditch contextNode = xwn.mapNode(input->getFragmentNode()); } } else contextNode = xwn.mapNode(input->getFragmentNode()); if (contextNode == NULL) { // Something wrong throw XSECException(XSECException::XPathError, "Error mapping context node"); } break; } default : throw XSECException(XSECException::XPathError); // Should never get here } safeBuffer str; XPathEnvSupportDefault xpesd; XObjectFactoryDefault xof; XPathExecutionContextDefault xpec(xpesd, xds, xof); ElementPrefixResolverProxy pr(xd->getDocumentElement(), xpesd, xds); // Work around the fact that the XPath implementation is designed for XSLT, so does // not allow here() as a NCName. // THIS IS A KLUDGE AND SHOULD BE DONE BETTER int offset = 0; safeBuffer k(KLUDGE_PREFIX); k.sbStrcatIn(":"); offset = inexpr.sbStrstr("here()"); while (offset >= 0) { if (offset == 0 || offset == 1 || (!(inexpr[offset - 1] == ':' && inexpr[offset - 2] != ':') && separator(inexpr[offset - 1]))) { inexpr.sbStrinsIn(k.rawCharBuffer(), offset); } offset = inexpr.sbOffsetStrstr("here()", offset + 11); } // Install the External function in the Environment handler if (hereNode != NULL) { xpesd.installExternalFunctionLocal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here"), DSIGXPathHere(hereNode)); } str.sbStrcpyIn("(descendant-or-self::node() | descendant-or-self::node()/attribute::* | descendant-or-self::node()/namespace::*)["); str.sbStrcatIn(inexpr); str.sbStrcatIn("]"); XPath * xp = xpf.create(); XalanDOMString Xexpr((char *) str.rawBuffer()); xppi.initXPath(*xp, xpcc, Xexpr, pr); // Now resolve XObjectPtr xObj = xp->execute(contextNode, pr, xpec); // Now map to a list that others can use (naieve list at this time) const NodeRefListBase& lst = xObj->nodeset(); int size = (int) lst.getLength(); const DOMNode *item; for (int i = 0; i < size; ++ i) { if (lst.item(i) == xd) m_XPathMap.addNode(document); else { item = xwn.mapNode(lst.item(i)); m_XPathMap.addNode(item); } } if (inputType == DOM_NODE_XPATH_NODESET) { //the input list was a XPATH nodeset, so we must intersect the // results of the XPath processing done above with the input nodeset m_XPathMap.intersect(input->getXPathNodeList()); } } catch (XSLException &e) { safeBuffer msg; // Whatever happens - fix any changes to the original document clearXPathNS(document, addedNodes, formatter, mp_nse); // Collate the exception message into an XSEC message. msg.sbTranscodeIn("Xalan Exception : "); #if defined (XSEC_XSLEXCEPTION_RETURNS_DOMSTRING) msg.sbXMLChCat(e.getType().c_str()); #else msg.sbXMLChCat(e.getType()); #endif msg.sbXMLChCat(" caught. Message : "); msg.sbXMLChCat(e.getMessage().c_str()); throw XSECException(XSECException::XPathError, msg.rawXMLChBuffer()); } clearXPathNS(document, addedNodes, formatter, mp_nse); }
XSECXPathNodeList * TXFMXPathFilter::evaluateSingleExpr(DSIGXPathFilterExpr *expr) { // Have a single expression that we wish to find the resultant nodeset // for XSECXPathNodeList addedNodes; setXPathNS(document, expr->mp_NSMap, addedNodes, mp_formatter, mp_nse); XPathProcessorImpl xppi; // The processor XercesParserLiaison xpl; #if XALAN_VERSION_MAJOR == 1 && XALAN_VERSION_MINOR > 10 XercesDOMSupport xds(xpl); #else XercesDOMSupport xds; #endif XPathEvaluator xpe; XPathFactoryDefault xpf; XPathConstructionContextDefault xpcc; XalanDocument * xd; XalanNode * contextNode; // Xalan can throw exceptions in all functions, so do one broad catch point. try { // Map to Xalan xd = xpl.createDocument(document); // For performing mapping XercesDocumentWrapper *xdw = xpl.mapDocumentToWrapper(xd); XercesWrapperNavigator xwn(xdw); // Map the "here" node XalanNode * hereNode = NULL; hereNode = xwn.mapNode(expr->mp_xpathFilterNode); if (hereNode == NULL) { hereNode = findHereNodeFromXalan(&xwn, xd, expr->mp_exprTextNode); if (hereNode == NULL) { throw XSECException(XSECException::XPathFilterError, "Unable to find here node in Xalan Wrapper map"); } } // Now work out what we have to set up in the new processing XalanDOMString cd; // For XPath Filter, the root is always the context node cd = XalanDOMString("/"); // Root node // The context node is the "root" node contextNode = xpe.selectSingleNode( xds, xd, cd.c_str(), xd->getDocumentElement()); XPathEnvSupportDefault xpesd; XObjectFactoryDefault xof; XPathExecutionContextDefault xpec(xpesd, xds, xof); ElementPrefixResolverProxy pr(xd->getDocumentElement(), xpesd, xds); // Work around the fact that the XPath implementation is designed for XSLT, so does // not allow here() as a NCName. // THIS IS A KLUDGE AND SHOULD BE DONE BETTER int offset = 0; safeBuffer k(KLUDGE_PREFIX); k.sbStrcatIn(":"); // Map the expression into a local code page string (silly - should be XMLCh) safeBuffer exprSB; exprSB << (*mp_formatter << expr->m_expr.rawXMLChBuffer()); offset = exprSB.sbStrstr("here()"); while (offset >= 0) { if (offset == 0 || offset == 1 || (!(exprSB[offset - 1] == ':' && exprSB[offset - 2] != ':') && separator(exprSB[offset - 1]))) { exprSB.sbStrinsIn(k.rawCharBuffer(), offset); } offset = exprSB.sbOffsetStrstr("here()", offset + 11); } // Install the External function in the Environment handler if (hereNode != NULL) { xpesd.installExternalFunctionLocal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here"), DSIGXPathHere(hereNode)); } XPath * xp = xpf.create(); XalanDOMString Xexpr((char *) exprSB.rawBuffer()); xppi.initXPath(*xp, xpcc, Xexpr, pr); // Now resolve XObjectPtr xObj = xp->execute(contextNode, pr, xpec); // Now map to a list that others can use (naieve list at this time) const NodeRefListBase& lst = xObj->nodeset(); int size = (int) lst.getLength(); const DOMNode *item; XSECXPathNodeList * ret; XSECnew(ret, XSECXPathNodeList); Janitor<XSECXPathNodeList> j_ret(ret); for (int i = 0; i < size; ++ i) { if (lst.item(i) == xd) ret->addNode(document); else { item = xwn.mapNode(lst.item(i)); ret->addNode(item); } } xpesd.uninstallExternalFunctionGlobal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here")); clearXPathNS(document, addedNodes, mp_formatter, mp_nse); j_ret.release(); return ret; } catch (XSLException &e) { safeBuffer msg; // Whatever happens - fix any changes to the original document clearXPathNS(document, addedNodes, mp_formatter, mp_nse); // Collate the exception message into an XSEC message. msg.sbTranscodeIn("Xalan Exception : "); #if defined (XSEC_XSLEXCEPTION_RETURNS_DOMSTRING) msg.sbXMLChCat(e.getType().c_str()); #else msg.sbXMLChCat(e.getType()); #endif msg.sbXMLChCat(" caught. Message : "); msg.sbXMLChCat(e.getMessage().c_str()); throw XSECException(XSECException::XPathFilterError, msg.rawXMLChBuffer()); } catch (...) { clearXPathNS(document, addedNodes, mp_formatter, mp_nse); throw; } return NULL; }