bool ofxGuiInputField<Type>::keyPressed(ofKeyEventArgs & args){ if(hasFocus && !bMousePressed){ int newCursorIdx = -1; if(args.key >= '0' && args.key <= '9'){ int digit = args.key - '0'; newCursorIdx = insertKeystroke(ofToString(digit)); }else if(args.key == '.' ){ newCursorIdx = insertKeystroke("."); }else if(args.key == OF_KEY_BACKSPACE || args.key == OF_KEY_DEL){ if(hasSelectedText()){ input.erase(selectStartPos,selectEndPos-selectStartPos); newCursorIdx = selectStartPos; parseInput(); }else{ int deleteIdx = -1; if(args.key == OF_KEY_BACKSPACE){ deleteIdx = selectStartPos-1; }else if(args.key == OF_KEY_DEL){ deleteIdx = selectStartPos; } //erase char if valid deleteIdx if(deleteIdx >= 0 && deleteIdx < (int)input.size()){ input.erase(deleteIdx,1); newCursorIdx = deleteIdx; parseInput(); } } }else if(args.key == OF_KEY_LEFT){ if(hasSelectedText()){ newCursorIdx = selectStartPos; }else{ newCursorIdx = selectStartPos == 0 ? 0 : selectStartPos-1; } }else if(args.key == OF_KEY_RIGHT){ if(hasSelectedText()){ newCursorIdx = selectEndPos; }else{ newCursorIdx = selectStartPos == (int)input.size() ? (int)input.size() : selectStartPos+1; } }else if(args.key == OF_KEY_RETURN){ leaveFocus(); }else if((args.key >= '!' && args.key <= '~') || (args.key <= 'a' && args.key >= 'Z') || (args.key == ' ')){ newCursorIdx = insertAlphabetic(ofToString((char)args.key)); } if(newCursorIdx != -1){ //set cursor calculateSelectionArea(newCursorIdx,newCursorIdx); } return true; } return false; }
void interaction::takeAction() { int status; switch((status=parseInput())) { case QUIT: quit(); break; case HELP: help(); break; case ME: traceMe(); break; case FNAME: traceFname(); break; case IPHOST: traceIpHost(ipHostFname); break; case INVLD: invalid(); break; default: break; } }
Engine::Engine(std::string inputFileName, unsigned int baseTicks) throw (std::string) { this->baseTicks = baseTicks; // set parse error message std::stringstream parseErrorStream; parseErrorStream << "Was not able to parse File." << std::endl << "Please check if syntax is valid" << std::endl << "Abborting ...." << std::endl; parseError = parseErrorStream.str(); // Try to open File inputFile = new std::ifstream(inputFileName.c_str(), std::ifstream::in); // Check if File was opened succesfull if (!*inputFile) { std::stringstream error; error << "Was not able to open File." << std::endl << "Please check if File exists" << std::endl << "Abborting ...." << std::endl; throw error.str(); } // Parse Input try { parseInput(); } catch (std::string error) { throw error; } }
int main(void) { char connect_param[200]; sprintf(connect_param, "host=csl2.cs.technion.ac.il dbname=%s user=%s password=%s", USERNAME, USERNAME, PASSWORD); conn = PQconnectdb(connect_param); /* check to see that the backend connection was successfully made */ if (!conn || PQstatus(conn) == CONNECTION_BAD) { fprintf(stderr, "Connection to server failed: %s\n", PQerrorMessage(conn)); PQfinish(conn); return 1; } parseInput(); /* Close the connection to the database and cleanup */ PQfinish(conn); return 0; }
int main() { while(loop == 0) { // Gets the current working directory for the application and prints it out char currDir[256]; getcwd(currDir, 255); fprintf(stdout, "%s\n", currDir); fgets(input, buffer, stdin); // Get a list of all the commands to be run cmdTok = strtok(input, &delim); numCmd = 1; while(cmdTok) { cmdArray = realloc (cmdArray, sizeof (char*) * numCmd); if(cmdTok[strlen(cmdTok)-1] == '\n') cmdTok[strlen(cmdTok)-1] = '\0'; cmdArray[numCmd-1] = cmdTok; numCmd++; cmdTok = strtok(NULL, &delim); } // Run all the commands (This didn't work for me in the one loop for some reason) for(i = 0; i < numCmd-1; i++) { parseInput(cmdArray[i]); } } return 0; }
void startDemon() { DWIFIClose(); sleep(500); DWIFITCPOpenServer(80); RS485clearRead(); parseInput(); }
/*** Parse a statement ***/ Node* Parser::parseStatement() { if(hasTokens(2) && peekToken().getType() == T_IDENTIFIER && peekToken(2).getType() == T_ASSIGN) return parseAssign(); if(hasTokens(2) && peekToken().getType() == T_IDENTIFIER && peekToken(2).getType() == T_LPAREN) return parseCall(); if(hasTokens() && peekToken().getType() == T_CALL) return parseCall(); if(hasTokens() && peekToken().getType() == T_CASE) return parseCase(); if(hasTokens() && peekToken().getType() == T_DO) return parseDo(); if(hasTokens() && peekToken().getType() == T_END) return parseEnd(); if(hasTokens() && peekToken().getType() == T_EXIT) return parseExit(); if(hasTokens() && peekToken().getType() == T_FOR) return parseFor(); if(hasTokens() && peekToken().getType() == T_IF) return parseIf(); if(hasTokens() && peekToken().getType() == T_INPUT) return parseInput(); if(hasTokens() && peekToken().getType() == T_OUTPUT) return parseOutput(); if(hasTokens() && peekToken().getType() == T_REPEAT) return parseRepeat(); if(hasTokens() && peekToken().getType() == T_RETURN) return parseReturn(); if(hasTokens(2) && peekToken(1).getType() == T_IDENTIFIER && peekToken(2).getType() == T_LBRACKET) return parseSliceSelectAssign(); if(hasTokens() && peekToken().getType() == T_WHILE) return parseWhile(); throw ParserSyntaxException(getToken(), "Invalid statement!"); return 0; }
//Read the blocks file int readBlocksFile() { FILE* fp; char line[256]; int blockIndex = 0; //if fp is null, display error fp = fopen("Blocks.txt", "r"); if(fp == NULL){ perror("[ERROR]"); return 0; } else { //loop through each line (ignoring text at beginning) and store relevant information while(fgets(line, 300, fp) != NULL) { if(line[0] == '#' || line[0] == ' ' || line[0] == '\n'){ continue; } else { parseInput(line, blockIndex); blockIndex++; } } fclose(fp); return blockIndex; } }
/* Note: When a single t is given, we assume R = r */ int main(void) { int T, input[MAX_NUM_INPUT], numInput; char line[MAX_LEN_LINE + 1]; double R, r; scanf("%d", &T); gets(line); while(T) { gets(line); numInput = parseInput(line, input); if(numInput == 1) { R = input[0] / 4.0; r = R; } else { R = (double) input[0]; r = (double) input[1]; } printf("%.4lf\n", computeCircleArea(R + r) - computeCircleArea(R) - computeCircleArea(r)); T--; } return 0; }
void acceptInput() { char line[256]; char input[256]; char request[256]; char response[256]; // infinite loop while(1) { // display prompt fputs(">> ", stderr); // accept input fgets(line, sizeof line, stdin); sscanf(line, "%s", input); // if input is "exit" if(strcmp(input, "exit") == 0) exit(0); // quit program else { fprintf(stdout, "String Entered %s, Characters read : %d\n", input, strlen(line) - 1); parseInput(input, request); submitRequest(request); acceptResponse(response); parseResponse(response); } } }
void shellLoop() { char *input, *originalInput; TokenContainer tc; bool running = true; while(running) { printf(YELLOW "λ mini437sh-JG-DS: " NORMAL_COLOR); input = getInput(); originalInput = malloc(strlen(input) + 1); strcpy(originalInput, input); tc = parseInput(input); if (!emptyInput(&tc)) { if (exitRequested(&tc)) running = false; else { running = launchCommands(&tc, originalInput); } } free(input); free(originalInput); } killChildren(); free(tc.tokens); }
void ManagerFilter::buildInitialWork() { // Get Params and Read Graph int numVertices; string graphFile = getArgument("n"); parseInput(graphFile, edges, numVertices); this->gamma = atof(getArgument("g").c_str()); this->minQCSize = atoi(getArgument("q").c_str()); // Initially, all vertices ar in candExt Candidate start; for (int i = 1; i <= numVertices; i++) { start.candExt.insert(i); } // Remove vertices that obviously are not candidates int min = (int) ceil(gamma*(minQCSize-1)); IntSet::iterator it = start.candExt.begin(); while (it != start.candExt.end()) { IntSet::iterator aux = it; it++; if (edges[*aux].size() < min) { start.candExt.erase(aux); } } // Add it as new work workQueue.push(start); }
void searchInput(const char *flastok, const char *fhit) { MFILE *mfbuf=mfopen(); const char *input, *ta, *hit, *select, *end, *test; hit=flastok; do{ input=strstr(hit, "<input"); ta=strstr(hit, "<textarea"); select=strstr(hit, "<select"); hit=(char*)0x8FFFFFFF; if(input!=NULL && input<hit) hit=input; if(ta!=NULL && ta<hit) hit=ta; if(select!=NULL && select < hit) hit=select; if(hit!=(char*)0x8FFFFFFF && hit<fhit){ end=strchr(hit, '>'); test=strchr(hit+1, '<'); if(test!=NULL && test<end) end=strchr(end+1, '>'); mfSetLength(mfbuf, 0); mfwrite((void*)hit+1, 1, end-hit-1, mfbuf); printf("Input: %s\n", mfGetData(mfbuf)); parseInput(mfGetData(mfbuf)); hit++; } }while(hit!=(char*)0x8FFFFFFF && hit<fhit); mfclose(mfbuf); }
SodController::SodController(QWidget* parent) : QWidget(parent) { input = new CLineEdit(this); output = new QPlainTextEdit(this); commandPos = 0; historySize = 300; connect(input, SIGNAL(returnPressed()), this, SLOT(parseInput()) ); connect(input, SIGNAL(arrowPressed(bool)), this, SLOT(repeatCommand(bool)) ); QVBoxLayout* mainBox = new QVBoxLayout(this); mainBox->addWidget(output); mainBox->addWidget(input); // and the set of general functions general_functions["read_distances"] = &SodController::read_distances; general_functions["read_positions"] = &SodController::read_positions; general_functions["read_annotation"] = &SodController::read_annotation; general_functions["shrink_dims"] = &SodController::shrink_dims; general_functions["set_plot_par"] = &SodController::set_plot_par; general_functions["titrate"] = &SodController::titrate; general_functions["gaussian_bg"] = &SodController::make_gaussian_background; general_functions["export_points"] = &SodController::export_points; general_functions["export_positions"] = &SodController::export_positions; general_functions["postscript"] = &SodController::postscript; general_functions["draw_grid"] = &SodController::drawGrid; }
progC::progC(std::ifstream& infile){ //infile.open("file1"); parseInput(infile); }
int main(int argc, char *argv[]) { char inputSequenceFile[100], log_desc[1000] ; int ret ; if(argc != 2) { printf("Usage: %s <input-transaction-file-path>\n", argv[0]) ; return 0 ; } strcpy(inputSequenceFile, argv[1]) ; ret = checkFileExists(inputSequenceFile) ; if(ret == -1) { printf("main: File %s does not exist or is an empty file. Exiting\n", inputSequenceFile) ; return 0 ; } FILE *fp = fopen("repcrec.log", "w") ; if(fp == NULL) { printf("main: failed to open log file in write mode. Error: %s\n", (char *)strerror(errno)) ; } else { fclose(fp) ; } initializeTransactionManager() ; initializeSiteData() ; ret = parseInput(inputSequenceFile) ; if(ret == -1) { printf("main: parseInput could not parse file %s. Exiting\n", inputSequenceFile) ; return 0 ; } startTransactionManager() ; sprintf(log_desc, "main: Transaction Manager exiting\n") ; logString(log_desc) ; return 0 ; }
XDebugCommand* XDebugServer::parseCommand() { assert(m_bufferAvail > 0); // Log the passed in command log("<- %s\n", m_bufferCur); logFlush(); // Attempt to parse the input. parseInput will initialize cmd_str and args. String cmd_str; Array args; folly::StringPiece input(m_bufferCur); // Bump the current buffer pointer forward *before* calling parseInput, so we // don't get stuck in an infinite loop if parseInput throws. auto consumed = strlen(m_bufferCur) + 1; assert(consumed <= m_bufferAvail); m_bufferCur += consumed; m_bufferAvail -= consumed; parseInput(input, cmd_str, args); // Create the command from the command string & args return XDebugCommand::fromString(*this, cmd_str, args); }
PtrWalker<uchar>* toByteCode(const char* text, size_t length) { init(text, length); parseInput(); return output; }
int main(void) { char string[64]; unsigned char count = 0; // run the initialization routines initializer(); //Begin forever chatting with the PC for(;;) { // Check to see if a character is waiting if( isCharAvailable() == 1 ) { // If a new character is received, get it string[count++] = receiveChar(); // receive a packet up to 64 bytes long if(string[count-1] == '\n')// Hyperterminal string ends with \r\n { string[count-2] = '\0'; //convert to a string parseInput(string); string[0] = '\0'; count = 0; } else if(count > 64) { count = 0; string[0] = '\0'; sendString("Error - received > 64 characters"); } } } return 0; }
TEST_F(VolatilizeTests, KeepAlreadyVolatileLoadsAndStoresVolatile) { std::string orig = R"( @r = global i32 0 define void @func() { %a = load i32, i32* @r store i32 %a, i32* @r %b = load volatile i32, i32* @r store volatile i32 %b, i32* @r ret void })"; parseInput(orig); // Volatilize. // pass.runOnModule(*module); std::string exp = R"( @r = global i32 0 define void @func() { %a = load volatile i32, i32* @r store volatile i32 %a, i32* @r %b = load volatile i32, i32* @r store volatile i32 %b, i32* @r ret void })"; checkModuleAgainstExpectedIr(exp); // Unvolatilize. // pass.runOnModule(*module); checkModuleAgainstExpectedIr(orig); }
void Console::newInput() { QString input_text = console_window->text(); d->getNoticeWindow()->write(tr("> ") + input_text); clearLine(); parseInput(input_text); }
int ofxGuiInputField<Type>::insertKeystroke(const std::string & character){ if(hasSelectedText()){ input.erase(selectStartPos,selectEndPos-selectStartPos); } input.insert(selectStartPos,character); parseInput(); return selectStartPos + 1; }
void Player::control() { updateInput(); parseInput(); //Clamp velocity float magnitude = sqrt(getVelocity().x * getVelocity().x + getVelocity().y * getVelocity().y); sf::Vector2f unit = getVelocity()/magnitude; setVelocity(unit * terminalVelocity); }
int main() { if(!parseInput("input.txt")) { log("ERR Unable to read file"); return 1; } return 0; }
void PlayerPawnMap::update(double delta) { MapEntity::update(delta); parseInput(); //freeMovement(); fixedGridMovement(); applySpeed(delta); }
/*! Default main. The idea of separating this from the rest of doxygen, * is to make it possible to write your own main, with a different * generateOutput() function for instance. */ int main(int argc,char **argv) { initDoxygen(); readConfiguration(argc,argv); checkConfiguration(); adjustConfiguration(); parseInput(); generateOutput(); return 0; }
Record* getRecordFromInput(){ std::vector < std::vector<std::string> > fieldsList = parseInput(); ID* id = new ID(DIMENSIONS); std::vector<bool> visited(DIMENSIONS, false); createID(fieldsList, id, visited); fillMissingData(visited, id); return new Record(id); }
int main(void) { FILE *in = fopen("input.txt", "r"); int result; interpreterInit(); parserInit(in); parseInput(); linkProgram(); result = runProgram(); printf("Calculation result: %d", result); return 0; }
int main(){ int v[3002]; while( parseInput(v) ){ if( solve(v) == TRUE ){ printf("%s\n", "Jolly"); } else{ printf("%s\n", "Not jolly"); } } return 0; }
void Toggl::doCycle( String input ) { this->currentState = parseInput( input ); if ( this->currentState == Toggl::TIME_RUNNING ) { this->oCommunicator->setRunningState(); } else if ( this->currentState == Toggl::TIME_STOPPED ) { this->oCommunicator->setStoppedState(); } else { this->oCommunicator->setErrorState(); } }