/* * input: * puzzle is the sudoku * lowerPerm is the starting permutation for this permutation finder * extra is how many more permutations to go * doNext is the function when created a new puzzle * return: * number of good puzzles found through doNext */ int row (int puzzle[9][9],int lowerPerm,int extra,int (*doNext)(int[9][9]))//216*block perm + 36*block 1 perm + 6 block 2 perm + block 3 perm { int i,j,k; int blocks[3] = {0,1,2}; int inBlock[3][3] = {{0,1,2},{3,4,5},{6,7,8}}; int cpyPz [9][9]; int count = 0; //Start the begining permutation if(start_permute(blocks,3,lowerPerm/216)) return 0; lowerPerm = lowerPerm % 216; start_permute(inBlock[0],3,lowerPerm/36); lowerPerm = lowerPerm % 36; start_permute (inBlock[1],3,lowerPerm/6); start_permute (inBlock[2],3,lowerPerm%6); //make copy of puzzle for swap for(i = 0; i < 9;++i) for(j = 0; j < 9;++j) { cpyPz[i][j] = puzzle[ inBlock[blocks[i/3]][i%3]][j]; } count += doNext(cpyPz); //Find each permutation for(k = 0; k < extra; ++k) { if (next_permutation (inBlock[0],3) == 1)//block one done { for(j = 0;j < 3;++j) inBlock[0][j] = j; if (next_permutation (inBlock [1],3)==1)//block two done { for(j = 0;j < 3;++j) inBlock[1][j] = j+3; if (next_permutation (inBlock[2],3)==1)//block three done { for(j = 0;j < 3;++j) inBlock[2][j] = j+6; if (next_permutation (blocks,3)==1)//final is done return count;//Done and ran to edge } } } //make a copy of the puzzle for(i = 0; i < 9;++i) for(j = 0; j < 9;++j) { cpyPz[i][j] = puzzle[ inBlock[blocks[i/3]][i%3]][j]; } count += doNext(cpyPz); } return count;//Done with extra }
void CJobRunner::contineuToNext(bool cont) { itsActionLabel->startAnimation(); if(cont) { if(CMD_INSTALL==itsCmd && Item::TYPE1_FONT==(*itsIt).type) // Did we error on a pfa/pfb? if so, exclude the afm/pfm... { QString currentName((*itsIt).fileName); ++itsIt; // Skip afm/pfm if(itsIt!=itsEnd && (*itsIt).fileName==currentName && (Item::TYPE1_AFM==(*itsIt).type || Item::TYPE1_PFM==(*itsIt).type)) ++itsIt; // Skip pfm/afm if(itsIt!=itsEnd && (*itsIt).fileName==currentName && (Item::TYPE1_AFM==(*itsIt).type || Item::TYPE1_PFM==(*itsIt).type)) ++itsIt; } else ++itsIt; } else { itsUrls.empty(); itsIt=itsEnd=itsUrls.constEnd(); } doNext(); }
void NewGame::onKeyDown(Event::Keyboard* event) { switch (event->keyCode()) { case SDLK_ESCAPE: case SDLK_b: doBack(); break; case SDLK_t: doBeginGame(); break; case SDLK_c: doCreate(); break; case SDLK_m: doEdit(); break; case SDLK_LEFT: doPrev(); break; case SDLK_RIGHT: doNext(); break; } }
bool PhraseScorer::skipTo(int32_t target) { for (PhrasePositions* pp = first; more && pp != NULL; pp = pp->_next) { more = pp->skipTo(target); } if (more) sort(); // re-sort return doNext(); }
bool PhraseScorer::next(){ if (firstTime) { init(); firstTime = false; } else if (more) { more = last->next(); // trigger further scanning } return doNext(); }
int CJobRunner::exec(ECommand cmd, const ItemList &urls, bool destIsSystem) { itsAutoSkip=itsCancelClicked=itsModified=false; switch(cmd) { case CMD_INSTALL: setCaption(i18n("Installing")); break; case CMD_DELETE: setCaption(i18n("Uninstalling")); break; case CMD_ENABLE: setCaption(i18n("Enabling")); break; case CMD_MOVE: setCaption(i18n("Moving")); break; case CMD_UPDATE: setCaption(i18n("Updating")); itsModified=true; break; case CMD_REMOVE_FILE: setCaption(i18n("Removing")); break; default: case CMD_DISABLE: setCaption(i18n("Disabling")); } itsDestIsSystem=destIsSystem; itsUrls=urls; if(CMD_INSTALL==cmd) qSort(itsUrls.begin(), itsUrls.end()); // Sort list of fonts so that we have type1 fonts followed by their metrics... else if(CMD_MOVE==cmd) addEnableActions(itsUrls); itsIt=itsUrls.constBegin(); itsEnd=itsUrls.constEnd(); itsPrev=itsEnd; itsProgress->setValue(0); itsProgress->setRange(0, itsUrls.count()+1); itsProgress->show(); itsCmd=cmd; itsCurrentFile=QString(); itsStatusLabel->setText(QString()); setPage(PAGE_PROGRESS); QTimer::singleShot(0, this, SLOT(doNext())); QTimer::singleShot(constInterfaceCheck, this, SLOT(checkInterface())); itsActionLabel->startAnimation(); int rv=KDialog::exec(); if(itsTempDir) { delete itsTempDir; itsTempDir=0L; } return rv; }
/* * input: * puzzle = the sudoku to work on * (*doNext) = function to be done when created a new puzzle * return: * count of good puzzles */ int rotate (int puzzle[9][9],int (*doNext)(int [9][9])) { int count = doNext(puzzle); int cpyPz [9][9]; int i ,j; for (i = 0; i < 9;++i) { for(j = 0; j < 9;++j) { puzzle[8-i][j] = puzzle[j][i]; } } count += doNext(cpyPz); return count; return count; }
void DirectoryIteratorImpl::findFirstFile(const tstring& sFindPath) { m_fileHandle = FindFirstFile(sFindPath.c_str(), &m_findData); if (m_fileHandle == INVALID_HANDLE_VALUE) { if (GetLastError() != ERROR_NO_MORE_FILES) FileImpl::handleLastError(sFindPath); } else { m_sCurrent = m_findData.cFileName; if (m_sCurrent == _T(".") || m_sCurrent == _T("..")) doNext(); } }
bool CDisjunctionScorer::skipTo(docid_t target,docid_t& nearTarget) { if(m_pScorerQueue == NULL) initScorerQueue(); nearTarget = target - 1; if ((int)m_pScorerQueue->size() < m_minShouldMatch) { return false; } docid_t currentDoc = target; score_t currentScore = 0; int32_t numDocs = -1; do { CScorer* top = (CScorer*) m_pScorerQueue->top(); if (top->doc() >= currentDoc) { if(doNext(nearTarget,currentScore) == false) { nearTarget = -1; return false; } else { m_numDocs = 1; m_docs[0] = nearTarget; m_scores[0] = currentScore; return (currentDoc == nearTarget); } } else if (top->skipTo(currentDoc,nearTarget)) { m_pScorerQueue->adjustTop(); } else { if(nearTarget < currentDoc) { m_pScorerQueue->pop(); if ((int32_t)m_pScorerQueue->size() < m_minShouldMatch) { return false; } } else m_pScorerQueue->adjustTop(); } } while (true); }
HistoryDlg::HistoryDlg(const XMPP::Jid& j, PsiAccount* pa) : pa_(pa), jidFull_(j), from_(0), count_(30) { setupUi(this); setModal(false); setAttribute(Qt::WA_DeleteOnClose); pa_->dialogRegister(this, jidFull_); setWindowTitle(tr("History for ") + j.full()); #ifndef Q_WS_MAC setWindowIcon(IconsetFactory::icon("psi/history").icon()); #endif DateTree->setHeaderLabel(tr("Date")); DateTree->setSortingEnabled(true); DateTree->setColumnHidden(1,true); connect(DateTree, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(doDateContextMenu(const QPoint &))); EventsTree->setColumnCount(4); QStringList headers; headers << tr("Type") << tr("Time") << tr("Origin") << tr("Text"); EventsTree->setHeaderLabels(headers); EventsTree->sortItems(1,Qt::AscendingOrder); EventsTree->setSortingEnabled(true); EventsTree->setWordWrap(true); EventsTree->hideColumn(2); connect(EventsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), SLOT(actionOpenEvent(QTreeWidgetItem *, int))); connect(EventsTree, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(doEventContextMenu(const QPoint &))); connect(tb_previousMonth, SIGNAL(clicked()), SLOT(doPrev())); connect(tb_latest, SIGNAL(clicked()), SLOT(doLatest())); connect(tb_nextMonth, SIGNAL(clicked()), SLOT(doNext())); connect(pb_find, SIGNAL(clicked()), SLOT(doFind())); connect(pb_export, SIGNAL(clicked()), SLOT(doExport())); connect(pb_close, SIGNAL(clicked()), SLOT(close())); jid_ = j.bare(); doLatest(); X11WM_CLASS("history"); }
stdErr = prevStout = QString(); output->setText(QString()); currentSession = sessions.begin(); endSession = sessions.end(); sessionCount = sessions.count(); if (!process) { process = new QProcess(this); QStringList env(QProcess::systemEnvironment()); env.append(CARBON_GUI_PARENT"=true"); process->setEnvironment(env); connect(process, SIGNAL(finished(int)), this, SLOT(processFinished(int))); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut())); connect(process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr())); } setButtons(Cancel); QTimer::singleShot(0, this, SLOT(doNext())); QTimer::singleShot(0, this, SLOT(showDetails())); exec(); } void RunnerDialog::doNext() { syncStatus = STARTUP; if (currentSession != endSession) { sessionLabel->setText((*currentSession)->name()); QStringList arguments; (*currentSession)->save(); arguments << (*currentSession)->fileName(); if (dryRun) {
void NewGame::onNextCharacterButtonClick(Event::Mouse* event) { doNext(); }
char doRegular(char expand, char c) { char toReturn; int i; int done = 0; label doorinfo; toReturn = FALSE; for (i = 0; !expand && i < MAXEXTERN && extCmd[i].name[0]; ++i) { if (c == toupper(extCmd[i].name[0]) && (onConsole || !extCmd[i].local)) { done = 1; mPrintf("\b%s", extCmd[i].name); doCR(); if (changedir(cfg.aplpath) == ERROR) { mPrintf(" -- Can't find application directory.\n\n"); changedir(cfg.homepath); } /* apsystem(extCmd[i].command); */ sprintf(doorinfo, "DORINFO%d.DEF", onConsole ? 0 : userdat.apl_com); extFmtRun(extCmd[i].command, doorinfo); } } if (!done) { switch (c) { case 'S': if (gl_user.sysop && expand) { mPrintf("\b\bSysop Menu"); doCR(); doSysop(); } else { toReturn = TRUE; } break; case 'A': if (gl_user.aide) { doAide(expand, 'E'); } else { toReturn = TRUE; } break; case 'C': doChat(expand, '\0'); break; case 'D': doDownload(expand); break; case 'E': doEnter(expand, 'm'); break; case 'F': doRead(expand, 'f'); break; case 'G': doGoto(expand, FALSE); break; case 'H': doHelp(expand); break; case 'I': doIntro(); break; case 'J': mPrintf("\bJump back to "); unGotoRoom(); break; case 'K': doKnown(expand, 'r'); break; case 'L': if (!loggedIn) { doLogin(expand); } else { if (!getYesNo(confirm, 0)) break; doLogout(expand, 's'); doLogin(expand); } break; case 'N': case 'O': case 'R': doRead(expand, tolower(c)); break; case 'B': doGoto(expand, TRUE); break; case 'T': doLogout(expand, 'q'); break; case 'U': doUpload(expand); break; case 'X': if (!expand) { doEnter(expand, 'x'); } else { doXpert(); } break; case '=': case '+': doNext(); break; case '\b': mPrintf(" "); case '-': doPrevious(); break; case ']': case '>': doNextHall(); break; case '[': case '<': doPreviousHall(); break; case '~': mPrintf("\bAnsi %s\n ", gl_term.ansiOn ? gl_str.off : gl_str.on); gl_term.ansiOn = !gl_term.ansiOn; break; case '!': mPrintf("\bIBM Graphics %s\n ", gl_term.IBMOn ? gl_str.off:gl_str.on); gl_term.IBMOn = !gl_term.IBMOn; break; case '?': nextmenu("mainopt", &(cfg.cnt.mainopttut), 1); listExterns(); break; case 0: /* never gets here in shell mode... */ if (newCarrier) { greeting(); if (cfg.forcelogin) { doCR(); doCR(); i = 0; while (!loggedIn && gotCarrier()) { doLogin(2); if (++i > 3) { Initport(); toReturn = TRUE; break; } } } newCarrier = FALSE; } if (logBuf.lbflags.NODE && loggedIn) { net_slave(); haveCarrier = FALSE; modStat = FALSE; newCarrier = FALSE; justLostCarrier = FALSE; onConsole = FALSE; disabled = FALSE; callout = FALSE; delay(2000); Initport(); cfg.callno++; terminate(FALSE, FALSE); } if (justLostCarrier || ExitToMsdos) { justLostCarrier = FALSE; if (loggedIn) terminate(FALSE, FALSE); } break; /* irrelevant value */ default: toReturn = TRUE; break; } } /* if they get unverified online */ if (logBuf.VERIFIED) terminate(FALSE, FALSE); /* update25(); */ do_idle(0); return toReturn; }
//0:exit,1:continue int CwxBinlogOp::doCommand(char* szCmd) { string strCmd; list < string > value; CwxCommon::trim(szCmd); strCmd = szCmd; CwxCommon::split(strCmd, value, ' '); list<string>::iterator iter = value.begin(); //remove the empty value while (iter != value.end()) { if ((*iter).length() == 0) { value.erase(iter); iter = value.begin(); continue; } iter++; } if (value.size() == 0) return 1; iter = value.begin(); CWX_UINT32 uiItemNum = value.size(); if (0 == strcasecmp((*iter).c_str(), "help")) { doHelp(); } else if (0 == strcasecmp((*iter).c_str(), "info")) { doInfo(); } else if (0 == strcasecmp((*iter).c_str(), "next")) { CWX_UINT32 uiNum = 1; if (1 != uiItemNum) { iter++; uiNum = strtoul((*iter).c_str(), NULL, 0); } doNext(uiNum); } else if (0 == strcasecmp((*iter).c_str(), "prev")) { CWX_UINT32 uiNum = 1; if (1 != uiItemNum) { iter++; uiNum = strtoul((*iter).c_str(), NULL, 0); } doPrev(uiNum); } else if (0 == strcasecmp((*iter).c_str(), "sid")) { if (2 != uiItemNum) { printf("Invalid sid command, using: sid value.\n"); return 1; } iter++; doSid(strtoull((*iter).c_str(), NULL, 0)); } else if (0 == strcasecmp((*iter).c_str(), "rec")) { if (2 != uiItemNum) { printf("Invalid rec command, using: rec value.\n"); return 1; } iter++; doRecord(strtoul((*iter).c_str(), NULL, 0)); } else if (0 == strcasecmp((*iter).c_str(), "group")) { if (2 != uiItemNum) { printf("Invalid group command, using: group value.\n"); return 1; } iter++; doGroup(strtoul((*iter).c_str(), NULL, 0)); } else if (0 == strcasecmp((*iter).c_str(), "key")) { if (3 != uiItemNum) { printf("Invalid key command, using: key k v.\n"); return 1; } iter++; string strKey = *iter; doKey(strKey.c_str(), (*iter).c_str()); } else if (0 == strcasecmp((*iter).c_str(), "head")) { doHead(); } else if (0 == strcasecmp((*iter).c_str(), "data")) { doData(); } else if (0 == strcasecmp((*iter).c_str(), "save")) { if (1 == uiItemNum) { printf("Invalid save command, using: save file.\n"); return 1; } iter++; doSave(*iter); } else if (0 == strcasecmp((*iter).c_str(), "exit")) { return 0; } else { printf("Invalid command %s\n", (*iter).c_str()); doHelp(); } return 1; }
void CJobRunner::dbusStatus(int pid, int status) { if(pid!=getpid()) return; if(CMD_UPDATE==itsCmd) { setPage(PAGE_COMPLETE); return; } itsLastDBusStatus=status; if(itsCancelClicked) { itsActionLabel->stopAnimation(); setPage(PAGE_CANCEL); return; /* if(RESP_CANCEL==itsResponse) itsIt=itsEnd; itsCancelClicked=false; setPage(PAGE_PROGRESS); itsActionLabel->startAnimation(); */ } // itsIt will equal itsEnd if user decided to cancel the current op if(itsIt==itsEnd) { doNext(); } else if (0==status) { itsModified=true; ++itsIt; doNext(); } else { bool cont(itsAutoSkip && itsUrls.count()>1); QString currentName((*itsIt).fileName); if(!cont) { itsActionLabel->stopAnimation(); if(FontInst::STATUS_SERVICE_DIED==status) { setPage(PAGE_ERROR, errorString(status)); itsIt=itsEnd; } else { ItemList::ConstIterator lastPartOfCurrent(itsIt), next(itsIt==itsEnd ? itsEnd : itsIt+1); // If we're installing a Type1 font, and its already installed - then we need to skip past AFM/PFM if(next!=itsEnd && Item::TYPE1_FONT==(*itsIt).type && (*next).fileName==currentName && (Item::TYPE1_AFM==(*next).type || Item::TYPE1_PFM==(*next).type)) { next++; if(next!=itsEnd && (*next).fileName==currentName && (Item::TYPE1_AFM==(*next).type || Item::TYPE1_PFM==(*next).type)) next++; } if(1==itsUrls.count() || next==itsEnd) setPage(PAGE_ERROR, errorString(status)); else { setPage(PAGE_SKIP, errorString(status)); return; } } } contineuToNext(cont); } }
HistoryDlg::HistoryDlg(const Jid &jid, PsiAccount *pa) { setAttribute(Qt::WA_DeleteOnClose); d = new Private; d->pa = pa; d->jid = jid; d->pa->dialogRegister(this, d->jid); d->exp = 0; setWindowTitle(d->jid.full()); #ifndef Q_WS_MAC setWindowIcon(IconsetFactory::icon("psi/history").icon()); #endif d->h = new EDBHandle(d->pa->edb()); connect(d->h, SIGNAL(finished()), SLOT(edb_finished())); QVBoxLayout *vb1 = new QVBoxLayout(this); d->lv = new HistoryView(this); d->lv->setVScrollBarMode(Q3ScrollView::AlwaysOn); connect(d->lv, SIGNAL(aOpenEvent(PsiEvent *)), SLOT(actionOpenEvent(PsiEvent *))); QSizePolicy sp = d->lv->sizePolicy(); sp.setVerticalStretch(1); d->lv->setSizePolicy(sp); vb1->addWidget(d->lv); QHBoxLayout *hb1 = new QHBoxLayout; vb1->addLayout(hb1); QVBoxLayout *vb2 = new QVBoxLayout; hb1->addLayout(vb2); QHBoxLayout *hb2 = new QHBoxLayout; vb2->addLayout(hb2); //d->busy = new BusyWidget(this); //hb1->addWidget(d->busy); d->pb_refresh = new QPushButton(tr("&Latest"), this); d->pb_refresh->setMinimumWidth(80); connect(d->pb_refresh, SIGNAL(clicked()), SLOT(doLatest())); hb2->addWidget(d->pb_refresh); d->pb_prev = new QPushButton(tr("&Previous"), this); d->pb_prev->setMinimumWidth(80); connect(d->pb_prev, SIGNAL(clicked()), SLOT(doPrev())); hb2->addWidget(d->pb_prev); d->pb_next = new QPushButton(tr("&Next"), this); d->pb_next->setMinimumWidth(80); connect(d->pb_next, SIGNAL(clicked()), SLOT(doNext())); hb2->addWidget(d->pb_next); QHBoxLayout *hb3 = new QHBoxLayout; vb2->addLayout(hb3); d->le_find = new QLineEdit(this); connect(d->le_find, SIGNAL(textChanged(const QString &)), SLOT(le_textChanged(const QString &))); connect(d->le_find, SIGNAL(returnPressed()), SLOT(doFind())); hb3->addWidget(d->le_find); d->pb_find = new QPushButton(tr("Find"), this); connect(d->pb_find, SIGNAL(clicked()), SLOT(doFind())); d->pb_find->setEnabled(false); hb3->addWidget(d->pb_find); QFrame *sep; sep = new QFrame(this); sep->setFrameShape(QFrame::VLine); hb1->addWidget(sep); QVBoxLayout *vb3 = new QVBoxLayout; hb1->addLayout(vb3); QPushButton *pb_save = new QPushButton(tr("&Export..."), this); connect(pb_save, SIGNAL(clicked()), SLOT(doSave())); vb3->addWidget(pb_save); QPushButton *pb_erase = new QPushButton(tr("Er&ase All"), this); connect(pb_erase, SIGNAL(clicked()), SLOT(doErase())); vb3->addWidget(pb_erase); sep = new QFrame(this); sep->setFrameShape(QFrame::VLine); hb1->addWidget(sep); hb1->addStretch(1); QVBoxLayout *vb4 = new QVBoxLayout; hb1->addLayout(vb4); vb4->addStretch(1); QPushButton *pb_close = new QPushButton(tr("&Close"), this); pb_close->setMinimumWidth(80); connect(pb_close, SIGNAL(clicked()), SLOT(close())); vb4->addWidget(pb_close); resize(520,320); X11WM_CLASS("history"); d->le_find->setFocus(); setButtons(); doLatest(); }
void doNext(int num) { if( num > 1 ) doNext( num - 1 ); printf("%d ", num); }
int main() { doNext(3); printf("\n"); return 0; }
std::shared_ptr<SpmvArchitecture> next() { return std::shared_ptr<SpmvArchitecture>(doNext()); }