string RIndexList::generateListStr() { string ret; if (!count()) return ret; for (int i = 0; i < count(); ++i) { string item = longToString(this->at(i)); if (item.empty()) continue; ret += item; if (i != count() - 1) ret += ' '; } return ret; }
/* * A general handler for any uncaught exception. * Prints details about the exception and then tries to print a stack trace. */ static void stanfordCppLibTerminateHandler() { signalHandlerDisable(); // don't want both a signal AND a terminate() call std::string DEFAULT_EXCEPTION_KIND = "An exception"; std::string DEFAULT_EXCEPTION_DETAILS = "(unknown exception details)"; std::string msg; msg += "\n"; msg += " ***\n"; msg += " *** STANFORD-WHITTIER C++ LIBRARY\n"; msg += " *** " + DEFAULT_EXCEPTION_KIND + " occurred during program execution: \n"; msg += " *** " + DEFAULT_EXCEPTION_DETAILS + "\n"; msg += " ***\n"; std::ostream& out = std::cerr; try { throw; // re-throws the exception that already occurred } catch (const ErrorException& ex) { FILL_IN_EXCEPTION_TRACE(ex, "An ErrorException", ex.what()); } // catch (const InterruptedIOException& /* iex */) { // // blocked console I/O was interrupted; just exit program immediately // // (doesn't close any other JBE-generated GUI windows, but oh well) // std::cout.flush(); // exit(0); // } catch (const std::exception& ex) { FILL_IN_EXCEPTION_TRACE(ex, "A C++ exception", ex.what()); } catch (std::string str) { FILL_IN_EXCEPTION_TRACE(str, "A string exception", str); } catch (char const* str) { FILL_IN_EXCEPTION_TRACE(str, "A string exception", str); } catch (int n) { FILL_IN_EXCEPTION_TRACE(n, "An int exception", integerToString(n)); } catch (long l) { FILL_IN_EXCEPTION_TRACE(l, "A long exception", longToString(l)); } catch (char c) { FILL_IN_EXCEPTION_TRACE(c, "A char exception", charToString(c)); } catch (bool b) { FILL_IN_EXCEPTION_TRACE(b, "A bool exception", boolToString(b)); } catch (double d) { FILL_IN_EXCEPTION_TRACE(d, "A double exception", realToString(d)); } catch (...) { std::string ex = "Unknown"; FILL_IN_EXCEPTION_TRACE(ex, "An exception", std::string()); } }
void runQuery() { unsigned long iTemp; //ON and OFF query if(strncmp(parameter,OKK,3)==0) { strncpy(msg_globe,OKOKOK,6); echo(); } else if(strncmp(parameter,QSW,3)==0) { if(QSWON==0) strncpy(msg_globe,TURN_OFF,6); else strncpy(msg_globe,TURN_ON,6); echo(); } else if(strncmp(parameter,SHT,3)==0) { if(SHTON==0) strncpy(msg_globe,TURN_OFF,6); else strncpy(msg_globe,TURN_ON,6); echo(); } else if(strncmp(parameter,EXT,3)==0) { if(QSWEXT==0) strncpy(msg_globe,TURN_OFF,6); else strncpy(msg_globe,TURN_ON,6); echo(); } else if(strncmp(parameter,RST,3)==0) { if(RESET==0) strncpy(msg_globe,TURN_OFF,6); else strncpy(msg_globe,TURN_ON,6); echo(); } else if(strncmp(parameter,DIO,3)==0) { if(RF_OFF==1) strncpy(msg_globe,TURN_OFF,6); else strncpy(msg_globe,TURN_ON,6); echo(); } //Quantitative query else if((strncmp(parameter,PRF, 3)==0)) { longToString(PULSERATE, msg_globe); echo(); } else if((strncmp(parameter,PWM, 3)==0))//++xiao { longToString(PWMTime, msg_globe); echo(); }//++xiao else if((strncmp(parameter,TEV, 3)==0)) { longToString((unsigned long)ENVACT, msg_globe); echo(); } else if((strncmp(parameter,TLA, 3)==0)) { longToString((unsigned long)LASACT, msg_globe); echo(); } else if((strncmp(parameter,TK1, 3)==0)) { longToString((unsigned long)XTL1ACT, msg_globe); echo(); } else if((strncmp(parameter,TK2, 3)==0)) { longToString((unsigned long)XTL2ACT, msg_globe); echo(); } else if((strncmp(parameter,TDI, 3)==0)) { longToString((unsigned long)D1_ACT, msg_globe); echo(); } else if((strncmp(parameter,IDI, 3)==0)) { longToString((unsigned long)DIODECUR_ACT, msg_globe); echo(); } /*else if((strncmp(parameter,PKP, 3)==0)) { longToString((unsigned long)Kp, msg_globe); echo(); } else if((strncmp(parameter,PKI, 3)==0)) { longToString((unsigned long)Ki, msg_globe); echo(); } else if((strncmp(parameter,PKD, 3)==0)) { longToString((unsigned long)Kd, msg_globe); echo(); }*/ else if(strncmp(parameter,FPS,3)==0) { longToString((unsigned long)FPS_ON, msg_globe); echo(); } else if((strncmp(parameter,FPL, 3)==0)) { longToString((unsigned long)FPS_LEVEL, msg_globe); echo(); } else if((strncmp(parameter,DCL, 3)==0)) { longToString((unsigned long)DIMAX, msg_globe); echo(); } else {strncpy(msg_globe,ERROR,6); echo(); } return; }
String StringConv::intToString(int _val, size_t _radix) { return longToString(_val, _radix); }
char * intToString(int value){ return longToString(value); }
String StringConv::shortToString(short _val, size_t _radix) { return longToString(_val, _radix); }
String StringConv::charToString(char _val, size_t _radix) { return longToString(_val, _radix); }
void ConvertMgr::convert (BIT8 *src, Value *pValue, int _iFuncID, int _iLen, int _iBitPos) { static int iAdjustLen; int iLen = 0; switch (_iFuncID) { case 0: // 不做转换, 内存直接赋值 //memcpy (pValue->m_sValue, src, _iLen); //pValue->m_sValue[_iLen]=0; iLen= _iLen>(sizeof(pValue->m_sValue)-1)?(sizeof(pValue->m_sValue)-1):_iLen; memcpy (pValue->m_sValue, src, iLen); pValue->m_sValue[iLen]=0; break; case 1: // 将 BIN 格式字段转换成为 ASC, 即数字转换为对应格式化字符串输出 iAdjustLen = MAX_STRING_VALUE_LEN-1 < _iLen ? MAX_STRING_VALUE_LEN-1 : _iLen ; binToAscii (src, pValue->m_sValue, iAdjustLen); break; case 2: // 将 BCD 格式转换成 long (BCD源格式不允许非数字bcd码,若有,则截断,如 123e56-->123) pValue->m_lValue = bcdToLong (src, _iLen); break; case 3: // 将 BIN 格式转换为 long pValue->m_lValue = binToLong (src, _iLen); if (_iBitPos>=1 && _iBitPos<=8 && _iLen==1) //## 需要取bit位的值 pValue->m_lValue = getBitValue ((unsigned char)pValue->m_lValue, _iBitPos); break; case 4: // 将 BCD 格式转换成 Ascii 码 (不允许非数字字符) iAdjustLen = (MAX_STRING_VALUE_LEN-1)/2 < _iLen ? (MAX_STRING_VALUE_LEN-1)/2 : _iLen ; bcdToAscii_Left_D (src, (BIT8 *)pValue->m_sValue, iAdjustLen); break; case 5: // 将 BCD 格式转换成 Ascii 码 (允许非数字字符A~F) iAdjustLen = (MAX_STRING_VALUE_LEN-1)/2 < _iLen ? (MAX_STRING_VALUE_LEN-1)/2 : _iLen ; bcdToAscii_Left_X (src, (BIT8 *)pValue->m_sValue, iAdjustLen); break; case 6: // Ascii码格式转换成Long pValue->m_lValue = asciiToLong (src, _iLen); break; case 7: // 将 BIN 格式转换为 long pValue->m_lValue = binToLong2 (src, _iLen); if (_iBitPos>=1 && _iBitPos<=8 && _iLen==1) //## 需要取bit位的值 pValue->m_lValue = getBitValue ((unsigned char)pValue->m_lValue, _iBitPos); break; case 8: // 将ASC码的 费用(单位元) 转换成数值型的费用(单位分) iAdjustLen = MAX_STRING_VALUE_LEN-1 < _iLen ? MAX_STRING_VALUE_LEN-1 : _iLen ; memcpy (pValue->m_sValue, src, iAdjustLen); pValue->m_sValue[iAdjustLen]=0; //pValue->m_lValue = (long)(atof(pValue->m_sValue)*100); strcat(pValue->m_sValue,"e+2"); pValue->m_lValue = (long)(atof(pValue->m_sValue)); break; case 9: longToString (src, (BIT8 *)pValue->m_sValue, _iLen); break; default : break; } }
static void foldCast(struct pfCompile *pfc, struct pfParse *pp) /* Fold down cast of constant. */ { struct pfBaseType *base = pp->ty->base; struct pfParse *constPp = pp->children; struct pfToken *constTok = constPp->tok; enum pfParseType ppType; enum pfTokType tokType; union pfTokVal oldVal =constTok->val; union pfTokVal val = oldVal; switch (pp->type) { case pptCastBitToByte: case pptCastBitToChar: case pptCastBitToShort: case pptCastBitToInt: case pptCastByteToChar: case pptCastByteToShort: case pptCastByteToInt: case pptCastCharToByte: case pptCastCharToShort: case pptCastCharToInt: case pptCastShortToInt: /* Effectively int-to-int conversion */ break; case pptCastByteToBit: case pptCastCharToBit: case pptCastShortToBit: case pptCastIntToBit: val.i = (oldVal.i == 0 ? 0 : 1); break; case pptCastShortToByte: case pptCastIntToByte: case pptCastShortToChar: case pptCastIntToChar: if (val.i < -128 || val.i > 127) errAt(constTok, "Byte overflow %d", val.i); break; case pptCastIntToShort: if (val.i < -32768 || val.i > 32767) errAt(constTok, "Short overflow %d", val.i); break; case pptCastBitToLong: case pptCastByteToLong: case pptCastCharToLong: case pptCastShortToLong: case pptCastIntToLong: /* Effectively int-to-long conversion */ val.l = oldVal.i; break; case pptCastBitToFloat: case pptCastBitToDouble: case pptCastByteToFloat: case pptCastByteToDouble: case pptCastShortToFloat: case pptCastShortToDouble: case pptCastCharToFloat: case pptCastCharToDouble: case pptCastIntToFloat: case pptCastIntToDouble: /* Effectively int-to-double conversion */ val.x = oldVal.i; break; case pptCastBitToString: case pptCastByteToString: case pptCastShortToString: case pptCastIntToString: /* Effectively int-to-string conversion */ val.s = longToString(oldVal.i); break; case pptCastCharToString: internalErrAt(pp->tok); /* I don't think this happens with constants. */ break; case pptCastLongToBit: val.i = (oldVal.l == 0 ? 0 : 1); break; case pptCastLongToByte: case pptCastLongToChar: if (val.l < -128 || val.l > 127) errAt(constTok, "Byte overflow %d", val.l); val.i = val.l; break; case pptCastLongToShort: if (val.l < -32768 || val.l > 32767) errAt(constTok, "Short overflow %d", val.l); val.i = val.l; break; case pptCastLongToInt: if (val.l < -2147483647 || val.l > 2147483647) errAt(constTok, "Int overflow %d", val.l); val.i = val.l; break; case pptCastLongToFloat: case pptCastLongToDouble: val.x = oldVal.l; break; case pptCastLongToString: val.s = longToString(oldVal.l); break; case pptCastFloatToBit: case pptCastDoubleToBit: val.i = (val.x == 0.0 ? 0 : 1); break; case pptCastFloatToByte: case pptCastFloatToChar: case pptCastDoubleToByte: case pptCastDoubleToChar: if (val.x < -128 || val.x > 127) errAt(constTok, "Byte overflow %d", val.x); val.i = val.x; break; case pptCastFloatToShort: case pptCastDoubleToShort: if (val.x < -32768 || val.x > 32767) errAt(constTok, "Short overflow %d", val.x); val.i = val.x; break; case pptCastFloatToInt: case pptCastDoubleToInt: if (val.x < -2147483647 || val.x > 2147483647) errAt(constTok, "Int overflow %d", val.x); val.i = val.x; break; case pptCastFloatToLong: case pptCastDoubleToLong: val.l = val.x; break; case pptCastFloatToDouble: case pptCastDoubleToFloat: break; case pptCastFloatToString: case pptCastDoubleToString: val.s = doubleToString(oldVal.x); break; case pptCastStringToBit: val.i = (val.s[0] == 0 ? 0 : 1); break; } if (base == pfc->bitType) { ppType = pptConstBit; tokType = pftInt; } else if (base == pfc->byteType) { ppType = pptConstByte; tokType = pftInt; } else if (base == pfc->shortType) { ppType = pptConstShort; tokType = pftInt; } else if (base == pfc->intType) { ppType = pptConstInt; tokType = pftInt; } else if (base == pfc->longType) { ppType = pptConstLong; tokType = pftLong; } else if (base == pfc->floatType) { ppType = pptConstFloat; tokType = pftFloat; } else if (base == pfc->doubleType) { ppType = pptConstDouble; tokType = pftFloat; } else if (base == pfc->stringType) { ppType = pptConstString; tokType = pftString; } else { internalErrAt(pp->tok); ppType = 0; tokType = 0; } pp->tok = fakeToken(pp->tok, tokType, &val); pp->children = NULL; pp->type = ppType; }
void* opimServer::handleClient( void* arg ) { Client* client = (Client*)arg; int cmd; while ( true ) { cmd = receiveCmd( client->socket() ); if ( cmd == discon || cmd == disconFlood ) //client disconnected? { pthread_mutex_lock( &_clientsMutex ); for ( clientIt it = 0 ; it != _clients.size() ; ++it ) //find the client in the clients list and remove them. { if ( _clients[it]->id() == client->id() ) { _clients.erase( _clients.begin() + it ); break; } } for ( convoIt it = 0 ; it != _convos.size() ; ++it ) //find and remove all conversations containing the disconnecting client. { if ( _convos[it]->inConvo( client ) ) { _convos.erase( _convos.begin() + it ); delete _convos[it]; --it; } } updateClientsLists( removeClient, client ); cout << client->name() << " disconnects\n" << flush; cout << _clients.size() << " client(s) now connected.\n" << flush; delete client; pthread_mutex_unlock( &_clientsMutex ); break; } else if ( cmd == startConvo ) //client wants to start a conversation with another client? { sendCmd( client->socket(), ack ); int clientId = atoi( receiveMessage( client->socket() ).c_str() ); cout << client->name() << " wants to talk to client " << clientId << endl << flush; if ( clientId != client->id() ) //not starting a conversation with themselves? { Query q( *_db ); q.get_result( makeSql( "select 1 from connected_users where user_id = ?", longToString( clientId ).c_str() ) ); if ( q.num_rows() ) //other client online? { pthread_mutex_lock( &_clientsMutex ); Client* otherClient = getClientById( clientId ); if ( otherClient != 0 ) //client found in clients list? { if ( notInAConvo( client, otherClient ) ) { convo* c = new convo(); c->addClient( client ); c->addClient( otherClient ); _convos.push_back( c ); sendCmd( otherClient->sendSock(), startConvo ); sendCmd( client->socket(), ack ); sendMessage( client->socket(), otherClient->ip() ); cout << "Conversation started between " << client->name() << " and " << otherClient->name() << endl << flush; } else { sendCmd( client->socket(), nak ); sendMessage( client->socket(), "Already in a conversation" ); cout << client->name() << " already in conversation with " << otherClient->name() << endl << flush; } } else { sendCmd( client->socket(), nak ); sendMessage( client->socket(), "Client is not online" ); cout << "Other client is not online\n" << flush; } pthread_mutex_unlock( &_clientsMutex ); } else { sendCmd( client->socket(), nak ); sendMessage( client->socket(), "Client is not online" ); cout << client->name() << " other client is not online\n" << flush; } q.free_result(); } else { sendCmd( client->socket(), nak ); sendMessage( client->socket(), "You cannot start a conversation with yourself" ); cout << client->name() << " tries to start a conversation with themself\n" << flush; } } else { sendCmd( client->socket(), nak ); sendMessage( client->socket(), "Command not recongnized" ); cout << client->name() << " send unrecongnized command: " << cmd << endl << flush; } } return 0; }