Skip to content

Commit 5a59e8d

Browse files
author
Giloo
committed
to correctly use DLM; <IDL_XX> default values must be correctly handled. So a dozen of files had to be changed.
1 parent a47a75a commit 5a59e8d

File tree

8 files changed

+108
-39
lines changed

8 files changed

+108
-39
lines changed

src/file.cpp

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@
9999
# define GLOB_PERIOD 0
100100
#endif
101101

102+
#include <iostream>
103+
#include <string>
104+
#include <algorithm>
105+
#include <iterator>
106+
#include <sstream>
107+
108+
inline std::string replaceAllOccurencesOfDefaultTokens(const std::string& s, const std::string& f, const std::string& r) {
109+
if (s.empty() || f.empty() || f == r || f.size() > s.size() || s.find(f) == std::string::npos) {
110+
return s;
111+
}
112+
std::ostringstream build_it;
113+
typedef std::string::const_iterator iter;
114+
iter i(s.begin());
115+
const iter::difference_type f_size(std::distance(f.begin(), f.end()));
116+
for (iter pos; (pos = search(i, s.end(), f.begin(), f.end())) != s.end();) {
117+
copy(i, pos, std::ostreambuf_iterator<char>(build_it));
118+
copy(r.begin(), r.end(), std::ostreambuf_iterator<char>(build_it));
119+
std::advance(pos, f_size);
120+
i = pos;
121+
}
122+
copy(i, s.end(), std::ostreambuf_iterator<char>(build_it));
123+
return build_it.str();
124+
}
125+
102126
#ifdef _MSC_VER
103127

104128
/*
@@ -584,14 +608,7 @@ static void ExpandPathN( FileListT& result,
584608

585609
if( dirN == "")
586610
return;
587-
588-
if( StrUpCase( dirN) == "<GDL_DEFAULT>" ||
589-
StrUpCase( dirN) == "<IDL_DEFAULT>")
590-
{
591-
// result.push_back( the default path here);
592-
return;
593-
}
594-
611+
595612
if( dirN[0] != '+' && dirN[0] != '~')
596613
{
597614
result.push_back( dirN);
@@ -649,26 +666,55 @@ static void ExpandPathN( FileListT& result,
649666
{
650667
e->NParam( 1);
651668

652-
DString pathString;
653-
e->AssureStringScalarPar( 0, pathString);
654-
WordExp(pathString);
655-
FileListT sArr;
656-
669+
int specialization=0;
670+
DString pattern = "*.pro";
657671

658-
static int all_dirsIx = e->KeywordIx( "ALL_DIRS");
659-
bool all_dirs = e->KeywordSet( all_dirsIx);
672+
static int all_dirsIx = e->KeywordIx("ALL_DIRS");
673+
bool all_dirs = e->KeywordSet(all_dirsIx);
660674

661-
static int arrayIx = e->KeywordIx( "ARRAY");
662-
bool array = e->KeywordSet( arrayIx);
675+
static int arrayIx = e->KeywordIx("ARRAY");
676+
bool array = e->KeywordSet(arrayIx);
663677

664-
static int countIx = e->KeywordIx( "COUNT");
678+
static int countIx = e->KeywordIx("COUNT");
665679

666-
DString pattern;
667-
static int typeIx = e->KeywordIx( "PATTERN");
668-
if(e->KeywordPresent(typeIx)) {
669-
e->AssureStringScalarKWIfPresent( typeIx, pattern);
680+
static int dlmtypeIx = e->KeywordIx("DLM");
681+
if (e->KeywordPresent(dlmtypeIx)) specialization=1;
682+
static int hlptypeIx = e->KeywordIx("HELP");
683+
if (e->KeywordPresent(hlptypeIx)) specialization=2;
684+
685+
DString pathString;
686+
e->AssureStringScalarPar(0, pathString);
687+
688+
// complex treatment of embedded "<IDL_XXX>" strings. Note that there is NO "<GDL_XXX>" equivalents, they are NOT NEEDED.
689+
if (pathString.find("<", 0) != std::string::npos) {
690+
if (pathString.find("<IDL_DEFAULT_PATH", 0) != std::string::npos) {
691+
pathString = replaceAllOccurencesOfDefaultTokens(pathString, "<IDL_DEFAULT_PATH>", gdl_default_path);
692+
pattern = "*.pro"; //in fact, should be "([^\\s]+(\\.(?i)(pro|sav))$)"
693+
} else if (pathString.find("<IDL_DEFAULT_DLM", 0) != std::string::npos) {
694+
pathString = replaceAllOccurencesOfDefaultTokens(pathString, "<IDL_DEFAULT_DLM>", gdl_default_dlm);
695+
pattern = "*.dlm";
696+
all_dirs=true; //DLM search use implicitely ALL_DIRS
697+
} else if (pathString.find("<IDL_DEFAULT_HELP", 0) != std::string::npos) {
698+
pathString = replaceAllOccurencesOfDefaultTokens(pathString, "<IDL_DEFAULT_HELP>", gdl_default_help);
699+
pattern = "*.*"; //should be "([^\\s]+(\\.(?i)(pdf|html|chm))$)"
700+
} else if (pathString.find("<IDL_DEFAULT>", 0) != std::string::npos) {
701+
switch (specialization) {
702+
case 0: pathString = replaceAllOccurencesOfDefaultTokens(pathString, "<IDL_DEFAULT>", gdl_default_path);
703+
pattern = "*.pro"; //in fact, should be "([^\\s]+(\\.(?i)(pro|sav))$)"
704+
break;
705+
case 1: pathString = replaceAllOccurencesOfDefaultTokens(pathString, "<IDL_DEFAULT>", gdl_default_dlm);
706+
pattern = "*.dlm";
707+
break;
708+
case 2: pathString = replaceAllOccurencesOfDefaultTokens(pathString, "<IDL_DEFAULT>", gdl_default_help);
709+
pattern = "*.*"; //should be "([^\\s]+(\\.(?i)(pdf|html|chm))$)"
710+
break;
711+
}
712+
}
670713
}
671-
else pattern = "*.pro";
714+
715+
// normal expand follows
716+
WordExp(pathString);
717+
FileListT sArr;
672718

673719
SizeT d;
674720
long sPos=0;

src/file.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#ifndef FILE_HPP_
1919
#define FILE_HPP_
2020
#include "dinterpreter.hpp"
21+
22+
std::string replaceAllOccurencesOfDefaultTokens(const std::string& s, const std::string& f, const std::string& r);
23+
2124
namespace lib {
2225
// library functions
2326
BaseGDL* file_test( EnvT* e);

src/gdl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,12 @@ int main(int argc, char *argv[])
598598
}
599599
}
600600
#endif // USE_MPI
601+
602+
//always between try{} catch{} when calling ExecuteStringLine!
601603
try {
602604
std::string dlmCommand=("dlm_register,/silent");
603605
interpreter.ExecuteStringLine(dlmCommand);
604606
} catch (...) {std::cerr<<"Problem starting DLMs\n";}
605-
// interpreter.ExecuteFile( gdlDataDir+"/dlm/getDlm.pro");
606607
interpreter.InterpreterLoop( startup, batch_files, statement);
607608

608609
return 0;

src/initsysvar.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace SysVar
8888
// return var == sysVarList[ dIx];
8989
// }
9090

91-
void SetGDLPath( const DString& newPath)
91+
void SetGDLPath( DString& newPath)
9292
{
9393
FileListT sArr;
9494
SizeT d;
@@ -97,8 +97,11 @@ namespace SysVar
9797
{
9898
d=newPath.find(lib::SearchPathSeparator(),sPos);
9999
string act = newPath.substr(sPos,d-sPos);
100+
101+
if (newPath.find("<IDL_DEFAULT_PATH", 0) != std::string::npos) newPath = replaceAllOccurencesOfDefaultTokens(newPath, "<IDL_DEFAULT_PATH>", gdl_default_path);
102+
if (newPath.find("<IDL_DEFAULT", 0) != std::string::npos) newPath = replaceAllOccurencesOfDefaultTokens(newPath, "<IDL_DEFAULT>", gdl_default_path);
100103

101-
lib::ExpandPath( sArr, act, "*.pro");
104+
lib::ExpandPath( sArr, act, "*.pro"); //indeed, !PATH contains only directories where a .pro is found
102105

103106
sPos=d+1;
104107
}
@@ -119,7 +122,8 @@ namespace SysVar
119122
// GJ version for( SizeT i=1; i<nArr; ++i)
120123
// GJ version path += pathsep + sArr[nArr-i-1];
121124
}
122-
void SetDlmPath( const DString& newPath)
125+
126+
void SetDlmPath( DString& newPath)
123127
{
124128
FileListT sArr;
125129
SizeT d;
@@ -128,8 +132,9 @@ namespace SysVar
128132
{
129133
d=newPath.find(lib::SearchPathSeparator(),sPos);
130134
string act = newPath.substr(sPos,d-sPos);
131-
132-
lib::ExpandPath( sArr, act, "*.dlm");
135+
136+
if (newPath.find("<IDL_DEFAULT_DLM", 0) != std::string::npos) newPath = replaceAllOccurencesOfDefaultTokens(newPath, "<IDL_DEFAULT_DLM>", gdl_default_dlm);
137+
lib::ExpandPath( sArr, act, "*.dlm", true); //ALL_DIRS since DLM_PATH contains all dirs, not only those with a valid .dlm
133138

134139
sPos=d+1;
135140
}

src/initsysvar.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ namespace SysVar
2525
DFloat* GetSC();
2626
// returns a StrArr with the path to search
2727
const StrArr& GDLPath();
28-
void SetGDLPath( const DString& newPath);
29-
void SetDlmPath( const DString& newPath);
28+
void SetGDLPath( DString& newPath);
29+
void SetDlmPath( DString& newPath);
3030

3131
// returns !P
3232
DStructGDL* P();

src/libinit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void LibInit()
210210
const string file_readlinkKey[]={"ALLOW_NONEXISTENT","ALLOW_NONSYMLINK","NOEXPAND_PATH",KLISTEND};
211211
new DLibFunRetNew(lib::file_readlink,string("FILE_READLINK"),1,file_readlinkKey);
212212

213-
const string expand_pathKey[]={"ARRAY","ALL_DIRS","COUNT","PATTERN",KLISTEND};
213+
const string expand_pathKey[]={"ARRAY","ALL_DIRS","COUNT","DLM","HELP",KLISTEND}; // ,"PATTERN" not in IDL doc
214214
new DLibFunRetNew(lib::expand_path,string("EXPAND_PATH"),1,expand_pathKey);
215215

216216
const string strjoinKey[]={"SINGLE",KLISTEND};

src/objects.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ antlr::ASTFactory DNodeFactory("DNode",DNode::factory);
103103

104104
//this string contains the value of DATADIR
105105
std::string gdlDataDir;
106+
//this string contains the value of <IDL_DEFAULT_PATH> that defines the default path to .pro and .sav files.
107+
std::string gdl_default_path;
108+
//this string contains the value of <IDL_DEFAULT_DLM> that defines the default path to .dlm files.
109+
std::string gdl_default_dlm;//do we use WxWidgets at all?
110+
//this string contains the value of <IDL_DEFAULT_HELP> that defines the default path to help files.
111+
std::string gdl_default_help;
112+
106113
//do we use WxWidgets at all?
107114
volatile bool useWxWidgets;
108115
//do we use WxWidgets for graphics?
@@ -938,19 +945,20 @@ void InitObjects()
938945
// We need to initialize the multi-device object that inherits from the single-device object.
939946
GraphicsMultiDevice::Init();
940947

948+
//default Path is gdl_default_path, i.e.:
949+
gdl_default_path= "+" + gdlDataDir + lib::PathSeparator() + "lib";
941950
string gdlPath=GetEnvPathString("GDL_PATH");
942951
if( gdlPath == "") gdlPath=GetEnvPathString("IDL_PATH");
943-
if( gdlPath == "") {
944-
gdlPath = "+" + gdlDataDir + lib::PathSeparator() + "lib";
945-
}
952+
if( gdlPath == "") gdlPath = gdl_default_path;
946953
SysVar::SetGDLPath( gdlPath);
947954

955+
gdl_default_dlm= "+" + gdlDataDir + lib::PathSeparator() + "dlm";
948956
string dlmgdlPath=GetEnvPathString("GDL_DLM_PATH");
949957
if( dlmgdlPath == "") dlmgdlPath=GetEnvPathString("IDL_DLM_PATH");
950-
if( dlmgdlPath == "") {
951-
dlmgdlPath = gdlDataDir + lib::PathSeparator() + "dlm";
952-
}
958+
if( dlmgdlPath == "") dlmgdlPath = gdl_default_dlm;
953959
SysVar::SetDlmPath( dlmgdlPath);
960+
961+
gdl_default_help = "";
954962
}
955963

956964
// returns GDL lun, 0 on failure

src/objects.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ extern volatile bool sigControlC;
7575

7676
//this string contains the value of DATADIR
7777
extern std::string gdlDataDir;
78+
//this string contains the value of <IDL_DEFAULT_PATH> that defines the default path to .pro and .sav files.
79+
extern std::string gdl_default_path;
80+
//this string contains the value of <IDL_DEFAULT_DLM> that defines the default path to .dlm files.
81+
extern std::string gdl_default_dlm;//do we use WxWidgets at all?
82+
//this string contains the value of <IDL_DEFAULT_HELP> that defines the default path to help files.
83+
extern std::string gdl_default_help;
7884

7985
extern volatile bool iAmANotebook;
8086

@@ -83,7 +89,7 @@ extern std::string whereami_gdl;
8389
extern volatile bool iAmMaster;
8490
extern volatile bool signalOnCommandReturn;
8591

86-
// tells if wxwidgets is to be used at all...
92+
//do we use WxWidgets at all?
8793
extern volatile bool useWxWidgets;
8894
// tells if wxwidgets backend for graphics is to be used...
8995
extern volatile bool useWxWidgetsForGraphics;

0 commit comments

Comments
 (0)