From 296aa8dfb529916b1142ad4baa4f90c945463ef0 Mon Sep 17 00:00:00 2001 From: Sven-Bodo Scholz Date: Wed, 21 Jan 2026 12:23:25 +0100 Subject: [PATCH 01/29] fixed Math.sac for sac_int --- src/CMakeLists.txt | 2 ++ src/numerical/Math.sac | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 76aee095..5b895ec9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -309,6 +309,8 @@ SET (C_DEPS_SRC numerical/src/Math/int_log.c numerical/src/Math/sign.c numerical/src/Math/isnan.c + numerical/src/Math/frexp.c + numerical/src/Math/ldexp.c numerical/src/Math/isinf.c numerical/src/Math/isfinite.c random/src/Xoshiro.c diff --git a/src/numerical/Math.sac b/src/numerical/Math.sac index 12fe7f97..80e074dd 100644 --- a/src/numerical/Math.sac +++ b/src/numerical/Math.sac @@ -160,20 +160,26 @@ external float exp(float X); external double, int frexp(double X); #pragma linksign [0,2,1] + #pragma linkname "SAC_MATH_frexp" + #pragma linkobj "src/Math/frexp.o" #pragma header "" external float, int frexp(float X); #pragma linksign [0,2,1] - #pragma linkname "frexpf" + #pragma linkname "SAC_MATH_frexpf" + #pragma linkobj "src/Math/frexp.o" #pragma header "" external double ldexp(double X, int EXP); #pragma linksign [0,1,2] + #pragma linkname "SAC_MATH_ldexp" + #pragma linkobj "src/Math/ldexp.o" #pragma header "" external float ldexp(float X, int EXP); #pragma linksign [0,1,2] - #pragma linkname "ldexpf" + #pragma linkname "SAC_MATH_ldexpf" + #pragma linkobj "src/Math/ldexp.o" #pragma header "" external double log(double X); From 07c9faf0f8c18efa4a2ef7724e819a25d8b93231 Mon Sep 17 00:00:00 2001 From: Sven-Bodo Scholz Date: Wed, 21 Jan 2026 12:38:16 +0100 Subject: [PATCH 02/29] missing C implementations --- src/numerical/src/Math/frexp.c | 29 +++++++++++++++++++++++++++++ src/numerical/src/Math/ldexp.c | 15 +++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/numerical/src/Math/frexp.c create mode 100644 src/numerical/src/Math/ldexp.c diff --git a/src/numerical/src/Math/frexp.c b/src/numerical/src/Math/frexp.c new file mode 100644 index 00000000..17fc003e --- /dev/null +++ b/src/numerical/src/Math/frexp.c @@ -0,0 +1,29 @@ +/** + * Dealing with sac_int arguments. + */ +#include +#include "sacinterface.h" + +double SAC_MATH_frexp( double val, sac_int *exp) +{ + int ex; + double res; + + res = frexp (val, &ex); + + *exp = (sac_int)ex; + + return res; +} + +float SAC_MATH_frexpf( float val, sac_int *exp) +{ + int ex; + float res; + + res = frexpf (val, &ex); + + *exp = (sac_int)ex; + + return res; +} diff --git a/src/numerical/src/Math/ldexp.c b/src/numerical/src/Math/ldexp.c new file mode 100644 index 00000000..2fb9f36a --- /dev/null +++ b/src/numerical/src/Math/ldexp.c @@ -0,0 +1,15 @@ +/** + * Dealing with sac_int arguments. + */ +#include +#include "sacinterface.h" + +double SAC_MATH_ldexp( double val, sac_int exp) +{ + return ldexp (val, (int)exp); +} + +float SAC_MATH_ldexpf( float val, sac_int exp) +{ + return ldexpf (val, (int)exp); +} From 4fec4a82aa866b085e8aa4ae8c32f5add2830172 Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 15:09:17 +0100 Subject: [PATCH 03/29] Update environment --- src/system/src/Environment/Environ.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/system/src/Environment/Environ.c b/src/system/src/Environment/Environ.c index c342b594..57bcca39 100644 --- a/src/system/src/Environment/Environ.c +++ b/src/system/src/Environment/Environ.c @@ -5,9 +5,9 @@ extern char **environ; -int EnvCount( void) +sac_int EnvCount( void) { - int i = 0; + sac_int i = 0; if (environ) { while (environ[i]) { @@ -18,10 +18,10 @@ int EnvCount( void) return i; } -char* IndexEnv( int i) +char* IndexEnv( sac_int i) { char* res; - int k = 0; + sac_int k = 0; if (environ) { while (k < i && environ[k]) { From d5b1a20b535dad54ad8f4a018d88e0c4727695ae Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 15:48:58 +0100 Subject: [PATCH 04/29] Modify file system --- src/system/src/FileSystem/access.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/system/src/FileSystem/access.c b/src/system/src/FileSystem/access.c index 37ed5eb7..d27df4ce 100644 --- a/src/system/src/FileSystem/access.c +++ b/src/system/src/FileSystem/access.c @@ -12,8 +12,9 @@ -int SACaccess(int *success, char *name, int how) +int SACaccess(int *success, char *name, sac_int how_in) { + int how = (int)how_in; int result, mode; switch (how) From ee3718134bac854ea3cd1d66fc0721dfb7422a50 Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 16:03:27 +0100 Subject: [PATCH 05/29] ComplexIO --- src/stdio/src/ComplexIO/PrintComplexArray.c | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/stdio/src/ComplexIO/PrintComplexArray.c b/src/stdio/src/ComplexIO/PrintComplexArray.c index 3bc29f13..d07d3018 100644 --- a/src/stdio/src/ComplexIO/PrintComplexArray.c +++ b/src/stdio/src/ComplexIO/PrintComplexArray.c @@ -7,7 +7,7 @@ #include #include -#include "sac.h" +#include "sacinterface.h" #define COMPLEX 1 @@ -15,11 +15,11 @@ typedef char* string; typedef double complex[2]; static -int Index2Offset( int dim, int *shp, int *index) +sac_int Index2Offset( sac_int dim, sac_int *shp, sac_int *index) { - int i,n; - int offset=0; - int fact; + sac_int i,n; + sac_int offset=0; + sac_int fact; for (i=0; i\n"); } else { - index = SAC_MALLOC(dim * sizeof(int)); + index = SAC_MALLOC(dim * sizeof(sac_int)); for (i=0; i Date: Wed, 21 Jan 2026 18:03:35 +0100 Subject: [PATCH 06/29] no sac_int needed, use long to avoid cast altogether --- src/system/RTimer.sac | 4 ++-- src/system/src/RTimer/rtimer.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/system/RTimer.sac b/src/system/RTimer.sac index cbc10b2f..b7905500 100644 --- a/src/system/RTimer.sac +++ b/src/system/RTimer.sac @@ -32,9 +32,9 @@ external void resetRTimer(RTimer &rtimer); #pragma linkobj "src/RTimer/rtimer.o" #pragma linkname "SAC_RTimer_resetRTimer" -external int, int getRTimerInts(RTimer &rtimer); +external long, long getRTimerLong(RTimer &rtimer); #pragma linkobj "src/RTimer/rtimer.o" - #pragma linkname "SAC_RTimer_getRTimerInts" + #pragma linkname "SAC_RTimer_getRTimerLong" #pragma linksign [2,3,1] external double getRTimerDbl(RTimer &rtimer); diff --git a/src/system/src/RTimer/rtimer.c b/src/system/src/RTimer/rtimer.c index 58147284..59f984b8 100644 --- a/src/system/src/RTimer/rtimer.c +++ b/src/system/src/RTimer/rtimer.c @@ -99,10 +99,10 @@ void SAC_RTimer_resetRTimer( struct rtimer *timer) } } -void SAC_RTimer_getRTimerInts(struct rtimer *timer, int *sec, int *nsec) +void SAC_RTimer_getRTimerLong(struct rtimer *timer, long *sec, long *nsec) { - *sec = (int)(timer->elapsed.tv_sec); - *nsec = (int)(timer->elapsed.tv_nsec); + *sec = timer->elapsed.tv_sec; + *nsec = timer->elapsed.tv_nsec; } double SAC_RTimer_getRTimerDbl(struct rtimer *timer) From ee75643933bfba8499c4edabad85e4fc11ae9ef0 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 18:30:56 +0100 Subject: [PATCH 07/29] sac_int in cmdline --- src/system/src/CommandLine/CommandLine.c | 134 ++++++++--------------- 1 file changed, 47 insertions(+), 87 deletions(-) diff --git a/src/system/src/CommandLine/CommandLine.c b/src/system/src/CommandLine/CommandLine.c index e52f52f8..a34771a2 100644 --- a/src/system/src/CommandLine/CommandLine.c +++ b/src/system/src/CommandLine/CommandLine.c @@ -2,108 +2,68 @@ * Implementation of external standard class CommandLine. */ - #include #include "sac.h" +#include "sacinterface.h" - -/*****************************************************/ - - -typedef struct COMLINE -{ - int argc; - char **argv; -} -ComLine; - - -/*****************************************************/ - +typedef struct COMLINE { + sac_int argc; + char **argv; +} ComLine; extern ComLine *SACo_CommandLine__TheCommandLine; - -/*****************************************************/ - - -ComLine *create_TheCommandLine( void) +ComLine *create_TheCommandLine(void) { - ComLine *parameters; - - parameters=(ComLine *)SAC_MALLOC(sizeof(ComLine)); - - SAC_COMMANDLINE_GET( parameters->argc, parameters->argv); - - return(parameters); + ComLine *parameters = (ComLine *)SAC_MALLOC(sizeof(ComLine)); + parameters->argc = (sac_int)SAC_commandline_argc; + parameters->argv = SAC_commandline_argv; + return parameters; } - -/*****************************************************/ - - -int SACargc( void) +sac_int SACargc(void) { - return(SACo_CommandLine__TheCommandLine->argc); + return SACo_CommandLine__TheCommandLine->argc; } - -/*****************************************************/ - - -char *SACargv(int n) +char *SACargv(sac_int n) { - char *result; - - if (nargc) - { - result=(char*)SAC_MALLOC(strlen((SACo_CommandLine__TheCommandLine->argv)[n])+1); - - strcpy(result, (SACo_CommandLine__TheCommandLine->argv)[n]); - } - else - { - result=(char*)SAC_MALLOC(1); - result[0]=0; - } - - return(result); + char *res; + + if (n < SACo_CommandLine__TheCommandLine->argc) + { + char *arg = (SACo_CommandLine__TheCommandLine->argv)[n]; + res = (char *)SAC_MALLOC(strlen(arg) + 1); + strcpy(res, arg); + } + else + { + res = (char *)SAC_MALLOC(1); + res[0] = '\0'; + } + + return res; } - -/*****************************************************/ - - -char *SACargvall( void) +char *SACargvall(void) { - char *result; - int len,i; - - len=0; - - for (i=0; iargc; i++) - { - len += strlen(SACo_CommandLine__TheCommandLine->argv[i]); - } - - result=(char*)SAC_MALLOC(len+1+SACo_CommandLine__TheCommandLine->argc); - - strcpy(result, (SACo_CommandLine__TheCommandLine->argv)[0]); - - for (i=1; iargc; i++) - { - strcat(result, " "); - strcat(result, (SACo_CommandLine__TheCommandLine->argv)[i]); - } - - return(result); + int len = 0; + for (int i = 0; i < SACo_CommandLine__TheCommandLine->argc; i++) + { + char *arg = (SACo_CommandLine__TheCommandLine->argv)[i]; + len += strlen(arg); + } + + char *res = (char *)SAC_MALLOC(len + 1 + SACo_CommandLine__TheCommandLine->argc); + + strcpy(res, (SACo_CommandLine__TheCommandLine->argv)[0]); + for (int i = 1; i < SACo_CommandLine__TheCommandLine->argc; i++) + { + strcat(res, " "); + char *arg = (SACo_CommandLine__TheCommandLine->argv)[i]; + strcat(res, arg); + } + + return res; } - - -/*****************************************************/ - - - - - From 608cd456a2a9b3fafe03cf45ba7fd4ddc7340234 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 18:33:44 +0100 Subject: [PATCH 08/29] SAC_MALLOC expects a size_t --- src/system/src/CommandLine/CommandLine.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/system/src/CommandLine/CommandLine.c b/src/system/src/CommandLine/CommandLine.c index a34771a2..a4c22474 100644 --- a/src/system/src/CommandLine/CommandLine.c +++ b/src/system/src/CommandLine/CommandLine.c @@ -48,17 +48,18 @@ char *SACargv(sac_int n) char *SACargvall(void) { - int len = 0; - for (int i = 0; i < SACo_CommandLine__TheCommandLine->argc; i++) + size_t len = 0; + for (sac_int i = 0; i < SACo_CommandLine__TheCommandLine->argc; i++) { char *arg = (SACo_CommandLine__TheCommandLine->argv)[i]; len += strlen(arg); } - char *res = (char *)SAC_MALLOC(len + 1 + SACo_CommandLine__TheCommandLine->argc); + size_t spaces = (size_t)SACo_CommandLine__TheCommandLine->argc; + char *res = (char *)SAC_MALLOC(len + spaces + 1); strcpy(res, (SACo_CommandLine__TheCommandLine->argv)[0]); - for (int i = 1; i < SACo_CommandLine__TheCommandLine->argc; i++) + for (sac_int i = 1; i < SACo_CommandLine__TheCommandLine->argc; i++) { strcat(res, " "); char *arg = (SACo_CommandLine__TheCommandLine->argv)[i]; From ba68fe98e38c3c07a2f1e319fdd09b8b1fb75041 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 18:34:11 +0100 Subject: [PATCH 09/29] SAC_MALLOC expects a size_t --- src/system/src/CommandLine/CommandLine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/src/CommandLine/CommandLine.c b/src/system/src/CommandLine/CommandLine.c index a4c22474..b57bcd18 100644 --- a/src/system/src/CommandLine/CommandLine.c +++ b/src/system/src/CommandLine/CommandLine.c @@ -55,7 +55,7 @@ char *SACargvall(void) len += strlen(arg); } - size_t spaces = (size_t)SACo_CommandLine__TheCommandLine->argc; + size_t spaces = (size_t)(SACo_CommandLine__TheCommandLine->argc); char *res = (char *)SAC_MALLOC(len + spaces + 1); strcpy(res, (SACo_CommandLine__TheCommandLine->argv)[0]); From 8e0287c129228744ee420edfb87ea7bf7200cfbb Mon Sep 17 00:00:00 2001 From: Sven-Bodo Scholz Date: Wed, 21 Jan 2026 18:25:14 +0100 Subject: [PATCH 10/29] inserted missing ampersands --- src/stdio/src/ComplexIO/PrintComplexArray.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdio/src/ComplexIO/PrintComplexArray.c b/src/stdio/src/ComplexIO/PrintComplexArray.c index d07d3018..dac4d46d 100644 --- a/src/stdio/src/ComplexIO/PrintComplexArray.c +++ b/src/stdio/src/ComplexIO/PrintComplexArray.c @@ -37,11 +37,11 @@ static void PrintArr(FILE *stream, int typeflag, string format, sac_int dim, sac char *space=" "; sac_int *index; - fprintf(stream, "Dimension: " PRIisac "\n", dim); + fprintf(stream, "Dimension: %" PRIisac "\n", dim); fprintf(stream, "Shape : <"); element_count = 1; for (i=0;i Date: Wed, 21 Jan 2026 18:33:57 +0100 Subject: [PATCH 11/29] get rid of SACs malloc and FREE --- src/stdio/src/ComplexIO/PrintComplexArray.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdio/src/ComplexIO/PrintComplexArray.c b/src/stdio/src/ComplexIO/PrintComplexArray.c index dac4d46d..54163283 100644 --- a/src/stdio/src/ComplexIO/PrintComplexArray.c +++ b/src/stdio/src/ComplexIO/PrintComplexArray.c @@ -70,7 +70,7 @@ static void PrintArr(FILE *stream, int typeflag, string format, sac_int dim, sac fprintf(stream, "<>\n"); } else { - index = SAC_MALLOC(dim * sizeof(sac_int)); + index = (sac_int *)malloc(dim * sizeof(sac_int)); for (i=0; i Date: Wed, 21 Jan 2026 18:39:45 +0100 Subject: [PATCH 12/29] just a cast needed for runtimerror --- src/system/src/RuntimeError/error.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/system/src/RuntimeError/error.c b/src/system/src/RuntimeError/error.c index bcd478b7..392accd6 100644 --- a/src/system/src/RuntimeError/error.c +++ b/src/system/src/RuntimeError/error.c @@ -1,21 +1,22 @@ #include "sac.h" +#include "sacinterface.h" #include #include #include -void SAC__RUNTIMEERROR_error( int result, const char *message, ...) +void SAC__RUNTIMEERROR_error(sac_int status, const char *msg, ...) { - va_list arg_p; + va_list arg_p; - fprintf(stderr, "\n\n*** USER runtime error\n"); - fprintf(stderr, "*** "); + fprintf(stderr, "\n\n*** USER runtime error\n"); + fprintf(stderr, "*** "); - va_start(arg_p, message); - vfprintf(stderr, message, arg_p); - va_end(arg_p); + va_start(arg_p, msg); + vfprintf(stderr, msg, arg_p); + va_end(arg_p); - fprintf(stderr, "\n\n"); + fprintf(stderr, "\n\n"); - exit(result); + exit((int)status); } From e0ea906dd99c830ffc83e1b1daa7e9de71a1fd3e Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 18:48:26 +0100 Subject: [PATCH 13/29] the errors are just #define constants, so no cast needed --- src/system/src/SysErr/errorcode.c | 136 ++++++++++++++---------------- 1 file changed, 63 insertions(+), 73 deletions(-) diff --git a/src/system/src/SysErr/errorcode.c b/src/system/src/SysErr/errorcode.c index 2673e9c3..f1cfe801 100644 --- a/src/system/src/SysErr/errorcode.c +++ b/src/system/src/SysErr/errorcode.c @@ -2,87 +2,77 @@ * implementation of external standard module SysErr */ - #include #include - #include - -/*****************************************************************/ - - - - -int Eperm( void) {return( EPERM );} /* Not owner */ -int Enoent( void) {return( ENOENT );} /* No such file or directory */ -int Esrch( void) {return( ESRCH );} /* No such process */ -int Eintr( void) {return( EINTR );} /* Interrupted system call */ -int Eio( void) {return( EIO );} /* I/O error */ -int Enxio( void) {return(ENXIO );} /* No such device or address */ -int E2big( void) {return( E2BIG );} /* Arg list too long */ -int Enoexec( void) {return( ENOEXEC );} /* Exec format error */ -int Ebadf( void) {return( EBADF );} /* Bad file number */ -int Echild( void) {return(ECHILD );} /* No children */ -int Eagain( void) {return( EAGAIN );} /* No more processes */ -int Enomem( void) {return( ENOMEM );} /* Not enough core */ -int Eacces( void) {return( EACCES );} /* Permission denied */ -int Efault( void) {return( EFAULT );} /* Bad address */ -int Enotblk( void) {return(ENOTBLK );} /* Block device required */ -int Ebusy( void) {return( EBUSY );} /* Mount device busy */ -int Eexist( void) {return( EEXIST );} /* File exists */ -int Exdev( void) {return( EXDEV );} /* Cross-device link */ -int Enodev( void) {return(ENODEV );} /* No such device */ -int Enotdir( void) {return( ENOTDIR );} /* Not a directory*/ -int Eisdir( void) {return( EISDIR );} /* Is a directory */ -int Einval( void) {return(EINVAL );} /* Invalid argument */ -int Enfile( void) {return(ENFILE );} /* File table overflow */ -int Emfile( void) {return( EMFILE );} /* Too many open files */ -int Enotty( void) {return( ENOTTY );} /* Not a typewriter */ -int Etxtbsy( void) {return( ETXTBSY );} /* Text file busy */ -int Efbig( void) {return( EFBIG );} /* File too large */ -int Enospc( void) {return( ENOSPC );} /* No space left on device */ -int Espipe( void) {return( ESPIPE );} /* Illegal seek */ -int Erofs( void) {return( EROFS );} /* Read-only file system */ -int Emlink( void) {return(EMLINK );} /* Too many links */ -int Epipe( void) {return(EPIPE );} /* Broken pipe */ +#include "sacinterface.h" + +sac_int Eperm(void) { return EPERM; } /* Not owner */ +sac_int Enoent(void) { return ENOENT; } /* No such file or directory */ +sac_int Esrch(void) { return ESRCH; } /* No such process */ +sac_int Eintr(void) { return EINTR; } /* Interrupted system call */ +sac_int Eio(void) { return EIO; } /* I/O error */ +sac_int Enxio(void) { return ENXIO; } /* No such device or address */ +sac_int E2big(void) { return E2BIG; } /* Arg list too long */ +sac_int Enoexec(void) { return ENOEXEC; } /* Exec format error */ +sac_int Ebadf(void) { return EBADF; } /* Bad file number */ +sac_int Echild(void) { return ECHILD; } /* No children */ +sac_int Eagain(void) { return EAGAIN; } /* No more processes */ +sac_int Enomem(void) { return ENOMEM; } /* Not enough core */ +sac_int Eacces(void) { return EACCES; } /* Permission denied */ +sac_int Efault(void) { return EFAULT; } /* Bad address */ +sac_int Enotblk(void) { return ENOTBLK; } /* Block device required */ +sac_int Ebusy(void) { return EBUSY; } /* Mount device busy */ +sac_int Eexist(void) { return EEXIST; } /* File exists */ +sac_int Exdev(void) { return EXDEV; } /* Cross-device link */ +sac_int Enodev(void) { return ENODEV; } /* No such device */ +sac_int Enotdir(void) { return ENOTDIR; } /* Not a directory*/ +sac_int Eisdir(void) { return EISDIR; } /* Is a directory */ +sac_int Einval(void) { return EINVAL; } /* Invalid argument */ +sac_int Enfile(void) { return ENFILE; } /* File table overflow */ +sac_int Emfile(void) { return EMFILE; } /* Too many open files */ +sac_int Enotty(void) { return ENOTTY; } /* Not a typewriter */ +sac_int Etxtbsy(void) { return ETXTBSY; } /* Text file busy */ +sac_int Efbig(void) { return EFBIG; } /* File too large */ +sac_int Enospc(void) { return ENOSPC; } /* No space left on device */ +sac_int Espipe(void) { return ESPIPE; } /* Illegal seek */ +sac_int Erofs(void) { return EROFS; } /* Read-only file system */ +sac_int Emlink(void) { return EMLINK; } /* Too many links */ +sac_int Epipe(void) { return EPIPE; } /* Broken pipe */ /* math software */ -int Edom( void) {return( EDOM );} /* Argument too large */ -int Erange( void) {return(ERANGE );} /* Result too large */ - - - /* operational errors */ -int Enetdown( void) {return( ENETDOWN);} /* Network is down */ -int Enetunreach( void) {return( ENETUNREACH );} /* Network is unreachable */ -int Enetreset( void) {return( ENETRESET );} /* Network dropped connection on reset */ -int Econnaborted( void) {return( ECONNABORTED );} /* Software caused connection abort */ -int Econnreset( void) {return( ECONNRESET );} /* Connection reset by peer */ -int Enobufs( void) {return( ENOBUFS );} /* No buffer space available */ -int Eisconn( void) {return( EISCONN );} /* Socket is already connected */ -int Enotconn( void) {return( ENOTCONN );} /* Socket is not connected */ -int Eshutdown( void) {return(ESHUTDOWN );} /* Can't send after socket shutdown */ -int Etoomanyrefs( void) {return( ETOOMANYREFS );} /* Too many references: can't splice */ -int Etimedout( void) {return( ETIMEDOUT );} /* Connection timed out */ -int Econnrefused( void) {return( ECONNREFUSED );} /* Connection refused */ - - /* */ -int Eloop( void) {return( ELOOP );} /* Too many levels of symbolic links */ -int Enametoolong( void) {return(ENAMETOOLONG );} /* File name too long */ +sac_int Edom(void) { return EDOM; } /* Argument too large */ +sac_int Erange(void) { return ERANGE; } /* Result too large */ + + +/* operational errors */ +sac_int Enetdown(void) { return ENETDOWN; } /* Network is down */ +sac_int Enetunreach(void) { return ENETUNREACH; } /* Network is unreachable */ +sac_int Enetreset(void) { return ENETRESET; } /* Network dropped connection on reset */ +sac_int Econnaborted(void) { return ECONNABORTED; } /* Software caused connection abort */ +sac_int Econnreset(void) { return ECONNRESET; } /* Connection reset by peer */ +sac_int Enobufs(void) { return ENOBUFS; } /* No buffer space available */ +sac_int Eisconn(void) { return EISCONN; } /* Socket is already connected */ +sac_int Enotconn(void) { return ENOTCONN; } /* Socket is not connected */ +sac_int Eshutdown(void) { return ESHUTDOWN; } /* Can't send after socket shutdown */ +sac_int Etoomanyrefs(void) { return ETOOMANYREFS; } /* Too many references: can't splice */ +sac_int Etimedout(void) { return ETIMEDOUT; } /* Connection timed out */ +sac_int Econnrefused(void) { return ECONNREFUSED; } /* Connection refused */ + +/* */ +sac_int Eloop(void) { return ELOOP; } /* Too many levels of symbolic links */ +sac_int Enametoolong(void) { return ENAMETOOLONG; } /* File name too long */ /* should be rearranged */ -int Ehostdown( void) {return(EHOSTDOWN );} /* Host is down */ -int Ehostunreach( void) {return( EHOSTUNREACH );} /* No route to host */ -int Enotempty( void) {return(ENOTEMPTY );} /* Directory not empty */ +sac_int Ehostdown(void) { return EHOSTDOWN; } /* Host is down */ +sac_int Ehostunreach(void) { return EHOSTUNREACH; } /* No route to host */ +sac_int Enotempty(void) { return ENOTEMPTY; } /* Directory not empty */ /* quotas & mush */ -int Eusers( void) {return( EUSERS );} /* Too many users */ -int Edquot( void) {return( EDQUOT );} /* Disc quota exceeded */ - -/* Network File System */ -int Estale( void) {return( ESTALE );} /* Stale NFS file handle */ -int Eremote( void) {return(EREMOTE );} /* Too many levels of remote in path */ - - - +sac_int Eusers(void) { return EUSERS; } /* Too many users */ +sac_int Edquot(void) { return EDQUOT; } /* Disc quota exceeded */ +/* network file system */ +sac_int Estale(void) { return ESTALE; } /* Stale NFS file handle */ +sac_int Eremote(void) { return EREMOTE; } /* Too many levels of remote in path */ From 9775283accdeada7fe06da30d8890d0e3fd8d2c4 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 18:52:05 +0100 Subject: [PATCH 14/29] sac_int in failsucc --- src/system/src/SysErr/failsucc.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/system/src/SysErr/failsucc.c b/src/system/src/SysErr/failsucc.c index 070973c5..018dd629 100644 --- a/src/system/src/SysErr/failsucc.c +++ b/src/system/src/SysErr/failsucc.c @@ -1,29 +1,19 @@ /* - * implementation of external standard module SysErr + * Implementation of external standard module SysErr */ - +#include #include #include +#include "sacinterface.h" - -/*****************************************************************/ - -int clear(int err) +bool clear(sac_int err) { - return(err==-1); + return (err == -1); } -/*****************************************************************/ - -int fail(int err) +bool fail(sac_int err) { - return(err!=-1); + return (err != -1); } - -/*****************************************************************/ - - - - From 2e27b3d234b23a88949b622270c1691f19d795ca Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 18:55:24 +0100 Subject: [PATCH 15/29] add sac_int to strerror --- src/system/src/SysErr/strerror.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/system/src/SysErr/strerror.c b/src/system/src/SysErr/strerror.c index 468c7e2e..9a0e3fe8 100644 --- a/src/system/src/SysErr/strerror.c +++ b/src/system/src/SysErr/strerror.c @@ -1,34 +1,18 @@ /* - * implementation of external standard module SysErr + * Implementation of external standard module SysErr */ - #include #include #include "sac.h" +#include "sacinterface.h" - -/*****************************************************************/ - -extern char *strerror(int num); - - -/*****************************************************************/ - - -char *SACstrerror(int num) +char *SACstrerror(sac_int num) { - char *buffer, *result; - - buffer=strerror(num); - - result=(char *)SAC_MALLOC(strlen(buffer)+1); - strcpy(result, buffer); - - return(result); + char *buf, *res; + buf = strerror((int)num); + res = (char *)SAC_MALLOC(strlen(buf) + 1); + strcpy(res, buf); + return res; } - -/*****************************************************************/ - - From 665ed283723caaad4b476b3d71714af5deb9a31e Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 19:06:05 +0100 Subject: [PATCH 16/29] add sac_int to dir --- src/system/Dir.sac | 13 ++++++------- src/system/src/Dir/Dir.h | 6 ++---- src/system/src/Dir/closedir.c | 15 +++------------ src/system/src/Dir/opendir.c | 27 +++++++++------------------ 4 files changed, 20 insertions(+), 41 deletions(-) diff --git a/src/system/Dir.sac b/src/system/Dir.sac index 0c215550..beee6578 100644 --- a/src/system/Dir.sac +++ b/src/system/Dir.sac @@ -9,7 +9,7 @@ use SysErr: { syserr }; export all; -external syserr, Dir opendir( string NAME); +external syserr, Dir opendir(string NAME); #pragma effect TheFileSystem #pragma linksign [0,1,2] #pragma linkobj "src/Dir/opendir.o" @@ -22,7 +22,7 @@ external syserr, Dir opendir( string NAME); * before using the directory handle. */ -external void closedir( Dir& DIR); +external void closedir(Dir& DIR); #pragma effect TheFileSystem #pragma linksign [1] #pragma linkobj "src/Dir/closedir.o" @@ -31,7 +31,7 @@ external void closedir( Dir& DIR); * Close the directory stream DIR. */ -external string readdir( Dir& DIR); +external string readdir(Dir& DIR); #pragma effect TheFileSystem #pragma linksign [0,1] #pragma linkobj "src/Dir/readdir.o" @@ -43,7 +43,7 @@ external string readdir( Dir& DIR); * an empty string is returned. */ -external void rewinddir( Dir& DIR); +external void rewinddir(Dir& DIR); #pragma effect TheFileSystem #pragma linksign [1] #pragma linkobj "src/Dir/rewinddir.o" @@ -52,7 +52,7 @@ external void rewinddir( Dir& DIR); * Reposition the directory stream DIR to the beginning. */ -external long telldir( Dir& DIR); +external long telldir(Dir& DIR); #pragma effect TheFileSystem #pragma linksign [0,1] #pragma linkobj "src/Dir/telldir.o" @@ -62,7 +62,7 @@ external long telldir( Dir& DIR); * On error -1 is returned. */ -external void seekdir( Dir& DIR, long POS); +external void seekdir(Dir& DIR, long POS); #pragma effect TheFileSystem #pragma linksign [1,2] #pragma linkobj "src/Dir/seekdir.o" @@ -70,4 +70,3 @@ external void seekdir( Dir& DIR, long POS); /* * Reposition the directory stream DIR to POS. */ - diff --git a/src/system/src/Dir/Dir.h b/src/system/src/Dir/Dir.h index 7c067946..cf5e144c 100644 --- a/src/system/src/Dir/Dir.h +++ b/src/system/src/Dir/Dir.h @@ -1,15 +1,13 @@ /* - * Implementation of standard module Dir + * Implementation of standard module Dir */ - #include #include #include #include #include "sac.h" +#include "sacinterface.h" typedef char* string; - - diff --git a/src/system/src/Dir/closedir.c b/src/system/src/Dir/closedir.c index 4f700cc7..7c345116 100644 --- a/src/system/src/Dir/closedir.c +++ b/src/system/src/Dir/closedir.c @@ -1,19 +1,10 @@ /* - * implementation of directory functions. + * Implementation of directory functions. */ - - #include "Dir.h" - - -/*****************************************************************/ - -void SACclosedir( DIR* stream) +void SACclosedir(DIR* stream) { - closedir( stream); + closedir(stream); } - - -/*****************************************************************/ diff --git a/src/system/src/Dir/opendir.c b/src/system/src/Dir/opendir.c index 08e7fb04..290c9562 100644 --- a/src/system/src/Dir/opendir.c +++ b/src/system/src/Dir/opendir.c @@ -1,28 +1,19 @@ /* - * implementation of directory functions. + * Implementation of directory functions. */ - - #include "Dir.h" - - -/*****************************************************************/ - -int SACopendir( DIR ** stream, string name) +sac_int SACopendir(DIR **stream, string name) { - int error = -1; + sac_int err = -1; - *stream = opendir( name); + *stream = opendir(name); - if (*stream == NULL) - { - error = errno; - } + if (*stream == NULL) + { + err = errno; + } - return( error); + return err; } - - -/*****************************************************************/ From 0765304a74a9e57f6ed72047e68dce500dd4a179 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 19:10:06 +0100 Subject: [PATCH 17/29] add sac_int to getopt --- src/system/src/GetOpt/getopt.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/system/src/GetOpt/getopt.c b/src/system/src/GetOpt/getopt.c index 9ecb080a..e94002aa 100644 --- a/src/system/src/GetOpt/getopt.c +++ b/src/system/src/GetOpt/getopt.c @@ -17,45 +17,46 @@ #include #include "sac.h" +#include "sacinterface.h" /* Import the following two prototypes from SAC's commandline parser: * stdlib/world/system/src/CommandLine/CommandLine.c */ int SACargc( void); char *SACargv(int n); -static int SAC_optind = 1; -static int SAC_opterr = 1; -static int SAC_optopt; +static sac_int SAC_optind = 1; +static sac_int SAC_opterr = 1; +static sac_int SAC_optopt; static char *SAC_optarg; -static int SAC_argind = 1; +static sac_int SAC_argind = 1; -int optEND(void) +char optEND(void) { return '\0'; } -int get_optind(void) +sac_int get_optind(void) { return SAC_optind; } -void set_optind(int set) +void set_optind(sac_int set) { SAC_optind = set; SAC_argind = 1; } -int get_opterr(void) +sac_int get_opterr(void) { return SAC_opterr; } -void set_opterr(int set) +void set_opterr(sac_int set) { SAC_opterr = set; } -int get_optopt(void) +sac_int get_optopt(void) { return SAC_optopt; } @@ -99,10 +100,10 @@ static void missing( void) } } -int getopt_sac(const char *opts) +char getopt_sac(const char *opts) { const int argc = SACargc(); - int retval; + char retval; setarg(NULL); From 93a72c6459fc7d1b0027f79c88cfcf55b9906010 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 19:25:05 +0100 Subject: [PATCH 18/29] convert clock to sac_int --- src/system/src/Clock/Clock.h | 10 +-- src/system/src/Clock/copytime.c | 21 +----- src/system/src/Clock/ctime.c | 26 ++----- src/system/src/Clock/date.c | 44 +++-------- src/system/src/Clock/difftime.c | 15 +--- src/system/src/Clock/extracttime.c | 114 ++++++----------------------- src/system/src/Clock/gettime.c | 20 +---- src/system/src/Clock/isdst.c | 21 +----- src/system/src/Clock/isleap.c | 34 ++------- src/system/src/Clock/mktime.c | 51 ++++--------- src/system/src/Clock/strftime.c | 32 +++----- src/system/src/Clock/strptime.c | 61 ++++++--------- src/system/src/Clock/to_time.c | 10 +-- 13 files changed, 119 insertions(+), 340 deletions(-) diff --git a/src/system/src/Clock/Clock.h b/src/system/src/Clock/Clock.h index eb85747d..47cc5e14 100644 --- a/src/system/src/Clock/Clock.h +++ b/src/system/src/Clock/Clock.h @@ -1,14 +1,12 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - -#include +#include #include - +#include #include "sac.h" +#include "sacinterface.h" typedef char* string; - - diff --git a/src/system/src/Clock/copytime.c b/src/system/src/Clock/copytime.c index d32755a3..206d208a 100644 --- a/src/system/src/Clock/copytime.c +++ b/src/system/src/Clock/copytime.c @@ -1,25 +1,12 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" - -/******************************************************************/ - - time_t *copy_time(time_t *t) { - time_t *res; - - res=(time_t*)SAC_MALLOC(sizeof(time_t)); - *res=*t; - return(res); + time_t *res = (time_t *)SAC_MALLOC(sizeof(time_t)); + *res = *t; + return res; } - - -/******************************************************************/ - - diff --git a/src/system/src/Clock/ctime.c b/src/system/src/Clock/ctime.c index 5aefc051..789614c5 100644 --- a/src/system/src/Clock/ctime.c +++ b/src/system/src/Clock/ctime.c @@ -1,28 +1,14 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - - string SACctime(time_t *t) { - string buffer, result; - - buffer=ctime(t); - - result=(string)SAC_MALLOC(strlen(buffer)+1); - strcpy(result, buffer); - - return(result); + string buf, res; + buf = ctime(t); + res = (string)SAC_MALLOC(strlen(buf)+1); + strcpy(res, buf); + return res; } - - - -/******************************************************************/ - - diff --git a/src/system/src/Clock/date.c b/src/system/src/Clock/date.c index d3423708..5f284460 100644 --- a/src/system/src/Clock/date.c +++ b/src/system/src/Clock/date.c @@ -1,43 +1,21 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - - -int SACdate(int *mon, int *day, time_t *t) +sac_int SACdate(sac_int *mon, sac_int *day, time_t *t) { - struct tm *tt; - - tt=localtime(t); - - *mon=tt->tm_mon; - *day=tt->tm_mday; - - return(tt->tm_year); + struct tm *tt = localtime(t); + *mon = (sac_int)(tt->tm_mon); + *day = (sac_int)(tt->tm_mday); + return (sac_int)(tt->tm_year); } - - -/******************************************************************/ - - -int SACclock(int *min, int *sec, time_t *t) +sac_int SACclock(sac_int *min, sac_int *sec, time_t *t) { - struct tm *tt; - - tt=localtime(t); - - *sec=tt->tm_sec; - *min=tt->tm_min; - - return(tt->tm_hour); + struct tm *tt = localtime(t); + *sec = (sac_int)(tt->tm_sec); + *min = (sac_int)(tt->tm_min); + return (sac_int)(tt->tm_hour); } - - - -/******************************************************************/ diff --git a/src/system/src/Clock/difftime.c b/src/system/src/Clock/difftime.c index 60626792..bed3264b 100644 --- a/src/system/src/Clock/difftime.c +++ b/src/system/src/Clock/difftime.c @@ -1,21 +1,10 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - - double SACdifftime(time_t *t1, time_t *t2) { - return(difftime(*t1, *t2)); + return difftime(*t1, *t2); } - - -/******************************************************************/ - - - diff --git a/src/system/src/Clock/extracttime.c b/src/system/src/Clock/extracttime.c index 3639786c..f788408b 100644 --- a/src/system/src/Clock/extracttime.c +++ b/src/system/src/Clock/extracttime.c @@ -1,119 +1,53 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - - -int SACsec(time_t *t) +sac_int SACsec(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_sec); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_sec); } - -/******************************************************************/ - - -int SACmin(time_t *t) +sac_int SACmin(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_min); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_min); } - -/******************************************************************/ - - -int SAChour(time_t *t) +sac_int SAChour(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_hour); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_hour); } - -/******************************************************************/ - - -int SACmday(time_t *t) +sac_int SACmday(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_mday); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_mday); } - -/******************************************************************/ - - -int SACmon(time_t *t) +sac_int SACmon(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_mon); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_mon); } - - -/******************************************************************/ - - -int SACyear(time_t *t) +sac_int SACyear(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_year); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_year); } - - -/******************************************************************/ - - -int SACwday(time_t *t) +sac_int SACwday(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_wday); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_wday); } - - -/******************************************************************/ - - int SACyday(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_yday); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_yday); } - - - -/******************************************************************/ - - diff --git a/src/system/src/Clock/gettime.c b/src/system/src/Clock/gettime.c index 2db05893..28206f63 100644 --- a/src/system/src/Clock/gettime.c +++ b/src/system/src/Clock/gettime.c @@ -1,24 +1,12 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - - time_t *SACgettime( void) { - time_t *res; - - res=(time_t*)SAC_MALLOC(sizeof(time_t)); - time(res); - return(res); + time_t *res = (time_t *)SAC_MALLOC(sizeof(time_t)); + time(res); + return res; } - - -/******************************************************************/ - - diff --git a/src/system/src/Clock/isdst.c b/src/system/src/Clock/isdst.c index eaec3b4c..cc42318a 100644 --- a/src/system/src/Clock/isdst.c +++ b/src/system/src/Clock/isdst.c @@ -1,24 +1,11 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - - -int SACisdst(time_t *t) +sac_int SACisdst(time_t *t) { - struct tm *tt; - - tt=localtime(t); - - return(tt->tm_isdst); + struct tm *tt = localtime(t); + return (sac_int)(tt->tm_isdst); } - - -/******************************************************************/ - - diff --git a/src/system/src/Clock/isleap.c b/src/system/src/Clock/isleap.c index 91dacd89..5d3225ee 100644 --- a/src/system/src/Clock/isleap.c +++ b/src/system/src/Clock/isleap.c @@ -1,37 +1,17 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - - -int SACisleap(int year) +bool SACisleap(sac_int year) { - return((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)); + return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); } - - -/******************************************************************/ - - -int SACisleapt(time_t *t) +bool SACisleapt(time_t *t) { - struct tm *tt; - int year; - - tt=localtime(t); - year=tt->tm_year + 1900; - - return((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)); + struct tm *tt = localtime(t); + int year=tt->tm_year + 1900; + return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); } - - - -/******************************************************************/ - - diff --git a/src/system/src/Clock/mktime.c b/src/system/src/Clock/mktime.c index 7bf4e946..e8ba679b 100644 --- a/src/system/src/Clock/mktime.c +++ b/src/system/src/Clock/mktime.c @@ -1,44 +1,25 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - - -time_t *SACmktime(int *success, int year, int mon, int day, - int hour, int min, int sec) +time_t *SACmktime(bool *success, + sac_int year, sac_int mon, sac_int day, + sac_int hour, sac_int min, sac_int sec) { - struct tm t; - time_t *res; - - t.tm_year=year; - t.tm_mon=mon; - t.tm_mday=day; - t.tm_hour=hour; - t.tm_min=min; - t.tm_sec=sec; - - res=(time_t*)SAC_MALLOC(sizeof(time_t)); + struct tm t; + t.tm_year = year; + t.tm_mon = mon; + t.tm_mday = day; + t.tm_hour = hour; + t.tm_min = min; + t.tm_sec = sec; - *res=mktime(&t); - - if (*res<(time_t)0) - { - *success=0; - } - else - { - *success=1; - } - - return(res); -} - - -/******************************************************************/ + time_t *res = (time_t *)SAC_MALLOC(sizeof(time_t)); + *res = mktime(&t); + *success = (*res < (time_t)0) ? 0 : 1; + return res; +} diff --git a/src/system/src/Clock/strftime.c b/src/system/src/Clock/strftime.c index 03ecc6e1..b2933b18 100644 --- a/src/system/src/Clock/strftime.c +++ b/src/system/src/Clock/strftime.c @@ -1,31 +1,21 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" -/******************************************************************/ - -string SACstrftime(int len, string format, time_t* t) +string SACstrftime(sac_int len, string format, time_t *t) { - string result; - struct tm *tt; - result = (string) SAC_MALLOC(len + 1); - result[0] = '\0'; + string res = (string)SAC_MALLOC((size_t)len + 1); + res[0] = '\0'; - tt = localtime(t); - if (tt != NULL) { - if (strftime(result, len, format, tt) == 0) { - result[0] = '\0'; - } - } + struct tm *tt = localtime(t); + if (tt != NULL) { + if (strftime(res, len, format, tt) == 0) { + res[0] = '\0'; + } + } - return (result); + return res; } - - - -/******************************************************************/ diff --git a/src/system/src/Clock/strptime.c b/src/system/src/Clock/strptime.c index 339bf864..4c240d75 100644 --- a/src/system/src/Clock/strptime.c +++ b/src/system/src/Clock/strptime.c @@ -1,15 +1,12 @@ /* - * Implementation of standard module Time + * Implementation of standard module Time */ - - #include "Clock.h" - extern char *strptime(const char *, const char *, struct tm *); -/* +/* * Unfortunately, the function strptime() is not declared in time.h ! * Fortunately, the standard library libc.a contains an implementation * of strptime(). @@ -18,38 +15,26 @@ extern char *strptime(const char *, const char *, struct tm *); * then _XOPEN_SOURCE must be defined before including time.h. */ - - -/******************************************************************/ - - -time_t *SACstrptime(string * result, string s, string format) +time_t *SACstrptime(string *res, string s, string format) { - struct tm tt; - string remain; - time_t *t; - - t = (time_t *) SAC_MALLOC(sizeof(time_t)); - - memset(&tt, 0, sizeof tt); - remain = strptime(s, format, &tt); - - /* strptime() may return NULL if it fails to match all of the format string. - * In that case an error occurred and the contents of tt is undefined. - */ - if (remain == NULL) { - *t = 0; - *result = (string) SAC_MALLOC(1); - **result = '\0'; - } else { - *t = mktime(&tt); - *result = (string) SAC_MALLOC(strlen(remain) + 1); - strcpy(*result, remain); - } - - return (t); + time_t *t = (time_t *) SAC_MALLOC(sizeof(time_t)); + + struct tm tt; + memset(&tt, 0, sizeof tt); + string remain = strptime(s, format, &tt); + + /* strptime() may return NULL if it fails to match all of the format string. + * In that case an error occurred and the contents of tt is undefined. + */ + if (remain == NULL) { + *t = 0; + *res = (string)SAC_MALLOC(1); + **res = '\0'; + } else { + *t = mktime(&tt); + *res = (string)SAC_MALLOC(strlen(remain) + 1); + strcpy(*res, remain); + } + + return t; } - - - -/******************************************************************/ diff --git a/src/system/src/Clock/to_time.c b/src/system/src/Clock/to_time.c index e20a84bf..a645c998 100644 --- a/src/system/src/Clock/to_time.c +++ b/src/system/src/Clock/to_time.c @@ -1,12 +1,8 @@ -/* $Id$ */ - #include "Clock.h" time_t *SACto_time( int secs) { - time_t *res = (time_t *) SAC_MALLOC( sizeof( time_t)); - - *res = (time_t) secs; - - return( res); + time_t *res = (time_t *)SAC_MALLOC(sizeof(time_t)); + *res = (time_t)secs; + return res; } From 56cefd7aed0e0a569b12b7ca74bc4115e4262450 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 19:30:36 +0100 Subject: [PATCH 19/29] oops, I did a booboo --- src/system/src/GetOpt/getopt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/system/src/GetOpt/getopt.c b/src/system/src/GetOpt/getopt.c index e94002aa..8bf9517a 100644 --- a/src/system/src/GetOpt/getopt.c +++ b/src/system/src/GetOpt/getopt.c @@ -77,7 +77,7 @@ static void badopt(void) { if (SAC_opterr) { char *prog = SACargv(0); - fprintf(stderr, "%s: invalid option -- '%c'\n", prog, SAC_optopt); + fprintf(stderr, "%s: invalid option -- '%"PRIisac"'\n", prog, SAC_optopt); free(prog); } } @@ -95,7 +95,7 @@ static void missing( void) { if (SAC_opterr == 1) { char *prog = SACargv(0); - fprintf(stderr, "%s: option requires an argument -- '%c'\n", prog, SAC_optopt); + fprintf(stderr, "%s: option requires an argument -- '%"PRIisac"'\n", prog, SAC_optopt); free(prog); } } From 5284a37f7a6d77c6b2b1b542501dfd17a890f6d0 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 21:12:22 +0100 Subject: [PATCH 20/29] use index types branch --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 42635a72..d082b000 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: sudo apt install xsltproc -y - name: Install sac2c run: | - git clone --recursive --single-branch https://gitlab.sac-home.org/sac-group/sac2c.git + git clone --single-branch --recursive -b index-types https://gitlab.sac-home.org/sac-group/sac2c.git cd sac2c make release -j2 cp build_p/sac2c_p /usr/local/bin/sac2c @@ -70,7 +70,7 @@ jobs: xcode-version: '14.2' - name: Install sac2c run: | - git clone --recursive --single-branch https://gitlab.sac-home.org/sac-group/sac2c.git + git clone --single-branch --recursive -b index-types https://gitlab.sac-home.org/sac-group/sac2c.git cd sac2c make release -j2 cp build_p/sac2c_p /usr/local/bin/sac2c @@ -119,7 +119,7 @@ jobs: xcode-version: '16.2' - name: Install sac2c run: | - git clone --recursive --single-branch https://gitlab.sac-home.org/sac-group/sac2c.git + git clone --single-branch --recursive -b index-types https://gitlab.sac-home.org/sac-group/sac2c.git cd sac2c make release -j2 cp build_p/sac2c_p /usr/local/bin/sac2c From 0cef93e62044a6072becaa96a6f8e47dcbaf4cec Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 21:19:51 +0100 Subject: [PATCH 21/29] macos13 was retired --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d082b000..b1908054 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,7 +53,7 @@ jobs: ./test.sh build-macos-x86: - runs-on: macos-13 + runs-on: macos-15-intel steps: - name: Get HEAD and submodules uses: actions/checkout@v2 @@ -102,7 +102,7 @@ jobs: ./test.sh build-macos-arm: - runs-on: macos-15 + runs-on: macos-26 steps: - name: Get HEAD and submodules uses: actions/checkout@v2 From 1f952085497f215c1a742f35b8c18a8a6f7870a0 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 21:24:42 +0100 Subject: [PATCH 22/29] macos13 was retired --- .github/workflows/main.yml | 53 ++------------------------------------ 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b1908054..23bfacda 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,57 +52,8 @@ jobs: make all ./test.sh - build-macos-x86: - runs-on: macos-15-intel - steps: - - name: Get HEAD and submodules - uses: actions/checkout@v2 - with: - fetch-depth: 0 - submodules: 'recursive' - - name: Install dependencies - run: | - brew update - brew install libxslt - - name: Set XCode version - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: '14.2' - - name: Install sac2c - run: | - git clone --single-branch --recursive -b index-types https://gitlab.sac-home.org/sac-group/sac2c.git - cd sac2c - make release -j2 - cp build_p/sac2c_p /usr/local/bin/sac2c - sac2c -V - - name: Create build dir - run: | - cmake -E make_directory ${{runner.workspace}}/build - - name: Configure build-system - shell: bash - working-directory: ${{runner.workspace}}/build - run: cmake ${GITHUB_WORKSPACE} - - name: Build - shell: bash - working-directory: ${{runner.workspace}}/build - run: | - cmake --build . -j4 >&1 | tee build.log - if [ ${PIPESTATUS[0]} -ne 0 ]; then - echo "!!! ERROR detected in build !!!"; - exit 1; - fi - ${GITHUB_WORKSPACE}/ci/fail-on-warning.sh build.log - - name: Test - shell: bash - working-directory: ${{runner.workspace}}/build - run: | - git clone --single-branch https://github.com/SacBase/IntegrationTests.git - cd IntegrationTests - make all - ./test.sh - build-macos-arm: - runs-on: macos-26 + runs-on: macos-latest steps: - name: Get HEAD and submodules uses: actions/checkout@v2 @@ -116,7 +67,7 @@ jobs: - name: Set XCode version uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: '16.2' + xcode-version: latest-stable - name: Install sac2c run: | git clone --single-branch --recursive -b index-types https://gitlab.sac-home.org/sac-group/sac2c.git From 7d1332258889dd0f2be3d476270305ca31751c4c Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 21:31:58 +0100 Subject: [PATCH 23/29] Char.sac --- src/structures/src/Char/ctype.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/structures/src/Char/ctype.c b/src/structures/src/Char/ctype.c index 23c76850..301e5ae3 100644 --- a/src/structures/src/Char/ctype.c +++ b/src/structures/src/Char/ctype.c @@ -9,6 +9,7 @@ * They may return any non-zero value when true, but a SAC bool is true if 1. */ +#include #include typedef unsigned char uchar; @@ -68,12 +69,12 @@ int SACiscntrl(uchar c) return iscntrl(c) != 0; } -int SACisascii(int c) +int SACisascii(sac_int c) { return c >= 0 && c < 256 && isascii(c) != 0; } -int SACtoascii(int c) +int SACtoascii(sac_int c) { return toascii(c & 0xFF); } From 3951337b7c6c7bfa4d5db03107d560a3488ff15e Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 21:40:20 +0100 Subject: [PATCH 24/29] Constants --- src/structures/Constants.sac | 4 ---- src/structures/src/Constants/maxint.c | 11 +++++++++-- src/structures/src/Constants/minint.c | 7 ++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/structures/Constants.sac b/src/structures/Constants.sac index 9c523f2d..062f4263 100644 --- a/src/structures/Constants.sac +++ b/src/structures/Constants.sac @@ -111,7 +111,3 @@ external double maxdouble(); external double epidouble(); #pragma linksign[0] #pragma linkobj "src/Constants/epidouble.o" - -external int randmax(); - #pragma linksign[0] - #pragma linkobj "src/Constants/randmax.o" diff --git a/src/structures/src/Constants/maxint.c b/src/structures/src/Constants/maxint.c index 2078a486..c2901bae 100644 --- a/src/structures/src/Constants/maxint.c +++ b/src/structures/src/Constants/maxint.c @@ -1,7 +1,14 @@ #include +#include -int maxint( void) +sac_int maxint( void) { - return( INT_MAX); + sac_int num_bits = 8 * sizeof(sac_int); + /** + * To avoid overflow: + * 2^(num_bits - 1) - 1 = 2 * 2^(num_bits - 2) - 1 = + * 2^(num_bits - 2) + (2^(num_bits - 2) - 1) + **/ + return (sac_int)1 << (num_bits - 2) + ((sac_int)1 << (num_bits - 2) - 1); } diff --git a/src/structures/src/Constants/minint.c b/src/structures/src/Constants/minint.c index d369f318..0c7cf520 100644 --- a/src/structures/src/Constants/minint.c +++ b/src/structures/src/Constants/minint.c @@ -1,7 +1,8 @@ +#include #include - -int minint( void) +sac_int minint( void) { - return( INT_MIN ); + sac_int num_bits = 8 * sizeof(sac_int); + return -(sac_int)1 << (num_bits - 1); } From f902e0d8cae81041b89deb36db3ec82c8cbfe636 Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 21:43:33 +0100 Subject: [PATCH 25/29] Precedence fix --- src/structures/src/Constants/minint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/src/Constants/minint.c b/src/structures/src/Constants/minint.c index 0c7cf520..b5127486 100644 --- a/src/structures/src/Constants/minint.c +++ b/src/structures/src/Constants/minint.c @@ -4,5 +4,5 @@ sac_int minint( void) { sac_int num_bits = 8 * sizeof(sac_int); - return -(sac_int)1 << (num_bits - 1); + return -((sac_int)1 << (num_bits - 1)); } From 24963c755593a56b4aa0aa8abcffa235e0e10ac7 Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 21:48:42 +0100 Subject: [PATCH 26/29] Fix --- src/structures/src/Constants/maxint.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/structures/src/Constants/maxint.c b/src/structures/src/Constants/maxint.c index c2901bae..f5080f5a 100644 --- a/src/structures/src/Constants/maxint.c +++ b/src/structures/src/Constants/maxint.c @@ -1,4 +1,4 @@ -#include +#include #include @@ -10,5 +10,6 @@ sac_int maxint( void) * 2^(num_bits - 1) - 1 = 2 * 2^(num_bits - 2) - 1 = * 2^(num_bits - 2) + (2^(num_bits - 2) - 1) **/ - return (sac_int)1 << (num_bits - 2) + ((sac_int)1 << (num_bits - 2) - 1); + sac_int half = (sac_int)1 << (num_bits - 2); + return half + (half - 1); } From 8ffb153eaefbf7083fa7c4a10c3c266c9844563c Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 21:49:02 +0100 Subject: [PATCH 27/29] Benchmarking --- src/auxiliary/src/C99Benchmarking/bench.c | 18 +++++++++--------- src/auxiliary/src/CudaBenchmarking/bench.cu | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/auxiliary/src/C99Benchmarking/bench.c b/src/auxiliary/src/C99Benchmarking/bench.c index 3d3ee1c1..9a15638c 100644 --- a/src/auxiliary/src/C99Benchmarking/bench.c +++ b/src/auxiliary/src/C99Benchmarking/bench.c @@ -16,9 +16,9 @@ static const char * unitName[] = {"s", "ms", "us", "ns"}; struct bench { - int num; + sac_int num; char * name; - int timeUnit; + sac_int timeUnit; double startTime; double stopTime; }; @@ -51,7 +51,7 @@ char* benchName( struct bench* interval) return( newName); } -int benchNum( struct bench* interval) +sac_int benchNum( struct bench* interval) { return( interval->num); } @@ -64,7 +64,7 @@ char* benchUnitName( struct bench* interval) return( unit_name); } -int benchUnit( struct bench* interval) +sac_int benchUnit( struct bench* interval) { return( interval->timeUnit); } @@ -74,7 +74,7 @@ void benchCreate( struct bench** interval) /* benchGetInterval actually creates the data structure */ } -struct bench* benchGetInterval_si(char * name, int num) +struct bench* benchGetInterval_si(char * name, sac_int num) { struct bench *interval; char* newName; @@ -87,7 +87,7 @@ struct bench* benchGetInterval_si(char * name, int num) return( interval); } -struct bench* benchGetInterval_i( int num) +struct bench* benchGetInterval_i( sac_int num) { struct bench *interval; interval = benchGetInterval_si("\0", num); @@ -101,7 +101,7 @@ struct bench* benchGetInterval_s( char *name) return( interval); } -struct bench* benchGetInterval_siu(char * name, int num, int timeunit) +struct bench* benchGetInterval_siu(char * name, sac_int num, sac_int timeunit) { struct bench *interval; char* newName; @@ -114,14 +114,14 @@ struct bench* benchGetInterval_siu(char * name, int num, int timeunit) return( interval); } -struct bench* benchGetInterval_iu( int num, int timeunit) +struct bench* benchGetInterval_iu( sac_int num, sac_int timeunit) { struct bench *interval; interval = benchGetInterval_siu("\0", num, timeunit); return( interval); } -struct bench* benchGetInterval_su( char *name, int timeunit) +struct bench* benchGetInterval_su( char *name, sac_int timeunit) { struct bench *interval; interval = benchGetInterval_siu(name, -1, timeunit); diff --git a/src/auxiliary/src/CudaBenchmarking/bench.cu b/src/auxiliary/src/CudaBenchmarking/bench.cu index bc5dca10..b37407b6 100644 --- a/src/auxiliary/src/CudaBenchmarking/bench.cu +++ b/src/auxiliary/src/CudaBenchmarking/bench.cu @@ -17,9 +17,9 @@ extern "C" { static const char * unitName[] = {"s", "ms", "us", "ns"}; struct cudabench { - int num; + sac_int num; char * name; - int timeUnit; + sac_int timeUnit; cudaEvent_t start; cudaEvent_t stop; }; @@ -57,7 +57,7 @@ char* benchName( struct cudabench* interval) return( newName); } -int benchNum( struct cudabench* interval) +sac_int benchNum( struct cudabench* interval) { return( interval->num); } @@ -70,7 +70,7 @@ char* benchUnitName( struct cudabench* interval) return( unit_name); } -int benchUnit( struct cudabench* interval) +sac_int benchUnit( struct cudabench* interval) { return( interval->timeUnit); } @@ -80,7 +80,7 @@ void benchCreate( struct cudabench** interval) /* benchGetInterval actually creates the data structure */ } -struct cudabench* benchGetInterval_si(char * name, int num) +struct cudabench* benchGetInterval_si(char * name, sac_int num) { struct cudabench *interval; char* newName; @@ -93,7 +93,7 @@ struct cudabench* benchGetInterval_si(char * name, int num) return( interval); } -struct cudabench* benchGetInterval_i( int num) +struct cudabench* benchGetInterval_i( sac_int num) { struct cudabench *interval; interval = benchGetInterval_si("\0", num); @@ -107,7 +107,7 @@ struct cudabench* benchGetInterval_s( char *name) return( interval); } -struct cudabench* benchGetInterval_siu(char * name, int num, int timeunit) +struct cudabench* benchGetInterval_siu(char * name, sac_int num, sac_int timeunit) { struct cudabench *interval; char* newName; @@ -120,14 +120,14 @@ struct cudabench* benchGetInterval_siu(char * name, int num, int timeunit) return( interval); } -struct cudabench* benchGetInterval_iu( int num, int timeunit) +struct cudabench* benchGetInterval_iu( sac_int num, sac_int timeunit) { struct cudabench *interval; interval = benchGetInterval_siu("\0", num, timeunit); return( interval); } -struct cudabench* benchGetInterval_su( char *name, int timeunit) +struct cudabench* benchGetInterval_su( char *name, sac_int timeunit) { struct cudabench *interval; interval = benchGetInterval_siu(name, -1, timeunit); From 471b3f0c71bcc90848bbaa342dee72041aba8a29 Mon Sep 17 00:00:00 2001 From: Thomas Koopman Date: Wed, 21 Jan 2026 21:52:34 +0100 Subject: [PATCH 28/29] System --- src/system/src/Process/system.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/system/src/Process/system.c b/src/system/src/Process/system.c index 05d08da3..dd2de223 100644 --- a/src/system/src/Process/system.c +++ b/src/system/src/Process/system.c @@ -1,8 +1,9 @@ +#include #include -int SACsystem (char *command) +sac_int SACsystem (char *command) { const char * cmd = command; - return system (cmd); + return (sac_int)system (cmd); } From 4dbf37082515d668c7a2b4758f55f13d34987e43 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 21 Jan 2026 22:50:16 +0100 Subject: [PATCH 29/29] use default sac2c branch (will fail the first time) --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 23bfacda..f88bd2cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: sudo apt install xsltproc -y - name: Install sac2c run: | - git clone --single-branch --recursive -b index-types https://gitlab.sac-home.org/sac-group/sac2c.git + git clone --single-branch --recursive https://gitlab.sac-home.org/sac-group/sac2c.git cd sac2c make release -j2 cp build_p/sac2c_p /usr/local/bin/sac2c @@ -70,7 +70,7 @@ jobs: xcode-version: latest-stable - name: Install sac2c run: | - git clone --single-branch --recursive -b index-types https://gitlab.sac-home.org/sac-group/sac2c.git + git clone --single-branch --recursive https://gitlab.sac-home.org/sac-group/sac2c.git cd sac2c make release -j2 cp build_p/sac2c_p /usr/local/bin/sac2c