//----------------------------------------------------------------------------------------------- // Reads the input file, generates a pressure drop calculator //----------------------------------------------------------------------------------------------- PressureDropCalculator* PipeReader::readFile(const QString &file_name) { PressureDropCalculator *calc = 0; // opening the input file QFile input(file_name); // checking if file opened ok... if(!input.open(QIODevice::ReadOnly | QIODevice::Text)) { qWarning("Could not open PIPE input file: %s", file_name.toLatin1().constData()); exit(1); } // starting to read the file, finding what type of calculator to produce QStringList list = processLine(input.readLine()); while(!input.atEnd() && !list.at(0).startsWith("EOF")) { if(list.at(0).startsWith("CORRELATION")) { if(list.at(1).startsWith("BB73")) calc = readBeggsBrill(input); // this is a beggs and brill correlation else if(list.at(1).startsWith("TABLE")) calc = readDpTable(input); // this is a table correlation } else if(!isEmpty(list)) { cout << endl << "### Error detected in PIPE definition file! ###" << endl << "File: " << file_name.toLatin1().constData() << endl << "Keyword: " << list.join(" ").toLatin1().constData() << endl << "Not understood in current context." << endl << endl; exit(1); } list = processLine(input.readLine()); } // everything ok, closing input file input.close(); return calc; }
void generate( options *o) { FILE *fileHandle = fopen( o->file, "r" ); char line[ 256 ]; if( !fileHandle ) { perror( "Error opening the source file" ); } else { assert( fileHandle ); while( fgets( line, 256, fileHandle ) ) { count( line ); } rewind( fileHandle ); OBJModel.vertices = calloc( OBJModel.numOfObjVertex , sizeof( vertex ) ); assert( OBJModel.vertices ); if( OBJModel.numOfObjNormal > 0 ) { OBJModel.normals = calloc( OBJModel.numOfObjNormal , sizeof( normal ) ); assert( OBJModel.normals ); } if( OBJModel.numOfObjNormal > 0 ) { OBJModel.textures = calloc( OBJModel.numOfObjTex , sizeof( texture ) ); assert( OBJModel.textures ); } OBJModel.faces = calloc( OBJModel.numOfObjFaces , sizeof( face ) ); OBJModel.indexLength = OBJModel.numOfObjFaces * 3; OBJModel.indices = calloc( OBJModel.indexLength, sizeof( Index ) ); assert( OBJModel.faces ); assert( OBJModel.indices ); while( fgets( line, 256, fileHandle ) ) { processLine( line ); } generateFile( o->outputFile ); if( o->verbose ) { printf( "Total Vertices: %i\n", OBJModel.numOfObjVertex ); printf( "Total Normals: %i\n", OBJModel.numOfObjNormal ); printf( "Total Textures: %i\n", OBJModel.numOfObjTex ); printf( "Total Index: %i\n", OBJModel.indexCount ); } fclose( fileHandle ); } }
void readBaseFileStatus(char* filename) { FILE* file; char line[MAXPATHLEN]; if (!(file = fopen(filename, "r"))) { // Let's try to create the .file_status in the baseline system fprintf(stderr, "CreateFileStatus (.file_status is missing)\n"); sprintf(line, "CreateFileStatus -d %s", dirs.working); if (execute(line)) { exit(-1); } if (!(file = fopen(filename, "r"))) { fprintf(stderr, "Couldn't open %s and CreateFileStatus failed.\n", filename); exit(-1); } } // The first line of the file is a comment so skip it. if (fgets(line_buf, line_buf_size, file) == NULL) { fprintf(stderr, "Couldn't read the first line of %s\n", filename); exit(-1); } while (fgets(line_buf, line_buf_size, file) != NULL) { processLine(line_buf); } if (fclose(file)) { fprintf(stderr, "Couldn't close %s\n", filename); exit(-1); } }
/* * handleHeader - scan through and process header information */ static void handleHeader( int *start, SAREA *line ) { int cur; cur = 0; if( strnicmp( helpInBuf, ":h", 2 ) == 0 ) { for( ;; ) { if( !mygetline() ) break; if( strnicmp( helpInBuf, ":t", 2 ) == 0 ) break; if( strnicmp( helpInBuf, ":eh", 3 ) == 0 ) break; processLine( helpInBuf, helpOutBuf, cur, false ); putline( helpOutBuf, cur ); cur ++; } line->row = cur; uivfill( &helpScreen, *line, AT( ATTR_NORMAL ), UiGChar[UI_SBOX_HORIZ_LINE] ); cur++; topPos = HelpTell( helpFileHdl ); if( strnicmp( helpInBuf, ":eh", 3 ) == 0 ) { mygetline(); } } *start = cur; }
/* * handleFooter - scan through and process footer information */ static void handleFooter( int *startline, SAREA *use, SAREA *line ) { int start; start = *startline; if( strnicmp( helpInBuf, ":t", 2 ) == 0 ) { ++start; /* leave room for line */ for( ;; ) { if( !mygetline() ) break; if( strnicmp( helpInBuf, ":et", 3 ) == 0 ) break; processLine( helpInBuf, helpOutBuf, start, false ); putline( helpOutBuf, start ); ++start; } vscroll_fields( &helpTab, *use, start - use->row - use->height ); vvscroll( &helpScreen, *use, start - use->row - use->height ); use->height -= start - use->row; line->row = use->row + use->height; uivfill( &helpScreen, *line, AT( ATTR_NORMAL ), UiGChar[UI_SBOX_HORIZ_LINE] ); topPos = HelpTell( helpFileHdl ); } *startline = start; }
void KateBuildView::slotReadReadyStdErr() { // FIXME This works for utf8 but not for all charsets QString l= QString::fromUtf8(m_proc->readAllStandardError()); l.remove(QLatin1Char('\r')); m_output_lines += l; QString tmp; int end=0; do { end = m_output_lines.indexOf(QLatin1Char('\n')); if (end < 0) break; end++; tmp = m_output_lines.mid(0, end); tmp.remove(QLatin1Char('\n')); m_buildUi.plainTextEdit->appendPlainText(tmp); processLine(tmp); m_output_lines.remove(0,end); } while (1); }
void CIniFile::ReadFile() { // Normally you would use ifstream, but the SGI CC compiler has // a few bugs with ifstream. So ... fstream used. fstream f; string line; Vector<string> iniLines; string x = path; string y(x.begin(), x.end()); y.assign(x.begin(), x.end()); f.open(y.c_str(), ios::in); if(!f.fail()) // This is true if the file cannot be opened or something... in which case we don't want to read the file! { while(getline(f, line)) if(line.length() > 2) // Anything shorter can't be useful... iniLines.push_back(line); f.close(); } lineCount = iniLines.size(); // Set our INI vector length // Process our INI lines, will provide sensible defaults for any missing or malformed entries for(S32 i = 0; i < lineCount; i++) processLine(iniLines[i]); }
void LR_IPC_IN::run() { while (!threadShouldExit()) { char line[256] = { '\0' }; int sizeRead = 0; bool canReadLine = true; // parse input until we have a line, then process that line while (!String(line).endsWithChar('\n') && !threadShouldExit()) { auto waitStatus = waitUntilReady(true, 0); if (waitStatus < 0) { canReadLine = false; break; } else if (waitStatus == 0) { wait(100); continue; } sizeRead += read(line + sizeRead, 1, false); } if (canReadLine) { String param(line); processLine(param); } } }
void processFile(char *fname, int searchincl) { FILE *fp; char *pathname; if (verbose) printf("Processing file:%s\r\n", fname); pathname = (char *)NULL; fp = fopen(fname, "r"); if (!fp) { if (searchincl) { searchenv(fname, "INCLUDE", &pathname); if (strlen(pathname)) { fp = fopen(pathname, "r"); if (fp) goto j1; } } printf("Can't open file <%s>\r\n", fname); goto j2; } j1: while (!feof(fp)) { fgets(buf, sizeof(buf)/sizeof(char), fp); processLine(buf); } fclose(fp); j2: if (pathname) free(pathname); }
/* * scans a char* buffer for lines that does not * start with the specified comment character. */ bool AnyOption::consumeFile (char *buffer) { if (buffer == NULL) return false; char *cursor = buffer; /* preserve the ptr */ char *pline = NULL; int linelength = 0; bool newline = true; for (unsigned int i = 0; i < strlen (buffer); i++) { if (*cursor == endofline) { /* end of line */ if (pline != NULL) /* valid line */ processLine (pline, linelength); pline = NULL; newline = true; } else if (newline) { /* start of line */ newline = false; if ((*cursor != comment)) { /* not a comment */ pline = cursor; linelength = 0; } } cursor++; /* keep moving */ linelength++; } free (buffer); return true; }
GaussianFchk::GaussianFchk(const QString &filename, BasisSet* basis) { // Open the file for reading and process it QFile* file = new QFile(filename); QtIOCompressor* compressedFile = 0; if (filename.endsWith(".gz")) { compressedFile = new QtIOCompressor(file); compressedFile->setStreamFormat(QtIOCompressor::GzipFormat); compressedFile->open(QIODevice::ReadOnly); m_in = compressedFile; } else { file->open(QIODevice::ReadOnly | QIODevice::Text); m_in = file; } qDebug() << "File" << filename << "opened."; // Process the formatted checkpoint and extract all the information we need while (!m_in->atEnd()) { processLine(); } // Now it should all be loaded load it into the basis set load(basis); if (compressedFile) delete compressedFile; else delete file; }
int at_send_command_to_data_channel(const char *command, ATResponse **pp_outResponse, RILChannelCtx *p_channel) { const char* line = NULL; int ret = writeline(command, p_channel); if (ret == 0) { p_channel->p_response = at_response_new(); do { line = readline(p_channel); if (line != NULL) RLOGI("readline: %s", line); else RLOGI("readline: EMPTY"); } while (line != NULL && !(strcmp(line, "OK") == 0 || strcmp(line, "NO CARRIER") == 0 || strStartsWith(line, "CONNECT") == 1 || strstr(line, "ERROR"))); if (line != NULL) { RLOGI("process line: %s", line); processLine(line, p_channel); if (pp_outResponse == NULL) { at_response_free(p_channel->p_response); } else { reverseIntermediates(p_channel->p_response); *pp_outResponse = p_channel->p_response; } return 0; } } return AT_ERROR_GENERIC; }
/** * Scan and process a configuration file, and store the retrieved * configuration values into the PortageSettings object. * * @param settings The PortageSettings object that will be filled * with configuration values. * @param filename Path of the configuration file. * * @return PortageLoaderBase::NoError if the file has successfully been handled. * PortageLoaderBase::OpenFileError if there was an error opening the file. * PortageLoaderBase::NullObjectError if the given settings object is NULL. */ PortageLoaderBase::Error FileMakeConfigLoader::loadFile( PortageSettings* settings, const QString& filename ) { // Check on a NULL settings object, which would be bad if( settings == NULL ) return NullObjectError; else this->settings = settings; // Open the file for reading QFile file( filename ); if( !file.open( IO_ReadOnly ) ) { return OpenFileError; } QString line; QTextStream stream( &file ); // Process each line while ( !stream.atEnd() ) { line = stream.readLine(); if( line.isEmpty() == true ) continue; processLine( line ); } return NoError; }
/* * Processes a packet of data that supposedly contains an HTTP request * This function looks for CR/LF (or just LF) and calls processLine * with each line of data found. */ boolean processPacket(char* data, int len) { // Address after the last byte of data char* end = data + len; // Start of current line char* start = data; // Scan through the bytes in the packet looking for a Line Feed character while (data < end) { if (*data == LF) { // Determine the length of the line excluding the Line Feed int lineLength = data - start; if (*(data - 1) == CR) { lineLength--; } *(start + lineLength) = 0; // Process the line if (processLine(start, lineLength)) { return true; } // Set up for the start of the next line start = ++data; } else { // Go to the next byte data++; } } return false; }
ConfigHandler::ConfigHandler() : lastSurf(0) { //check to see whether config file exists QDir home = QDir().home(); QFile configFile; QDir::setCurrent(home.path()); configFile.setFileName(".cangjie"); if(configFile.exists()) { //read it configFile.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream config(&configFile); QString line(config.readLine()); while(!line.isNull()) { processLine(line); line = config.readLine(); } } else { //make it configFile.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream config(&configFile); config << "lastSurf=0\n"; configFile.close(); } }
TextSplitter::TextSplitter(Common::SeekableReadStream *data) { char *line; int i; uint32 len = data->size(); _stringData = new char[len + 1]; data->read(_stringData, len); _stringData[len] = '\0'; // Find out how many lines of text there are _numLines = _lineIndex = 0; line = (char *)_stringData; while (line) { line = strchr(line, '\n'); if (line) { _numLines++; line++; } } // Allocate an array of the lines _lines = new char *[_numLines]; line = (char *)_stringData; for (i = 0; i < _numLines;i++) { char *lastLine = line; line = strchr(lastLine, '\n'); *line = '\0'; _lines[i] = lastLine; line++; } _currLine = NULL; processLine(); }
char GetSourceChar() { char c; char * result; if (colno == 0) { lineno++; result = fgets(line, MAXLINE + 1, source); processLine(line); if (result == NULL) { return EOF; } if (listing != stdout) { fprintf(listing, "%-3d: %s", lineno, line); } } c = line[colno++]; if (c == '\n') { colno = 0; newLine = true; } return c; }
bool BasicOECakeReader::processFile(char * fileName) { FILE * fp = fopen(fileName, "rb"); if (fp == NULL) { char newFileName[512]; sprintf(newFileName,"../../%s",fileName); fp = fopen(newFileName, "rb"); if (fp == NULL) { sprintf(newFileName,"../../../%s",fileName); fp = fopen(newFileName, "rb"); if (fp == NULL) { printf("ERROR: file(%s) not found", fileName); return false; } } } int size; if (fseek(fp, 0, SEEK_END) || (size = ftell(fp)) == EOF || fseek(fp, 0, SEEK_SET)) { printf("ERROR: problem reading file(%s)", fileName); fclose(fp); return false; } else { rewind (fp); char * buffer = (char *) malloc(size+1); memset(buffer,0,size); if (fread(buffer,1,size,fp) != size) { printf("Error reading file %s!\n",fileName); fclose(fp); return false; } int totalBytesRead = 0; while(totalBytesRead<size) { int remainingSize = size-totalBytesRead; // if (remainingSize<1229) // { // printf(".."); // } totalBytesRead +=processLine(&buffer[totalBytesRead],remainingSize); } } convertParticleGroup(); fclose(fp); return false; }
/* * doFileInput() * * Get lines from a file (be that a file on disk or stdin) and pass the lines * to processLine() for calculation. */ int doFileInput(FILE *fptr, int quiet, displayMode dm, char siPrefix, int precision) { char *line; int rc = errNoError; if(!fptr) return errBadInput; line = calloc(1024, sizeof(char)); if(!line){ fprintf(stderr, _("Error: Out of memory\n")); return errMemory; } fgets(line, 1024, fptr); while(!feof(fptr)){ if(line[strlen(line)-1] == 10 || line[strlen(line)-1] == 13){ line[strlen(line)-1] = '\0'; } /* Quit if "q" (or "quit" etc.) is an input */ if(line[0] == 'q' || line[0] == 'Q'){ rc = errNoError; break; } rc = processLine(line, quiet, dm, siPrefix, precision); if(rc != errNoError){ break; } fgets(line, 1024, fptr); } free(line); return rc; }
Local void processOneBar(struct LOC_musicParagraph *LINK) { paragraph_index0 m, cm; voice_index voice, cvoice; boolean ignore_voice; boolean wrote_repeat = false; boolean alone; Char STR2[256]; Char STR3[256]; if (bar_of_line > 1) { sprintf(STR3, "%cBar %s", comment, toString(STR2, bar_no)); putLine(STR3); } last_bar = (bar_of_line == nbars && final_paragraph); if (last_bar && !strcmp(repeat_sign, "|")) *repeat_sign = '\0'; writeRepeat(repeat_sign); *LINK->new_meter = '\0'; for (voice = nvoices; voice >= 1; voice--) { if (musicLineNo(voice) > 0) { gotoBar(voice, bar_of_line); getMeterChange(voice, LINK->new_meter); } } if (last_bar && *LINK->new_meter == '\0' && nleft > pickup && meternum > 0) meterChange(LINK->new_meter, nleft, 64, true); if (*LINK->new_meter != '\0') putLine(LINK->new_meter); for (voice = nvoices; voice >= 1; voice--) { ignore_voice = !selected[voice-1]; cvoice = companion(voice); m = musicLineNo(voice); cm = musicLineNo(cvoice); alone = (voice == cvoice || m > 0 && cm == 0 || m == 0 && cm == 0 && voice < cvoice || !selected[cvoice-1]); if (selected[voice-1]) { if (m > 0) processLine(voice, bar_of_line); else if (alone) supplyRests(voice); else ignore_voice = true; if (last_bar && *repeat_sign != '\0' && !wrote_repeat) { writeRepeat(repeat_sign); wrote_repeat = true; } if (!ignore_voice) { if (alone || voicePos(voice) == 1) putLine(" /"); else putLine(" //"); } } } bar_no++; pickup = 0; putLine(""); }
DataList EFPFragment::parse(QTextStream& textStream) { while (!textStream.atEnd() && !m_done) { processLine(textStream); } return m_dataList; }
// if lines are read from stdin, // this function takes in and open the file and // parse it line by line void readStream(int qualThreshold, int coverageThreshold) { for (string line; getline(cin, line);) { stringList columns = split(line,'\t'); processLine(columns, qualThreshold, coverageThreshold); } }
void DumpRenderTree::loadNextTestInStandAloneMode() { if (m_standAloneModeTestList.isEmpty()) { emit quit(); return; } QString first = m_standAloneModeTestList.takeFirst(); processLine(first); }
void QAtChat::incoming() { char buf[256]; char ch; int posn; bool resetTimer = false; // Process the lines in the incoming input. posn = 0; while ( d->device->getChar(&ch) ) { if ( ch == 0x0A ) { // LF terminates the line. buf[posn] = '\0'; d->line += buf; if ( !d->wakeupInProgress ) { resetTimer |= processLine( d->line ); } else { // Discard response lines while a wakeup is in progress. // Notifications are still processed in case an important event // like an incoming SMS arrives during the wakeup process. QString command; if ( d->matcher->lookup( d->line, command ) == QPrefixMatcher::Notification ) qLog(AtChat) << d->notifyChar << ":" << d->line; else qLog(AtChat) << "W :" << d->line; } d->line = ""; posn = 0; } else if ( ch != 0x00 && ch != 0x0D ) { buf[posn++] = (char)ch; if ( posn >= (int)(sizeof(buf) - 1) ) { buf[posn] = '\0'; d->line += buf; posn = 0; } } } if ( posn > 0 ) { buf[posn] = '\0'; d->line += buf; } // Reset the dead timer if we got some useful data. if ( resetTimer && d->deadTimer->isActive() ) { d->deadTimer->start( d->deadTimeout ); } // If the line buffer contains "> ", then we need to send the pdu. if ( d->line == "> " && d->first ) { d->line = ""; // Write the PDU, terminated by ^Z, but without a trailing CR. // A trailing CR will cause Wavecom modems to fail when they // are in multiplexing mode. writePduLine( d->first->d->pdu ); } }
void SevenZipArch::slotReceivedTOC( TDEProcess*, char* data, int length ) { char endchar = data[ length ]; data[ length ] = '\0'; appendShellOutputData( data ); int startChar = 0; while ( !m_finished ) { int lfChar; for ( lfChar = startChar; data[ lfChar ] != '\n' && lfChar < length; lfChar++ ); if ( data[ lfChar ] != '\n') break; // We are done all the complete lines data[ lfChar ] = '\0'; m_buffer.append( data + startChar ); data[ lfChar ] = '\n'; startChar = lfChar + 1; // Check if the header was found if ( m_buffer.find( m_headerString.data() ) != -1 ) { if ( !m_header_removed ) { m_nameColumnPos = m_buffer.findRev( ' ' ) + 1; m_header_removed = true; } else { m_finished = true; } } else { // If the header was not found, process the line if ( m_header_removed && !m_finished ) { if ( !processLine( m_buffer ) ) { m_header_removed = false; m_error = true; } } } m_buffer.resize( 0 ); } if ( !m_finished ) m_buffer.append( data + startChar); // Append what's left of the buffer data[ length ] = endchar; }
// if lines are read from file, // this function takes in and open the file and // parse it line by line void readFile(const char* filename, int qualThreshold, int coverageThreshold) { ifstream myfile(filename); for (string line; getline(myfile, line);) { stringList columns = split(line,'\t'); processLine(columns, qualThreshold, coverageThreshold); } }
void readLinesFromFile(const char* filePath) { assert(filePath); std::string lineBuffer; std::ifstream file; file.open(filePath); while (std::getline(file, lineBuffer)) { if (lineBuffer.empty()) { continue; } processLine(lineBuffer); } }
void MVCommandProcessor::doProcess() { do { std::cout << "Enter a command (h for help) : "; std::cin.getline(cmdLine,255); processLine(); } while (strcmp(cmdLine,"q") != 0); }
// if lines are read from stdin, // this function takes in and open the file and // parse it line by line int readStream(int qualThreshold, int covThreshold) { int seqCount = 0; for (string line; getline(cin, line);) { stringList columns = split(line,'\t'); processLine(columns, qualThreshold, covThreshold,seqCount); } return 0; }
void DumpRenderTree::loadNextTestInStandAloneMode() { if (m_standAloneModeTestList.isEmpty()) { emit quit(); return; } processLine(m_standAloneModeTestList.first()); m_standAloneModeTestList.removeFirst(); }