Skip to content

Commit

Permalink
Remove CALIAS environmental variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ParfenovIgor committed Jan 6, 2025
1 parent c2bb4fc commit 3457c8e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions compiler/include/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <process.h>
#include <settings.h>

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*);
1 change: 0 additions & 1 deletion compiler/include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
3 changes: 2 additions & 1 deletion compiler/src/languageserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <posix.h>
#include <httpd.h>
#include <lexer.h>
#include <process.h>
#include <string.h>

const char *check_errors(const char *payload, struct Settings *settings) {
Expand Down Expand Up @@ -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]);
Expand Down
5 changes: 0 additions & 5 deletions compiler/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
}
Expand Down
40 changes: 20 additions & 20 deletions compiler/src/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@
#include <stdio.h>
#include <string.h>

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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 3457c8e

Please sign in to comment.