bool istream_line_splitter:: parse_line() { _n_word=0; _is.getline(_buf,_buf_size); const unsigned previous_line_no(_line_no); if(! check_istream(_is,_line_no)) return false; // normal eof unsigned buflen(strlen(_buf)); while(((buflen+1) == _buf_size) && (previous_line_no==_line_no)) { increase_buffer_size(); _is.getline(_buf+buflen,_buf_size-buflen); if(! check_istream(_is,_line_no)) { std::ostringstream oss; oss << "ERROR: Unexpected read failure in parse_line() at line_no: " << _line_no << "\n"; throw blt_exception(oss.str().c_str()); } buflen=(strlen(_buf)); } if((buflen+1) >_buf_size) { std::ostringstream oss; oss << "ERROR: Unexpected read failure in parse_line() at line_no: " << _line_no << "\n"; throw blt_exception(oss.str().c_str()); } if(NULL == _buf) return false; assert(buflen); // do a low-level separator parse: { char* p(_buf); word[0]=p; unsigned i(1); while(i<_max_word){ if((*p == '\n') || (*p == '\0')) break; if (*p == _sep) { *p = '\0'; word[i++] = p+1; } ++p; } _n_word=i; } return true; }
static void add_chr_to_buffer(char c) { if (section_buffer == NULL) { section_buffer = (char *) malloc(section_buffer_size + 1); if (section_buffer == NULL) diagnostics(ERROR, "Could not allocate enough memory to process file. Sorry."); } section_buffer_end++; *(section_buffer + section_buffer_end) = c; if (section_buffer_end + 2 >= section_buffer_size) increase_buffer_size(); if (0) { if (c == '\0') diagnostics(WARNING, "[\\0]"); else if (c == '\n') diagnostics(WARNING, "[\\n]"); else diagnostics(WARNING, "[%c]", (int) c); diagnostics(WARNING, "<%ld>", section_buffer_end); } }