void MainWindow::doPlay(QString vertex){ if(game_over) return; if(players.getCurrent()->getSpecies() == "Computer"){ QString result = gtp.genmove( players.getCurrent()->getColorString() ); if(result == "pass"){ addHistory(players.currentColor(),tr("Passed")); updateScore(players.currentColor(),tr("Passed")); players.setCurrentPass(); }else if( result == "resign"){ addHistory(players.currentColor(),tr("Resigned")); updateScore(players.currentColor(),tr("Resigned")); players.setCurrentResigned(); }else{ players.setCurrentPlays(); } QString reason = players.getGameOver(); //if(reason.length()>0) emit gameOver(reason); if(reason.length()>0) setGameOver(reason); }else{ if(gtp.play( players.getCurrent()->getColorString(), vertex)){ players.setCurrentPlays(); }else{ addHistory(players.currentColor(),tr("Illegal move, try another")); return; } } int cnt= gtp.captures(players.getCurrent()->getColorString()); if(cnt != players.getCurrent()->getCaptures()){ players.getCurrent()->setCaptures(cnt); ui->gameBoard->checkStones(players.getNext()->getColorString(), gtp.list_stones( players.getNext()->getColorString())); } afterMove(); }
QString PathMapper::mapLocalPathToServer(const QString &localpath) { if(localpath.isEmpty()) return localpath; if(m_localBasedir == "/" && m_serverBasedir == "/") return localpath; QString newpath = translate(localpath, m_localBasedir, m_serverBasedir); // If no translation occurred, check and see if some of the other translations does if(newpath == localpath) { for (unsigned int cnt = 0; cnt < m_serverlist.count(); cnt++ ) { // If the entire filename matches, count it as a match even if there is no difference if(m_locallist[cnt] == localpath) return localpath; // If both are slashes, count it as a local project if(m_locallist[cnt] == "/" && m_serverlist[cnt] == "/") return localpath; // Check if it translates into something newpath = translate(localpath, m_locallist[cnt], m_serverlist[cnt]); if(newpath != localpath) { addHistory(localpath, newpath, true); return newpath; } } // No translation found -> show dialog PathMapperDialog pmdlg(localpath, PathMapperDialog::LocalToServer); for (unsigned int cnt = 0; cnt < m_serverlist.count(); cnt++ ) pmdlg.addHistory(m_serverlist[cnt], m_locallist[cnt]); if(pmdlg.exec() == QDialog::Accepted ) { newpath = translate(localpath, pmdlg.localPath(), pmdlg.serverPath()); addHistory(pmdlg.localPath(), pmdlg.serverPath(), newpath != localpath); return newpath; } return localpath; } return newpath; }
void line(XEvent ev,Window *layer_expose,Window *layer,Window *mask,int num){ int xs,ys,xe,ye; XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, None, ShapeSet);//いったんマスクを解除 XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, None, ShapeSet); XCopyArea( dis, layer[num], copy_pix[0], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); xs=ev.xbutton.x; ys=ev.xbutton.y; while( !(ev.type == ButtonRelease && ev.xbutton.button == 1) ){ if(ev.type == MotionNotify){ XCopyArea( dis, copy_pix[0], copy_pix[1], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); xe=ev.xbutton.x; ye=ev.xbutton.y; XDrawLine(dis, copy_pix[1], gc, xs, ys, xe, ye); XCopyArea( dis, copy_pix[1], layer[num], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); XFlush(dis); } XNextEvent( dis, &ev ); } XDrawLine(dis, mask[num], mask_gc, xs, ys, xe, ye); XDrawLine(dis, layer_expose[num], gc, xs, ys, xe, ye); XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, mask[num], ShapeSet); XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, mask[num], ShapeSet); addHistory(layer_expose,mask,num);//履歴に追加 }
void freeHand(XEvent ev,Window *layer_expose,Window *layer,Window *mask,int num){ int x,y; int i; x=ev.xbutton.x; y=ev.xbutton.y; XSetForeground( dis, gc, current_color ); // 図形の色を設定 XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, None, ShapeSet);//いったんマスクを解除 XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, None, ShapeSet); XNextEvent( dis, &ev ); while( !(ev.type == ButtonRelease && ev.xbutton.button == 1) ){ if(ev.type == MotionNotify){ XDrawLine( dis, layer_expose[num], gc, x, y, ev.xbutton.x, ev.xbutton.y ); XDrawLine( dis, layer[num], gc, x, y, ev.xbutton.x, ev.xbutton.y ); XDrawLine( dis, mask[num], mask_gc, x, y, ev.xbutton.x, ev.xbutton.y ); XFlush( dis ); x=ev.xbutton.x; y=ev.xbutton.y; } XNextEvent( dis, &ev ); } XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, mask[num], ShapeSet); XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, mask[num], ShapeSet); addHistory(layer_expose,mask,num);//履歴に追加 }
void KSlovar::slotShowBrowser(const KURL &url, const KParts::URLArgs &) { bool selected = false; QString id = url.host(); QListViewItem *current=m_list->firstChild(); while(current) { if(static_cast<KSListViewItem*> (current)->getId() == id) { m_list->setSelected(current, true); selected = true; break; } current=current->nextSibling(); } if(!selected) { m_list->clearSelection(); m_editPhrase->setEnabled(true); m_removePhrase->setEnabled(true); if(m_history == false) { addHistory(); } m_selectedPhrase = id; showDictionary(); } }
void KSlovar::slotNextPhrase() { int temp = m_forwardHistory.first(); addHistory(false); m_itForward = m_forwardHistory.remove(m_itForward); if(m_forwardHistory.isEmpty()) { m_forward->setEnabled(false); } m_history=true; QListViewItem *current=m_list->firstChild(); while(current) { if(static_cast<KSListViewItem*> (current)->getId().toInt()==temp) { m_list->setSelected(current, true); break; } current=current->nextSibling(); } }
/** * This method performs the search and displays * the result to the screen. */ void Kiten::searchAndDisplay( const DictQuery &query ) { /* keep the user informed of what we are doing */ _statusBar->showMessage( i18n( "Searching..." ) ); /* This gorgeous incantation is all that's necessary to fill a DictQuery with a query and an Entrylist with all of the results form all of the requested dictionaries */ EntryList *results = _dictionaryManager.doSearch( query ); /* if there are no results */ if ( results->size() == 0 ) //TODO: check here if the user actually prefers this { //create a modifiable copy of the original query DictQuery newQuery( query ); bool tryAgain = false; do { //by default we don't try again tryAgain = false; //but if the matchtype is changed we try again if ( newQuery.getMatchType() == DictQuery::Exact ) { newQuery.setMatchType( DictQuery::Beginning ); tryAgain = true; } else if ( newQuery.getMatchType() == DictQuery::Beginning ) { newQuery.setMatchType( DictQuery::Anywhere ); tryAgain = true; } //try another search if ( tryAgain ) { delete results; results = _dictionaryManager.doSearch( newQuery ); //results means all is ok; don't try again if ( results->size() > 0 ) { tryAgain = false; } } } while ( tryAgain ); } /* synchronize the history (and store this pointer there) */ addHistory( results ); /* Add the current search to our drop down list */ _inputManager->setSearchQuery( results->getQuery() ); /* suppose it's about time to show the users the results. */ displayResults( results ); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); computer_timer.setSingleShot(true); connect(&computer_timer, SIGNAL(timeout()), this, SLOT(computerPlay())); //connect(this, SIGNAL(gameOver(QString)), this, SLOT(setGameOver(QString))); //connect(ui->gameBoard, SIGNAL(boardLeftClicked(QString,QString)),this,SLOT(doPlay(QString))); connect(ui->gameBoard, SIGNAL(boardLeftClicked(QString)),this,SLOT(doPlay(QString))); connect(&players, SIGNAL(blackScore(QString)), this, SLOT(updateBlackScore(QString))); connect(&players, SIGNAL(whiteScore(QString)), this, SLOT(updateWhiteScore(QString))); connect(>p, SIGNAL(move(QString,QString)),ui->gameBoard,SLOT(placeStone(QString,QString))); connect(>p, SIGNAL(move(QString,QString)),this,SLOT(addHistory(QString,QString))); connect(>p, SIGNAL(stoneListing(QString,QStringList)), ui->gameBoard, SLOT(checkStones(QString,QStringList))); connect(>p, SIGNAL(hints(QString,QStringList)), ui->gameBoard, SLOT(showTopMoves(QString,QStringList))); connect(>p, SIGNAL(blackScore(QString)), this, SLOT(updateBlackScore(QString))); connect(>p, SIGNAL(whiteScore(QString)), this, SLOT(updateWhiteScore(QString))); connect(&engine.process, SIGNAL(started()), this, SLOT(engineStarted())); readSettings(); engine.addProgramArg("--mode gtp"); engine.addProgramArg("--level 1"); engine.start(); gtp.setEngine(engine); ui->labelBlack->setStyleSheet("#labelBlack { color:#000000; background: #785229;}"); ui->labelWhite->setStyleSheet("#labelWhite { color:#FFFFFF; background: #785229;}"); }
/**************************************************************** main主函数 ****************************************************************/ int main(int argc, char** argv) { int i; char c; init(); //初始化环境 commandDone = 0; printf("user-sh> "); //打印提示符信息 while(1){ i = 0; while((c = getchar()) != '\n'){ //读入一行命令 inputBuff[i++] = c; } inputBuff[i] = '\0'; len = i; offset = 0; yyparse(); //调用语法分析函数,该函数由yylex()提供当前输入的单词符号 if(commandDone == 1){ //命令已经执行完成后,添加历史记录信息 commandDone = 0; addHistory(inputBuff); } printf("user-sh> "); //打印提示符信息 } return (EXIT_SUCCESS); }
/**************************************************************** main主函数 ****************************************************************/ int main(int argc, char** argv) { init(); commandDone = 0; printf("cyl@computer:%s$ ", get_current_dir_name()); //打印提示符信息 while(1) { i = 0; c = getchar(); if(c != -1) ungetc(c,stdin); yyparse(); strcpy(lastBuff, inputBuff); if(commandDone == 1){ commandDone = 0; addHistory(inputBuff); } inputBuff[0] = '\0'; printf("cyl@computer:%s$ ", get_current_dir_name()); //打印提示符信息 } return EXIT_SUCCESS; }
void readInHistory(History ** head, int maxSize){ FILE * fin = fopen(".mssh_history", "r+"); if(fin == NULL) fin = fopen(".mssh_history", "w+"); while(!feof(fin)){ char temp[1000]; fgets(temp, 100, fin); if(strlen(temp) == 0){ break; } #if TESTER printf(" %d\t%s", counter, temp); #endif strip(temp); addHistory(head, temp, maxSize); temp[0] = '\0'; } fclose(fin); }
void DialPanel::inputValidated() { QString ext = m_input->currentText(); if (ext.isEmpty()) return; b_engine->actionDial(ext); addHistory(ext); m_input->clearEditText(); }
QLineEditEx::QLineEditEx(QWidget *parent) : QLineEdit(parent) { m_Index = -1; m_Limit = 100; m_TabIndex = -1; connect(this, SIGNAL(returnPressed()), this, SLOT(addHistory())); }
/** * Search in the previous results, identical to * searchAndDisplay except for the one call. */ void Kiten::searchInResults() { _statusBar->showMessage( i18n( "Searching..." ) ); DictQuery searchQuery = _inputManager->getSearchQuery(); EntryList *results = _dictionaryManager.doSearchInList( searchQuery ,_historyList.current() ); addHistory( results ); _inputManager->setSearchQuery( searchQuery ); displayResults( results ); }
void square(XEvent ev,Window *layer_expose,Window *layer,Window *mask,int num){ int xs,ys,xe,ye; XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, None, ShapeSet);//いったんマスクを解除 XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, None, ShapeSet); XCopyArea( dis, layer[num], copy_pix[0], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); xs=ev.xbutton.x; ys=ev.xbutton.y; while( !(ev.type == ButtonRelease && ev.xbutton.button == 1) ){ if(ev.type == MotionNotify){ XCopyArea( dis, copy_pix[0], copy_pix[1], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); xe=ev.xbutton.x; ye=ev.xbutton.y; if(sub_state==0){ XDrawRectangle(dis, copy_pix[1], gc, (xs<xe)?xs:xe, (ys<ye)?ys:ye, abs(xe-xs), abs(ye-ys)); }else{ XFillRectangle(dis, copy_pix[1], gc, (xs<xe)?xs:xe, (ys<ye)?ys:ye, abs(xe-xs), abs(ye-ys)); } XCopyArea( dis, copy_pix[1], layer[num], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); XFlush(dis); } XNextEvent( dis, &ev ); } if(sub_state==0){ XDrawRectangle(dis, mask[num], mask_gc, (xs<xe)?xs:xe, (ys<ye)?ys:ye, abs(xe-xs), abs(ye-ys)); XDrawRectangle(dis, layer_expose[num], gc, (xs<xe)?xs:xe, (ys<ye)?ys:ye, abs(xe-xs), abs(ye-ys)); }else{ XFillRectangle(dis, mask[num], mask_gc, (xs<xe)?xs:xe, (ys<ye)?ys:ye, abs(xe-xs), abs(ye-ys)); XFillRectangle(dis, layer_expose[num], gc, (xs<xe)?xs:xe, (ys<ye)?ys:ye, abs(xe-xs), abs(ye-ys)); } XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, mask[num], ShapeSet); XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, mask[num], ShapeSet); addHistory(layer_expose,mask,num);//履歴に追加 }
void MainWindow::on_buttonResign_clicked() { players.setCurrentResigned(); addHistory(players.currentColor(),tr("Resigned")); updateScore(players.currentColor(),tr("Resigned")); QString reason = players.getGameOver(); if(reason.length()>0) { //emit gameOver(reason); setGameOver(reason); }else{ afterMove(); } }
void DialPanel::dropEvent(QDropEvent * event) { QString originator = QString::fromLatin1(event->mimeData()->data(XUSERID_MIMETYPE)); qDebug() << Q_FUNC_INFO << event << originator << m_input->currentText(); QString ext = m_input->currentText(); if (ext.isEmpty()) return; b_engine->actionCall("originate", "user:"******"exten:%1/%2").arg(b_engine->ipbxid()).arg(ext)); addHistory(ext); m_input->clearEditText(); }
void KSlovar::slotShowList(QListViewItem *selected) { m_editPhrase->setEnabled(true); m_removePhrase->setEnabled(true); if(m_history == false) { addHistory(); } m_selectedPhrase = static_cast<KSListViewItem*> (selected)->getId(); showDictionary(); }
void RS_ActionDrawLine::coordinateEvent(RS_CoordinateEvent* e) { RS_DEBUG->print("RS_ActionDrawLine::coordinateEvent"); if (e==NULL) { RS_DEBUG->print("RS_ActionDrawLine::coordinateEvent: event was NULL"); return; } RS_Vector mouse = e->getCoordinate(); if(pPoints->data.startpoint.valid == false && getStatus()==SetEndpoint) setStatus(SetStartpoint); switch (getStatus()) { case SetStartpoint: pPoints->data.startpoint = mouse; addHistory(mouse); pPoints->start = pPoints->data.startpoint; setStatus(SetEndpoint); graphicView->moveRelativeZero(mouse); updateMouseButtonHints(); break; case SetEndpoint: if((mouse-pPoints->data.startpoint).squared() > RS_TOLERANCE2) { //refuse zero length lines pPoints->data.endpoint = mouse; addHistory(mouse); trigger(); pPoints->data.startpoint = pPoints->data.endpoint; if(pPoints->history.size()>=2) updateMouseButtonHints(); } //graphicView->moveRelativeZero(mouse); break; default: break; } RS_DEBUG->print("RS_ActionDrawLine::coordinateEvent: OK"); }
void KSlovar::slotHome() { if(m_selectedPhrase=="0") { return; } addHistory(); m_selectedPhrase.setNum(0); m_list->clearSelection(); m_editPhrase->setEnabled(false); showDictionary(); }
void MainWindow::on_buttonPass_clicked() { if(gtp.pass(players.getCurrent()->getColorString())){ players.setCurrentPass(); addHistory(players.currentColor(),tr("Passed")); updateScore(players.currentColor(),tr("Passed")); QString reason = players.getGameOver(); if(reason.length()>0){ //emit gameOver(reason); setGameOver(reason); }else{ afterMove(); } } }
void RS_ActionDrawLine::close() { if (pPoints->historyIndex>2 && pPoints->start.valid && (pPoints->data.startpoint - pPoints->start).squared() > RS_TOLERANCE2 ) { pPoints->data.endpoint = pPoints->start; addHistory(pPoints->data.endpoint); trigger(); setStatus(SetStartpoint); // graphicView->moveRelativeZero(start); } else { if (RS_DIALOGFACTORY) { RS_DIALOGFACTORY->commandMessage( tr("Cannot close sequence of lines: " "Not enough entities defined yet, or already closed.")); } } }
void ZhscWidget::changePoem( int index ) { nPoem = index; buildTEPoem(); sPoemNo = smPoem[index]; if ( bManualSign ) { bManualSign = FALSE; addHistory(); } calPoemIndex(); }
/** * Displays calculation and result to user */ void displayResult(double operand1, double operand2, char *operator, double result, bool binary) { char operation[BUFSIZ]; if (binary) { sprintf(operation, "%f %s %f = %f", operand1, operator, operand2, result); } else { sprintf(operation, "%s(%f) = %f", operator, operand1, result); } printf("\n%s\n\n", operation); addHistory(operation); }
void fill(XEvent ev,Window *layer_expose,Window *layer,Window *mask,int num){ int i,j; int x,y; unsigned long pixel; //unsigned long pixelmap[CANV_WIDTH][CANV_HEIGHT]; XImage *ximage[CANV_HEIGHT]; XImage *xmaskimage; XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, None, ShapeSet);//いったんマスクを解除 XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, None, ShapeSet); x=ev.xbutton.x; y=ev.xbutton.y; XCopyArea( dis, layer_expose[num], copy_pix[0], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); for (j = 0; j < CANV_HEIGHT; j++) { ximage[j] = XGetImage(dis,copy_pix[0],0,j,CANV_WIDTH,1,AllPlanes,ZPixmap); } xmaskimage = XGetImage(dis,mask[num],0,0,CANV_WIDTH,CANV_HEIGHT,AllPlanes,ZPixmap); pixel=XGetPixel(ximage[y],x,0); if(pixel==current_color){ XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, mask[num], ShapeSet); XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, mask[num], ShapeSet); return; } XPutPixel(ximage[y],x,0,current_color); XPutPixel(xmaskimage,x,y,1); fillCheck(x,y,pixel,ximage,xmaskimage); for (j = 0; j < CANV_HEIGHT; j++) { XPutImage(dis,copy_pix[0],gc,ximage[j],0,0,0,j,CANV_WIDTH,1); } XPutImage(dis,mask[num],mask_gc,xmaskimage,0,0,0,0,CANV_WIDTH,CANV_HEIGHT); XCopyArea( dis, copy_pix[0], layer[num], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); XCopyArea( dis, copy_pix[0], layer_expose[num], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 ); XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, mask[num], ShapeSet); XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, mask[num], ShapeSet); addHistory(layer_expose,mask,num);//履歴に追加 }
void getInput(){ printf("Prompt> "); char userInput[size]; char* token; count = 1; if (fgets(userInput, size, stdin)){ //Convert input into array token = (char*) strtok(userInput, " \t\n"); args[0] = (char*) token; while((token = (char*) strtok(NULL, " \t\n")) != NULL){ args[count] = token; count++; } args[count] = NULL; if (args[0] != NULL){ addHistory(userInput); } } }
QString PathMapper::mapServerPathToLocal(const QString &serverpath) { QString newpath; if(serverpath.isEmpty()) return serverpath; newpath = translate(serverpath, m_serverBasedir, m_localBasedir); // Check if this dir is matched by the basedirs if(QExtFileInfo::exists(newpath, true, 0L)) return newpath; // Check if any previous mappings fit... for (unsigned int cnt = 0; cnt < m_serverlist.count(); cnt++ ) { newpath = translate(serverpath, m_serverlist[cnt], m_locallist[cnt]); if(QExtFileInfo::exists(newpath, true, 0L)) return newpath; } // If the basedirs didnt match, check if the file exists, // otherwise scan through the mapping history or show the // mapping dialog if(!QExtFileInfo::exists(serverpath, true, 0L)) { PathMapperDialog pmdlg(serverpath, PathMapperDialog::ServerToLocal); for (unsigned int cnt = 0; cnt < m_serverlist.count(); cnt++ ) pmdlg.addHistory(m_serverlist[cnt], m_locallist[cnt]); if(pmdlg.exec() == QDialog::Accepted ) { addHistory(pmdlg.localPath(), pmdlg.serverPath(), true); newpath = translate(serverpath, pmdlg.localPath(), pmdlg.serverPath()); return newpath; } } return serverpath; }
/* * getStringInWindow: main routine */ static bool getStringInWindow( input_buffer *input ) { vi_key event; bool old_mode; ReadingAString = true; initInput( input ); input->last_str = alloca( input->buffer_length ); memset( input->last_str, 0, input->buffer_length ); if( input->h != NULL ) { input->curr_hist = input->h->curr; } for( ;; ) { event = GetNextEvent( false ); event = cursorKeyFilter( input, event ); event = historyFilter( input, event ); event = specialKeyFilter( input, event ); switch( event ) { case VI_KEY( NULL ): break; case VI_KEY( SHIFT_TAB ): case VI_KEY( TAB ): if( !fileComplete( input, event ) ) { endColumn( input ); break; } /* fall through */ case VI_KEY( ENTER ): if( input->buffer[0] == NO_ADD_TO_HISTORY_KEY ) { strcpy( &input->buffer[0], &input->buffer[1] ); } else { addHistory( input ); } /* fall through */ case VI_KEY( ESC ): finiInput( input ); /* * this call may not be necessary if the file complete window has * already closed of natural causes but it doesn't harm anything * if called when not needed - so we leave it here. */ FinishFileComplete(); ReadingAString = false; return( event != VI_KEY( ESC ) ); case VI_KEY( INS ): input->overstrike = !input->overstrike; if( !EditFlags.NoInputWindow ) { NewCursor( input->window.id, input->overstrike ? EditVars.NormalCursorType : EditVars.InsertCursorType ); } break; case VI_KEY( CTRL_END ): saveStr( input ); input->buffer[input->curr_pos] = '\0'; break; case VI_KEY( CTRL_X ): case VI_KEY( CTRL_U ): saveStr( input ); input->buffer[0] = '\0'; endColumn( input ); break; case VI_KEY( CTRL_INS ): swapString( input ); break; case VI_KEY( CTRL_V ): case VI_KEY( CTRL_Q ): insertChar( input, '^' ); displayLine( input ); // here we have a bit of a kluge input->curr_pos -= 1; event = GetNextEvent( false ); saveStr( input ); old_mode = input->overstrike; input->overstrike = true; insertChar( input, event ); input->overstrike = old_mode; break; case VI_KEY( ALT_END ): /* just want to redraw the line - for windows */ break; default: if( (event >= 32 && event < 256) || event == VI_KEY( CTRL_A ) ) { saveStr( input ); if( !insertChar( input, event ) ) { MyBeep(); } } } if( !EditFlags.NoInputWindow ) { displayLine( input ); } } } /* getStringInWindow */
int main(int argc, char *argv[]){ char *line; pipeline pl; int run; //flags int redo = 0; int skip = 0; int isResume = 0; char *promptstr; char* buffer; numExits = 0; jobIndex = 0; histIndex = 0; back = 0; script = 0; FILE* in; /* check for the right number of arguments */ //if ( argc > 2 ) { // printusage(argv[0]); // exit(-1); //} if (argc >= 2) { DIR* dirp; struct dirent *dp; int isFound = 0; if ((dirp = opendir(".")) == NULL) { perror("couldn't open path"); return 0; } //put files into array and sort their names while ((dp = readdir(dirp)) != NULL) { if (strcmp(dp->d_name, argv[1]) == 0) { isFound = 1; } } if (isFound == 0) { printf("%s: Command not found\n", argv[1]); } else { in = fopen(argv[1], "r"); buffer = (char*)malloc(sizeof(in)); script = 1; } } //struct termios saved_term_mode; struct sigaction action; action.sa_handler = killHandle; /* set tick to be the handler function */ sigemptyset(&action.sa_mask); /* clear out masked functions */ action.sa_flags = 0; /* no special handling */ struct sigaction action2; action2.sa_handler = susHandle; /* set tick to be the handler function */ sigemptyset(&action2.sa_mask); /* clear out masked functions */ action2.sa_flags = 0; /* no special handling */ /* * Use the sigaction function to associate the signal action with SIGALRM. */ if (sigaction(SIGINT, &action, NULL) < 0 ) { fprintf(stderr, "SIGINT\n"); exit(-1); } if(sigaction(SIGTSTP, &action2, NULL) < 0) { fprintf(stderr, "SIGTSTP\n"); exit(-1); } //saved_term_mode = set_raw_term_mode(); initHistory(); initJobs(); //strcpy(jobs[1], "hey"); /* set prompt */ promptstr = PROMPT; run = TRUE; if (script == 0) prompt(promptstr); while ( run ) { /// if reexecute was not called if (redo == 0) { if (script == 0) { if ( NULL == (line = readLongString(stdin)) ) { if ( feof(stdin) ) run = FALSE; } } else { fgets(line, sizeof(in), in); if (line[0] == '%') { line++; isResume = 1; } } } else { //printf("histInd: %d\n", histIndex); ///if reexecute was called, ///find the correct place in the history ///list to extract the reexecuted command int temp = histIndex; temp--; int ind = 0; while (ind != reNumber) { temp--; ind++; } line = history[temp]; printf("%s\n", line); } if (line == NULL) { if (feof(stdin)) run = FALSE; } else { if (line[0] == '%') { line++; isResume = 1; } /* We got a line, send it off to the pipeline cracker and * launch it */ //if (redo == 0) //{ pl = crack_pipeline(line); //} redo = 0; /* * Show that it worked. This is where you're going to do * something radically different: rather than printing the * pipeline, you're going to execute it. */ if ( pl != NULL && strlen(pl->cline) > 0) { /* if (pl->cline[0] == '%') { int i; isResume = 1; pl->stage[0].argv[0][0] = ' '; for (i = 0; i < strlen(pl->cline)-1; i++) { pl->stage[0].argv[0][i] = pl->stage[0].argv[0][i+1]; } pl->stage[0].argv[0][strlen(pl->cline)-1] = '\0'; } */ //print_pipeline(stdout,pl); /* print it. */ addHistory(pl->cline); ///add to the history what was typed into the command line if (strcmp(pl->stage[0].argv[0], "history") == 0) { ///print the history if possible if (pl->stage[0].argc > 1) { printf("Junk after built-in command\n"); skip = 1; } numExits = 0; if (skip == 0) printHistory(); skip = 0; } else if (strcmp(pl->stage[0].argv[0], "jobs") == 0) { ///print the suspended jobs if possible if (pl->stage[0].argc > 1) { printf("Junk after built-in command\n"); skip = 1; } numExits = 0; if (skip == 0) printJobs(); skip = 0; } else if (strcmp(pl->stage[0].argv[0], "exit") == 0) { ///exit vssh if possible if (pl->stage[0].argc > 1) { fprintf(stderr, "Junk after built-in command\n"); skip = 1; } numExits++; if (skip == 0) exitCmd(); skip = 0; } else if (strcmp(pl->stage[0].argv[0], "bg") == 0) { ///background the most recently suspended job if possible if (pl->stage[0].argc > 1) { fprintf(stderr, "Junk after built-in command\n"); skip = 1; } numExits = 0; if (skip == 0) bg(jobs[jobIndex-1]); skip = 0; } else if (strcmp(pl->stage[0].argv[0], "fg") == 0) { ///foreground the most recently backgrounded job if possible if (pl->stage[0].argc > 1) { fprintf(stderr, "Junk after built-in command\n"); skip = 1; } numExits = 0; if (skip == 0) fg(jobs[jobIndex-1]); skip = 0; } else if (strcmp(pl->stage[0].argv[0], "cd") == 0) { ///change the directory of vssh if possible if (pl->stage[0].argc > 2) { fprintf(stderr, "Junk after built-in command\n"); skip = 1; } numExits = 0; if (skip == 0) cd(pl->stage[0].argv[1]); skip = 0; } else if (isResume == 1) { ///foreground the specified job if possible if (pl->stage[0].argc > 1) { fprintf(stderr, "Junk after built-in command\n"); skip = 1; } numExits = 0; if (skip == 0) { //pl->stage[0].argv[0]++; int i; int killFlag = 0; for (i = 0; i < strlen(pl->stage[0].argv[0]); i++) { if (!isdigit(pl->stage[0].argv[0][i])) { ///if the supplied job number is not a number ///then print error killFlag = 1; fprintf(stderr, "%s: No such job.\n", pl->stage[0].argv[0]); } } if (killFlag == 0) { if (atoi(pl->stage[0].argv[0]) <= 0 || atoi(pl->stage[0].argv[0]) > jobIndex) ///if the supplied job number is not a valid job index ///then print error fprintf(stderr, "%s: No such job.\n", pl->stage[0].argv[0]); else resume(jobs[atoi(pl->stage[0].argv[0])-1]->id, atoi(pl->stage[0].argv[0])-1); } } skip = 0; } else if (strcmp(pl->stage[0].argv[0], "!") == 0) { ///reexecute the specified history command if possible if (pl->stage[0].argc > 2 || strlen(pl->stage[0].argv[1]) > 3) { fprintf(stderr, "Junk after built-in command\n"); skip = 1; } ///if the number supplied is not a valid history index ///then print error if (pl->stage[0].argv[1][0] == '0' && skip == 0) { fprintf(stderr, "%s: Event not found\n", pl->stage[0].argv[1]); skip = 1; } if (strlen(history[atoi(pl->stage[0].argv[1])]) <= 0 && skip == 0) { fprintf(stderr, "%s: Event not found\n", pl->stage[0].argv[1]); skip = 1; } int i; for (i = 0; i < strlen(pl->stage[0].argv[1]); i++) { if (!isdigit(pl->stage[0].argv[1][i]) && skip == 0) { ///if the number supplied is not a number ///then print error fprintf(stderr, "%s: Event not found\n", pl->stage[0].argv[1]); skip = 1; } } numExits = 0; if (skip == 0) { redo = 1; reNumber = atoi(pl->stage[0].argv[1]); //printf("renum: %d\n", reNumber); //pl = crack_pipeline(history[atoi(pl->stage[0].argv[1])]); //printf("%s\n", pl->cline); //lineno++; //continue; } skip = 0; } else if (strcmp(pl->stage[0].argv[0], "kill") == 0) { ///kill the specified job if possible if (pl->stage[0].argc > 2) { fprintf(stderr, "Junk after built-in command\n"); skip = 1; } numExits = 0; if (skip == 0) { int i; int killFlag = 0; for (i = 0; i < strlen(pl->stage[0].argv[1]); i++) { ///if the supplied job number is not a number ///then print error if (!isdigit(pl->stage[0].argv[1][i])) { killFlag = 1; fprintf(stderr, "%s: No such job.\n", pl->stage[0].argv[1]); } } if (killFlag == 0) { if (atoi(pl->stage[0].argv[1]) <= 0 || atoi(pl->stage[0].argv[1]) > jobIndex) ///if the supplied job number is not a valid job index ///then print error fprintf(stderr, "%s: No such job.\n", pl->stage[0].argv[1]); else killProcess(atoi(pl->stage[0].argv[1])-1, jobs[atoi(pl->stage[0].argv[1])-1]->id); } } skip = 0; } else { ///pipe/redirect as necessary numExits = 0; //int i; //for (i = 0; i < pl->length; i++) //{ //else //{ //handle backgrounding "&" //find the & int j; int andFound = 0; int pipeFound = 0; for (j = 1; j < strlen(pl->cline); j++) { if (pl->cline[j] == '|') { //fprintf(stderr, "Pipelines cannot be backgrounded\n"); pipeFound = 1; } else if (pl->cline[j] == '&') { //error if & is not the last arg, exec nothing if (pipeFound == 1) { fprintf(stderr, "Pipelines cannot be backgrounded\n"); } else if (j != strlen(pl->cline) - 1) { andFound = 1; fprintf(stderr, "Junk after '&'.\n"); } else if (pl->cline[j-1] == ' ') { andFound = 1; pl->cline[j] = '\0'; //backExec(pl->stage[0].argv[0], pl->stage[0].argv, pl->cline); back = 1; } } } if (pl->length >= 2) { ///pipe if the pipline has 2 or more stages pipeCmd(pl); } else if (pl->stage[0].outname != NULL && pl->stage[0].inname != NULL) { redirectBoth(pl->stage[0].argv, pl->stage[0].inname, pl->stage[0].outname); } else if (pl->stage[0].outname != NULL) { ///otherwise redirect output if there is an outfile redirectOutput(pl->stage[0].argv, pl->stage[0].outname, pl->cline); } else if (pl->stage[0].inname != NULL) { ///otherwise redirect input if there is an infile redirectInput(pl->stage[0].argv, pl->stage[0].inname, pl->cline); } else if (andFound == 0) { //execute if not a built-in command execute(pl->stage[0].argv[0], pl->stage[0].argv, pl->cline); } back = 0; //} //} } } free_pipeline(pl); fflush(stdout); /* also frees line */ lineno++; /* readLongString trims newlines, so increment it manually */ } if (run ) { if (script == 0) /* assuming we still want to run */ prompt(promptstr); } } return 0; }
static int play(void *userData) { srand(time(NULL)); int scroll = 0; int quit = 0; int down; int redraw = 0; int mapNum = 0; touchPosition touch; gui = new Gui(); console = new Console(); try { anagram = new Anagram(); } catch (const char* err) { delete console; delete gui; return EXIT_FAILURE; } //copy bg tiles decompress(map[mapNum], bgGetMapPtr(1)); reset(); scroll = printList(scroll); console->flush(); keysSetRepeat(30, 6); while(!quit) { swiWaitForVBlank(); bgScrollf(1, -48, 48); bgUpdate(); scanKeys(); if(redraw) { scroll = printList(scroll); console->flush(); } redraw = 0; down = keysDown() | (keysDownRepeat() & (KEY_UP|KEY_DOWN)); if(down & KEY_UP) redraw = 1, scroll--; else if(down & KEY_DOWN) redraw = 1, scroll++; else if(down & KEY_B) redraw = 1, quit = 1; else if(down & KEY_START) redraw = 1, scroll = reset(); else if(down & KEY_X) { redraw = 1; strfry(choices); if(strlen(choices) == strlen(solution)) strcpy(solution, choices); } else if(down & KEY_Y) { mapNum = (mapNum+1)%NUM_MAPS; decompress(map[mapNum], bgGetMapPtr(1)); } if(down & KEY_TOUCH) touchRead(&touch); else memset(&touch, 0, sizeof(touch)); if(gui->update(choices, guess, touch) == GuiRC_Submit) { if(strlen(guess) > 2) { anagram->attempt(guess); addHistory(guess); } memset(guess, 0, sizeof(guess)); memset(choices, 0, sizeof(choices)); strcpy(choices, solution); redraw = 1; } } delete gui; delete console; delete anagram; return EXIT_SUCCESS; }