From: Francois Fleuret Date: Fri, 30 Oct 2009 22:59:17 +0000 (-0400) Subject: No more C++ includes. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=074a731c1d1e849790ae45fdf58492be6d54d016;p=breezed.git No more C++ includes. --- diff --git a/breezed.cc b/breezed.cc index 473e409..14809ac 100644 --- a/breezed.cc +++ b/breezed.cc @@ -22,17 +22,15 @@ */ -#include -#include #include #include - -#include -#include #include #include +#include #include +#define BUFFER_SIZE 4096 + using namespace std; const int major_version_number = 1; @@ -316,22 +314,72 @@ Written by Francois Fleuret (francois@fleuret.org).\n", ////////////////////////////////////////////////////////////////////// if(configuration_file) { - ifstream cf(configuration_file); + char raw_line[BUFFER_SIZE]; + int start, end, eol, k; + FILE *file; + + file = fopen(configuration_file, "r"); - if(cf.fail()) { - fprintf(stderr, "Can not open %s for reading.\n", configuration_file); + if(!file) { + fprintf(stderr, "Can not open `%s' for reading.\n", configuration_file); exit(1); } + start = 0; + end = 0; + char *s; int line_number = 0; - while(!cf.eof()) { - cf.getline(buffer, buffer_size); + while(end > start || !feof(file)) { + eol = start; + + /* Look for the end of a line in what is already in the buffer */ + while(eol < end && raw_line[eol] != '\n') eol++; + + /* if we did not find the of a line, move what has not been + processed and is in the buffer to the beginning of the buffer, + fill the buffer with new data from the file, and look for the + end of a line */ + if(eol == end) { + for(k = 0; k < end - start; k++) { + raw_line[k] = raw_line[k + start]; + } + end -= start; + eol -= start; + start = 0; + end += fread(raw_line + end, sizeof(char), BUFFER_SIZE - end, file); + while(eol < end && raw_line[eol] != '\n') eol++; + } + + /* The end of the line is the buffer size, which means the line is + too long */ + + if(eol == BUFFER_SIZE) { + raw_line[BUFFER_SIZE - 1] = '\0'; + fprintf(stderr, "Selector: Line too long (max is %d characters):\n", + BUFFER_SIZE); + fprintf(stderr, raw_line); + fprintf(stderr, "\n"); + exit(1); + } + + /* If we got a line, we replace the carriage return by a \0 to + finish the string */ + + raw_line[eol] = '\0'; + + /* here we process the line */ + line_number++; - s = next_word(token, buffer, buffer_size); + if(debug) { + printf("%s:%d \"%s\"\n", + configuration_file, line_number, raw_line + start); + } + + s = next_word(token, raw_line + start, buffer_size); if(strcmp(token, "thermal_files") == 0) { if(s == 0) { @@ -374,7 +422,10 @@ Written by Francois Fleuret (francois@fleuret.org).\n", token, configuration_file, line_number); exit(1); } + + start = eol + 1; } + } //////////////////////////////////////////////////////////////////////