void cacheCall(Cache *cache, int index, int *cacheIndex, bool *compute){ CacheNode *requested = cache->cacheMap[index]; CacheList *list = cache->list; if(cache->cacheMap[index] == NULL){// cache miss cache->misses++; *compute = true; if(cache->occupancy == cache->maxSize){ //move first node to end requested = list->first; moveToEnd(list,requested); //rewrite map, overwriting the lru node and erasing it from the map cache->cacheMap[index] = requested; cache->cacheMap[requested->index] = NULL; int removed = requested->index; requested->index = index; // printf("Overwrote Node with index %d!\n",removed); }else{ requested = createCacheNode(cache->occupancy,index); cache->cacheMap[index] = requested; addToEnd(list,requested); cache->occupancy++; // printf("Added node!\n"); } *cacheIndex = requested->cacheLineNum; }else{// cache hit cache->hits++; //move to end moveToEnd(list, requested); *cacheIndex = requested->cacheLineNum; *compute = false; } // printf("Last node index: %d\n",cache->list->last->index); }
void SkinExportSerializer::sortByAlign(Data::VectorData& childs) { moveToEnd(childs, findIndex(childs, "Left Top")); moveToEnd(childs, findIndex(childs, "Top")); moveToEnd(childs, findIndex(childs, "Right Top")); moveToEnd(childs, findIndex(childs, "Right")); moveToEnd(childs, findIndex(childs, "Right Bottom")); moveToEnd(childs, findIndex(childs, "Bottom")); moveToEnd(childs, findIndex(childs, "Left Bottom")); moveToEnd(childs, findIndex(childs, "Left")); moveToEnd(childs, findIndex(childs, "Center")); }
ActionItem::ActionItem( QListViewItem *i, QAction *ac ) : QListViewItem( i ), a( 0 ), g( 0 ) { g = ::qt_cast<QDesignerActionGroup*>(ac); if ( !g ) a = ::qt_cast<QDesignerAction*>(ac); setDragEnabled( TRUE ); moveToEnd(); }
CompileDialog::CompileDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CompileDialog),compileStatus(false) { ui->setupUi(this); ui->pushButton->setEnabled(false); ui->checkBox->setChecked(true); connect(ui->plainTextEdit,SIGNAL(textChanged()),this,SLOT(moveToEnd())); connect(&process,SIGNAL(readyRead()),this,SLOT(updateOutput())); connect(&process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(processFinished(int,QProcess::ExitStatus))); connect(&process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(processError(QProcess::ProcessError))); compile(&process); }
/*=============================================================*/ DIGITS* add(DIGITS *p, DIGITS *q){ int sum, remainder, len; DIGITS *head, *big, *small; head = NULL; big = moveToEnd(p); small = moveToEnd(q); remainder = 0; len = 1; while (big != NULL){ if (small != NULL){ sum = big->digit + small->digit + remainder; small = small->prev; } else{ sum = big->digit + remainder; } if (sum > 9){ sum = 0; remainder = 1; } else{ remainder = 0; } head = insertDigit(head, sum); big = big->prev; } if (remainder == 1){ head = insertDigit(head, 1); } freeNodes(p); freeNodes(q); return head; }
/*=============================================================*/ DIGITS* addDigit(DIGITS *head, int digit){ DIGITS *prev = NULL; DIGITS *ptr = NULL; ptr = (DIGITS*)malloc(sizeof(DIGITS)); ptr->digit = digit; ptr->next = NULL; if (head == NULL){ ptr->prev = NULL; head = ptr; } else{ //Move to the end DIGITS. prev = moveToEnd(head); prev->next = ptr; ptr->prev = prev; } return head; }
/* ///////////////////////////////////////////////////////////////////////////// * Application main window constructor */ TTCutMainWindow::TTCutMainWindow() : QMainWindow() { // setup Qt Designer UI setupUi( this ); // images // -------------------------------------------------------------------------- TTCut::imgDownArrow = new QPixmap( downarrow_18_xpm ); TTCut::imgUpArrow = new QPixmap( uparrow_18_xpm ); TTCut::imgDelete = new QPixmap( cancel_18_xpm ); TTCut::imgFileOpen24 = new QPixmap( fileopen_24_xpm ); TTCut::imgFileNew = new QPixmap( filenew_16_xpm ); TTCut::imgFileOpen = new QPixmap( fileopen_16_xpm ); TTCut::imgFileSave = new QPixmap( filesave_16_xpm );; TTCut::imgFileSaveAs = new QPixmap( filesaveas_16_xpm ); TTCut::imgSaveImage = new QPixmap( saveimage_16_xpm ); TTCut::imgSettings = new QPixmap( settings_16_xpm ); TTCut::imgSettings18 = new QPixmap( settings_18_xpm ); TTCut::imgExit = new QPixmap( exit_16_xpm ); TTCut::imgPlay = new QPixmap( play_18_xpm ); TTCut::imgStop = new QPixmap( stop_18_xpm ); TTCut::imgSearch = new QPixmap( search_18_xpm ); TTCut::imgChapter = new QPixmap( chapter_18_xpm ); TTCut::imgPreview = new QPixmap( preview_18_xpm ); TTCut::imgCutAV = new QPixmap( cutav_18_xpm ); TTCut::imgCutAudio = new QPixmap( cutaudio_18_xpm ); TTCut::imgGoTo = new QPixmap( goto_18_xpm ); TTCut::imgMarker = new QPixmap( note_18_xpm ); TTCut::imgClock = new QPixmap( clock_16_xpm ); TTCut::imgApply = new QPixmap( apply_18_xpm ); TTCut::imgAddToList = new QPixmap( addtolist_18_xpm ); TTCut::imgFileClose = new QPixmap( fileclose_18_xpm ); setFocusPolicy(Qt::StrongFocus); // Message logger instance log = TTMessageLogger::getInstance(); // Get the current Qt version at runtime log->infoMsg(oName, "TTCut-Version: %s", qPrintable(TTCut::versionString)); log->infoMsg(oName, "Qt-Version: %s", qVersion()); #if QT_VERSION < 0x040100 // TODO: Show message box and abort session log->errorMsg(oName, "Qt-Version >= 4.1.0 required"); #endif // Settings TTCut::recentFileList.clear(); settings = new TTCutSettings(); settings->readSettings(); log->enableLogFile(TTCut::createLogFile); log->setLogModeConsole(TTCut::logModeConsole); log->setLogModeExtended(TTCut::logModeExtended); // Audio list audioList = new TTAudioListData(); audioFileInfo->setListData(audioList); // Mux list and mplex provider (later by plugin) muxListData = new TTMuxListData(); mplexProvider = new TTMplexProvider(); // no navigation navigationEnabled( false ); // init cutListData = NULL; mpegStream = NULL; TTCut::isVideoOpen = false; TTCut::projectFileName = ""; // Signal and slot connections // // Connect signals from main menu // -------------------------------------------------------------------------- connect(actionOpenVideo, SIGNAL(triggered()), videoFileInfo, SLOT(onFileOpen())); connect(actionOpenAudio, SIGNAL(triggered()), audioFileInfo, SLOT(onFileOpen())); connect(actionFileNew, SIGNAL(triggered()), SLOT(onFileNew())); connect(actionFileOpen, SIGNAL(triggered()), SLOT(onFileOpen())); connect(actionFileSave, SIGNAL(triggered()), SLOT(onFileSave())); connect(actionFileSaveAs, SIGNAL(triggered()), SLOT(onFileSaveAs())); connect(actionExit, SIGNAL(triggered()), SLOT(onFileExit())); connect(actionSaveCurrentFrame, SIGNAL(triggered()), SLOT(onActionSave())); connect(actionSettings, SIGNAL(triggered()), SLOT(onActionSettings())); connect(actionAbout, SIGNAL(triggered()), SLOT(onHelpAbout())); // recent files for (int i = 0; i < MaxRecentFiles; ++i) { recentFileAction[i] = new QAction(this); recentFileAction[i]->setVisible(false); menuRecentProjects->addAction(recentFileAction[i]); connect(recentFileAction[i], SIGNAL(triggered()), SLOT(onFileRecent())); } updateRecentFileActions(); // Connect signals from video and audio info // -------------------------------------------------------------------------- connect(videoFileInfo, SIGNAL(fileOpened(QString)), SLOT(onReadVideoStream(QString))); connect(audioFileInfo, SIGNAL(fileOpened(QString)), SLOT(onReadAudioStream(QString))); // Connect signals from navigation widget // -------------------------------------------------------------------------- connect(navigation, SIGNAL(prevIFrame()), currentFrame, SLOT(onPrevIFrame())); connect(navigation, SIGNAL(nextIFrame()), currentFrame, SLOT(onNextIFrame())); connect(navigation, SIGNAL(prevPFrame()), currentFrame, SLOT(onPrevPFrame())); connect(navigation, SIGNAL(nextPFrame()), currentFrame, SLOT(onNextPFrame())); connect(navigation, SIGNAL(prevBFrame()), currentFrame, SLOT(onPrevBFrame())); connect(navigation, SIGNAL(nextBFrame()), currentFrame, SLOT(onNextBFrame())); connect(navigation, SIGNAL(setCutOut(int)), currentFrame, SLOT(onSetCutOut(int))); connect(navigation, SIGNAL(setCutOut(int)), cutOutFrame, SLOT(onGotoCutOut(int))); connect(navigation, SIGNAL(setCutIn(int)), currentFrame, SLOT(onSetCutIn(int))); connect(navigation, SIGNAL(gotoCutIn(int)), currentFrame, SLOT(onGotoCutIn(int))); connect(navigation, SIGNAL(gotoCutOut(int)), currentFrame, SLOT(onGotoCutOut(int))); connect(navigation, SIGNAL(addCutRange(int, int)), cutList, SLOT(onAddEntry(int, int))); connect(navigation, SIGNAL(gotoMarker(int)), currentFrame, SLOT(onGotoMarker(int))); connect(navigation, SIGNAL(moveNumSteps(int)), currentFrame, SLOT(onMoveNumSteps(int))); connect(navigation, SIGNAL(moveToHome()), currentFrame, SLOT(onMoveToHome())); connect(navigation, SIGNAL(moveToEnd()), currentFrame, SLOT(onMoveToEnd())); // Connect signal from video slider // -------------------------------------------------------------------------- connect(streamNavigator, SIGNAL(sliderValueChanged(int)), SLOT(onVideoSliderChanged(int))); // Connect signals from cut-out frame widget // -------------------------------------------------------------------------- connect(cutOutFrame, SIGNAL(equalFrameFound(int)), currentFrame, SLOT(onGotoFrame(int))); connect(cutOutFrame, SIGNAL(newCutOutFramePos(int)), cutList, SLOT(onEditCutOut(int))); // Connect signals from current frame widget // -------------------------------------------------------------------------- connect(currentFrame, SIGNAL(newFramePosition(int)), SLOT(onNewFramePos(int))); // Connect signals from cut list widget // -------------------------------------------------------------------------- connect(cutList, SIGNAL(entrySelected(int)), cutOutFrame, SLOT(onGotoCutOut(int))); connect(cutList, SIGNAL(entryEdit(const TTCutListDataItem&)), navigation, SLOT(onEditCut(const TTCutListDataItem&))); connect(cutList, SIGNAL(gotoCutIn(int)), currentFrame, SLOT(onGotoFrame(int))); connect(cutList, SIGNAL(gotoCutOut(int)), currentFrame, SLOT(onGotoFrame(int))); connect(cutList, SIGNAL(refreshDisplay()), streamNavigator, SLOT(onRefreshDisplay())); connect(cutList, SIGNAL(previewCut(int)), SLOT(onPreviewCut(int))); connect(cutList, SIGNAL(audioVideoCut(int)), SLOT(onAudioVideoCut(int))); connect(cutList, SIGNAL(audioCut(int)), SLOT(onAudioCut(int))); }
void TTNavigation::keyPressEvent(QKeyEvent* e) { int steps = 0; if (!isControlEnabled) return; //log->infoMsg(oName, "key press event"); switch ( e->key() ) { // left arrow key case Qt::Key_Left: switch (e->modifiers()) { // backward TTCut::stepPlusAlt case Qt::AltModifier: steps -= TTCut::stepPlusAlt; break; // backward TTCut::stepPlusCtrl case Qt::ControlModifier: steps -= TTCut::stepPlusCtrl; break; // backward TTCut::stepPlusShift case Qt::ShiftModifier: steps -= TTCut::stepPlusShift; break; // backward one frame default: steps -= 1; break; } emit moveNumSteps(steps); break; // right arrow key case Qt::Key_Right: switch (e->modifiers()) { // forward TTCut::stepPlusAlt case Qt::AltModifier: steps += TTCut::stepPlusAlt; break; // forward TTCut::stepPlusCtrl case Qt::ControlModifier: steps += TTCut::stepPlusCtrl; break; // forward TTCut::stepPlusShift case Qt::ShiftModifier: steps += TTCut::stepPlusShift; break; // forward one frame default: steps += 1; break; } emit moveNumSteps(steps); break; // home key: show first frame case Qt::Key_Home: emit moveToHome(); break; // end key: show last frame case Qt::Key_End: emit moveToEnd(); break; // page down case Qt::Key_PageUp: steps -= TTCut::stepPgUpDown; emit moveNumSteps(steps); break; // page up case Qt::Key_PageDown: steps += TTCut::stepPgUpDown; emit moveNumSteps(steps); break; // I-frame case Qt::Key_I: // previous I-Frame if ( e->modifiers() == Qt::ControlModifier ) emit prevIFrame(); // next I-frame else emit nextIFrame(); break; // --------------------------------------------------------------------------- // P-frame // --------------------------------------------------------------------------- case Qt::Key_P: // previous P-Frame if ( e->modifiers() == Qt::ControlModifier ) emit prevPFrame(); // next P-frame else emit nextPFrame(); break; // --------------------------------------------------------------------------- // B-frame // --------------------------------------------------------------------------- case Qt::Key_B: // previous B-Frame if ( e->modifiers() == Qt::ControlModifier ) emit prevBFrame(); // next B-frame else emit nextBFrame(); break; default: break; } }
void eListbox::moveSelection(long dir) { /* refuse to do anything without a valid list. */ if (!m_content) return; /* if our list does not have one entry, don't do anything. */ if (!m_items_per_page) return; /* we need the old top/sel to see what we have to redraw */ int oldtop = m_top; int oldsel = m_selected; /* first, move cursor */ switch (dir) { case moveUp: { m_content->cursorMove(-1); if (m_enabled_wrap_around && oldsel == m_content->cursorGet()) // must wrap around ? moveToEnd(); break; } case moveDown: m_content->cursorMove(1); /* ok - we could have reached the end. So we do wrap around. */ if (!m_content->cursorValid()) { if (m_enabled_wrap_around) { m_top = 0; m_content->cursorHome(); } else m_content->cursorMove(-1); } break; case pageUp: if (m_content->cursorGet() >= m_items_per_page) { m_content->cursorMove(-m_items_per_page); m_top -= m_items_per_page; if (m_top < 0) m_top = 0; } else { m_top = 0; m_content->cursorHome(); } break; case moveTop: m_content->cursorHome(); m_top = 0; /* align with top, speeds up process */ break; case pageDown: m_content->cursorMove(m_items_per_page); if (m_content->cursorValid()) break; /* fall through */ case moveEnd: moveToEnd(); break; case justCheck: break; } if (m_content->cursorValid() && !m_content->currentCursorSelectable()) { /* ok, our cursor position is valid (i.e. in list), but not selectable. */ /* when moving up, continue until we found a valid position. */ if ((dir == moveUp) || (dir == pageDown)) { while (m_content->cursorGet()) { m_content->cursorMove(-1); if (m_content->currentCursorSelectable()) { break; } } } else { /* else move down */ while (m_content->cursorValid()) { m_content->cursorMove(+1); if (m_content->currentCursorSelectable()) { break; } } if (!m_content->cursorValid()) m_content->cursorMove(-1); } if (!m_content->currentCursorSelectable()) m_content->cursorSet(oldsel); } /* note that we could be on an invalid cursor position, but we don't care. this only happens on empty lists, and should have almost no side effects. */ /* now, look wether the current selection is out of screen */ m_selected = m_content->cursorGet(); while (m_selected < m_top) { m_top -= m_items_per_page; if (m_top < 0) m_top = 0; } while (m_selected >= m_top + m_items_per_page) /* m_top should be always valid here as it's selected */ m_top += m_items_per_page; if (oldsel != m_selected) /* emit */ selectionChanged(); updateScrollBar(); if (m_top != oldtop) invalidate(); else if (m_selected != oldsel) { /* redraw the old and newly selected */ gRegion inv = eRect(0, m_itemheight * (m_selected-m_top), size().width(), m_itemheight); inv |= eRect(0, m_itemheight * (oldsel-m_top), size().width(), m_itemheight); invalidate(inv); } }
int get(int key) { if(key2Node.count(key)==0) return -1; //for use key in the cache, move to the end moveToEnd(key); return key2Node[key]->val; }
int handleclient(struct client *p, struct client *top) { char outbuf[512]; struct client *oppo; int len; //New client, ask the name. if (p->name == NULL) { //Ask the name int inbuf = 0; int where; // buffer is empty; has no bytes int room = sizeof(p->name_buf); // room == capacity of the whole buffer char *after; after = p->name_buf; //Return number of bytes read //nbytes = len while (( len = read(p->fd, after, sizeof(p->name_buf) - 1)) > 0) { inbuf += len; where = find_network_newline(p->name_buf, inbuf); if (where >= 0) { // OK. we have a full line p->name_buf[where] = '\0'; p->name_buf[where+1] = '\0'; inbuf -= where + 2 ; break; } room = sizeof(p->name_buf) - inbuf; after = p->name_buf + inbuf; } p->name = p->name_buf; //Tell the world someone joined. sprintf(outbuf, "\r\n**%s joined the area.**\r\n", p->name); broadcast(top, outbuf, strlen(outbuf)); sprintf(outbuf, "Welcome, %s! Awaiting opponent...\n", p->name); write(p->fd, outbuf, strlen(outbuf)); } //Start matching. if(p->opponent == NULL) { for (oppo = top; oppo != NULL; oppo = oppo->next) { if(oppo != p) { if(oppo->opponent == NULL && oppo->lastplayed != p) { p->opponent = oppo; p->hitpoints = rand() % 11 + 20; p->powermoves = rand() % 3 + 1; p->status = 1;//Attacking first oppo->opponent = p; oppo->hitpoints = rand() % 11 + 20; oppo->powermoves = rand() % 3 + 1; oppo->status = -1;//Defend first. sprintf(outbuf, "You engage %s!\n", p->opponent->name); write(p->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "You engage %s!\n", p->name); write(p->opponent->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "\nReady for battle?(Please type 'y')\n"); write(p->fd, outbuf, strlen(outbuf)); } } } return 0; } len = read(p->fd, p->buf, sizeof(p->buf) - 1); //Handle battle. if(p->opponent) { if (p->status == 1) { sprintf(outbuf, "Your hitpoints:%d\nYour powermoves: %d\n\n%s's hitpoints:%d\n\n", p->hitpoints, p->powermoves, p->opponent->name, p->opponent->hitpoints); write(p->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "Your hitpoints:%d\nYour powermoves: %d\n\n%s's hitpoints:%d\n\n", p->opponent->hitpoints, p->opponent->powermoves, p->name, p->hitpoints); write(p->opponent->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "(a)ttack\n(p)owermove\n(s)peak something\n"); write(p->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "Waiting for %s to strike...\n", p->name); write(p->opponent->fd, outbuf, strlen(outbuf)); len = read(p->fd, p->buf, sizeof(p->buf) - 1); p->status = -1; p->opponent->status = 1; } else if(p->status == -1) { return 0; } if (len > 0) { if(p->buf[0] == 'a') { p->buf[0] = '\0'; int damage; damage = rand() % 5 + 2; p->opponent->hitpoints -= damage; sprintf(outbuf, "\nYou hit %s for %d damage!\n", p->opponent->name, damage); write(p->fd, outbuf, strlen(outbuf));//write outbuf to every client in top. sprintf(outbuf, "\n%s hits you for %d damage!\n", p->name, damage); write(p->opponent->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "\nReady for attacking/speaking?(Please say 'y')\n"); write(p->opponent->fd, outbuf, strlen(outbuf)); if(p->opponent->hitpoints <= 0) { sprintf(outbuf, "\n%s gives up. You win!\n", p->opponent->name); write(p->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "\nYou are no match for %s. You scurry away...\n", p->name); write(p->opponent->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "Awaiting opponent...\n"); write(p->fd, outbuf, strlen(outbuf)); write(p->opponent->fd, outbuf, strlen(outbuf)); p->lastplayed = p->opponent; p->opponent->lastplayed = p; moveToEnd(top, p); moveToEnd(top, p->opponent); p->opponent->opponent = NULL; p->opponent = NULL; } return 0; } else if(p->buf[0] == 'p') { p->buf[0] = '\0'; int possibility; int damage; possibility = rand() % 2 + 0; p->powermoves -= 1; if(possibility == 0) { //Miss it; sprintf(outbuf, "\nYou missed %s!\n", p->opponent->name); write(p->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "\n%s missed you!\n", p->name); write(p->opponent->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "\nReady for attacking/speaking?(Please say 'y')\n"); write(p->opponent->fd, outbuf, strlen(outbuf)); return 0; } else { damage = 3 * (rand() % 5 + 2); p->opponent->hitpoints -= damage; sprintf(outbuf, "\nYou powermoves %s for %d damage!\n", p->opponent->name, damage); write(p->fd, outbuf, strlen(outbuf));//write outbuf to every client in top. sprintf(outbuf, "\n%s powermoves you for %d damage!\n", p->name, damage); write(p->opponent->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "\nReady for attacking/speaking?(Please say 'y')\n"); write(p->opponent->fd, outbuf, strlen(outbuf)); if(p->opponent->hitpoints <= 0) { sprintf(outbuf, "\n%s gives up. You win!\n", p->opponent->name); write(p->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "\nYou are no match for %s. You scurry away...\n", p->name); write(p->opponent->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "Awaiting opponent...\n"); write(p->fd, outbuf, strlen(outbuf)); write(p->opponent->fd, outbuf, strlen(outbuf)); p->lastplayed = p->opponent; p->opponent->lastplayed = p; moveToEnd(top, p); moveToEnd(top, p->opponent); p->opponent->opponent = NULL; p->opponent = NULL; } return 0; } } else if(p->buf[0] == 's') { p->buf[0] = '\0'; sprintf(outbuf, "Speak:"); write(p->fd, outbuf, strlen(outbuf)); int inbuf = 0; int where; int room = sizeof(p->buf); char *after; //char name_buf[256]; p->buf[0] = '\0'; after = p->buf; while (( len = read(p->fd, after, sizeof(p->buf) - 1)) > 0) { inbuf += len; where = find_network_newline(p->buf, inbuf); if (where >= 0) { // OK. we have a full line p->buf[where] = '\0'; p->buf[where+1] = '\0'; inbuf -= where + 2 ; break; } room = sizeof(p->buf) - inbuf; after = p->buf + inbuf; } sprintf(outbuf, "You spoke:%s\n", p->buf); write(p->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "%s spoke:%s\n", p->name, p->buf); write(p->opponent->fd, outbuf, strlen(outbuf)); sprintf(outbuf, "\nReady for attacking/speaking?(Please say 'y')\n"); write(p->opponent->fd, outbuf, strlen(outbuf)); return 0; } } else if (len == 0) {//nothing in client p's fd // socket is closed printf("active\n"); sprintf(outbuf, "Awaiting opponent...\n"); write(p->opponent->fd, outbuf, strlen(outbuf)); p->opponent->opponent = NULL; sprintf(outbuf, "--%s dropped. You win!\n", p->name); write(p->opponent->fd, outbuf, strlen(outbuf)); printf("Disconnect from %s\n", inet_ntoa(p->ipaddr)); return -1; } else { // shouldn't happen perror("read"); return -1; } } return -1; }
void Variable::moveToEnd( const std::vector<std::string> &v ) { for ( const std::string &i: v ) moveToEnd( i ); }
time_t parseDuration(const char *string) { /* * Allowed format: * jj hh:mn:ss * hh:mn:ss * nn * nn s * nn mn * nn h * nn j */ durationParserStates state = init; time_t duration = 0; register const char *cursor = string; unsigned int n; while(*cursor != '\0') { cursor = parseInteger(cursor,&n); cursor = moveToNextToken(cursor); switch(*cursor) { case '\0': duration = duration * 60 + n; break; case 's': duration += n; cursor++; break; case 'm': cursor++; if ('n' == *cursor) { duration += n*60; cursor++; } else { WARNING_MSG("unknow time unit at m%s", cursor); duration = 0; cursor = moveToEnd(cursor); } break; case 'h': duration += n*3600; cursor++; break; case 'j': duration += n*24*3600; cursor++; break; case ':': /* hh:mn:ss */ switch(state) { case init: duration = n; state = hours; /* hours read */ break; case days: duration = duration * 24 + n; state = hours; /* hours read */ break; case hours: duration = duration * 60 + n; state = minutes; /* minutes read */ break; case minutes: duration = (duration + n) * 60; state = seconds; /* seconds read */ case seconds: WARNING_MSG("bad string time format %s",string); duration = 0; cursor = moveToEnd(cursor) - 1; break; } /* switch(state) */ cursor++; break; default: if (isdigit(*cursor)) { /* jj hh:mn:ss */ state = days; /* days read */ duration = n; } else { WARNING_MSG("bad string format %s",string); duration = 0; cursor = moveToEnd(cursor) - 1; } } /* switch(*cursor) */ } /*(cursor != '\0')*/ return duration; }
void CustomElementUpgradeCandidateMap::elementDidFinishParsingChildren(Element* element) { // An upgrade candidate finished parsing; reorder so that eventual // upgrade order matches finished-parsing order. moveToEnd(element); }