void PlayerSource::run() { // initial data if (m_player == QString("mpd")) { // mpd QHash<QString, QVariant> data = getPlayerMpdInfo(m_mpdAddress); for (auto key : data.keys()) values[key] = data[key]; } else if (m_player == QString("mpris")) { // players which supports mpris QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris; QHash<QString, QVariant> data = getPlayerMprisInfo(mpris); for (auto key : data.keys()) values[key] = data[key]; } // dymanic properties // solid values[QString("player/salbum")] = stripString(values[QString("player/album")].toString(), m_symbols); values[QString("player/sartist")] = stripString(values[QString("player/artist")].toString(), m_symbols); values[QString("player/stitle")] = stripString(values[QString("player/title")].toString(), m_symbols); // dynamic values[QString("player/dalbum")] = buildString(values[QString("player/dalbum")].toString(), values[QString("player/album")].toString(), m_symbols); values[QString("player/dartist")] = buildString(values[QString("player/dartist")].toString(), values[QString("player/artist")].toString(), m_symbols); values[QString("player/dtitle")] = buildString(values[QString("player/dtitle")].toString(), values[QString("player/title")].toString(), m_symbols); }
void buildString(TreeNode* root, string& str) { if (!root) str += "X,"; else { str += to_string(root->val)+","; buildString(root->left, str); buildString(root->right, str); } }
virtual void output( const devs::Time& /* time */, devs::ExternalEventList& output ) const { if (m_phase == CONTROL) { typedef std::vector<std::string>::const_iterator NodeIterator; vv::Map* nodeObservations = vv::Map::create(); for (NodeIterator it = m_interventions.begin()->second.begin(); it != m_interventions.begin()->second.end(); it++) { nodeObservations->addString(*it, "R"); vd::ExternalEvent * ev = new vd::ExternalEvent (*it); ev << vd::attribute ("type", buildString("clean")); output.addEvent (ev); } if (getModel().existOutputPort("info_center")) { vd::ExternalEvent * evInfo = new vd::ExternalEvent ("info_center"); evInfo << vd::attribute("nodesStates", nodeObservations); output.addEvent(evInfo); } else { delete nodeObservations; } } }
Reslice::Reslice(int argc, char** argv) { std::cerr << "Reslice Client\n"; if (!CL::parse(argc, argv, "Slice")) return; if (verbosity >= 1) std::cerr << buildString() << '\n'; Buffer2DInfo info; std::string description; std::vector<CBuffer2D> buffers(numSlices); buffers[0].load(inName + "0.tiff", info, description); for (size_t i = 1; i < static_cast<size_t>(numSlices); ++i) { Buffer2DInfo newInfo; buffers[i].load(inName + std::to_string(i) + ".tiff", newInfo, description); if (info != newInfo) AURORA_THROW(EInvalidParameter, "Buffers do not match"); } const int64_t cols = info.cols(); const int64_t rows = info.rows(); if (-1 == row) row.setValue(rows / 2); std::cerr << "Row: " << row << '\n'; if ("NOTSET" == outName) { std::cout << "# x z value\n"; // output to std::out for (int64_t z = 0; z < numSlices; ++z) { std::cout << '\n'; for (int64_t x = 0; x < cols; ++x) { std::cout << x << ' ' << z << ' ' << buffers[static_cast<size_t>(z)].pixel(x, row).real() << '\n'; } } } else { CBuffer2D result(cols, numSlices); for (int64_t z = 0; z < numSlices; ++z) for (int64_t x = 0; x < cols; ++x) result.pixel(x, z) = buffers[static_cast<size_t>(z)].pixel(x, row); Buffer2DInfo resultInfo(cols, numSlices, info.width(), numSlices, info.energy()); result.save(outName, resultInfo, ""); } }
void DisplayRenderer::render(RunData *runData, bool realDisplayData) { this->runData = runData; QImage im(widget1->getDotSize().width(), widget1->getDotSize().height(), QImage::Format_Mono); im.fill(0); QPainter p(&im); p.setPen(QColor(Qt::white)); p.setRenderHint(QPainter::TextAntialiasing, false); // render display 1 int ySum=0; for(int n=1; n<=3; n++) { QFont font = settingsDialog->getFont(n); font.setStyleStrategy(QFont::NoAntialias); p.setFont(font); int y = settingsDialog->getFont(n).pointSize(); ySum+=y; p.drawText(0, ySum-settingsDialog->getOffset(n), buildString(settingsDialog->getFormat(n))); ySum-=settingsDialog->getOffset(n); } widget1->setImage(im); QImage im1(im); // save a copy of image 1 // render display 2 im.fill(0); ySum=0; for(int n=4; n<=6; n++) { QFont font = settingsDialog->getFont(n); font.setStyleStrategy(QFont::NoAntialias); p.setFont(font); int y = font.pointSize(); ySum+=y; p.drawText(0, ySum-settingsDialog->getOffset(n), buildString(settingsDialog->getFormat(n))); ySum-=settingsDialog->getOffset(n); } widget2->setImage(im); if(realDisplayData && settingsDialog->getEnabled()) { sendDisplayData(im1, im); } }
QSize Nepomuk::AnnotationDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const { QFontMetrics fm( option.font ); QTextDocument doc; doc.setHtml( buildString( index.data( AnnotationModel::AnnotationRole ).value<Nepomuk::Annotation*>(), option ) ); QSize size = doc.size().toSize(); return size + QSize( 36 + ( size.height() - 16 )/2, 0 ); }
void add_builtins() { // Adds built ins: Object, IO, String, Int, Bool ast->add(buildObject()); ast->add(buildIO()); ast->add(buildString()); ast->add(buildBool()); add_nums(); ast->add(buildConvert()); }
ReturnCode getCoordinateValue(xmlDocPtr xmlDocument, char* pointPath, int pointIndex, char* name, int ignoreError, double* value) { xmlNodePtr coordinate = NULL; ReturnCode error = -1; xmlXPathObjectPtr xpathObject = NULL; size_t suffixStringLength = 0; size_t pointPathLength = strlen(pointPath); size_t coordinatePathStringLength = 0; char* coordinatePath = NULL; char* suffixString = buildString("[%d]/%1s", pointIndex, name); if (!suffixString) { printMsg(MESSAGETYPE_ERROR, "Internal Error: Failed to allocate memory in getCoordinateValue.\n"); exit(1); } suffixStringLength = strlen(suffixString); coordinatePathStringLength = suffixStringLength + pointPathLength + 1; coordinatePath = (char*) malloc(coordinatePathStringLength * sizeof(char)); strcpy(coordinatePath, pointPath); strcat(coordinatePath, suffixString); error = checkElement(xmlDocument, coordinatePath, &coordinate, &xpathObject); free(coordinatePath); free(suffixString); coordinatePath = NULL; suffixString = NULL; if (!error) { char* textPtr = (char*) xmlNodeListGetString(xmlDocument, coordinate->children, 0); if (textPtr) { *value = atof(textPtr); xmlFree(textPtr); } else { error = FAILED; } xmlXPathFreeObject(xpathObject); } else { if (!ignoreError) { printMsg(MESSAGETYPE_ERROR, "Internal Error: point element \"%s\" has no %s-coordinate.\n", pointPath, name); } error = COORDINATE_NOT_FOUND; } return error; }
int RequestVars::appendSubst( const SubstItem * pItem, HttpSession *pSession, char * &pBegin, int len, int noDupSlash, const RegexResult * pRegRes, const char * pTmFmt ) { char * pValue = pBegin; int valLen; if ( pItem->getType() == REF_FORMAT_STR ) { valLen = len; buildString( (const SubstFormat *)pItem->getAny(), pSession, pValue, valLen, noDupSlash, pRegRes, pTmFmt ); } else { if ( pItem->getType() == REF_RULE_SUBSTR ) { if ( pRegRes ) valLen = pRegRes->getSubstr( pItem->getIndex(), pValue ); else return 0; } else { if ( pTmFmt &&(( pItem->getType() == REF_DATE_LOCAL )|| ( pItem->getType() == REF_LAST_MODIFIED )|| ( pItem->getType() == REF_DATE_GMT ))) memccpy( pValue, pTmFmt, 0, len ); valLen = getSubstValue( pItem, pSession, pValue, len ); } if ( valLen <= 0 ) return valLen; if ( len <= valLen ) return 0; if ( pValue != pBegin ) { if (( *pValue == '/' )&&( noDupSlash )&&(pBegin[-1] == '/')) --pBegin; memmove( pBegin, pValue, valLen ); } else { if (( *pValue == '/' )&&( noDupSlash )&&(pBegin[-1] == '/')) { --valLen; memmove( pBegin, pBegin+1, valLen ); } } } pBegin += valLen; return 0; }
QString SqlExport::getResultSetHeader(const QStringList& strings) const { QString retval; for(int i = 0; i < strings.count(); ++i) { QString type = strings.at(i); if(i > 0) { retval += separator; retval += buildString(type); } else retval += type; } retval += printEndl(); return retval; }
int fromName(const std::string& name) { int i=0; while (names[i].name != NULL && name != names[i].name) ++i; if (names[i].name != NULL) return names[i].t; else if (name.substr(0,7)=="String<") { int n = 0; sscanf(name.c_str(), "String<%d>", &n); return buildString(n); } else if (name.substr(0,4)=="Mat<") { int nx = 0; int ny = 0; int pos = 8; sscanf(name.c_str(), "Mat<%d,%d,%n", &ny,&nx,&pos); int elem = fromName(name.substr(pos,name.length()-1-pos)); return matrix(elem, nx, ny); } else if (name.substr(0,4)=="Vec<") { int nx = 0; int pos = 8; sscanf(name.c_str(), "Vec<%d,%n", &nx,&pos); int elem = fromName(name.substr(pos,name.length()-1-pos)); return vector(elem, nx); } else if (name.substr(0,2)=="0x") { int t = 0; sscanf(name.c_str(), "0x%x", &t); return t; } else { std::cerr << "ERROR converting type from name "<<name<<std::endl; return Null; } }
/* * Class: disy_jnipcap_Pcap * Method: lookupdev * Signature: (Ljava/lang/StringBuilder;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_disy_jnipcap_Pcap_lookupdev (JNIEnv *env, jclass cls, jobject jerrbuf) { if (jerrbuf == NULL) { throwException (env, "Ljava/lang/NullPointerException;", "errbuf must not be NULL"); return NULL; } char errbuf[PCAP_ERRBUF_SIZE]; errbuf[0] = '\0'; char *dev = pcap_lookupdev(errbuf); buildString (env, jerrbuf, 0, errbuf); if (dev == NULL) { throwException (env, "Ljava/lang/Exception;", errbuf); return NULL; } return (*env)->NewStringUTF (env, dev); }
/* * Class: disy_jnipcap_Pcap * Method: lookupnet * Signature: (Ljava/lang/String;IILjava/lang/StringBuilder;)I */ JNIEXPORT jint JNICALL Java_disy_jnipcap_Pcap_lookupnet (JNIEnv *env, jclass cls, jstring jdev, jobject jnet, jobject jmask, jobject jerrbuf) { if (jdev == NULL || jnet == NULL || jmask == NULL || jerrbuf == NULL) { throwException (env, "Ljava/lang/NullPointerException;", NULL); return -1; } char errbuf[PCAP_ERRBUF_SIZE]; errbuf[0] = '\0'; const char *dev = (*env)->GetStringUTFChars (env, jdev, 0); bpf_u_int32 net, mask; int ret = pcap_lookupnet (dev, &net, &mask, errbuf); setIntegerValue (env, jnet, net); setIntegerValue (env, jmask, mask); buildString (env, jerrbuf, 0, errbuf); (*env)->ReleaseStringUTFChars (env, jdev, dev); return (jint) ret; }
QString SqlExport::printValue(QVariant value) const { QString retval; if(!value.isValid() && !value.isNull()) retval += "[INVALID_VALUE]"; else if(value.isNull()) retval += nullValue; else { if(value.canConvert(QVariant::String)) retval += buildString(value.toString()); else { retval += "[CANNOT_CONVERT_VALUE:"; retval += value.typeName(); retval += "]"; } } return retval; }
void Nepomuk::AnnotationDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { if ( option.state & QStyle::State_Selected ) { painter->fillRect( option.rect, option.palette.highlight() ); } // one line label, one line comment (italic or something) // big icon before both or in the background // fancy buttons - and + at the right hand Annotation* anno = index.data( AnnotationModel::AnnotationRole ).value<Nepomuk::Annotation*>(); double score = index.data( AnnotationModel::RelevanceRole ).toDouble(); QIcon icon = index.data( Qt::DecorationRole ).value<QIcon>(); QTextDocument doc; doc.setHtml( buildString( anno, option ) ); if ( !icon.isNull() ) { int iconSize = doc.size().height(); QPixmap pix = icon.pixmap( iconSize, iconSize ); int iconX = option.rect.left(); int iconY = option.rect.top() + (option.rect.height() - pix.height())/2; painter->save(); painter->setOpacity( 0.3 ); painter->drawPixmap( iconX, iconY, pix ); painter->restore(); } painter->save(); painter->translate( option.rect.topLeft() ); doc.drawContents( painter ); painter->restore(); QPixmap plus = KIcon( "list-add" ).pixmap( 16, 16 ); QPixmap minus = KIcon( "list-remove" ).pixmap( 16, 16 ); painter->drawPixmap( plusRect( option ), plus ); painter->drawPixmap( minusRect( option ), minus ); }
/* * Class: disy_jnipcap_Pcap * Method: openOffline * Signature: (Ljava/lang/String;Ljava/lang/StringBuilder;)J */ JNIEXPORT jlong JNICALL Java_disy_jnipcap_Pcap_openOffline (JNIEnv *env, jclass jcls, jstring jfname, jobject jerrbuf) { if (jfname == NULL || jerrbuf == NULL) { throwException (env, "Ljava/lang/NullPointerException;", NULL); return (jlong) NULL; } char errbuf[PCAP_ERRBUF_SIZE]; errbuf[0] = '\0'; const char *fname = (*env)->GetStringUTFChars (env, jfname, 0); pcap_t *p = pcap_open_offline(fname, errbuf); (*env)->ReleaseStringUTFChars (env, jfname, fname); buildString (env, jerrbuf, 0, errbuf); if (p == NULL) return (jlong) NULL; if (mid_Pcap_init == NULL) { pcap_close (p); return (jlong) NULL; } return (jlong) p; }
/* * Class: disy_jnipcap_Pcap * Method: openLive * Signature: (Ljava/lang/String;IIILjava/lang/StringBuilder;)J */ JNIEXPORT jlong JNICALL Java_disy_jnipcap_Pcap_openLive (JNIEnv *env, jclass jcls, jstring jdev, jint jsnaplen, jint jpromisc, jint jtoms, jobject jerrbuf) { if (jdev == NULL || jerrbuf == NULL) { throwException (env, "Ljava/lang/NullPointerException;", NULL); return (jlong) NULL; } char errbuf[PCAP_ERRBUF_SIZE]; errbuf[0] = '\0'; const char *dev = (*env)->GetStringUTFChars (env, jdev, 0); pcap_t *p = pcap_open_live(dev, (int)jsnaplen, (int)jpromisc, (int)jtoms, errbuf); (*env)->ReleaseStringUTFChars (env, jdev, dev); buildString (env, jerrbuf, 0, errbuf); if (p == NULL) return (jlong) NULL; if (mid_Pcap_init == NULL) { pcap_close (p); return (jlong) NULL; } return (jlong) p; }
int RewriteEngine::processCond( const RewriteCond * pCond, HttpConnection *pConn ) { int len = REWRITE_BUF_SIZE - 1; char * pTest; if ( m_pLastCondStr && m_pLastCondStr->equal( * pCond->getTestStringFormat() ) ) { pTest = m_pLastTestStr; len = m_lastTestStrLen; } else { pTest = buildString( pCond->getTestStringFormat(), pConn, m_pFreeBuf, len ); m_pLastCondStr = pCond->getTestStringFormat(); m_pLastTestStr = pTest; m_lastTestStrLen = len; m_noStat = 1; } int ret = 0; if ( !pTest ) return -1; int condVec[ MAX_REWRITE_MATCH * 3 ]; int condMatches = 0; //m_condMatches = 0; int code = pCond->getOpcode(); if ( code == COND_OP_REGEX ) { ret = pCond->getRegex()->exec( pTest, len, 0, 0, condVec, MAX_REWRITE_MATCH * 3); if ( m_logLevel > 2 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] Cond: Match '%s' with pattern '%s', result: %d", pConn->getLogId(), pTest, pCond->getPattern(), ret )); if ( ret == 0 ) condMatches = 10; else condMatches = ret; ret = (ret < 0 ); } else if (( code >= COND_OP_LESS)&&( code <= COND_OP_EQ )) { if ( pCond->getFlag() & COND_FLAG_NOCASE ) ret = strcasecmp( pTest, pCond->getPattern() ); else ret = strcmp( pTest, pCond->getPattern() ); if ( m_logLevel > 2 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] Cond: Compare '%s' with pattern '%s', result: %d", pConn->getLogId(), pTest, pCond->getPattern(), ret )); switch( code ) { case COND_OP_LESS: ret = ( ret >= 0 ); break; case COND_OP_GREATER: ret = ( ret <= 0 ); break; case COND_OP_EQ: ret = ( ret != 0 ); break; } } else if (( code >= COND_OP_DIR )&& (code <= COND_OP_FILE_ACC )) { if ( m_noStat == 1 ) m_noStat = nio_stat( pTest, &m_st ); if ( m_noStat == 0 ) { switch( code ) { case COND_OP_DIR: ret = !S_ISDIR( m_st.st_mode ); break; case COND_OP_FILE: ret = !S_ISREG( m_st.st_mode ); break; case COND_OP_SIZE: ret = (!S_ISREG( m_st.st_mode )||( m_st.st_size == 0 )); break; case COND_OP_SYM: ret = !S_ISLNK( m_st.st_mode ); break; case COND_OP_FILE_ACC: ret = !S_ISREG( m_st.st_mode ); break; default: ret = -1; } if ( m_logLevel > 2 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] Cond: test '%s' with pattern '%s', result: %d", pConn->getLogId(), pTest, pCond->getPattern(), ret )); } else { if ( m_logLevel > 2 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] stat( %s ) failed ", pConn->getLogId(), pTest )); ret = -1; } } else if ( code == COND_OP_URL_ACC ) { //do nothing. } else assert( 0 ); if (!(pCond->getFlag() & COND_FLAG_NOMATCH) ) { if ( condMatches > 0 ) { if ( pTest == m_pFreeBuf ) { m_pFreeBuf = m_pCondBuf; m_pCondBuf = pTest; } m_condMatches = condMatches; memmove( m_condVec, condVec, condMatches * 3 * sizeof( int ) ); } return ret; } else return !ret; }
int RewriteEngine::getSubstValue( const RewriteSubstItem * pItem, HttpConnection *pConn, char * &pValue, int bufLen ) { HttpReq * pReq = pConn->getReq(); int type = pItem->getType(); int i; if ( type < REF_STRING ) { pValue = (char *)pReq->getHeader( type ); if ( *pValue ) return pReq->getHeaderLen( type ); else return 0; } /* if ( type >= REF_TIME ) { time_t t = time(NULL); struct tm *tm = localtime(&t); switch( type ) { case REF_TIME: i = snprintf( pValue, bufLen, "%04d%02d%02d%02d%02d%02d", tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); break; case REF_TIME_YEAR: i = snprintf( pValue, bufLen, "%04d", tm->tm_year + 1900); break; case REF_TIME_MON: i = snprintf( pValue, bufLen, "%02d", tm->tm_mon+1 ); break; case REF_TIME_DAY: i = snprintf( pValue, bufLen, "%02d", tm->tm_mday); break; case REF_TIME_HOUR: i = snprintf( pValue, bufLen, "%02d", tm->tm_hour); break; case REF_TIME_MIN: i = snprintf( pValue, bufLen, "%02d", tm->tm_min); break; case REF_TIME_SEC: i = snprintf( pValue, bufLen, "%02d", tm->tm_sec); break; case REF_TIME_WDAY: i = snprintf( pValue, bufLen, "%d", tm->tm_wday); break; default: return 0; } return i; } */ switch( type ) { case REF_STRING: pValue = (char *)pItem->getStr()->c_str(); return pItem->getStr()->len(); case REF_MAP: { MapRefItem * pRef = pItem->getMapRef(); int len = 1024; char achBuf[1024]; if ( buildString( pRef->getKeyFormat(), pConn, achBuf, len ) == NULL ) return 0; if ( (len = pRef->getMap()->lookup( achBuf, len, pValue, bufLen )) == -1 ) { if ( pRef->getDefaultFormat() ) { if ( buildString( pRef->getDefaultFormat(), pConn, pValue, bufLen ) == NULL ) return 0; len = bufLen; } else len = 0; } return len; } break; case REF_RULE_SUBSTR: return getSubstr( m_pSourceURL, m_ruleVec, m_ruleMatches, pItem->getIndex(), pValue, m_flag & RULE_FLAG_BR_ESCAPE ); case REF_COND_SUBSTR: return getSubstr( m_pCondBuf, m_condVec, m_condMatches, pItem->getIndex(), pValue, m_flag & RULE_FLAG_BR_ESCAPE ); case REF_ENV: pValue = (char *)RequestVars::getEnv( pConn, pItem->getStr()->c_str(), pItem->getStr()->len(), i ); if ( !pValue ) { i = 0; } return i; case REF_HTTP_HEADER: pValue = (char *)pReq->getHeader( pItem->getStr()->c_str(), pItem->getStr()->len(), i ); if ( !pValue ) i = 0; return i; case REF_REQUST_FN: case REF_SCRIPTFILENAME: if ( m_iScriptLen == -1 ) { pReq->checkPathInfo( m_pSourceURL, m_sourceURLLen, m_iFilePathLen, m_iScriptLen, m_iPathInfoLen, m_pContext ); } pValue = HttpGlobals::g_achBuf; //if ( m_pStrip ) // return m_iFilePathLen; //else // return m_iFilePathLen + m_iPathInfoLen; return m_iFilePathLen; case REF_PATH_INFO: if ( m_iScriptLen == -1 ) { pReq->checkPathInfo( m_pSourceURL, m_sourceURLLen, m_iFilePathLen, m_iScriptLen, m_iPathInfoLen, m_pContext ); } pValue = &HttpGlobals::g_achBuf[ m_iFilePathLen ]; return m_iPathInfoLen; case REF_SCRIPT_NAME: if ( m_iScriptLen == -1 ) { pReq->checkPathInfo( m_pSourceURL, m_sourceURLLen, m_iFilePathLen, m_iScriptLen, m_iPathInfoLen, m_pContext ); } pValue = (char *)pReq->getOrgReqURL(); return m_iScriptLen; case REF_REQ_URI: //in rewrite rule, this does not include Query String part if ( pReq->getRedirects() == 0 ) { pValue = (char *)pReq->getOrgReqURL(); return pReq->getOrgReqURILen(); } if ( m_pStrip ) { memmove( pValue, m_pStrip->c_str(), m_pStrip->len() ); memmove( pValue + m_pStrip->len(), m_pSourceURL, m_sourceURLLen ); return m_pStrip->len() + m_sourceURLLen; } //fall through case REF_CUR_URI: pValue = (char *)m_pSourceURL; return m_sourceURLLen; case REF_QUERY_STRING: pValue = (char *)m_pQS; return m_qsLen; default: return RequestVars::getReqVar( pConn, type, pValue, bufLen ); } return 0; }
// Encodes a tree to a single string. string serialize(TreeNode* root) { string str = ""; buildString(root, str); return str; }
AREXPORT void ArRobotConfigPacketReader::log(void) const { std::string str; str = buildString(); ArLog::log(ArLog::Terse, str.c_str()); }
int main(int argc, char* argv[]) { char * string; string = buildString(); // string = "abcab"; // printf("STRING : %s\n",string); int state = 0; int state_amt = 4; int threadAmt; if(argc < 2 ) { threadAmt = 4; }else{ threadAmt = atoi(argv[1]); threadAmt = threadAmt+1; } // printf("threads = %d, states : %d string size : %d\n",threadAmt , state_amt, STRINGSIZE); // 1D : each thread // 2D : for each start state int states2[threadAmt][state_amt-1]; printf("START\n"); struct timeval start, end; gettimeofday(&start, NULL); // 10 executions int i; for(i = 0 ; i < 10 ; i++) { //executeThreads creates map in states2 states2[0][0] = 0; executeThreads(threadAmt, state_amt - 1 , states2, string); //initial state is states[0][0] as we start at 0th index on the 0th state state = states2[0][0]; //use mapping if(threadAmt > 1){ int i; for(i = 1 ; i < threadAmt ; i++) { //break if reject state if(state == REJECTSTATE) break; // -1 since the index is increased by 1 state = states2[i][state-1]; } } } gettimeofday(&end,NULL); printf("end state = %d\nelapsed time = %ld\n\n", state,((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec))/1000); return 0; }
int main (int argc, char * argv[]) { const char chars[] = "./0123456789ABCDEFGHIJKLMNOPQRST" "UVWXYZabcdefghijklmnopqrstuvwxyz\0"; char * guess = (char*) malloc (sizeof(char)*13+1); char target[] = "............."; char salt[] = ".."; int * count = (int*) malloc (sizeof(int)*10+1); int * work = (int*) malloc (sizeof(int)*3); int zIndex = -1; int i; int stat = 0; /* for wait() call */ char *hash; int foundOne = -1; int processCount = 0; pid_t child; if (argc != 2) { printf("Please choose a value between 0 and 12 as argument!\n"); exit(1); } zIndex = atoi(argv[1]); if (zIndex < 0 || zIndex > 12) { printf("Argument out of range!\n"); exit(1); } else printf("%d\n", zIndex); target[zIndex] = 'z'; // reset count for (i=0; i<10; ++i) count[i] = 0; count[10] = '\0'; /* Initialization done! * Now start sending out miners. */ hash = crypt(target,salt); printf("Target: %s\nHash:%s\n", target, crypt(target,salt)); while (foundOne == -1) { buildString(count,chars,&guess); if (processCount < 4) { child = fork(); if (child == -1) { perror("fork"); exit(1); } if (child == 0) { /* This is the childs process */ execl( "miner", /* path of the program */ "miner", /* name of the program, i.e. argv[0] */ hash, /* first argument, i.e. argv[1] */ guess, /* second argument with the first ten characters of the guess */ (char*)NULL /* terminate list of arguments */ ); /* not reached except if execl failed */ perror("miner"); exit(1); } ++processCount; incrementCount(&count); } else { if (wait(&stat) != -1) { --processCount; if (WEXITSTATUS(stat) == 0) foundOne=0; } } } // reset work for (i=0; i<3; ++i) work[i] = 0; while (wait(&stat) != -1); exit(0); }
void Trace2552::logTrace2(const string& message, char*file, int line) { if (ofGetLogLevel() >= OF_LOG_NOTICE) { ofLog(OF_LOG_NOTICE, buildString(message, file, line)); } }
void Trace2552::logError2(const string& errorIn, char* file, int line ) { ofLog(OF_LOG_FATAL_ERROR, buildString(errorIn, file, line)); }
int RewriteEngine::expandEnv( const RewriteRule * pRule, HttpConnection * pConn ) { RewriteSubstFormat * pEnv = pRule->getEnv()->begin(); const char * pKey; const char * pKeyEnd; const char * pValue; const char * pValEnd; char achCacheCtrl[REWRITE_BUF_SIZE]; int ccLen = 0; int len = REWRITE_BUF_SIZE; char achBuf[REWRITE_BUF_SIZE]; if ( !pEnv ) return 0; while( pEnv ) { len = REWRITE_BUF_SIZE - 1; buildString( pEnv, pConn, achBuf, len ); if ( pEnv->isCookie() ) { //FIXME: enable it later setCookie( achBuf, len, pConn ); pEnv = (RewriteSubstFormat *)pEnv->next(); continue; } pKeyEnd = strchr( achBuf, ':' ); if ( pKeyEnd ) { pKey = achBuf; pValue = pKeyEnd + 1; pValEnd = &achBuf[len]; StringTool::strtrim( pKey, pKeyEnd ); StringTool::strtrim( pValue, pValEnd ); *(char*)pKeyEnd = 0; *(char*)pValEnd = 0; if ( strcasecmp( pKey, "dontlog" ) == 0 ) { if ( m_logLevel > 4 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] disable access log for this request.", pConn->getLogId() )); pConn->getResp()->needLogAccess(0); } else if ( strcasecmp( pKey, "nokeepalive" ) == 0 ) { if ( m_logLevel > 4 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] turn off connection keepalive.", pConn->getLogId() )); pConn->getReq()->keepAlive( false ); } // else if ( strcasecmp( pKey, "noconntimeout" ) == 0 ) // { // if ( m_logLevel > 4 ) // LOG_INFO(( pConn->getLogger(), // "[%s] [REWRITE] turn off connection timeout.", // pConn->getLogId() )); // pConn->getReq()->orContextState( NO_CONN_TIMEOUT ); // } // else if (( pRule->getAction() == RULE_ACTION_PROXY)&& // ( strcasecmp( pKey, "Proxy-Host" ) == 0 )) // { // pConn->getReq()->setNewHost( pValue, // pValEnd - pValue ); // if ( m_logLevel > 4 ) // LOG_INFO(( pConn->getLogger(), // "[%s] [REWRITE] Set Proxy Host header to: '%s' ", // pConn->getLogId(), pKey, pValue )); // } else if ( strcasecmp( pKey, "no-gzip" ) == 0 ) { if ( strncmp( pValue, "0", 1 ) != 0 ) { if ( m_logLevel > 4 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] turn off gzip compression for this requst.", pConn->getLogId())); pConn->getReq()->andGzip( ~GZIP_ENABLED ); } } else { pConn->getReq()->addEnv( pKey, pKeyEnd - pKey, pValue, pValEnd - pValue ); if ( m_logLevel > 4 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] add ENV: '%s:%s' ", pConn->getLogId(), pKey, pValue )); } } pEnv = (RewriteSubstFormat *)pEnv->next(); } return 0; }
int RewriteEngine::processRewrite( const RewriteRule * pRule, HttpConnection *pConn ) { char * pBuf; int flag = pRule->getFlag(); expandEnv( pRule, pConn ); m_rewritten |= 1; if (!( flag & RULE_FLAG_NOREWRITE )) { int len = REWRITE_BUF_SIZE - 1; pBuf = m_pDestURL; m_pDestURL = m_pFreeBuf; m_pFreeBuf = pBuf; m_flag = flag; pBuf = buildString( pRule->getTargetFmt(), pConn, m_pDestURL, len, 1, 1 ); // log rewrite result here if ( !pBuf ) { if ( m_logLevel > 0 ) LOG_ERR(( pConn->getLogger(), "[%s] [REWRITE] Failed to build the target URI", pConn->getLogId() )); return -1; } // if ( strchr( pBuf, '%' ) ) // { // int c; // int l, l1; // char * pEnd = strchr( pBuf, '?' ); // if ( pEnd ) // l = pEnd - pBuf; // else // l = len; // l1 = transform_urlDecode( pBuf, l, pBuf, l, &c ); // len -= l - l1; // } if ( m_logLevel > 0 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] Source URI: '%s' => Result URI: '%s'", pConn->getLogId(), m_pSourceURL, pBuf )); m_rewritten |= 2; m_pOrgSourceURL = m_pSourceURL; m_orgSourceURLLen = m_sourceURLLen; m_pSourceURL = pBuf; m_sourceURLLen = len; m_iScriptLen = -1; m_iPathInfoLen = 0; if ( flag & (RULE_FLAG_WITHQS|RULE_FLAG_QSDISCARD) ) { processQueryString( pConn, flag ); } } else if ( m_logLevel > 0 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] No substition", pConn->getLogId())); if ( pRule->getAction() != RULE_ACTION_NONE ) { m_action = pRule->getAction(); m_statusCode = pRule->getStatusCode(); return 0; } if ( pRule->getMimeType() ) { if ( m_logLevel > 4 ) LOG_INFO(( pConn->getLogger(), "[%s] [REWRITE] set forced type: '%s'", pConn->getLogId(), pRule->getMimeType() )); pConn->getReq()->setForcedType( pRule->getMimeType() ); } return 0; }
ReturnCode openExternalFiles(TixiDocument* aTixiDocument, int* number) { int iNode = 0; int handle = aTixiDocument->handle; xmlNodePtr cur = NULL; ReturnCode error = SUCCESS; assert(aTixiDocument != NULL); *number = 0; while(1) { // loop until there are no externaldata nodes included xmlXPathObjectPtr xpathObject = XPathEvaluateExpression(aTixiDocument->docPtr, "//externaldata"); xmlNodeSetPtr nodeset = NULL; char* externalDataNodeXPath, *externalDataDirectoryXPath, *externalDataDirectory, *resolvedDirectory; int externalFileCount = 0; if (!xpathObject) { // no more external data, stop break; } nodeset = xpathObject->nodesetval; if (!nodeset || nodeset->nodeNr < 1) { break; } // goto the first node that is an element for (iNode = 0; iNode < nodeset->nodeNr; ++iNode) { cur = nodeset->nodeTab[iNode]; if (cur->type == XML_ELEMENT_NODE) { break; // for loop } } if (iNode == nodeset->nodeNr) { // no element node found xmlXPathFreeObject(xpathObject); break; // while loop } // found external data node xmlXPathFreeObject(xpathObject); /* get nodes XPath */ externalDataNodeXPath = (char*) xmlGetNodePath(cur); /* now get the subdirectory */ externalDataDirectoryXPath = buildString("%s/%s", externalDataNodeXPath, EXTERNAL_DATA_NODE_NAME_PATH); error = tixiGetTextElement(handle, externalDataDirectoryXPath, &externalDataDirectory); free(externalDataDirectoryXPath); if (error) { printMsg(MESSAGETYPE_ERROR, "Error: openExternalFiles returns %d. No path defined in externaldata node!\n", error); xmlFree(externalDataNodeXPath); return OPEN_FAILED; } // resolv data directory (in case of relative paths) resolvedDirectory = resolveDirectory(aTixiDocument->dirname, externalDataDirectory); /* now get number and names of all external files */ tixiGetNamedChildrenCount(handle, externalDataNodeXPath, EXTERNAL_DATA_NODE_NAME_FILENAME, &externalFileCount); if (externalFileCount == 0) { printMsg(MESSAGETYPE_ERROR, "Error: no filename nodes defined in externalData node.\n"); xmlFree(externalDataNodeXPath); free(resolvedDirectory); return OPEN_FAILED; } for (iNode = 1; iNode <= externalFileCount; iNode++) { char* externalFileName, *externalFullFileName, *newDocumentString, *fileNameXPath; xmlDocPtr xmlDocument = NULL; fileNameXPath = buildString("%s/filename[%d]", externalDataNodeXPath, iNode); tixiGetTextElement(handle, fileNameXPath, &externalFileName); free(fileNameXPath); /* Build complete filename */ externalFullFileName = buildString("%s%s", resolvedDirectory, externalFileName); /* open files */ newDocumentString = loadExternalFileToString(externalFullFileName); if (newDocumentString == NULL) { printMsg(MESSAGETYPE_ERROR, "\nError in fetching external file \"%s\".\n", externalFullFileName); free(externalFullFileName); xmlFree(externalDataNodeXPath); free(resolvedDirectory); return OPEN_FAILED; } /* now parse the file to DOM */ xmlDocument = xmlReadMemory(newDocumentString, (int) strlen(newDocumentString), "urlResource", NULL, 0); free(newDocumentString); if (xmlDocument) { xmlNodePtr rootToInsert = xmlDocGetRootElement(xmlDocument); xmlNodePtr parent = cur->parent; if (parent) { xmlChar* nodePathNew = NULL; char* dataURI = localPathToURI(externalDataDirectory); xmlNodePtr nodeToInsert = xmlDocCopyNode(rootToInsert, aTixiDocument->docPtr, 1); /* add metadata to node, to allow saving external node data */ xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_FILENAME, (xmlChar*) externalFileName); /* save the sub-directory */ xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_DIRECTORY, (xmlChar*) dataURI); free(dataURI); /* save the external data node position */ nodePathNew = xmlGetNodePath(parent); xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_NODEPATH, nodePathNew); xmlFree(nodePathNew); /* replace externalData node with xml file's content */ xmlReplaceNode(cur, nodeToInsert); /* file could be loaded and parsed, increase the counter */ (*number)++; } xmlFreeDoc(xmlDocument); } else { printMsg(MESSAGETYPE_WARNING, "Document %s will be ignored. No valid XML document!\n", externalFullFileName); /* remove external data node */ xmlUnlinkNode(cur); } free(externalFullFileName); } /* end for files */ free(resolvedDirectory); free(externalDataNodeXPath); xmlFreeNode(cur); } if (*number == 0) { printMsg(MESSAGETYPE_WARNING, "WARNING: Unable to load any externaldata files.\n"); } return SUCCESS; }
String::String(int n) : m_str(buildString(n)) { }
ReturnCode saveExternalFiles(xmlNodePtr aNodePtr, TixiDocument* aTixiDocument) { TixiDocumentHandle handle = aTixiDocument->handle; xmlNodePtr cur_node = NULL; xmlNodePtr copiedNode = NULL; char* externalDataDirectory = NULL; char* externalFileName = NULL; char* fullExternalFileName = NULL; char* externalDataNodePath = NULL; char* fullExternalDataNodePath = NULL; xmlDocPtr xmlDocument = NULL; /* find external data nodes */ for (cur_node = aNodePtr; cur_node; cur_node = cur_node->next) { /* recurse down with the next element */ saveExternalFiles(cur_node->children, aTixiDocument); if( checkExternalNode( cur_node ) != SUCCESS) { continue; } if ( cur_node->type == XML_ELEMENT_NODE ) { char* dirResolved = NULL; char* includetNodeName = (char*) xmlGetNodePath(cur_node); /* collect node information - externalFileName */ tixiGetTextAttribute(handle, includetNodeName, EXTERNAL_DATA_XML_ATTR_FILENAME, &externalFileName); /* collect node information - externalDataDirectory */ tixiGetTextAttribute(handle, includetNodeName, EXTERNAL_DATA_XML_ATTR_DIRECTORY, &externalDataDirectory); /* collect node information - externalDataNodePath */ tixiGetTextAttribute(handle, includetNodeName, EXTERNAL_DATA_XML_ATTR_NODEPATH, &externalDataNodePath); free(includetNodeName); /* remove attributes */ xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_FILENAME); xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_DIRECTORY); xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_NODEPATH); /* create new document */ xmlDocument = xmlNewDoc((xmlChar*) "1.0"); if (!xmlDocument) { printMsg(MESSAGETYPE_ERROR, "Error in TIXI::saveExternalFiles ==> Could not create new document.\n"); return FAILED; } /* deep copy of nodes from external files */ copiedNode = xmlDocCopyNode(cur_node, xmlDocument, 1); xmlDocSetRootElement(xmlDocument, copiedNode); dirResolved = resolveDirectory(aTixiDocument->dirname, externalDataDirectory); /* only save to local paths */ if(string_startsWith(dirResolved, "file://") == 0) { char* externalDataDirectoryNotUrl = uriToLocalPath(dirResolved); assert(externalDataDirectoryNotUrl); fullExternalFileName = buildString("%s%s", externalDataDirectoryNotUrl, externalFileName); xmlSaveFormatFileEnc(fullExternalFileName, xmlDocument, "utf-8", 1); free(fullExternalFileName); free(externalDataDirectoryNotUrl); } free(dirResolved); xmlFreeDoc(xmlDocument); /* create external data node structure */ fullExternalDataNodePath = buildString("%s/%s", externalDataNodePath, EXTERNAL_DATA_NODE_NAME); /* add parent node if not exists */ if(tixiCheckElement(handle, fullExternalDataNodePath) != SUCCESS) { tixiAddTextElement(handle, externalDataNodePath, EXTERNAL_DATA_NODE_NAME, ""); tixiAddTextElement(handle, fullExternalDataNodePath, EXTERNAL_DATA_NODE_NAME_PATH, externalDataDirectory); } /* add node for external reference */ tixiAddTextElement(handle, fullExternalDataNodePath, EXTERNAL_DATA_NODE_NAME_FILENAME, externalFileName); /* remove the copied nodes from document*/ copiedNode = cur_node->prev; xmlUnlinkNode(cur_node); xmlFreeNode(cur_node); free(fullExternalDataNodePath); cur_node = copiedNode; } } return SUCCESS; }