--- freem/src/init.c 2025/04/17 14:34:27 1.13
+++ freem/src/init.c 2025/05/16 04:02:14 1.15
@@ -1,5 +1,5 @@
/*
- * $Id: init.c,v 1.13 2025/04/17 14:34:27 snw Exp $
+ * $Id: init.c,v 1.15 2025/05/16 04:02:14 snw Exp $
* FreeM initialization
*
*
@@ -24,6 +24,12 @@
* along with FreeM. If not, see .
*
* $Log: init.c,v $
+ * Revision 1.15 2025/05/16 04:02:14 snw
+ * Make FreeM build on macOS on Apple Silicon
+ *
+ * Revision 1.14 2025/04/20 03:13:17 snw
+ * Updates to init_execution_context
+ *
* Revision 1.13 2025/04/17 14:34:27 snw
* Further logging improvements
*
@@ -82,6 +88,12 @@
# include
#endif
+#if defined(__APPLE__)
+# define termio termios
+# define TCGETA TIOCGETA
+# define TCSETA TIOCSETA
+#endif
+
#include "config.h"
#if defined(HAVE_MWAPI_MOTIF)
@@ -398,8 +410,7 @@ void init_timezone (void)
long clock;
-#ifdef __CYGWIN__
-
+#if defined(__CYGWIN__)
tzset (); /* may be required in order */
/* to guarantee _timezone set */
#else
@@ -487,9 +498,10 @@ void init_execution_context (void)
codptr = code;
code[0] = EOL; /* init code_pointer */
- partition = calloc ((unsigned) (PSIZE + 2), 1);
- if (partition == NULL) exit (2); /* could not allocate stuff... */
+ if ((partition = calloc ((unsigned) (PSIZE + 2), 1)) == NULL) {
+ logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate symbol table (error code %d [%s])", errno, strerror (errno));
+ }
for (i = 0; i < MAXNO_OF_RBUF; i++) {
rbuf_flags[i].standard = standard;
@@ -503,39 +515,44 @@ void init_execution_context (void)
s = &partition[PSIZE] - 256; /* pointer to symlen_offset */
argptr = partition; /* pointer to beg of tmp-storage */
- svntable = calloc ((unsigned) (UDFSVSIZ + 1), 1);
- if (svntable == NULL) exit (2); /* could not allocate stuff... */
-
+ if ((svntable = calloc ((unsigned) (UDFSVSIZ + 1), 1)) == NULL) {
+ logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate user-defined ISV table (error code %d [%s])", errno, strerror (errno));
+ }
svnlen = UDFSVSIZ; /* begin of udf_svn_table */
- buff = calloc ((unsigned) NO_OF_RBUF * (unsigned) PSIZE0, 1); /* routine buffer pool */
- if (buff == NULL) exit (2); /* could not allocate stuff... */
+ if ((buff = calloc ((unsigned) NO_OF_RBUF * (unsigned) PSIZE0, 1)) == NULL) {
+ logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate routine buffers (error code %d [%s])", errno, strerror (errno));
+ }
- newstack = calloc ((unsigned) NSIZE, 1);
- if (newstack == NULL) exit (2); /* could not allocate stuff... */
+ if ((newstack = calloc ((unsigned) NSIZE, 1)) == NULL) {
+ logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate NEW stack (error code %d [%s])", errno, strerror (errno));
+ }
- #ifdef DEBUG_NEWPTR
- printf("Allocating newptr stack...\r\n");
- #endif
+ logprintf (FM_LOG_DEBUG, "allocating newptr stack...");
newptr = newstack;
newlimit = newstack + NSIZE - 1024;
- namstck = calloc ((unsigned) NESTLEVLS * 13, 1);
- if (namstck == NULL) exit (2); /* could not allocate stuff... */
-
+ if ((namstck = calloc ((unsigned) NESTLEVLS * 13, 1)) == NULL) {
+ logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate newptr stack (error code %d [%s])", errno, strerror (errno));
+ }
+
*namstck = EOL;
*(namstck + 1) = EOL;
namptr = namstck; /* routine name stack pointer */
- framstck = calloc ((unsigned) NESTLEVLS * 256, 1);
- if (framstck == NULL) exit (2); /* could not allocate stuff... */
+
+ if ((framstck = calloc ((unsigned) NESTLEVLS * 256, 1)) == NULL) {
+ logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate DO frame stack stack (error code %d [%s])", errno, strerror (errno));
+ }
*framstck = EOL;
*(framstck + 1) = EOL;
dofrmptr = framstck; /* DO_frame stack pointer */
- cmdstack = calloc ((unsigned) NESTLEVLS * 256, 1);
- if (cmdstack == NULL) exit (2); /* could not allocate stuff... */
+
+ if ((cmdstack = calloc ((unsigned) NESTLEVLS * 256, 1)) == NULL) {
+ logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate command stack (error code %d [%s])", errno, strerror (errno));
+ }
cmdptr = cmdstack; /* command stack */