From 4508526f77ec2560b97bff523aac6108888e900c Mon Sep 17 00:00:00 2001 From: Vincent Barrilliot Date: Wed, 8 Dec 2021 23:09:44 +0100 Subject: [PATCH] Address warning messages in cli.c and dependencies. Made internal handlers's argv const as it' safe to do for internal purposes and helps the compiler's optimizations. --- src/cli/cli.c | 46 +++++++++++++++++++++++--------------------- src/cli/cli.h | 4 ++-- src/cli/dos_cmds.c | 32 +++++++++++++++--------------- src/cli/dos_cmds.h | 28 +++++++++++++-------------- src/cli/settings.c | 6 +++--- src/cli/settings.h | 4 ++-- src/cli/sound_cmds.c | 12 ++++++------ src/cli/sound_cmds.h | 12 ++++++------ src/cli/test_cmd2.c | 20 +++++++++---------- src/cli/test_cmds.h | 2 +- src/dev/fsys.c | 4 +++- src/dev/fsys.h | 2 +- src/log.c | 5 ++++- src/log.h | 2 +- 14 files changed, 93 insertions(+), 86 deletions(-) diff --git a/src/cli/cli.c b/src/cli/cli.c index afd9239..f513076 100644 --- a/src/cli/cli.c +++ b/src/cli/cli.c @@ -3,7 +3,9 @@ */ #include +#include #include + #include "log.h" #include "types.h" #include "interrupt.h" @@ -39,11 +41,11 @@ typedef struct s_cli_command { cli_cmd_handler handler; } t_cli_command, *p_cli_command; -extern short cmd_sysinfo(short channel, int argc, char * argv[]); -extern short cmd_cls(short channel, int argc, char * argv[]); -extern short cmd_showint(short channel, int argc, char * argv[]); -extern short cmd_getjiffies(short channel, int argc, char * argv[]); -extern short cmd_get_ticks(short channel, int argc, char * argv[]); +extern short cmd_sysinfo(short channel, int argc, const char * argv[]); +extern short cmd_cls(short channel, int argc, const char * argv[]); +extern short cmd_showint(short channel, int argc, const char * argv[]); +extern short cmd_getjiffies(short channel, int argc, const char * argv[]); +extern short cmd_get_ticks(short channel, int argc, const char * argv[]); /* * Variables @@ -89,20 +91,20 @@ const t_cli_command g_cli_commands[] = { // // List all the commands // -int cmd_help(short channel, int argc, char * argv[]) { +short cmd_help(short channel, int argc, const char * argv[]) { p_cli_command command; - for (command = g_cli_commands; (command != 0) && (command->name != 0); command++) { + for (command = (p_cli_command)g_cli_commands; (command != 0) && (command->name != 0); command++) { sys_chan_write(channel, command->help, strlen(command->help)); sys_chan_write(channel, "\n", 2); } return 0; } -short cmd_getjiffies(short channel, int argc, char * argv[]) { +short cmd_getjiffies(short channel, int argc, const char * argv[]) { char buffer[80]; - sprintf(buffer, "%d\n", timers_jiffies()); + sprintf(buffer, "%ld\n", timers_jiffies()); sys_chan_write(channel, buffer, strlen(buffer));; return 0; } @@ -110,10 +112,10 @@ short cmd_getjiffies(short channel, int argc, char * argv[]) { /* * Print the number of ticks since last restart */ -short cmd_get_ticks(short channel, int argc, char * argv[]) { +short cmd_get_ticks(short channel, int argc, const char * argv[]) { char buffer[80]; - sprintf(buffer, "%d\n", rtc_get_jiffies()); + sprintf(buffer, "%ld\n", rtc_get_jiffies()); sys_chan_write(channel, buffer, strlen(buffer)); return 0; } @@ -121,7 +123,7 @@ short cmd_get_ticks(short channel, int argc, char * argv[]) { /* * Clear the screen */ -short cmd_cls(short channel, int argc, char * argv[]) { +short cmd_cls(short channel, int argc, const char * argv[]) { const char * ansi_cls = "\x1B[2J\x1B[H"; sys_chan_write(channel, ansi_cls, strlen(ansi_cls)); @@ -131,7 +133,7 @@ short cmd_cls(short channel, int argc, char * argv[]) { /* * Display information about the system */ -short cmd_sysinfo(short channel, int argc, char * argv[]) { +short cmd_sysinfo(short channel, int argc, const char * argv[]) { t_sys_info info; char buffer[80]; @@ -143,22 +145,22 @@ short cmd_sysinfo(short channel, int argc, char * argv[]) { sprintf(buffer, "\nCPU: %s", info.cpu_name); sys_chan_write(channel, buffer, strlen(buffer)); - sprintf(buffer, "\nSystem Memory: 0x%X", info.system_ram_size); + sprintf(buffer, "\nSystem Memory: 0x%lX", info.system_ram_size); sys_chan_write(channel, buffer, strlen(buffer)); - sprintf(buffer, "\nPCB version: %s", &info.pcb_version); + sprintf(buffer, "\nPCB version: %s", (char*)&info.pcb_version); sys_chan_write(channel, buffer, strlen(buffer)); - sprintf(buffer, "\nFPGA Date: %08X", info.fpga_date); + sprintf(buffer, "\nFPGA Date: %08lX", info.fpga_date); sys_chan_write(channel, buffer, strlen(buffer)); - sprintf(buffer, "\nFPGA Model: %08X", info.fpga_model); + sprintf(buffer, "\nFPGA Model: %08lX", info.fpga_model); sys_chan_write(channel, buffer, strlen(buffer)); sprintf(buffer, "\nFPGA Version: %04X.%04X", info.fpga_version, info.fpga_subver); sys_chan_write(channel, buffer, strlen(buffer)); - sprintf(buffer, "\nMCP version: v%02d.%02d.%04d\n", info.mcp_version, info.mcp_rev, info.mcp_build); + sprintf(buffer, "\nMCP version: v%02u.%02u.%04u\n", info.mcp_version, info.mcp_rev, info.mcp_build); sys_chan_write(channel, buffer, strlen(buffer)); return 0; @@ -167,7 +169,7 @@ short cmd_sysinfo(short channel, int argc, char * argv[]) { /* * Show information about the interrupt registers */ -short cmd_showint(short channel, int argc, char * argv[]) { +short cmd_showint(short channel, int argc, const char * argv[]) { char buffer[80]; TRACE("cmd_showint"); @@ -197,9 +199,9 @@ short cmd_showint(short channel, int argc, char * argv[]) { // command = the upper case name of the command (first word of the command line) // parameters = the string of parameters to be passed to the command // -short cli_exec(short channel, char * command, int argc, char * argv[]) { +short cli_exec(short channel, char * command, int argc, const char * argv[]) { const char * cmd_not_found = "Command not found.\n"; - p_cli_command commands = g_cli_commands; + p_cli_command commands = (p_cli_command)g_cli_commands; log3(LOG_INFO, "cli_exec: '", argv[0], "'"); log_num(LOG_INFO, "argc = ", argc); @@ -249,7 +251,7 @@ char * strtok_r(char * source, const char * delimiter, char ** saveptr) { return x; } -short cli_rerepl() { +void cli_rerepl() { while (1) { cli_repl(g_current_channel); } diff --git a/src/cli/cli.h b/src/cli/cli.h index 0f8d135..e1ef1c7 100644 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -9,7 +9,7 @@ * A function pointer for command implementations: * short cmd_foo(short screen, char * parameters) { ... } */ -typedef short (*cli_cmd_handler)(short screen, int argc, char * argv[]); +typedef short (*cli_cmd_handler)(short screen, int argc, const char * argv[]); /** * About the CLI... @@ -42,6 +42,6 @@ extern long cli_eval_number(const char * arg); /* * Print a help message */ -extern int cmd_help(short channel, int argc, char * argv[]); +extern short cmd_help(short channel, int argc, const char * argv[]); #endif diff --git a/src/cli/dos_cmds.c b/src/cli/dos_cmds.c index 40f03b4..099c16a 100644 --- a/src/cli/dos_cmds.c +++ b/src/cli/dos_cmds.c @@ -19,7 +19,7 @@ * * DISKREAD */ -short cmd_diskread(short screen, int argc, char * argv[]) { +short cmd_diskread(short screen, int argc, const char * argv[]) { unsigned char buffer[512]; short bdev_number = 0; long lba = 0; @@ -53,7 +53,7 @@ short cmd_diskread(short screen, int argc, char * argv[]) { * * DISKFILL */ -short cmd_diskfill(short screen, int argc, char * argv[]) { +short cmd_diskfill(short screen, int argc, const char * argv[]) { unsigned char buffer[512]; unsigned char value; short bdev_number = 0; @@ -93,7 +93,7 @@ short cmd_diskfill(short screen, int argc, char * argv[]) { * * Command name is in argv[0]. */ -short cmd_run(short screen, int argc, char * argv[]) { +short cmd_run(short screen, int argc, const char * argv[]) { TRACE("cmd_run"); short result = proc_run(argv[0], argc, argv); @@ -108,7 +108,7 @@ short cmd_run(short screen, int argc, char * argv[]) { /* * Create a directory */ -short cmd_mkdir(short screen, int argc, char * argv[]) { +short cmd_mkdir(short screen, int argc, const char * argv[]) { TRACE("cmd_mkdir"); @@ -127,7 +127,7 @@ short cmd_mkdir(short screen, int argc, char * argv[]) { /* * Delete a file */ -short cmd_del(short screen, int argc, char * argv[]) { +short cmd_del(short screen, int argc, const char * argv[]) { TRACE("cmd_del"); @@ -143,7 +143,7 @@ short cmd_del(short screen, int argc, char * argv[]) { } } -short cmd_copy(short screen, int argc, char * argv[]) { +short cmd_copy(short screen, int argc, const char * argv[]) { FRESULT find_result; FRESULT result; DIR dir; /* Directory object */ @@ -228,7 +228,7 @@ error: /* * Change the directory */ -short cmd_cd(short screen, int argc, char * argv[]) { +short cmd_cd(short screen, int argc, const char * argv[]) { TRACE("cmd_cd"); @@ -253,7 +253,7 @@ short cmd_cd(short screen, int argc, char * argv[]) { /* * Change the directory */ -short cmd_pwd(short screen, int argc, char * argv[]) { +short cmd_pwd(short screen, int argc, const char * argv[]) { char buffer[128]; TRACE("cmd_pwd"); @@ -271,7 +271,7 @@ short cmd_pwd(short screen, int argc, char * argv[]) { /* * Rename a file or directory */ -short cmd_rename(short screen, int argc, char * argv[]) { +short cmd_rename(short screen, int argc, const char * argv[]) { TRACE("cmd_rename"); @@ -286,7 +286,7 @@ short cmd_rename(short screen, int argc, char * argv[]) { return 0; } -short cmd_dir(short screen, int argc, char * argv[]) { +short cmd_dir(short screen, int argc, const char * argv[]) { short result; char buffer[80]; t_file_info my_file; @@ -294,7 +294,7 @@ short cmd_dir(short screen, int argc, char * argv[]) { char label[40]; if (argc > 1) { - path = argv[1]; + path = (char*)(argv[1]); } short dir = fsys_opendir(path); @@ -342,11 +342,11 @@ short cmd_dir(short screen, int argc, char * argv[]) { /* * Print the contents of a file to the screen */ -short cmd_type(short screen, int argc, char * argv[]) { +short cmd_type(short screen, int argc, const char * argv[]) { if (argc > 1) { unsigned char buffer[128]; - log3(LOG_INFO, "Attempting to type [", argv[1], "]"); + log3(LOG_INFO, "Attempting to type [", (char*)(argv[1]), "]"); short fd = fsys_open(argv[1], FA_READ); if (fd >= 0) { log_num(LOG_INFO, "File open: ", fd); @@ -379,7 +379,7 @@ short cmd_type(short screen, int argc, char * argv[]) { * Load a binary file into memory * parameters: path [address] */ -short cmd_load(short screen, int argc, char * argv[]) { +short cmd_load(short screen, int argc, const char * argv[]) { if (argc > 1) { long start = 0; long destination = 0; @@ -413,7 +413,7 @@ short cmd_load(short screen, int argc, char * argv[]) { * LABEL