From 3457c8ecf147185548691727b7e607615f1fdc07 Mon Sep 17 00:00:00 2001 From: Igor Parfenov Date: Mon, 6 Jan 2025 22:27:47 +0300 Subject: [PATCH] Remove CALIAS environmental variable --- README.md | 3 +-- compiler/include/process.h | 1 + compiler/include/settings.h | 1 - compiler/src/languageserver.c | 3 ++- compiler/src/main.c | 5 ----- compiler/src/process.c | 40 +++++++++++++++++------------------ 6 files changed, 24 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index b5074b9..0e8380f 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,8 @@ Build options: * `make test` - build the compiler and altlib, run tests except performance tests. * `make perftest` - build the compiler and altlib, run performance tests. -For further usage preferably add two new environmental variables: +For further usage preferably add a new environmental variable: - * `CALIAS` - **absolute** path to `build/calias` * `ALTLIB` - **absolute** path to `build/altlib_ext` ## flakes.nix diff --git a/compiler/include/process.h b/compiler/include/process.h index c0aad92..a8b193a 100644 --- a/compiler/include/process.h +++ b/compiler/include/process.h @@ -4,6 +4,7 @@ #include #include +int _execvp(const char *filename, const char *const argv[], const char *const envp[], const char *path); struct Node *process_parse(const char*, struct Settings*); struct Node *process_parse_fd(int, struct Settings*); int process(struct Settings*); diff --git a/compiler/include/settings.h b/compiler/include/settings.h index 52a4226..6c36d52 100644 --- a/compiler/include/settings.h +++ b/compiler/include/settings.h @@ -15,7 +15,6 @@ struct Settings { const char *filename_input; const char *filename_output; const char *filename_compile_output; - const char *calias_directory; const char *path_variable; struct Vector included_files; }; diff --git a/compiler/src/languageserver.c b/compiler/src/languageserver.c index 1eaad75..15e6181 100644 --- a/compiler/src/languageserver.c +++ b/compiler/src/languageserver.c @@ -2,6 +2,7 @@ #include #include #include +#include #include const char *check_errors(const char *payload, struct Settings *settings) { @@ -29,7 +30,7 @@ const char *check_errors(const char *payload, struct Settings *settings) { if (pid == 0) { posix_dup2(fd[1], STDERR); posix_close(STDOUT); - posix_execve(settings->calias_directory, (const char *const*)argv, 0); + _execvp("calias", (const char *const*)argv, 0, settings->path_variable); } posix_wait4(pid, 0, 0, 0); posix_close(fd[1]); diff --git a/compiler/src/main.c b/compiler/src/main.c index 73013b4..8322949 100644 --- a/compiler/src/main.c +++ b/compiler/src/main.c @@ -31,7 +31,6 @@ struct Settings *build_settings(int argc, char **argv, char **envp) { settings->filename_input = NULL; settings->filename_output = NULL; settings->filename_compile_output = NULL; - settings->calias_directory = _strdup(argv[0]); settings->path_variable = ""; for (int i = 1; i < argc; i++) { @@ -87,10 +86,6 @@ struct Settings *build_settings(int argc, char **argv, char **envp) { } } if (delim == -1) continue; - if (_strncmp(str, "CALIAS", delim) == 0) { - _free((void*)settings->calias_directory); - settings->calias_directory = _strdup(str + delim + 1); - } if (_strncmp(str, "PATH", delim) == 0) { settings->path_variable = _strdup(str + delim + 1); } diff --git a/compiler/src/process.c b/compiler/src/process.c index 959b26d..c9cbc3f 100644 --- a/compiler/src/process.c +++ b/compiler/src/process.c @@ -9,6 +9,26 @@ #include #include +int _execvp(const char *filename, const char *const argv[], const char *const envp[], const char *path) { + int n = _strlen(path); + char full_path[1024]; + for (int l = 0; l < n;) { + int r = l; + while (r + 1 < n && path[r + 1] != ':') r++; + + int x = r - l + 1; + _strncpy(full_path, path + l, x); + full_path[x] = '/'; + _strcpy(full_path + x + 1, filename); + + posix_execve(full_path, argv, envp); + + l = r + 2; + } + + return -1; +} + struct Node *process_parse(const char *filename, struct Settings *settings) { char *buffer = read_file(filename); if (!buffer) { @@ -30,26 +50,6 @@ struct Node *process_parse_fd(int fd, struct Settings *settings) { return node; } -int _execvp(const char *filename, const char *const argv[], const char *const envp[], const char *path) { - int n = _strlen(path); - char full_path[1024]; - for (int l = 0; l < n;) { - int r = l; - while (r + 1 < n && path[r + 1] != ':') r++; - - int x = r - l + 1; - _strncpy(full_path, path + l, x); - full_path[x] = '/'; - _strcpy(full_path + x + 1, filename); - - posix_execve(full_path, argv, envp); - - l = r + 2; - } - - return -1; -} - void process_assemble(const char *input, const char *output, struct Settings *settings) { int pid = posix_fork(); if (pid == 0) {