void modCalcVlsr::slotRunBatch() { QString inputFileName; inputFileName = InputFileBoxBatch->url().toLocalFile(); // We open the input file and read its content if ( QFile::exists(inputFileName) ) { QFile f( inputFileName ); if ( !f.open( QIODevice::ReadOnly) ) { QString message = i18n( "Could not open file %1.", f.fileName() ); KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) ); inputFileName.clear(); return; } // processLines(&f); QTextStream istream(&f); processLines(istream); // readFile( istream ); f.close(); } else { QString message = i18n( "Invalid file: %1", inputFileName ); KMessageBox::sorry( 0, message, i18n( "Invalid file" ) ); inputFileName.clear(); InputFileBoxBatch->setUrl( inputFileName ); return; } }
void modCalcAngDist::slotRunBatch() { QString inputFileName; inputFileName = InputLineEditBatch->text(); // We open the input file and read its content if ( QFile::exists(inputFileName) ) { QFile f( inputFileName ); if ( !f.open( IO_ReadOnly) ) { QString message = i18n( "Could not open file %1.").arg( f.name() ); KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) ); inputFileName = ""; return; } // processLines(&f); QTextStream istream(&f); processLines(istream); // readFile( istream ); f.close(); } else { QString message = i18n( "Invalid file: %1" ).arg( inputFileName ); KMessageBox::sorry( 0, message, i18n( "Invalid file" ) ); inputFileName = ""; InputLineEditBatch->setText( inputFileName ); return; } }
void modCalcEquinox::slotRunBatch() { QString inputFileName = InputFileBatch->url().toLocalFile(); if ( QFile::exists(inputFileName) ) { QFile f( inputFileName ); if ( !f.open( QIODevice::ReadOnly) ) { QString message = i18n( "Could not open file %1.", f.fileName() ); KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) ); inputFileName.clear(); return; } QTextStream istream(&f); processLines( istream ); ViewButtonBatch->setEnabled( true ); f.close(); } else { QString message = i18n( "Invalid file: %1", inputFileName ); KMessageBox::sorry( 0, message, i18n( "Invalid file" ) ); inputFileName.clear(); return; } }
void startMain(FILE * logf, struct SCRIPT * script, struct TYPING * types){ int pos = 0; //Following the execution path while(pos<script->nblines){ //Analyze code pos = processLines(logf,script,types,MAINLEVEL,pos); }//while }
int processLoop(FILE * logf, struct SCRIPT * script, struct TYPING * types, unsigned long location, int lineindex, int statement){ struct LINE * nextline; char * tokens = (char *) calloc(TOKENMAXNB*TOKENSIZE,sizeof(char)); char endtoken[5]; int nbtokens, maxpos, pos; endtoken[0] = 0; //for to or for each...next statement switch(statement){ case 1: printf(" for to/each case\n"); strcat_s(endtoken,5,"next"); break; case 2: printf(" do while/until case\n"); strcat_s(endtoken,5,"loop"); break; case 3: printf(" while case\n"); strcat_s(endtoken,5,"wend"); }//switch printLogEntry(logf, types, L_LOOP, 0, 0); //Process the line for calls into the statement processLine(logf,script,types,location, accessLine(script,location,lineindex)); //Blocks on new lines, parse following ones pos = lineindex+1; maxpos = recoverMaximalPosition(script,location); while(pos<maxpos){ nextline = accessLine(script,location,pos); if(nextline->type==COMMENT){pos++; continue;} //skip comment if(nextline->type==MANAGER){pos++; continue;} //skip manager declaration if(nextline->type==DECLARATION){pos++; continue;} //(declaration may require variable typing).... if(nextline->type==MARKUP){pos++; continue;} nbtokens = decomposeLine(nextline->line,(char*)tokens,TOKENMAXNB,TOKENSIZE); //Loop structure if(!strncasecmp(ACCESS(tokens,0),endtoken,4)){ printf("[+] End of loop statement\n"); printLogEntry(logf, types, R_LOOP, 0, 0); return pos+1; }else{ pos = processLines(logf,script,types,location,pos); } }//while free(tokens); return pos; }
/** Begin Code emulation ********************************************************************/ void startFunction(FILE * logf, struct SCRIPT * script, struct TYPING * types, int funcindex, struct LINE * line){ char * tokens = (char *) calloc(TOKENMAXNB*TOKENSIZE,sizeof(char)); int parameters[10]; char arguments[10][TOKENSIZE]; int i, j, retobj, nbtokens, nbarg, nextparam, pos = 0; //Jump to function printf("[+] Jump inside function %s\n", script->functionslist[funcindex].name); //Merge parameters with local aliases from the signature nbarg = script->functionslist[funcindex].nbarg; nbtokens = decomposeLine(line->line,(char*)tokens,TOKENMAXNB,TOKENSIZE); for(i=0;i<nbtokens;i++){ if(!strcasecmp(ACCESS(tokens,i),script->functionslist[funcindex].name)) break; } nextparam = i+1; for(j=1;j<=nbarg;j++){ processExpression(logf,script,types,FUNCLEVEL|funcindex, line,nextparam,0,arguments[j-1],&nextparam); parameters[j-1] = updateTypesBeforeLocCall(types, arguments[j-1], script->functionslist[funcindex].arguments[j-1]); } //Following the execution path while(pos<script->functionslist[funcindex].nblines){ //Analyze code pos = processLines(logf,script,types,FUNCLEVEL|funcindex,pos); }//while //Return from function printf("[+] Return from function %s\n",script->functionslist[funcindex].name); //Unmerge parameters with local aliases from the signature for(j=1;j<=nbarg;j++){ removeObjectReference(types, parameters[j-1], script->functionslist[funcindex].arguments[j-1]); } retobj = isKnownObject(types,script->functionslist[funcindex].name); if(retobj>-1){ removeObjectReference(types,retobj,script->functionslist[funcindex].name); //If the return value is affected if(i>1 && ((char*)ACCESS(tokens,i-1))[0]== '='){ addObjectReference(types,retobj,ACCESS(tokens,i-2)); }//if affectation } free(tokens); }
static void processConfigurationFile ( OptionProcessingInformation *info, const char *path, int optional ) { FILE *file = openDataFile(path, "r", optional); if (file) { ConfigurationFileProcessingData conf; conf.info = info; ; if ((conf.settings = malloc(info->optionCount * sizeof(*conf.settings)))) { int processed; unsigned int index; for (index=0; index<info->optionCount; index+=1) conf.settings[index] = NULL; processed = processLines(file, processConfigurationLine, &conf); for (index=0; index<info->optionCount; index+=1) { char *setting = conf.settings[index]; if (setting) { ensureSetting(info, &info->optionTable[index], setting); free(setting); } } if (!processed) { logMessage(LOG_ERR, gettext("file '%s' processing error."), path); info->warning = 1; } free(conf.settings); } else { logMallocError(); } fclose(file); } else if (!optional || (errno != ENOENT)) { info->warning = 1; } }
void TextviewView::setScript(const char *resourceName, TextviewCallback callback) { _callback = callback; if (_script) _vm->res()->toss(_resourceName); if (_spareScreen) { delete _spareScreen; _spareScreen = NULL; } reset(); strncpy(_resourceName, resourceName, 15); _resourceName[15] = '\0'; if (!strchr(_resourceName, '.')) strcat(_resourceName, ".txr"); _script = _vm->res()->get(_resourceName); processLines(); }
bool GameResultProcessor::process(GameContext &context) const { auto &gInfo = context.gameInfo; processHall(context, gInfo); processGameDetail(context, gInfo); processLines(context, gInfo); // is free to play if (!gInfo.bFreeGame) { context.events.push_back(EventInfo(ECT_BET_SUM, gInfo.bet)); } else { // reduce freeGameTimes --gInfo.freeGameTimes; } // update user fortune processMoney(context, gInfo); // update user exp&level processExp(context, gInfo); // save this result to history context.preGameInfo = gInfo; return true; }
void startProcedure(FILE * logf, struct SCRIPT * script, struct TYPING * types, int procindex, struct LINE * line){ char * tokens = (char *) calloc(TOKENMAXNB*TOKENSIZE,sizeof(char)); int parameters[ARG_MAX_NB]; int arguments[ARG_MAX_NB][TOKENSIZE]; int i, j, nbtokens, nbarg, nextparam, pos = 0; //Jump to procedure printf("[+] Jump inside procedure %s\n", script->procedureslist[procindex].name); //Merge parameters with local aliases from the signature nbarg = script->procedureslist[procindex].nbarg; nbtokens = decomposeLine(line->line,(char*)tokens,TOKENMAXNB,TOKENSIZE); for(i=0;i<nbtokens;i++){ if(!strcasecmp(ACCESS(tokens,i),script->procedureslist[procindex].name)) break; } nextparam = i+1; for(j=1;j<=nbarg;j++){ processExpression(logf,script,types,PROCLEVEL|procindex, line,nextparam,0,arguments[j-1],&nextparam); parameters[j-1] = updateTypesBeforeLocCall(types, arguments[j-1], script->procedureslist[procindex].arguments[j-1]); } //Following the execution path while(pos<script->procedureslist[procindex].nblines){ //Analyze code pos = processLines(logf,script,types,PROCLEVEL|procindex,pos); }//while //Return from procedure printf("[+] Return from procedure %s\n",script->procedureslist[procindex].name); //Unmerge parameters with local aliases from the signature for(j=1;j<=nbarg;j++){ removeObjectReference(types, parameters[j-1], script->procedureslist[procindex].arguments[j-1]); } free(tokens); }
int main_old(int argc, char *argv[]) { int MARKOV = 0; int LINES = 0; int RANDOM = 0; char method[MAXLEN]; fprintf(stderr, "which method > "); scanf("%s", method); if (strncmp(method,"mar",3) == 0) MARKOV = 1; if (strncmp(method,"lin",3) == 0) LINES = 1; if (strncmp(method,"ran",3) == 0) RANDOM = 1; if (MARKOV) processMarkov(); /* symmetric/markov matrix */ if (LINES) processLines(); /* information from lines */ if (RANDOM) processRandom(); /* 4 neigbors */ }
void TextviewView::updateState() { if (!_animating) return; // Only update state if wait period has expired uint32 currTime = g_system->getMillis(); // If a screen transition is in progress and it's time for another column, handle it if (_spareScreen) { byte *srcP = _spareScreen->getBasePtr(_translationX, 0); byte *destP = _bgSurface.getBasePtr(_translationX, 0); for (int y = 0; y < _bgSurface.height(); ++y, srcP += _spareScreen->width(), destP += _bgSurface.width()) { *destP = *srcP; } if (++_translationX >= _bgSurface.width()) { // Surface transition is complete delete _spareScreen; _spareScreen = NULL; _vm->_palette->deleteRange(_bgCurrent); delete _bgCurrent; _bgCurrent = _bgSpare; _bgSpare = NULL; } } // Make sure it's time for an update if (currTime < _scrollTimeout) return; _scrollTimeout = g_system->getMillis() + TEXT_ANIMATION_DELAY; // If any panning values are set, pan the background surface if ((_panX != 0) || (_panY != 0)) { if (_panCountdown > 0) { --_panCountdown; return; } // Handle horizontal panning if (_panX != 0) { byte *lineTemp = new byte[_panX]; for (int y = 0; y < _bgSurface.height(); ++y) { byte *pixelsP = _bgSurface.getBasePtr(0, y); // Copy the first X pixels into temp buffer, move the rest of the line // to the start of the line, and then move temp buffer pixels to end of line Common::copy(pixelsP, pixelsP + _panX, lineTemp); Common::copy(pixelsP + _panX, pixelsP + _bgSurface.width(), pixelsP); Common::copy(lineTemp, lineTemp + _panX, pixelsP + _bgSurface.width() - _panX); } delete[] lineTemp; } // Handle vertical panning if (_panY != 0) { // Store the bottom Y lines into a temp buffer, move the rest of the lines down, // and then copy the stored lines back to the top of the screen byte *linesTemp = new byte[_panY * _bgSurface.width()]; byte *pixelsP = _bgSurface.getBasePtr(0, _bgSurface.height() - _panY); Common::copy(pixelsP, pixelsP + _bgSurface.width() * _panY, linesTemp); for (int y = _bgSurface.height() - 1; y >= _panY; --y) { byte *destP = _bgSurface.getBasePtr(0, y); byte *srcP = _bgSurface.getBasePtr(0, y - _panY); Common::copy(srcP, srcP + _bgSurface.width(), destP); } Common::copy(linesTemp, linesTemp + _panY * _bgSurface.width(), _bgSurface.getBasePtr(0, 0)); delete[] linesTemp; } } // Scroll the text surface up by one row byte *pixelsP = _textSurface.getBasePtr(0, 0); Common::copy(pixelsP + width(), pixelsP + _textSurface.width() * _textSurface.height(), pixelsP); pixelsP = _textSurface.getBasePtr(0, _textSurface.height() - 1); Common::set_to(pixelsP, pixelsP + _textSurface.width(), _vm->_palette->BLACK); if (_scrollCount > 0) { // Handling final scrolling of text off of screen if (--_scrollCount == 0) { scriptDone(); return; } } else { // Handling a text row if (++_lineY == (_vm->_font->current()->getHeight() + TEXTVIEW_LINE_SPACING)) processLines(); } // Refresh the view int yp = (height() - _bgSurface.height()) / 2; _bgSurface.copyTo(this, 0, yp); _textSurface.copyTo(this, Common::Rect(0, 0, _textSurface.width(), _bgSurface.height()), 0, yp, _vm->_palette->BLACK); }
int main (int argc, char *argv[]) { ProgramExitStatus exitStatus; const char *driver = NULL; void *object; float speechRate; float speechVolume; { static const OptionsDescriptor descriptor = { OPTION_TABLE(programOptions), .applicationName = "spktest", .argumentsSummary = "[driver [parameter=value ...]]" }; PROCESS_OPTIONS(descriptor, argc, argv); } { char **const paths[] = { &opt_driversDirectory, &opt_dataDirectory, NULL }; fixInstallPaths(paths); } speechRate = 1.0; if (opt_speechRate && *opt_speechRate) { static const float minimum = 0.1; static const float maximum = 10.0; if (!validateFloat(&speechRate, opt_speechRate, &minimum, &maximum)) { logMessage(LOG_ERR, "%s: %s", "invalid rate multiplier", opt_speechRate); return PROG_EXIT_SYNTAX; } } speechVolume = 1.0; if (opt_speechVolume && *opt_speechVolume) { static const float minimum = 0.0; static const float maximum = 2.0; if (!validateFloat(&speechVolume, opt_speechVolume, &minimum, &maximum)) { logMessage(LOG_ERR, "%s: %s", "invalid volume multiplier", opt_speechVolume); return PROG_EXIT_SYNTAX; } } if (argc) { driver = *argv++; --argc; } if ((speech = loadSpeechDriver(driver, &object, opt_driversDirectory))) { const char *const *parameterNames = speech->parameters; char **parameterSettings; if (!parameterNames) { static const char *const noNames[] = {NULL}; parameterNames = noNames; } { const char *const *name = parameterNames; unsigned int count; char **setting; while (*name) ++name; count = name - parameterNames; if (!(parameterSettings = malloc((count + 1) * sizeof(*parameterSettings)))) { logMallocError(); return PROG_EXIT_FATAL; } setting = parameterSettings; while (count--) *setting++ = ""; *setting = NULL; } while (argc) { char *assignment = *argv++; int ok = 0; char *delimiter = strchr(assignment, '='); if (!delimiter) { logMessage(LOG_ERR, "missing speech driver parameter value: %s", assignment); } else if (delimiter == assignment) { logMessage(LOG_ERR, "missing speech driver parameter name: %s", assignment); } else { size_t nameLength = delimiter - assignment; const char *const *name = parameterNames; while (*name) { if (strncasecmp(assignment, *name, nameLength) == 0) { parameterSettings[name - parameterNames] = delimiter + 1; ok = 1; break; } ++name; } if (!ok) logMessage(LOG_ERR, "invalid speech driver parameter: %s", assignment); } if (!ok) return PROG_EXIT_SYNTAX; --argc; } initializeSpeechSynthesizer(&spk); identifySpeechDriver(speech, 0); /* start-up messages */ if (speech->construct(&spk, parameterSettings)) { if (speech->setVolume) speech->setVolume(&spk, speechVolume); if (speech->setRate) speech->setRate(&spk, speechRate); if (opt_textString && *opt_textString) { sayString(&spk, opt_textString, 0); } else { processLines(stdin, sayLine, NULL); } speech->destruct(&spk); /* finish with the display */ exitStatus = PROG_EXIT_SUCCESS; } else { logMessage(LOG_ERR, "can't initialize speech driver."); exitStatus = PROG_EXIT_FATAL; } } else { logMessage(LOG_ERR, "can't load speech driver."); exitStatus = PROG_EXIT_FATAL; } return exitStatus; }
} if (!processCharacters(character, length, '\n', data)) return 0; if (opt_forceOutput) if (!flushOutputStream(data)) return 0; return 1; } static ProgramExitStatus processStream (FILE *stream) { LineProcessingData lpd = { .exitStatus = PROG_EXIT_SUCCESS }; ProgramExitStatus exitStatus = processLines(stream, processLine, &lpd)? lpd.exitStatus: PROG_EXIT_FATAL; if (exitStatus == PROG_EXIT_SUCCESS) if (!(flushCharacters('\n', &lpd) && flushOutputStream(&lpd))) exitStatus = lpd.exitStatus; return exitStatus; } int main (int argc, char *argv[]) { ProgramExitStatus exitStatus = PROG_EXIT_FATAL; resetPreferences(); prefs.expandCurrentWord = 0;
int processConditional(FILE * logf, struct SCRIPT * script, struct TYPING * types, unsigned long location, int lineindex, int statement){ char * thentag = NULL; struct LINE * curline, * nextline; struct LINE ifline, thenline; char * tokens = (char *) calloc(TOKENMAXNB*TOKENSIZE,sizeof(char)); int i, nbtokens, maxpos, pos, elsefound, thenindex; maxpos = recoverMaximalPosition(script,location); //if...then...else/elseif...end if statement if(statement==1){ printf(" if case\n"); //Recover then position (if none considered at the end of first line) thenindex = lineindex-1; do{ thenindex++; curline = accessLine(script,location,thenindex); thentag = strcasestr(curline->line,"then"); if(thenindex>=maxpos){//No then thenindex = lineindex; break; } }while(!thentag); //Parse conditions line for(i=lineindex;i<=thenindex;i++){ //Process condition (requires new line) curline = accessLine(script,location,i); ifline.type = 0; if(i==lineindex){//On if line skip if or elseif nbtokens = decomposeLine(curline->line,(char*)tokens,TOKENMAXNB,TOKENSIZE); strcpy_s(ifline.line,LINE_LENGTH,&(curline->line[strlen(ACCESS(tokens,0))])); }else{ strcpy_s(ifline.line,LINE_LENGTH,curline->line); } //Recover then position thentag = strcasestr(ifline.line,"then"); if(thentag){thentag[0] = '\n'; thentag[1] = 0;} processLine(logf,script,types,location,&ifline); } lineindex = i; printLogEntry(logf, types, L_COND, 0, 0); //Process code blocks //One line conditional (requires newline) elsefound = 0; if(thentag&&strcasecmp(ACCESS(tokens,nbtokens-1),"then")){ printf("%s\n",ACCESS(tokens,nbtokens-1)); thenline.type = 0; strcpy_s(thenline.line,LINE_LENGTH,&thentag[5]); //skip then processLine(logf,script,types,location,&thenline); printf("[+] End of if conditional statement\n"); printLogEntry(logf, types, M_COND, 0, 0); printLogEntry(logf, types, R_COND, 0, 0); return lineindex; }else{ //Blocks on new lines, parse following ones pos = lineindex; while(pos<maxpos){ nextline = accessLine(script,location,pos); if(nextline->type==COMMENT){pos++; continue;} //skip comment if(nextline->type==MANAGER){pos++; continue;} //skip manager declaration if(nextline->type==DECLARATION){pos++; continue;} //(declaration may require variable typing).... if(nextline->type==MARKUP){pos++; continue;} decomposeLine(nextline->line,(char*)tokens,TOKENMAXNB,TOKENSIZE); //Conditional structure if(strcasestr(nextline->line,"end if")){//end of conditional printf("[+] End of if conditional statement\n"); if(!elsefound){printLogEntry(logf, types, M_COND, 0, 0);} printLogEntry(logf, types, R_COND, 0, 0); return pos+1; }else if(!strncasecmp(ACCESS(tokens,0),"elseif",6)){ //printf("[+]Elseif\n"); printLogEntry(logf, types, M_COND, 0, 0); return processConditional(logf,script,types,location,pos,1); }else if(!strncasecmp(ACCESS(tokens,0),"else",4)){ //printf("[+]Else\n"); elsefound = 1; printLogEntry(logf, types, M_COND, 0, 0); pos++; }else{ pos = processLines(logf,script,types,location,pos); } }//while }//uni/multi line statement }//if type statement //select case...case...end select statement if(statement==2){ printf(" select case\n"); //Blocks on new lines, parse following ones pos = lineindex+2;//Skip first case statement while(pos<maxpos){ nextline = accessLine(script,location,pos); if(nextline->type==COMMENT){pos++; continue;} //skip comment if(nextline->type==MANAGER){pos++; continue;} //skip manager declaration if(nextline->type==DECLARATION){pos++; continue;} //(declaration may require variable typing).... if(nextline->type==MARKUP){pos++; continue;} decomposeLine(nextline->line,(char*)tokens,TOKENMAXNB,TOKENSIZE); //Conditional structure if(strcasestr(nextline->line,"end select")){//end of conditional printf("[+] End of select conditional statement\n"); printLogEntry(logf, types, R_COND, 0, 0); return pos+1; }else if(!strncasecmp(ACCESS(tokens,0),"case",4)){ //printf("[+]Case\n"); printLogEntry(logf, types, M_COND, 0, 0); pos++; }else{ pos = processLines(logf,script,types,location,pos); } }//while }//select statement free(tokens); return pos; }