Skip to content

Commit

Permalink
Feature #2691 main_v11.1 vx_config_tmp_files (#2695)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway authored Oct 2, 2023
1 parent 929f153 commit cb5105f
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 121 deletions.
2 changes: 1 addition & 1 deletion src/basic/vx_config/config.tab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extern "C" int configwrap();

char * configtext;

FILE * configin;
stringstream * configin;

int LineNumber = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/basic/vx_config/config.tab.yy
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern "C" int configwrap();

char * configtext;

FILE * configin;
stringstream * configin;

int LineNumber = 1;

Expand Down
181 changes: 103 additions & 78 deletions src/basic/vx_config/config_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using namespace std;

extern int configparse();

extern FILE * configin;
extern stringstream * configin;

extern int configdebug;

Expand Down Expand Up @@ -152,6 +152,8 @@ void MetConfig::clear()

Filename.clear();

ConfigStream.clear();

Dictionary::clear();

Debug = false;
Expand All @@ -172,6 +174,8 @@ clear();

Filename = c.Filename;

ConfigStream << c.ConfigStream.str();

Dictionary::assign(c);

Debug = c.Debug;
Expand Down Expand Up @@ -298,156 +302,177 @@ return n;
////////////////////////////////////////////////////////////////////////


bool MetConfig::read(const char * name)
bool MetConfig::read(const char * filename)

{

if ( empty(name) ) {
set_buffer_from_file(filename);

mlog << Error << "\nMetConfig::read(const char *) -> "
<< "empty filename!\n\n";

exit ( 1 );
return parse_buffer();

}

DictionaryStack DS(*this);
ConcatString temp_filename = get_tmp_dir();

temp_filename << "/" << "met_config";
temp_filename = make_temp_file_name(temp_filename.c_str(), nullptr);

recursive_envs(name, temp_filename.c_str());

bison_input_filename = temp_filename.c_str();
////////////////////////////////////////////////////////////////////////

dict_stack = &DS;

LineNumber = 1;
bool MetConfig::read_string(const char * config_string)

Column = 1;
{

is_lhs = true;
set_buffer_from_string(config_string);

Filename.add(bison_input_filename);
return parse_buffer();

configdebug = (Debug ? 1 : 0);
}

if ( (configin = met_fopen(bison_input_filename, "r")) == nullptr ) {

mlog << Error << "\nMetConfig::read(const char *) -> "
<< "unable to open input file \"" << bison_input_filename << "\"\n\n";
////////////////////////////////////////////////////////////////////////


void MetConfig::set_buffer_from_file(const char * filename)

{

if ( empty(filename) ) {

mlog << Error << "\nMetConfig::set_buffer_from_file(const char *) -> "
<< "empty filename!\n\n";

exit ( 1 );

}

int parse_status;
// Open input config file

ifstream configfilein;

met_open(configfilein, filename);

parse_status = configparse();
if ( ! configfilein ) {

if ( configin ) {
mlog << Error << "\nMetConfig::read(const char *) -> "
<< "unable to open input file \"" << filename << "\"\n\n";

fclose(configin);
configin = (FILE *) nullptr;
exit ( 1 );

}

if ( parse_status != 0 ) {
// Initialize stream and load contents

return false;
ConfigStream.clear();

}
string line;

if ( DS.n_elements() != 1 ) {
while ( getline(configfilein, line) ) {

mlog << Error << "\nMetConfig::read(const char *) -> "
<< "should be only one dictionary left after parsing! ...("
<< DS.n_elements() << ")\n\n";
recursive_envs(line);

DS.dump(cout);
DS.dump_config_format(cout);
ConfigStream << line << "\n";

mlog << Error << "\n"
<< "parse failed!\n\n";
}

exit ( 1 );
// Close the input file

configfilein.close();

bison_input_filename = filename;

Filename.add(filename);

return;

}

//
// done
//

patch_parents();
////////////////////////////////////////////////////////////////////////

bison_input_filename = (const char *) nullptr;

dict_stack = (DictionaryStack *) nullptr;
void MetConfig::set_buffer_from_string(const char * config_string)

LineNumber = 1;
{

Column = 1;
string line(config_string);

is_lhs = true;
recursive_envs(line);

set_exit_on_warning();
ConfigStream.clear();

unlink(temp_filename.c_str());
ConfigStream << line << "\n";

return true;
bison_input_filename = "config_string";

Filename.add("config_string");

return;

}


////////////////////////////////////////////////////////////////////////


bool MetConfig::read_string(const char * s)
bool MetConfig::parse_buffer()

{

if ( empty(s) ) {
configin = &ConfigStream;

mlog << Error << "\nMetConfig::read_string(const char *) -> "
<< "empty input string!\n\n";
DictionaryStack DS(*this);

exit ( 1 );
dict_stack = &DS;

}
LineNumber = 1;

//
// write temporary config file
// default to the current directory
//
Column = 1;

ofstream out;
ConcatString temp_filename = get_tmp_dir();
is_lhs = true;

temp_filename << "/" << "met_config";
temp_filename = make_temp_file_name(temp_filename.c_str(), nullptr);

out.open(temp_filename.c_str());
configdebug = (Debug ? 1 : 0);

if ( ! out ) {
int parse_status = configparse();

if ( parse_status != 0 ) {

mlog << Error << "\nMetConfig::read_string(const char *) -> "
<< "unable to open temp file \"" << temp_filename << "\".\n"
<< "Set MET_TMP_DIR to specify a temporary directory.\n\n";
return false;

}

if ( DS.n_elements() != 1 ) {

mlog << Error << "\nMetConfig::parse_buffer(const char *) -> "
<< "should be only one dictionary left after parsing! ...("
<< DS.n_elements() << ")\n\n";

DS.dump(cout);
DS.dump_config_format(cout);

mlog << Error << "\n"
<< "parse failed!\n\n";

exit ( 1 );

}

out << s << '\n';
//
// done
//

out.close();
patch_parents();

bool status = read(temp_filename.c_str());
bison_input_filename = (const char *) nullptr;

remove_temp_file(temp_filename);
dict_stack = (DictionaryStack *) nullptr;

return status;
LineNumber = 1;

Column = 1;

is_lhs = true;

set_exit_on_warning();

return true;

}

Expand Down
10 changes: 9 additions & 1 deletion src/basic/vx_config/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ class MetConfig : public Dictionary {

void assign(const MetConfig &);

void set_buffer_from_file(const char *);

void set_buffer_from_string(const char *);

bool parse_buffer();

StringArray Filename;

std::stringstream ConfigStream;

bool Debug;

public:
Expand Down Expand Up @@ -78,7 +86,7 @@ class MetConfig : public Dictionary {

bool read(const char * filename);

bool read_string(const char *);
bool read_string(const char * config_string);

const DictionaryEntry * lookup(const char * name);

Expand Down
5 changes: 0 additions & 5 deletions src/basic/vx_config/config_scanner.ll
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,6 @@ const DictionaryEntry * e = dict_stack->lookup(configtext);
if ( e && (e->is_number()) && (! is_lhs) ) {
// cout << "=================== id = \"" << configtext << "\" is_lhs = " << (is_lhs ? "true" : "false") << "\n";
// cout << "do_id() -> \n";
// e->dump(cout);
if ( e->type() == IntegerType ) {
set_int(configlval.nval, e->i_value());
Expand Down
Loading

0 comments on commit cb5105f

Please sign in to comment.