bool OperatorF1::execute(Stack<double> &stack, double &result) { if (!stack.pop(result)) { setErrMsg("Missing operand"); return false; } return execute(result); }
bool OperatorDiv::execute(double left, double right, double &result) { if (right == 0) { setErrMsg("Divide by zero"); return false; } result = left / right; return true; }
bool Program::checkGlErrors() { GLenum errCode = glGetError(); if (errCode) { const GLubyte * errStr = gluErrorString(errCode); if (errStr) setErrMsg((const char*)errStr); else setErrMsg("Unknown error"); } else setErrMsg(""); errorFlagged = errCode != 0; return errorFlagged; }
bool OperatorTrigonometricArc::executeAngle(double &value) { if (!checkValue(value)) { setErrMsg("Invalid arc trigonometric value"); return false; } if (!executeRadian(value)) { return false; } value = radian2angle(value); if (!checkAngle(value)) { setErrMsg("Invalid trigonometric angle"); return false; } return true; }
bool OperatorMod::execute(double left, double right, double &result) { if (right == 0) { setErrMsg("Divide by zero"); return false; } result = fmod(left, right); return true; }
bool OperatorF2::execute(Stack<double> &stack, double &result) { double left, right; if (!(stack.pop(right) && stack.pop(left))) { setErrMsg("Missing operand"); return false; } return execute(left, right, result); }
bool Calculator::execute(const char *formula, double &result) { const char *formula_end = formula + strlen(formula); if (check_bracket_match_pair(formula, formula_end) < 0) { setErrMsg("No matching brackets"); return false; } return execute(formula, formula_end, result); }
bool OperatorTrigonometric::executeAngle(double &value) { value = angleAdjust(value); if (!checkAngle(value)) { setErrMsg("Invalid trigonometric angle"); return false; } value = angle2radian(value); return executeRadian(value); }
bool OperatorAvg::execute(Stack<double> &stack, double &result) { OperatorSum sum; int count = stack.count(); if (!sum.execute(stack, result)) { setErrMsg(sum.getErrMsg()); return false; } result /= count; return true; }
bool Operator::execute(Stack<double> &stackData, Stack<double> &stackResult) { double result; if (!execute(stackData, result)) { return false; } if (!stackResult.push(result)) { setErrMsg("Data stack overfrow"); return false; } return true; }
bool OperatorN1::execute(double &value) { ulong nValue = value; if (nValue != value) { setErrMsg("Need a integer"); return false; } bool res = execute(nValue); if (res) { value = nValue; } return res; }
int T_TX_InterfaceSerial::init (SimpleXMLTransfer *config)/*{{{*/ { DEBUG ("int T_TX_InterfaceSerial::init (SimpleXMLTransfer *config)\n"); // Initialize the port settings SimpleXMLTransfer *port=config->getChild (getXmlChildName ()+".port", true); portName = port->getString ("name", DEFAULT_PORT_NAME); baudRate = port->getInt ("baudrate", getDefaultBaudRate ()); // Initialize the subsystems if (mixer->init (config, getXmlChildName ())!=0) { setErrMsg("Mixer initialization failed."); return 1; } calib->init (config, getXmlChildName ()); map->init (config, getXmlChildName ()); try { // Try-Methode? ostringstream options; options << portName << "," << baudRate; string optionString=options.str (); cout << "Opening the serial port with option string " << optionString << endl; charDevice=new SerialCharDevice (optionString.c_str (), false); } catch (CharDevice::ConfigureDeviceException e) { setErrMsg ("The device could not be configured."); cerr << "Serial interface initialization: " << getErrMsg () << endl; return 1; } cout << "Serial interface initialization: OK" << endl; return 0; }
bool OperatorN2::execute(double left, double right, double &result) { ulong nResult; ulong nLeft = left; ulong nRight = right; if (nLeft != left || nRight != right) { setErrMsg("Need a integer"); return false; } bool res = execute(nLeft, nRight, nResult); if (res) { result = nResult; } return res; }
/** * Initialize the interface. * * The base class handles all hardware initialization for us, so we only * have to set up the correct control line states to power the interface. */ int T_TX_InterfaceSerPIC::init (SimpleXMLTransfer *config) { #if DEBUG_TX_INTERFACE > 0 std::cout << "T_TX_InterfaceSerPIC::init ()\n"; #endif int ret = T_TX_InterfaceSerial::init (config); if (ret == 0) { // initialized successfully, now turn on the power supply for the // interface hardware (careful, could throw an exception) try { setRts (true); setDtr (false); } catch (CharDevice::ConfigureDeviceException e) { setErrMsg ("Setting Rts/Dtr states failed."); cerr << "Serial interface initialization: " << getErrMsg () << endl; ret = 1; } int default_sync_byte = DEFAULT_SYNC_BYTE_19200; int default_button_channel = DEFAULT_BUTTON_CHANNEL_19200; if (T_TX_InterfaceSerial::getBaudRate() == 9600) { default_sync_byte = DEFAULT_SYNC_BYTE_9600; default_button_channel = DEFAULT_BUTTON_CHANNEL_9600; } // read sync and button byte settings from config file SimpleXMLTransfer *port = config->getChild(getXmlChildName() + ".port", true); ucSyncByte = port->attributeAsInt("sync", default_sync_byte); iSPIC_ButtonChannel = port->attributeAsInt("button_channel", default_button_channel); #if DEBUG_TX_INTERFACE > 0 std::cout << " Configured sync byte: 0x" << std::hex << int(ucSyncByte) << std::dec; std::cout << ", " << std::string((iSPIC_ButtonChannel == 0) ? "no" : "has") << " button channel"; std::cout << std::endl; #endif } return ret; }
bool Program::link() { GLint Result = GL_FALSE; if (!id) { setErrMsg("No shaders to link"); return false; } glLinkProgram(id); if (checkGlErrors()) return false; glGetProgramiv(id, GL_LINK_STATUS, &Result); if (checkGlErrors()) return false; if (Result == GL_FALSE) { int length = 0; glGetProgramiv(id, GL_INFO_LOG_LENGTH, &length); if (checkGlErrors()) return false; errMsg.resize(length); glGetProgramInfoLog(id, length, NULL, &errMsg.front()); checkGlErrors(); errorFlagged = true; return false; } errorFlagged = false; return true; }
bool Calculator::parseDataList(const char *formula, const char *formula_end, const char **last, Stack<double> &stack) { while (formula < formula_end && cavan_isspace(*formula)) { formula++; } if (!cavan_isbracket_left(*formula)) { setErrMsg("Need a bracket"); return false; } formula_end = get_bracket_pair(formula, formula_end); if (formula_end == NULL) { setErrMsg("Bracket not pair"); return false; } int bracket = 0; const char *formula_tail = ++formula; while (1) { if (formula_tail >= formula_end || (*formula_tail == ',' && bracket == 0)) { double value; Calculator calculator; if (formula == formula_tail) { value = 0; } else if (!calculator.execute(formula, formula_tail, value)) { setErrMsg(calculator.getErrMsg()); return false; } if (!stack.push(value)) { setErrMsg("Data stack overfrow"); return false; } if (formula_tail >= formula_end) { break; } formula = ++formula_tail; } else { if (cavan_isbracket(*formula_tail)) { if (cavan_isbracket_left(*formula_tail)) { bracket++; } else if (bracket > 0) { bracket--; } else { setErrMsg("Bracket is not pair"); return false; } } formula_tail++; } } *last = formula_end + 1; return true; }
bool Calculator::execute(const char *formula, const char *formula_end, double &result) { double value; #if CAVAN_MATH_DEBUG println("formula = %s", text_header(formula, formula_end - formula)); #endif mStackOperand.clear(); mStackOperator.clear(); mLastFieldType = FIELD_TYPE_NONE; while (formula < formula_end) { Operator *op = matchOperator(formula); if (op) { Operator *top; if (mStackOperator.top(top)) { if (top->getPriority() <= op->getPriority()) { if (!top->execute(mStackOperand)) { setErrMsg(top->getErrMsg()); return false; } mStackOperator.pop(top); } } if (op->getOmitMul() && mLastFieldType == FIELD_TYPE_VALUE && mStackOperand.hasData()) { Operator *mul = matchOperator("*"); if (mul) { mStackOperator.push(mul); } } switch (op->getType()) { case OPERATOR_TYPE2: case OPERATOR_TYPE1_RIGHT: if (!mStackOperator.push(op)) { setErrMsg("Operator stack overfrow"); return false; } formula += op->getLength(); break; case OPERATOR_TYPE1_LEFT: case OPERATOR_TYPE_CONSTANT: if (!op->execute(mStackOperand)) { setErrMsg(op->getErrMsg()); return false; } formula += op->getLength(); break; case OPERATOR_TYPE_LIST: { Stack<double> stack(200); if (!parseDataList(formula + op->getLength(), formula_end, &formula, stack)) { return false; } if (!op->execute(stack, mStackOperand)) { setErrMsg(op->getErrMsg()); return false; } break; } default: setErrMsg("Invalid operator"); return false; } mLastFieldType = FIELD_TYPE_OPERATOR; } else { switch (*formula) { case ' ': case '\r': case '\n': case '\t': case '\f': formula++; break; case '0' ... '9': value = text2double_unsigned(formula, formula_end, &formula, 10); if (mLastFieldType == FIELD_TYPE_OPERATOR && mStackOperator.count() == 1 && mStackOperand.isEmpty()) { Operator *op; if (mStackOperator.top(op) && strcmp(op->getSymbol(), "-") == 0) { value = -value; mStackOperator.pop(op); } } if (!mStackOperand.push(value)) { setErrMsg("Operand stack overfrow"); return false; } mLastFieldType = FIELD_TYPE_VALUE; break; case '(': case '[': case '{': { const char *p = get_bracket_pair(formula, formula_end); if (p == NULL) { setErrMsg("No matching brackets"); return false; } Calculator calculator; if (!calculator.execute(formula + 1, p, value)) { setErrMsg(calculator.getErrMsg()); return false; } if (!mStackOperand.push(value)) { setErrMsg("Operand stack overfrow"); return false; } formula = p + 1; mLastFieldType = FIELD_TYPE_BRACKET; break; } default: setErrMsg("Invalid symbol"); return false; } } } while (1) { Operator *op; if (!mStackOperator.pop(op)) { break; } if (!op->execute(mStackOperand)) { setErrMsg(op->getErrMsg()); return false; } } if (!mStackOperand.pop(result)) { setErrMsg("Missing operand"); return false; } if (mStackOperand.hasData()) { setErrMsg("Too much operand"); return false; } return true; }
/** * Try load VBoxXPCOMC.so/dylib/dll from the specified location and resolve all * the symbols we need. * * @returns 0 on success, -1 on failure. * @param pszHome The director where to try load VBoxXPCOMC from. Can * be NULL. * @param fSetAppHome Whether to set the VBOX_APP_HOME env.var. or not * (boolean). */ static int tryLoadOne(const char *pszHome, int fSetAppHome) { size_t cchHome = pszHome ? strlen(pszHome) : 0; size_t cbBufNeeded; char szName[4096]; int rc = -1; /* * Construct the full name. */ cbBufNeeded = cchHome + sizeof("/" DYNLIB_NAME); if (cbBufNeeded > sizeof(szName)) { setErrMsg(1, "path buffer too small: %u bytes needed", (unsigned)cbBufNeeded); return -1; } if (cchHome) { memcpy(szName, pszHome, cchHome); szName[cchHome] = '/'; cchHome++; } memcpy(&szName[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME)); /* * Try load it by that name, setting the VBOX_APP_HOME first (for now). * Then resolve and call the function table getter. */ if (fSetAppHome) { if (pszHome) setenv("VBOX_APP_HOME", pszHome, 1 /* always override */); else unsetenv("VBOX_APP_HOME"); } g_hVBoxXPCOMC = dlopen(szName, RTLD_NOW | RTLD_LOCAL); if (g_hVBoxXPCOMC) { PFNVBOXGETXPCOMCFUNCTIONS pfnGetFunctions; pfnGetFunctions = (PFNVBOXGETXPCOMCFUNCTIONS) dlsym(g_hVBoxXPCOMC, VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME); if (pfnGetFunctions) { g_pVBoxFuncs = pfnGetFunctions(VBOX_XPCOMC_VERSION); if (g_pVBoxFuncs) { g_pfnGetFunctions = pfnGetFunctions; return 0; } /* bail out */ setErrMsg(1, "%.80s: pfnGetFunctions(%#x) failed", szName, VBOX_XPCOMC_VERSION); } else setErrMsg(1, "dlsym(%.80s/%.32s): %.128s", szName, VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME, dlerror()); dlclose(g_hVBoxXPCOMC); g_hVBoxXPCOMC = NULL; } else setErrMsg(0, "dlopen(%.80s): %.160s", szName, dlerror()); return rc; }
void setErrorMessage(EQNet* net, const char* msg) { setErrMsg(net, msg); queueEvent(net, EQNET_EVENT_Error); }
/** * Try load C API .so/dylib/dll from the specified location and resolve all * the symbols we need. Tries both the new style and legacy name. * * @returns 0 on success, -1 on failure. * @param pszHome The directory where to try load VBoxCAPI/VBoxXPCOMC * from. Can be NULL. * @param fSetAppHome Whether to set the VBOX_APP_HOME env.var. or not * (boolean). */ static int tryLoadLibrary(const char *pszHome, int fSetAppHome) { size_t cchHome = pszHome ? strlen(pszHome) : 0; size_t cbBufNeeded; char szName[4096]; /* * Construct the full name. */ cbBufNeeded = cchHome + sizeof("/" DYNLIB_NAME); if (cbBufNeeded > sizeof(szName)) { setErrMsg(1, "path buffer too small: %u bytes needed", (unsigned)cbBufNeeded); return -1; } if (cchHome) { memcpy(szName, pszHome, cchHome); szName[cchHome] = '/'; cchHome++; } memcpy(&szName[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME)); /* * Try load it by that name, setting the VBOX_APP_HOME first (for now). * Then resolve and call the function table getter. */ if (fSetAppHome) { #ifndef WIN32 if (pszHome) setenv("VBOX_APP_HOME", pszHome, 1 /* always override */); else unsetenv("VBOX_APP_HOME"); #endif /* !WIN32 */ } #ifndef WIN32 g_hVBoxCAPI = dlopen(szName, RTLD_NOW | RTLD_LOCAL); #else /* WIN32 */ g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, 0 /* dwFlags */); #endif /* WIN32 */ if (g_hVBoxCAPI) { PFNVBOXGETCAPIFUNCTIONS pfnGetFunctions; #ifndef WIN32 pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS)(uintptr_t) dlsym(g_hVBoxCAPI, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME); # ifdef VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME if (!pfnGetFunctions) pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS)(uintptr_t) dlsym(g_hVBoxCAPI, VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME); # endif /* VBOX_GET_XPCOM_FUNCTIONS_SYMBOL_NAME */ #else /* WIN32 */ pfnGetFunctions = (PFNVBOXGETCAPIFUNCTIONS) GetProcAddress(g_hVBoxCAPI, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME); #endif /* WIN32 */ if (pfnGetFunctions) { g_pVBoxFuncs = pfnGetFunctions(VBOX_CAPI_VERSION); if (g_pVBoxFuncs) { if ( ( VBOX_CAPI_MAJOR(g_pVBoxFuncs->uVersion) == VBOX_CAPI_MAJOR(VBOX_CAPI_VERSION)) && ( VBOX_CAPI_MINOR(g_pVBoxFuncs->uVersion) >= VBOX_CAPI_MINOR(VBOX_CAPI_VERSION))) { g_pfnGetFunctions = pfnGetFunctions; return 0; } setErrMsg(1, "%.80s: pfnGetFunctions(%#x) returned incompatible version %#x", szName, VBOX_CAPI_VERSION, g_pVBoxFuncs->uVersion); g_pVBoxFuncs = NULL; } else { /* bail out */ setErrMsg(1, "%.80s: pfnGetFunctions(%#x) failed", szName, VBOX_CAPI_VERSION); } } else { #ifndef WIN32 setErrMsg(1, "dlsym(%.80s/%.32s): %.128s", szName, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME, dlerror()); #else /* WIN32 */ setErrMsg(1, "GetProcAddress(%.80s/%.32s): %d", szName, VBOX_GET_CAPI_FUNCTIONS_SYMBOL_NAME, GetLastError()); #endif /* WIN32 */ } #ifndef WIN32 dlclose(g_hVBoxCAPI); #else /* WIN32 */ FreeLibrary(g_hVBoxCAPI); #endif /* WIN32 */ g_hVBoxCAPI = NULL; } else { #ifndef WIN32 setErrMsg(0, "dlopen(%.80s): %.160s", szName, dlerror()); #else /* WIN32 */ setErrMsg(0, "LoadLibraryEx(%.80s): %d", szName, GetLastError()); #endif /* WIN32 */ } return -1; }