Skip to content

Commit

Permalink
extract custom configuration directory if provided, and fall back to …
Browse files Browse the repository at this point in the history
…that for includes #96
  • Loading branch information
proycon committed Sep 11, 2024
1 parent 0c25d9e commit c8b9515
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/setting.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,18 @@ namespace Tokenizer {
// }
}

string get_filename( const string& name ){
string get_filename( const string& name , const string customConfigDir = ""){
string result;
if ( TiCC::isFile( name ) ){
result = name;
}
else {
if (!customConfigDir.empty()) {
result = customConfigDir + name;
if (TiCC::isFile(result)) {
return result;
}
}
result = localConfigDir + name;
if ( !TiCC::isFile( result ) ){
result = defaultConfigDir + name;
Expand Down Expand Up @@ -608,6 +614,14 @@ namespace Tokenizer {
{ ORDINALS, "" } };
string conffile = get_filename( settings_name );

string customconfdir = TiCC::dirname(settings_name);
if (!TiCC::match_back( customconfdir, "/")) {
customconfdir += "/";
}
if (customconfdir == "./") {
customconfdir.clear();
}

if ( !TiCC::isFile( conffile ) ){
LOG << "Unable to open configfile: " << conffile << endl;
return false;
Expand Down Expand Up @@ -638,7 +652,7 @@ namespace Tokenizer {
if ( !TiCC::match_back( file, ".rule" ) ){
file += ".rule";
}
file = get_filename( file );
file = get_filename( file, customconfdir);
if ( !read_rules( file ) ){
throw uConfigError( "'" + rawline + "' failed", set_file );
}
Expand All @@ -648,7 +662,7 @@ namespace Tokenizer {
if ( !TiCC::match_back( file, ".filter" ) ){
file += ".filter";
}
file = get_filename( file );
file = get_filename( file, customconfdir );
if ( !read_filters( file ) ){
throw uConfigError( "'" + rawline + "' failed", set_file );
}
Expand All @@ -658,7 +672,7 @@ namespace Tokenizer {
if ( !TiCC::match_back( file, ".quote" ) ){
file += ".quote";
}
file = get_filename( file );
file = get_filename( file, customconfdir );
if ( !read_quotes( file ) ){
throw uConfigError( "'" + rawline + "' failed", set_file );
}
Expand All @@ -668,7 +682,7 @@ namespace Tokenizer {
if ( !TiCC::match_back( file, ".eos" ) ){
file += ".eos";
}
file = get_filename( file );
file = get_filename( file, customconfdir);
if ( !read_eosmarkers( file ) ){
throw uConfigError( "'" + rawline + "' failed", set_file );
}
Expand All @@ -678,7 +692,7 @@ namespace Tokenizer {
if ( !TiCC::match_back( file, ".abr" ) ){
file += ".abr";
}
file = get_filename( file );
file = get_filename( file, customconfdir );
if ( !read_abbreviations( file, patterns[ABBREVIATIONS] ) ){
throw uConfigError( "'" + rawline + "' failed", set_file );
}
Expand Down

0 comments on commit c8b9515

Please sign in to comment.