Skip to content
Snippets Groups Projects
Commit 80490b61 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

fl: now looking for y08 _and_ yda.

parent 508c18bc
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@
using namespace std;
namespace NFileIn {
void Load_08( ifstream& F_in, string flong );
void Load_08( ifstream& F_in, string fnam );
}
......@@ -41,43 +41,39 @@ namespace NFileIn {
void NFileIn::load(void)
{
string fnames = sask( "Load file(s)" );
vector<string> vflong = triv::glob_file_list( fnames, "y08" );
for( int i=0; i<vflong.size(); ++i ) {
FILE *F_in = fopen(vflong[i].c_str(), "r");
if( !F_in )
throw "cannot open file " + vflong[i];
string pattern = sask( "Load file(s)" );
vector<string> fNames = triv::glob_file_list( pattern, "yda y08" );
for( string fnam: fNames ) {
try{
cout << ".. loading file " << vflong[i] << "\n";
string fdir, fshort, fext;
triv::fname_divide( vflong[i], &fdir, &fshort, &fext);
if ( fext=="y08" ) {
ifstream FS (vflong[i].c_str(), ios_base::in);
if( FS.fail() )
throw S("cannot open file");
Load_08( FS, vflong[i] );
FS.close();
} else
throw "unknown file extension [" + fext + "]";
fclose( F_in );
triv::fname_divide( fnam, &fdir, &fshort, &fext);
if ( !(fext=="y08" || fext=="yda") )
throw "unknown extension " + fext;
ifstream FS (fnam.c_str(), ios_base::in);
if( FS.fail() )
throw string("cannot open file");
cout << ".. loading file " << fnam << "\n";
if ( fext=="y08" )
Load_08( FS, fshort );
else if ( fext=="yda" )
cout << "TODO\n";
else
throw "BUG: unforeseen extension " + fext;
FS.close();
}
catch(string& ex) {
throw "Cannot load " + vflong[i] + ": " + ex;
throw "Cannot load " + fnam + ": " + ex;
}
catch(std::exception& ex) {
throw "Cannot load " + vflong[i] + ": " + ex.what();
throw "Cannot load " + fnam + ": " + ex.what();
}
}
}
//! Load a YAML file in y08 format.
void NFileIn::Load_08(ifstream& FS,string flong)
void NFileIn::Load_08(ifstream& FS, string fnam)
{
string fdir, fshort, fext;
triv::fname_divide( flong, &fdir, &fshort, &fext);
const YAML::Node doc = YAML::Load(FS);
if( doc.Type() != YAML::NodeType::Map )
throw S("document root is not of MAP type");
......@@ -112,7 +108,7 @@ void NFileIn::Load_08(ifstream& FS,string flong)
fc = POlc( new COlc );
fout = fc;
} else
throw "File "+flong+" has invalid type "+type;
throw "Meta section has invalid type "+type;
// read history
if(!doc["History"])
......@@ -237,7 +233,7 @@ void NFileIn::Load_08(ifstream& FS,string flong)
}
}
fout->name = fshort;
fout->name = fnam;
fout->as_on_disk = true;
NOlm::mem_store( fout );
}
......@@ -146,26 +146,32 @@ string triv::next_tmp_file( const string& path_format )
}
//! Returns a list of file names obtained by shell-like expansion of pattern with optional extension
//! Returns a list of file names obtained by shell-like expansion of patterns.
vector<string> triv::glob_file_list( const string& pattern, const string& extension)
//! Pattern is a blank-separated list of subpatterns.
//! Extensions is a blank-separated list of strings to be appended to subpatterns that have
//! no extension.
vector<string> triv::glob_file_list( const string& patterns, const string& extensions)
{
string extended_pattern = "";
vector<string> words;
split( pattern, words );
if ( !words.size() )
string extended_patterns = "";
vector<string> vPattern;
split( patterns, vPattern );
if ( !vPattern.size() )
throw string( "empty file list" );
for ( size_t i=0; ; ) {
vector<string> vExtension;
split( extensions, vExtension );
for ( string pat: vPattern ) {
string fmain, fext;
fname_divide( words[i], nullptr, &fmain, &fext );
extended_pattern += words[i];
if ( fext=="" && extension!="" )
extended_pattern += "." + extension;
if ( ++i>=words.size() )
break;
extended_pattern += " ";
fname_divide( pat, nullptr, &fmain, &fext );
if ( fext=="" && extensions!="" ) {
for( string ext: vExtension )
extended_patterns += pat + "." + ext + " ";
} else {
extended_patterns += pat + " ";
}
}
return triv::wordexp_multi(extended_pattern);
return triv::wordexp_multi(extended_patterns);
}
......
......@@ -16,7 +16,7 @@ namespace triv {
void fname_divide( const std::string& fname, std::string *fdir,
std::string *fshort, std::string *fext);
std::vector<std::string> glob_file_list(
const std::string& pattern, const std::string& extension);
const std::string& patterns, const std::string& extensions);
std::string wordexp_unique( const std::string& s );
std::vector<std::string> wordexp_multi( const std::string& s );
std::string next_tmp_file( const std::string& path_format );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment