summaryrefslogtreecommitdiffstats
path: root/tester/covoar
diff options
context:
space:
mode:
authorRyan Long <ryan.long@oarcorp.com>2021-10-20 16:36:32 -0400
committerJoel Sherrill <joel@rtems.org>2021-12-10 11:05:16 -0600
commit7578f43da3418c999f54c73b4fe8a8afe5dd8a24 (patch)
treeebb6b20b4a4c07be23193e3d66740c3170f410bd /tester/covoar
parentTarget: Convert to C++ (diff)
downloadrtems-tools-7578f43da3418c999f54c73b4fe8a8afe5dd8a24.tar.bz2
ConfigFile: Convert to C++
Diffstat (limited to 'tester/covoar')
-rw-r--r--tester/covoar/ConfigFile.cc82
-rw-r--r--tester/covoar/ConfigFile.h2
2 files changed, 33 insertions, 51 deletions
diff --git a/tester/covoar/ConfigFile.cc b/tester/covoar/ConfigFile.cc
index c16b64a..7109b2c 100644
--- a/tester/covoar/ConfigFile.cc
+++ b/tester/covoar/ConfigFile.cc
@@ -7,9 +7,18 @@
#include "ConfigFile.h"
#include <string.h>
-#include <stdio.h>
#include <ctype.h>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+static void print_invalid_line_number( const std::string& file, int line_no )
+{
+ std::cerr << file << ": line" << line_no << " is invalid: " << line
+ << std::endl;
+}
+
namespace Configuration {
FileReader::FileReader(
@@ -24,43 +33,40 @@ namespace Configuration {
}
bool FileReader::processFile(
- const char* const file
+ const std::string& file
)
{
#define METHOD "FileReader::processFile - "
- FILE * in;
- char line[256];
- char option[256];
- char value[256];
+ #define MAX_LENGTH 256
+ std::ifstream in;
+ std::string line;
+ char option[MAX_LENGTH];
+ char value[MAX_LENGTH];
int line_no;
int i;
int j;
- if ( file == NULL ) {
- fprintf( stderr, METHOD "NULL filename\n" );
+ if ( file.empty() ) {
+ std::cerr << METHOD << "Empty filename" << std::endl;
return false;
}
- in = fopen( file, "r" );
- if ( !in ) {
- fprintf( stderr, METHOD "unable to open %s\n", file );
+ in.open( file );
+ if ( !in.is_open() ) {
+ std::cerr << METHOD << "unable to open " << file << std::endl;
return false;
}
line_no = 0;
- while (fgets(line, sizeof(line), in) != NULL) {
+ while ( std::getline( line, MAX_LENGTH ) ) {
int length;
line_no++;
- length = (int) strlen( line );
- if ( line[length - 1] != '\n' ) {
- fprintf(
- stderr,
- "%s: line %d is too long",
- file,
- line_no
- );
+ length = (int) line.length();
+ if ( length > MAX_LENGTH ) {
+ std::cerr << file << ": line " << line_no << " is too long"
+ << std::endl;
continue;
}
@@ -96,14 +102,8 @@ namespace Configuration {
if (line[0] == '\0')
continue;
- if (sscanf(line, "%s", option) != 1) {
- fprintf(
- stderr,
- "%s: line %d is invalid: %s\n",
- file,
- line_no,
- line
- );
+ if (std::sscanf(line.c_str(), "%s", option) != 1) {
+ print_invalid_line_number(file, line_no);
continue;
}
@@ -111,13 +111,7 @@ namespace Configuration {
;
if (i == length) {
- fprintf(
- stderr,
- "%s: line %d is invalid: %s\n",
- file,
- line_no,
- line
- );
+ print_invalid_line_number(file, line_no);
continue;
}
@@ -129,24 +123,12 @@ namespace Configuration {
value[j] = line[i];
value[j] = '\0';
if (value[0] == '\0') {
- fprintf(
- stderr,
- "%s: line %d is invalid: %s\n",
- file,
- line_no,
- line
- );
+ print_invalid_line_number(file, line_no);
continue;
}
if ( !setOption(option, value) ) {
- fprintf(
- stderr,
- "%s: line %d: option %s is unknown\n",
- file,
- line_no,
- option
- );
+ print_invalid_line_number(file, line_no);
continue;
}
@@ -190,7 +172,7 @@ namespace Configuration {
Options_t *o;
for ( o=options_m ; o->option ; o++ ) {
- fprintf( stderr, "(%s)=(%s)\n", o->option, o->value );
+ std::cerr << '(' << o->option << ")=(" << o->value << ')' << std::endl;
}
}
}
diff --git a/tester/covoar/ConfigFile.h b/tester/covoar/ConfigFile.h
index 0bae7ac..f8bd9c5 100644
--- a/tester/covoar/ConfigFile.h
+++ b/tester/covoar/ConfigFile.h
@@ -54,7 +54,7 @@ namespace Configuration {
* @return Returns TRUE if the method succeeded and FALSE if it failed.
*/
virtual bool processFile(
- const char* const file
+ const std::string& file
);
bool setOption(