Lookup() constify WindGetCommandTable() returns 'const'

This commit related to the dynamic creation of data that is used
to parse commands and options via Lookup.

windows/windows.h: Lookup() constify call-site
tcltk/tclmagic.c: Lookup() constify call-site
graphics/W3Dmain.c: Lookup() constify call-site
windows/windSend.c: Lookup() constify call-site
windows/windMain.c: Lookup() constify call-site
windows/windInt.h: Lookup() constify call-site
textio/txMain.c: Lookup() constify call-site
This commit is contained in:
Darryl L. Miles 2024-10-10 20:16:36 +01:00 committed by Tim Edwards
parent 882d82a8ae
commit 586e9f1e36
7 changed files with 16 additions and 15 deletions

View File

@ -645,7 +645,7 @@ w3dHelp(w, cmd)
MagWindow *w; MagWindow *w;
TxCommand *cmd; TxCommand *cmd;
{ {
char **msg; const char * const *msg;
W3DclientRec *crec = (W3DclientRec *) w->w_clientData; W3DclientRec *crec = (W3DclientRec *) w->w_clientData;
if (cmd->tx_argc == 1) if (cmd->tx_argc == 1)

View File

@ -512,7 +512,7 @@ _magic_initialize(ClientData clientData,
int n, i; int n, i;
char keyword[100]; char keyword[100];
char *kwptr = keyword + 7; char *kwptr = keyword + 7;
char **commandTable; const char * const *commandTable;
int result; int result;
/* Is magic being executed in a slave interpreter? */ /* Is magic being executed in a slave interpreter? */

View File

@ -104,7 +104,7 @@ void
TxInitReadline() TxInitReadline()
{ {
int i, j; int i, j;
char **commandTable; const char * const *commandTable;
char nobell[] = "set bell-style none"; char nobell[] = "set bell-style none";
rl_getc_function = TxGetChar; rl_getc_function = TxGetChar;

View File

@ -36,7 +36,7 @@ typedef struct WIND_S3 {
bool (*w_exit)(); bool (*w_exit)();
void (*w_reposition)(); /* called when a window moves or changes size */ void (*w_reposition)(); /* called when a window moves or changes size */
GrGlyph *w_icon; GrGlyph *w_icon;
char **w_commandTable; const char * const *w_commandTable;
void (**w_functionTable)(); void (**w_functionTable)();
struct WIND_S3 *w_nextClient; struct WIND_S3 *w_nextClient;
} clientRec; } clientRec;

View File

@ -260,8 +260,9 @@ WindAddClient(clientName, create, delete, redisplay, command, update,
/* Commands and functions should be registered with the client */ /* Commands and functions should be registered with the client */
/* using the WindAddCommand() function. */ /* using the WindAddCommand() function. */
res->w_commandTable = (char **)mallocMagic(sizeof(char *)); const char **newtable = (const char **)mallocMagic(sizeof(char *));
*(res->w_commandTable) = NULL; newtable[0] = NULL;
res->w_commandTable = newtable;
res->w_functionTable = (void (**)())mallocMagic(sizeof(void (*)())); res->w_functionTable = (void (**)())mallocMagic(sizeof(void (*)()));
*(res->w_functionTable) = NULL; *(res->w_functionTable) = NULL;
@ -406,7 +407,7 @@ WindExecute(w, rc, cmd)
{ {
int cmdNum; int cmdNum;
clientRec *client = (clientRec *) rc; clientRec *client = (clientRec *) rc;
char **commandTable = client->w_commandTable; const char * const *commandTable = client->w_commandTable;
void (**functionTable)() = client->w_functionTable; void (**functionTable)() = client->w_functionTable;
if (cmd->tx_argc > 0) if (cmd->tx_argc > 0)
@ -452,9 +453,9 @@ WindAddCommand(rc, text, func, dynamic)
{ {
int cidx, numCommands = 0; int cidx, numCommands = 0;
clientRec *client = (clientRec *) rc; clientRec *client = (clientRec *) rc;
char **commandTable = client->w_commandTable; const char * const *commandTable = client->w_commandTable;
void (**functionTable)() = client->w_functionTable; void (**functionTable)() = client->w_functionTable;
char **newcmdTable; const char **newcmdTable;
void (**newfnTable)(); void (**newfnTable)();
/* Find the number of commands and functions, increment by one, and */ /* Find the number of commands and functions, increment by one, and */
@ -463,7 +464,7 @@ WindAddCommand(rc, text, func, dynamic)
while (commandTable[numCommands] != NULL) numCommands++; while (commandTable[numCommands] != NULL) numCommands++;
numCommands++; numCommands++;
newcmdTable = (char **)mallocMagic((numCommands + 1) * sizeof(char *)); newcmdTable = (const char **)mallocMagic((numCommands + 1) * sizeof(char *));
newfnTable = (void (**)())mallocMagic((numCommands + 1) * sizeof(void (*)())); newfnTable = (void (**)())mallocMagic((numCommands + 1) * sizeof(void (*)()));
/* Copy the old values, inserting the new command in alphabetical */ /* Copy the old values, inserting the new command in alphabetical */
@ -493,7 +494,7 @@ WindAddCommand(rc, text, func, dynamic)
/* Release memory for the original pointers, and replace the */ /* Release memory for the original pointers, and replace the */
/* pointers in the client record. */ /* pointers in the client record. */
freeMagic(commandTable); freeMagic((void*)commandTable);
freeMagic(functionTable); freeMagic(functionTable);
client->w_commandTable = newcmdTable; client->w_commandTable = newcmdTable;
@ -534,7 +535,7 @@ WindReplaceCommand(rc, command, newfunc)
{ {
int cidx, clen; int cidx, clen;
clientRec *client = (clientRec *) rc; clientRec *client = (clientRec *) rc;
char **commandTable = client->w_commandTable; const char * const *commandTable = client->w_commandTable;
void (**functionTable)() = client->w_functionTable; void (**functionTable)() = client->w_functionTable;
clen = strlen(command); clen = strlen(command);
@ -569,7 +570,7 @@ WindReplaceCommand(rc, command, newfunc)
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
char ** const char * const *
WindGetCommandTable(rc) WindGetCommandTable(rc)
WindClient rc; WindClient rc;
{ {

View File

@ -265,7 +265,7 @@ WindSendCommand(w, cmd, quiet)
(*(windClient->w_command))(w, cmd); (*(windClient->w_command))(w, cmd);
else if ((windCmdNum >= 0) && (clientCmdNum >= 0)) else if ((windCmdNum >= 0) && (clientCmdNum >= 0))
{ {
char *(ownTable[3]); const char *(ownTable[3]);
int ownCmdNum; int ownCmdNum;
ownTable[0] = rc->w_commandTable[clientCmdNum]; ownTable[0] = rc->w_commandTable[clientCmdNum];

View File

@ -250,7 +250,7 @@ extern void windFixSurfaceArea();
extern int WindExecute(); extern int WindExecute();
extern void WindAddCommand(); extern void WindAddCommand();
extern int WindReplaceCommand(); extern int WindReplaceCommand();
extern char **WindGetCommandTable(); extern const char * const *WindGetCommandTable();
extern int windCheckOnlyWindow(MagWindow **, WindClient); extern int windCheckOnlyWindow(MagWindow **, WindClient);