Skip to content

Commit

Permalink
Fix the issue 13
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Apr 12, 2021
1 parent 5df1b6d commit e48d4aa
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ vector<string> *Environment::getImportPaths(const char *key)
return getImportPaths(&tmp);
}

string Environment::getImportPaths(void)
{
string ans = "PATH=";
for (const auto& [key, paths] : m_import_paths){
for(auto &s : paths)
ans += s + ":";
}
ans.pop_back();
return ans;
}

bool Environment::isImportPath(string *key)
{
return m_import_paths.find(*key) != m_import_paths.end();
Expand Down
1 change: 1 addition & 0 deletions src/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Environment
void setImportPath(string *key, string *value);
vector<string> *getImportPaths(string *key);
vector<string> *getImportPaths(const char *key);
string getImportPaths(void);
bool isImportPath(string *key);

void removeFiles(void);
Expand Down
8 changes: 7 additions & 1 deletion src/ExeExtCom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <fcntl.h>
#include <signal.h>
#include "Feeder.h"
#include "string.h"
using namespace std;

ExeExtCom::ExeExtCom(Feeder *f, Environment *env, vector<int> *scopes) : Exe(f,env,scopes)
Expand Down Expand Up @@ -49,8 +50,13 @@ void ExeExtCom::execChild(DefFile *f, DefFile *ef, DefStr *s)
vOptProc(argv[0]);
char *str = getenv("PATH");
auto env = new const char* [2];
env[0] = str;
//extern char **environ;
string path = m_env->getImportPaths();
char *tmp = new char[path.size() + 1];
char_traits<char>::copy(tmp, path.c_str(), path.size() + 1);
env[0] = (const char *)tmp;
env[1] = NULL;
execve(argv[0],(char **)argv,(char **)env);
//execve(argv[0],(char **)argv, environ);
}

2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CXX = g++
TARGET = glue
BINDIR = /usr/local/bin
CXXFLAGS = -Wall -O2 --static -std=c++14
CXXFLAGS = -Wall -O2 --static -std=c++17
LDFLAGS = -lm
SRCS := $(wildcard *.cc)
OBJS := $(SRCS:.cc=.o)
Expand Down
2 changes: 1 addition & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int scriptPos(int argc, char const* argv[])

void version(void)
{
cerr << "GlueLang v0.2.4 🌸🌸\n\n"
cerr << "GlueLang v0.2.5 🌸🌸🌸\n\n"
<< "Copyright (C) 2021 Ryuichi Ueda\n"
<< "Released under the MIT License.\n"
<< "https://github.com/ryuichiueda/GlueLang" << endl;
Expand Down
2 changes: 2 additions & 0 deletions test/varstring.test
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ cat << FIN > $tmp-out
FIN

cat << FIN > $tmp-glue
import PATH
str tmp = /usr/bin/seq '1' '3' >>= /usr/bin/xargs
/bin/echo tmp
/bin/echo tmp
Expand Down

0 comments on commit e48d4aa

Please sign in to comment.