From e48d4aab58b103c11860d159ef90f0fb5576a852 Mon Sep 17 00:00:00 2001 From: Ryuichi Ueda Date: Mon, 12 Apr 2021 20:26:22 +0900 Subject: [PATCH] Fix the issue 13 https://github.com/ryuichiueda/GlueLang/issues/13 --- src/Environment.cc | 11 +++++++++++ src/Environment.h | 1 + src/ExeExtCom.cc | 8 +++++++- src/Makefile | 2 +- src/main.cc | 2 +- test/varstring.test | 2 ++ 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Environment.cc b/src/Environment.cc index 6d6e2e5..f7b4587 100644 --- a/src/Environment.cc +++ b/src/Environment.cc @@ -116,6 +116,17 @@ vector *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(); diff --git a/src/Environment.h b/src/Environment.h index ec8e0e4..776bfdd 100644 --- a/src/Environment.h +++ b/src/Environment.h @@ -43,6 +43,7 @@ class Environment void setImportPath(string *key, string *value); vector *getImportPaths(string *key); vector *getImportPaths(const char *key); + string getImportPaths(void); bool isImportPath(string *key); void removeFiles(void); diff --git a/src/ExeExtCom.cc b/src/ExeExtCom.cc index 4028357..4f4c7d4 100644 --- a/src/ExeExtCom.cc +++ b/src/ExeExtCom.cc @@ -17,6 +17,7 @@ #include #include #include "Feeder.h" +#include "string.h" using namespace std; ExeExtCom::ExeExtCom(Feeder *f, Environment *env, vector *scopes) : Exe(f,env,scopes) @@ -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::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); } diff --git a/src/Makefile b/src/Makefile index 0cd9b38..13ff9f5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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) diff --git a/src/main.cc b/src/main.cc index 67b6dac..1e33bcb 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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; diff --git a/test/varstring.test b/test/varstring.test index 2cc0c16..e47cd4c 100755 --- a/test/varstring.test +++ b/test/varstring.test @@ -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