diff -N -r -u -b boost_1_34_0/tools/jam/src/execamiga.c boost_1_34_0_amiga/tools/jam/src/execamiga.c --- boost_1_34_0/tools/jam/src/execamiga.c 2114-02-06 23:28:16 +++ boost_1_34_0_amiga/tools/jam/src/execamiga.c 2007-06-02 08:16:12 @@ -0,0 +1,204 @@ +/* + * This file is part of Jam - see jam.c for Copyright information. + */ + +#include "jam.h" + +#if defined(OS_AMIGA) + +#include "lists.h" +#include "execcmd.h" +#include "patchlevel.h" + +#include +#include + +#include +#include + +#include +#include +#include + +#define MAX_ENV_SIZE 1024 /* maximum number of environ entries */ + + +/* clib2 specific controls */ +int __minimum_os_lib_version = 52; +char * __minimum_os_lib_error = "Requires AmigaOS 4.0"; +BOOL __open_locale = FALSE; +BOOL __disable_dos_requesters = TRUE; + + +static const char* version __attribute__((used)) = + "$VER: bjam "VERSION"-1 (2.6.2007)"; /* dd.mm.yyyy */ + + +/* + * execamiga.c - execute a shell script + * + * Uses the abc-shell to execute all commands synchronously. + */ +void execcmd +( + char *string, + void (*func)(void *closure, int status, timing_info*), + void *closure, + LIST *shell +) +{ + timing_info time = {0, 0}; + + static char tmpbuf[128]; + tmpbuf[0] = '\0'; + strlcpy(tmpbuf, "/t/bjamXXXXXX", sizeof(tmpbuf)); + + int fd = mkstemp(tmpbuf); + if ( fd == -1 ) + { + printf("can't open command file\n"); + (*func)(closure, EXEC_CMD_FAIL, &time); + return; + } + + int len = strlen(string); + if ( write(fd, string, len) != len ) + { + printf("can't write command file\n"); + (*func)(closure, EXEC_CMD_FAIL, &time); + unlink(tmpbuf); + close(fd); + return; + } + + static char cmdbuf[128]; + cmdbuf[0] = '\0'; + snprintf(cmdbuf, sizeof(cmdbuf), "/sdk/c/sh %s", tmpbuf); + + if ( DEBUG_EXECCMD ) + { + printf("string = '%s'\n", string); + printf("cmdbuf = '%s'\n", cmdbuf); + } + + int status = system(cmdbuf); + + unlink(tmpbuf); + close(fd); + + if ( status == 0 ) + { + (*func)(closure, EXEC_CMD_OK, &time); + } + else + { + (*func)(closure, EXEC_CMD_FAIL, &time); + } +} + + +int execwait() +{ + return 0; +} + + +/* + * environ - AmigaOS environment support + * + * The following code implements environ support for AmigaOS. + */ +void make_environ() __attribute__((constructor)); +void free_environ() __attribute__((destructor)); + +char **environ = NULL; + + +int is_ascii_string(char* str) +{ + while ( *str != '\0' ) + { + if ( !isascii(*str) ) + { + return 0; + } + + ++str; + } + + return 1; +} + + +uint32 copy_env(struct Hook *hook, APTR data, struct ScanVarsMsg *msg) +{ + static uint32 env_size = 1; /* environ is null terminated */ + + if ( env_size == MAX_ENV_SIZE ) + { + return 0; + } + + if ( msg->sv_Name == 0 || + msg->sv_Var == 0 || + strlen(msg->sv_GDir) > 4 || /* excludes ENVARC: sub-directories */ + !is_ascii_string(msg->sv_Name) || + !is_ascii_string(msg->sv_Var) || + strstr(msg->sv_Name, ".prefs") != 0 || + strstr(msg->sv_Name, ".xml") != 0 || + strstr(msg->sv_Name, ".cfg") != 0 ) + + { + return 0; + } + + uint32 var_size = strlen(msg->sv_Name) + 1 + msg->sv_VarLen + 1; + char* var_buf = malloc(var_size); + if ( var_buf == 0 ) + { + return 0; + } + + snprintf(var_buf, var_size, "%s=%s", msg->sv_Name, msg->sv_Var); + + char **env = hook->h_Data; + env[env_size - 1] = var_buf; + ++env_size; + + return 0; +} + + +void make_environ() +{ + size_t environ_size = MAX_ENV_SIZE * sizeof(char*); + + environ = (char**)malloc(environ_size); + if ( environ == 0 ) + { + return; + } + + memset(environ, 0, environ_size); + + struct Hook hook; + memset(&hook, 0, sizeof(struct Hook)); + hook.h_Entry = copy_env; + hook.h_Data = environ; + (void) IDOS->ScanVars(&hook, 0, 0); +} + + +void free_environ() +{ + char **i; + for ( i = environ; *i != 0; ++i ) + { + free(*i); + } + + free(environ); +} + + +#endif