Compare commits
5 Commits
893d360a55
...
61935bd866
Author | SHA1 | Date |
---|---|---|
Lassi Kortela | 61935bd866 | |
Lassi Kortela | 5815921625 | |
Lassi Kortela | 2e8bc1eb35 | |
Lassi Kortela | 4a1a76f45f | |
Lassi Kortela | 43262ccb0e |
89
c/env.c
89
c/env.c
|
@ -10,8 +10,13 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h> // TODO: Unix only
|
||||
extern char **environ; // TODO: Unix only
|
||||
|
||||
#include "scheme.h"
|
||||
|
||||
#define BITSIZEOF(t) (sizeof(t) * CHAR_BIT)
|
||||
|
||||
value_t envst_language(void)
|
||||
{
|
||||
struct accum acc = ACCUM_EMPTY;
|
||||
|
@ -63,13 +68,13 @@ static value_t build_c_type_bits_list(void)
|
|||
struct accum acc;
|
||||
|
||||
accum_init(&acc);
|
||||
accum_name_value1(&acc, "int", fixnum(sizeof(int) * CHAR_BIT));
|
||||
accum_name_value1(&acc, "long", fixnum(sizeof(long) * CHAR_BIT));
|
||||
accum_name_value1(&acc, "float", fixnum(sizeof(float) * CHAR_BIT));
|
||||
accum_name_value1(&acc, "double", fixnum(sizeof(double) * CHAR_BIT));
|
||||
accum_name_value1(&acc, "pointer", fixnum(sizeof(void *) * CHAR_BIT));
|
||||
accum_name_value1(&acc, "size_t", fixnum(sizeof(size_t) * CHAR_BIT));
|
||||
accum_name_value1(&acc, "value_t", fixnum(sizeof(value_t) * CHAR_BIT));
|
||||
accum_name_value1(&acc, "int", fixnum(BITSIZEOF(int)));
|
||||
accum_name_value1(&acc, "long", fixnum(BITSIZEOF(long)));
|
||||
accum_name_value1(&acc, "float", fixnum(BITSIZEOF(float)));
|
||||
accum_name_value1(&acc, "double", fixnum(BITSIZEOF(double)));
|
||||
accum_name_value1(&acc, "pointer", fixnum(BITSIZEOF(void *)));
|
||||
accum_name_value1(&acc, "size_t", fixnum(BITSIZEOF(size_t)));
|
||||
accum_name_value1(&acc, "value_t", fixnum(BITSIZEOF(value_t)));
|
||||
return acc.list;
|
||||
}
|
||||
|
||||
|
@ -233,16 +238,17 @@ value_t get_version_alist(void)
|
|||
accum_name_value1(&acc, "release", string_from_cstr(env_release));
|
||||
accum_name_value1(&acc, "release.date",
|
||||
string_from_cstr(env_release_date));
|
||||
accum_name_value(&acc, "encodings", fl_cons(symbol("utf-8"), FL_NIL));
|
||||
accum_name_value(
|
||||
&acc, "languages",
|
||||
fl_cons(symbol("scheme"), fl_cons(symbol("r7rs"), FL_NIL)));
|
||||
accum_name_value1(&acc, "scheme.id", symbol("upscheme"));
|
||||
accum_name_value(&acc, "scheme.srfi", build_srfi_list());
|
||||
accum_name_value(&acc, "scheme.features", get_features_list());
|
||||
accum_name_value1(&acc, "build.platform",
|
||||
string_from_cstr(get_build_platform()));
|
||||
accum_name_value1(&acc, "build.date",
|
||||
string_from_cstr(env_build_date));
|
||||
accum_name_value1(&acc, "build.platform",
|
||||
string_from_cstr(get_build_platform()));
|
||||
accum_name_value1(&acc, "build.git.branch",
|
||||
string_from_cstr(env_build_git_branch));
|
||||
accum_name_value1(&acc, "build.git.commit",
|
||||
|
@ -356,17 +362,74 @@ value_t builtin_command_line(value_t *args, uint32_t nargs)
|
|||
return fl_cons(cmdname, cmdargs);
|
||||
}
|
||||
|
||||
value_t builtin_os_command_line(value_t *args, uint32_t nargs)
|
||||
//
|
||||
|
||||
value_t builtin_os_current_directory_as_bytevector(value_t *args,
|
||||
uint32_t nargs)
|
||||
{
|
||||
(void)args;
|
||||
argcount("os-command-line", nargs, 0);
|
||||
argcount("os-current-directory-as-bytevector", nargs, 0);
|
||||
return string_from_cstr(getcwd(NULL, 0));
|
||||
}
|
||||
|
||||
value_t builtin_os_environment_variable_as_bytevector(value_t *args,
|
||||
uint32_t nargs)
|
||||
{
|
||||
argcount("os-environment-variable-as-bytevector", nargs, 1);
|
||||
char *name = tostring(args[0], "os-environment-variable-as-bytevector");
|
||||
const char *value = getenv(name);
|
||||
return value ? string_from_cstr(value) : FL_F;
|
||||
}
|
||||
|
||||
value_t builtin_os_environment_variables_as_bytevectors(value_t *args,
|
||||
uint32_t nargs)
|
||||
{
|
||||
char **varp;
|
||||
const char *var;
|
||||
const char *sep;
|
||||
value_t head, tail, newtail;
|
||||
|
||||
(void)args;
|
||||
argcount("os-environment-variables-as-bytevectors", nargs, 0);
|
||||
head = tail = newtail = FL_NIL;
|
||||
fl_gc_handle(&head);
|
||||
fl_gc_handle(&tail);
|
||||
fl_gc_handle(&newtail);
|
||||
head = tail = fl_cons(FL_NIL, FL_NIL);
|
||||
for (varp = environ; (var = *varp); varp++) {
|
||||
if ((sep = strchr(var, '='))) {
|
||||
newtail = fl_cons(string_from_cstrn(var, sep - var),
|
||||
string_from_cstr(sep + 1));
|
||||
} else {
|
||||
newtail = fl_cons(string_from_cstr(var), FL_NIL);
|
||||
}
|
||||
newtail = fl_cons(newtail, FL_NIL);
|
||||
cdr_(tail) = newtail;
|
||||
tail = newtail;
|
||||
}
|
||||
fl_free_gc_handles(3);
|
||||
return cdr_(head);
|
||||
}
|
||||
|
||||
value_t builtin_os_command_line_as_bytevector(value_t *args, uint32_t nargs)
|
||||
{
|
||||
(void)args;
|
||||
argcount("os-command-line-as-bytevector", nargs, 0);
|
||||
return FL_F;
|
||||
}
|
||||
|
||||
value_t builtin_os_command_line_as_bytevectors(value_t *args, uint32_t nargs)
|
||||
{
|
||||
(void)args;
|
||||
argcount("os-command-line-as-bytevectors", nargs, 0);
|
||||
return os_command_line;
|
||||
}
|
||||
|
||||
value_t builtin_os_executable_file(value_t *args, uint32_t nargs)
|
||||
value_t builtin_os_executable_file_as_bytevector(value_t *args,
|
||||
uint32_t nargs)
|
||||
{
|
||||
(void)args;
|
||||
argcount("os-executable-file", nargs, 0);
|
||||
argcount("os-executable-file-as-bytevector", nargs, 0);
|
||||
char buf[512];
|
||||
char *exe = get_exename(buf, sizeof(buf));
|
||||
return exe ? string_from_cstr(exe) : FL_F;
|
||||
|
|
|
@ -68,8 +68,6 @@ static struct builtin_procedure builtin_procedures[] = {
|
|||
{ "command-name", builtin_command_name, UP_2019 },
|
||||
{ "command-args", builtin_command_args, UP_2019 },
|
||||
{ "command-line", builtin_command_line, UP_2019 },
|
||||
{ "os-command-line", builtin_os_command_line, UP_2019 },
|
||||
{ "os-executable-file", builtin_os_executable_file, UP_2019 },
|
||||
|
||||
{ "string?", fl_stringp, SRFI_13 | R7RS_BASE | UP_2019 },
|
||||
{ "string-reverse", fl_string_reverse, SRFI_13 | UP_2019 },
|
||||
|
@ -109,6 +107,19 @@ static struct builtin_procedure builtin_procedures[] = {
|
|||
{ "set-environment-variable", builtin_set_environment_variable,
|
||||
R7RS_PROCESS_CONTEXT | UP_2019 },
|
||||
|
||||
{ "os-current-directory-as-bytevector",
|
||||
builtin_os_current_directory_as_bytevector, UP_2019 },
|
||||
{ "os-environment-variable-as-bytevector",
|
||||
builtin_os_environment_variable_as_bytevector, UP_2019 },
|
||||
{ "os-environment-variables-as-bytevectors",
|
||||
builtin_os_environment_variables_as_bytevectors, UP_2019 },
|
||||
{ "os-command-line-as-bytevector", builtin_os_command_line_as_bytevector,
|
||||
UP_2019 },
|
||||
{ "os-command-line-as-bytevectors",
|
||||
builtin_os_command_line_as_bytevectors, UP_2019 },
|
||||
{ "os-executable-file-as-bytevector",
|
||||
builtin_os_executable_file_as_bytevector, UP_2019 },
|
||||
|
||||
{ "ascii-codepoint?", builtin_ascii_codepoint_p, SRFI_175 | UP_2019 },
|
||||
//{ "ascii-bytevector?", builtin_ascii_bytevector_p, SRFI_175 | UP_2019 },
|
||||
{ "ascii-char?", builtin_ascii_char_p, SRFI_175 | UP_2019 },
|
||||
|
|
7
c/main.c
7
c/main.c
|
@ -220,9 +220,10 @@ static const char **parse_command_line_flags(const char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char **cargv = (const char **)argv;
|
||||
const char **command_line;
|
||||
static const char **cargv;
|
||||
static const char **command_line;
|
||||
|
||||
cargv = (const char **)argv;
|
||||
command_line = parse_command_line_flags(cargv + 1);
|
||||
if (helpflag) {
|
||||
generic_usage(stdout, 0);
|
||||
|
@ -231,7 +232,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
fl_gc_handle(&os_command_line);
|
||||
os_command_line = argv_list(argc, cargv);
|
||||
command_line_offset = (command_line - cargv) / sizeof(*cargv);
|
||||
command_line_offset = command_line - cargv;
|
||||
FL_TRY_EXTERN
|
||||
{
|
||||
if (versionflag) {
|
||||
|
|
|
@ -1015,8 +1015,13 @@ value_t builtin_script_directory(value_t *args, uint32_t nargs);
|
|||
value_t builtin_command_name(value_t *args, uint32_t nargs);
|
||||
value_t builtin_command_args(value_t *args, uint32_t nargs);
|
||||
value_t builtin_command_line(value_t *args, uint32_t nargs);
|
||||
value_t builtin_os_command_line(value_t *args, uint32_t nargs);
|
||||
value_t builtin_os_executable_file(value_t *args, uint32_t nargs);
|
||||
|
||||
value_t builtin_os_current_directory_as_bytevector(value_t *args, uint32_t nargs);
|
||||
value_t builtin_os_environment_variable_as_bytevector(value_t *args, uint32_t nargs);
|
||||
value_t builtin_os_environment_variables_as_bytevectors(value_t *args, uint32_t nargs);
|
||||
value_t builtin_os_command_line_as_bytevector(value_t *args, uint32_t nargs);
|
||||
value_t builtin_os_command_line_as_bytevectors(value_t *args, uint32_t nargs);
|
||||
value_t builtin_os_executable_file_as_bytevector(value_t *args, uint32_t nargs);
|
||||
|
||||
// env_*.c
|
||||
|
||||
|
|
Loading…
Reference in New Issue