From e7e967e3a8cbba7cf913a955e4dbcf55bf092aed Mon Sep 17 00:00:00 2001
From: Michael Gernoth <michael@gernoth.net>
Date: Sat, 21 Sep 2024 14:12:54 +0200
Subject: [PATCH] Fix compilation with gcc 14

gcc 14 upgrades warnings about incompatible pointer types to errors,
fix this and also add includes for undefined functions.

Fixes #58
---
 src/dapi/src/api/ttsapi.c             | 12 ++++++------
 src/dapi/src/cmd/cm_main.c            |  4 ++--
 src/dapi/src/cmd/par_dict.c           |  2 +-
 src/dapi/src/include/kernel.h         |  8 ++++----
 src/dapi/src/lts/walker.c             |  2 +-
 src/dapi/src/ph/ph_task.c             |  3 ---
 src/dapi/src/vtm/sync.c               |  8 ++++----
 src/dapi/src/vtm/vtmiont.c            |  6 +++---
 src/dtalkml/src/dtalk_ml.c            |  2 +-
 src/licunix/src/csn.c                 |  2 +-
 src/samplosf/src/dtsamples/dtmemory.c |  3 ---
 11 files changed, 23 insertions(+), 29 deletions(-)

diff --git dapi/src/api/ttsapi.c dapi/src/api/ttsapi.c
index 2fc03a87..37f3d466 100644
--- dapi/src/api/ttsapi.c
+++ dapi/src/api/ttsapi.c
@@ -3834,7 +3834,7 @@ static void DeleteTextToSpeechObjects( LPTTS_HANDLE_T phTTS )
 		if ( phTTS->hThread_SYNC != NULL )
 		{
 			exit_pipe( pKsd_t->sync_pipe );
-			write_pipe( pKsd_t->sync_pipe, dwDump, 3 );
+			write_pipe( pKsd_t->sync_pipe, (unsigned char*)dwDump, 3 );
 #ifdef WIN32
 			WaitForSingleObject( phTTS->hThread_SYNC,
 				TIMEOUT_INTERVAL_IN_MSEC );
@@ -7922,7 +7922,7 @@ MMRESULT TextToSpeechAddBuffer( LPTTS_HANDLE_T phTTS,
 		return( MMSYSERR_ERROR );
 	}
 
-	write_pipe( phTTS->pKernelShareData->buffer_pipe, pPipeArray, 1 );
+	write_pipe( phTTS->pKernelShareData->buffer_pipe, (unsigned char*)pPipeArray, 1 );
 	uiI = pipe_count( phTTS->pKernelShareData->buffer_pipe );
 #ifdef WIN32
 #ifdef API_DEBUG
@@ -8579,7 +8579,7 @@ static LPTTS_BUFFER_T GetBuffer( LPTTS_HANDLE_T phTTS )
 	LPTTS_BUFFER_T pTTS_BufferArray[1];  /*MVP : Not a static */
 	LPTTS_BUFFER_T pTTS_Buffer;              /*MVP : Not a static */
 	
-	read_pipeEx( &(phTTS->pKernelShareData->buffer_pipe), &pTTS_BufferArray[0], 1 );
+	read_pipeEx( &(phTTS->pKernelShareData->buffer_pipe), (unsigned char*)&pTTS_BufferArray[0], 1 );
 	
 	pTTS_Buffer = pTTS_BufferArray[0];
 	
@@ -8822,16 +8822,16 @@ void ReturnRemainingBuffers( LPTTS_HANDLE_T phTTS )
 	
 	while (pipe_count( phTTS->pKernelShareData->buffer_pipe )  && phTTS->dwOutputState == STATE_OUTPUT_MEMORY)
 	{
-		read_pipeEx( &(phTTS->pKernelShareData->buffer_pipe), &pPipeArray, 1 );
+		read_pipeEx( &(phTTS->pKernelShareData->buffer_pipe), (unsigned char*)&pPipeArray, 1 );
 //#ifdef WIN32
-		write_pipe(phTTS->pKernelShareData->buffer_delay_pipe, pPipeArray, 1 );
+		write_pipe(phTTS->pKernelShareData->buffer_delay_pipe, (unsigned char*)pPipeArray, 1 );
 	}
 //	OP_UnlockMutex(phTTS->pcsBufferPipe);
 	//UnlockPipe(phTTS->pKernelShareData->buffer_pipe);
 	
 	while (pipe_count( phTTS->pKernelShareData->buffer_delay_pipe ) && phTTS->dwOutputState == STATE_OUTPUT_MEMORY)
 	{
-		read_pipeEx( &(phTTS->pKernelShareData->buffer_delay_pipe), &pPipeArray, 1 );
+		read_pipeEx( &(phTTS->pKernelShareData->buffer_delay_pipe), (unsigned char*)&pPipeArray, 1 );
 		
 //#endif
 //#if defined __osf__ || defined __linux__ || defined VXWORKS
diff --git dapi/src/cmd/cm_main.c dapi/src/cmd/cm_main.c
index 1c9cbdac..eea69020 100644
--- dapi/src/cmd/cm_main.c
+++ dapi/src/cmd/cm_main.c
@@ -176,7 +176,7 @@ OP_THREAD_ROUTINE( cmd_main, LPTTS_HANDLE_T phTTS )
 	        phTTS->uiThreadError = MMSYSERR_NOMEM;
         else
 		/***************Thread specific structure initialization MVP ***************/
-			if((pCmd_t->cm = (int*)calloc(total_commands,sizeof(int) ))== NULL)
+			if((pCmd_t->cm = (short int*)calloc(total_commands,sizeof(int) ))== NULL)
 				phTTS->uiThreadError = MMSYSERR_NOMEM;
 #ifdef ESCAPE_SEQ
 			else
diff --git dapi/src/cmd/par_dict.c dapi/src/cmd/par_dict.c
index dfac5fee..fed47697 100644
--- dapi/src/cmd/par_dict.c
+++ dapi/src/cmd/par_dict.c
@@ -67,10 +67,10 @@
 #include "par_def.h"
 #include "tts.h"
 #include <stdio.h> // NAL warning removal
+#include <string.h>
 
 #if defined ARM7 || defined __EMSCRIPTEN__ || defined (__APPLE__)
 #include "stdlib.h"
-#include "string.h"
 #endif
 
  
diff --git dapi/src/include/kernel.h dapi/src/include/kernel.h
index c9d4158a..48bcea3e 100644
--- dapi/src/include/kernel.h
+++ dapi/src/include/kernel.h
@@ -468,8 +468,8 @@ struct dtpc_language_tables {
 	unsigned char _far *                    lang_arpabet;
 	int                                     lang_arpa_size;
 	int                                     lang_arpa_case;
-	unsigned char _far *    _far *          lang_typing;
-	unsigned char _far *    _far *          lang_error;
+	const unsigned char _far *    _far *    lang_typing;
+	const unsigned char _far *    _far *    lang_error;
 };
 
 #define NULL_CP ((struct dtpc_code_pages _far *)0L)
@@ -815,8 +815,8 @@ volatile int iSwVolume;
 	volatile unsigned char _far *				arpabet;
 	volatile int								arpa_size;
 	volatile int								arpa_case;
-	volatile unsigned char _far * _far *		typing_table;
-	volatile unsigned char _far *   _far *		error_table;
+	volatile const unsigned char _far * _far *		typing_table;
+	volatile const unsigned char _far *   _far *		error_table;
 	
 #ifdef DTPC2
 /* images of read-only registers */
diff --git dapi/src/lts/walker.c dapi/src/lts/walker.c
index 8f96464d..4bd71635 100644
--- dapi/src/lts/walker.c
+++ dapi/src/lts/walker.c
@@ -1262,7 +1262,7 @@ void register_word_part(WalkCNTXT *cntxt, GERLETTER *name, U16 from, U16 to, BOO
     }
 }
   
-void split_inline_morph_phonemes(const GERLETTER *name, int *comparelength, int *phonestart, int *phonelength, U16 *rule)
+void split_inline_morph_phonemes(const GERLETTER *name, S16 *comparelength, S16 *phonestart, S16 *phonelength, U16 *rule)
      /* This special cludge function applies to strings in the form "ed @d 1" where ed is a compare
 	string, @d is a phoneme string and 1 is a rule number. We want to know how many 
 	characters are in the compare string, where the phoneme string begins, and how long it is,
diff --git dapi/src/ph/ph_task.c dapi/src/ph/ph_task.c
index 8fa1e235..ea15907e 100644
--- dapi/src/ph/ph_task.c
+++ dapi/src/ph/ph_task.c
@@ -152,9 +152,6 @@
 
 #if defined __linux__ || defined VXWORKS || defined _SPARC_SOLARIS_ || defined ARM7 || defined __EMSCRIPTEN__ || defined (__APPLE__)
 #include <stdlib.h>
-#endif
-
-#if defined (__APPLE__)
 #include <string.h>
 #endif
 
diff --git dapi/src/vtm/sync.c dapi/src/vtm/sync.c
index aa00b818..b9cc055e 100644
--- dapi/src/vtm/sync.c
+++ dapi/src/vtm/sync.c
@@ -198,13 +198,13 @@ OP_THREAD_ROUTINE(sync_main, LPTTS_HANDLE_T phTTS)
 
   for(;;)
   {
-	read_pipe( pKsd_t->sync_pipe, &control, 1 );
+	read_pipe( pKsd_t->sync_pipe, (unsigned char*)&control, 1 );
 
 	switch ( control )
 	{
 	case SPC_type_sync:
 
-	read_pipe( pKsd_t->sync_pipe, dwSyncParams, 1 );
+	read_pipe( pKsd_t->sync_pipe, (unsigned char*)dwSyncParams, 1 );
 
 #ifdef TYPING_MODE
 	// never wait for the sample to play when we're in typing mode..
@@ -240,7 +240,7 @@ OP_THREAD_ROUTINE(sync_main, LPTTS_HANDLE_T phTTS)
 	case SPC_type_visual: // tek 27aug97
 		// this is a lot like the index types below, but that was getting so 
 		// cluttered that I put it in a separate case arm. 
-		read_pipe( pKsd_t->sync_pipe, dwSyncParams, 3 );  // get the rest of the pkt
+		read_pipe( pKsd_t->sync_pipe, (unsigned char*)dwSyncParams, 3 );  // get the rest of the pkt
 //#ifdef WIN32 // tek 08jan98 we only process these for WIN32 for now.
 		// wait for it to play
 		if (dwSyncParams[2]) //toss nulls
@@ -389,7 +389,7 @@ OP_THREAD_ROUTINE(sync_main, LPTTS_HANDLE_T phTTS)
 	// tek 15aug97 these are now all changed to always either process the
 	// mark or free the contained memory,
 
-	read_pipe( pKsd_t->sync_pipe, dwSyncParams, 3 );
+	read_pipe( pKsd_t->sync_pipe, (unsigned char*)dwSyncParams, 3 );
 
 
 	  /************************************************************/
diff --git dapi/src/vtm/vtmiont.c dapi/src/vtm/vtmiont.c
index 57d3d94b..66af958e 100644
--- dapi/src/vtm/vtmiont.c
+++ dapi/src/vtm/vtmiont.c
@@ -1750,7 +1750,7 @@ typedef struct tagLLFrame {
 	  pVtm_t->dwSyncParams[1] = phTTS->dwQueuedSampleCount;
 		  OP_UnlockMutex( phTTS->pcsQueuedSampleCount );
 
-	  write_pipe( pKsd_t->sync_pipe, pVtm_t->dwSyncParams, 2 );
+	  write_pipe( pKsd_t->sync_pipe, (unsigned char*)pVtm_t->dwSyncParams, 2 );
 #ifdef TYPING_MODE
 	  }
 #endif //TYPING_MODE
@@ -2003,7 +2003,7 @@ typedef struct tagLLFrame {
 		 write_pipe( pKsd_t->sync_pipe, pVtm_t->dwSyncParams, 4 );
 	  }
 #else // USE_BOOKMARKS_FOR_SYNC
-	  write_pipe( pKsd_t->sync_pipe, pVtm_t->dwSyncParams, 4 );
+	  write_pipe( pKsd_t->sync_pipe, (unsigned char*)pVtm_t->dwSyncParams, 4 );
 #endif //USE_BOOKMARKS.
 	  break;
 
@@ -2765,7 +2765,7 @@ void SendVisualNotification(LPTTS_HANDLE_T phTTS, DWORD dwPhoneme, DWORD dwDurat
 		dwSyncParams[2]=(DWORD)((((QWORD)(pvdPacket)) & 0xFFFFFFFF00000000) >> 32);
 		dwSyncParams[3]=(DWORD)(((QWORD)(pvdPacket)) & 0x00000000FFFFFFFF);
 #endif
-		write_pipe(pKsd_t->sync_pipe, dwSyncParams,4);
+		write_pipe(pKsd_t->sync_pipe, (unsigned char*)dwSyncParams,4);
 		
 	}
 	
diff --git dtalkml/src/dtalk_ml.c dtalkml/src/dtalk_ml.c
index 40b2c7e8..c7dcd89e 100644
--- dtalkml/src/dtalk_ml.c
+++ dtalkml/src/dtalk_ml.c
@@ -766,7 +766,7 @@ MMRESULT TextToSpeechStartup(LPTTS_HANDLE_T *a, UINT b, DWORD c, VOID (*d)(LONG,
 	*b = (LPTTS_HANDLE_T)handle;
 	lang = find_pid(GetCurrentProcessId());
 #else
-	*a = handle;
+	*a = (LPTTS_HANDLE_T)handle;
 	lang = find_pid(_getpid());
 #endif
 
diff --git licunix/src/csn.c licunix/src/csn.c
index 4eaf7da5..73249dd8 100644
--- licunix/src/csn.c
+++ licunix/src/csn.c
@@ -7,7 +7,7 @@
 #endif
 #include	"csn.h"
 
-#if defined (__APPLE__)
+#if defined __osf__ || defined __linux__ || defined VXWORKS || defined _SPARC_SOLARIS_ || defined __EMSCRIPTEN__ || defined (__APPLE__)
 #include <ctype.h>
 #endif
 
diff --git samplosf/src/dtsamples/dtmemory.c samplosf/src/dtsamples/dtmemory.c
index f620ab03..3952f1bb 100644
--- samplosf/src/dtsamples/dtmemory.c
+++ samplosf/src/dtsamples/dtmemory.c
@@ -95,9 +95,6 @@
 #if defined __linux__ || defined _SPARC_SOLARIS_ || defined (__APPLE__)
 #include <stdlib.h> /* for atoi(), malloc() */
 #include <unistd.h> /* for sleep() */
-#endif
-
-#if defined (__APPLE__)
 #include <string.h> 
 #endif
 
