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.

This commit is contained in:
Vincent Barrilliot 2021-12-08 23:09:44 +01:00
parent 4b46f4e7d8
commit 4508526f77
14 changed files with 93 additions and 86 deletions

View file

@ -3,7 +3,9 @@
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#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);
}

View file

@ -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

View file

@ -19,7 +19,7 @@
*
* DISKREAD <drive #> <sector #>
*/
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 <drive #> <sector #> <value>
*/
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 <drive #> <label>
*
*/
short cmd_label(short screen, int argc, char * argv[]) {
short cmd_label(short screen, int argc, const char * argv[]) {
if (argc > 2) {
short drive = cli_eval_number(argv[1]);
short result = fsys_setlabel(drive, argv[2]);
@ -433,7 +433,7 @@ short cmd_label(short screen, int argc, char * argv[]) {
*
* FORMAT <drive #>
*/
short cmd_format(short screen, int argc, char * argv[]) {
short cmd_format(short screen, int argc, const char * argv[]) {
if (argc > 1) {
short drive = cli_eval_number(argv[1]);
short result = fsys_mkfs(drive, "");

View file

@ -8,66 +8,66 @@
/*
* Execute a binary file
*/
extern short cmd_run(short screen, int argc, char * argv[]);
extern short cmd_run(short screen, int argc, const char * argv[]);
/*
* List the directory at the given path
*/
extern short cmd_dir(short screen, int argc, char * argv[]);
extern short cmd_dir(short screen, int argc, const char * argv[]);
/*
* Create a directory
*/
extern short cmd_mkdir(short screen, int argc, char * argv[]);
extern short cmd_mkdir(short screen, int argc, const char * argv[]);
/*
* Delete a file or directory
*/
extern short cmd_del(short screen, int argc, char * argv[]);
extern short cmd_del(short screen, int argc, const char * argv[]);
/*
* Copies file(s) to destination
*/
extern short cmd_copy(short screen, int argc, char * argv[]);
extern short cmd_copy(short screen, int argc, const char * argv[]);
/*
* Set the current working directory
*/
extern short cmd_cd(short screen, int argc, char * argv[]);
extern short cmd_cd(short screen, int argc, const char * argv[]);
/*
* Print the current working directory
*/
extern short cmd_pwd(short screen, int argc, char * argv[]);
extern short cmd_pwd(short screen, int argc, const char * argv[]);
/*
* Rename a file or directory
*/
extern short cmd_rename(short screen, int argc, char * argv[]);
extern short cmd_rename(short screen, int argc, const char * argv[]);
/*
* Print the contents of a file to the screen
*/
extern short cmd_type(short screen, int argc, char * argv[]);
extern short cmd_type(short screen, int argc, const char * argv[]);
/*
* Load a binary file into memory
*/
extern short cmd_load(short screen, int argc, char * argv[]);
extern short cmd_load(short screen, int argc, const char * argv[]);
/*
* Read a sector off a drive
*
* DISKREAD <drive #> <sector #>
*/
extern short cmd_diskread(short screen, int argc, char * argv[]);
extern short cmd_diskread(short screen, int argc, const char * argv[]);
/*
* Fill a sector of a drive with a byte value
*
* DISKFILL <drive #> <sector #> <value>
*/
extern short cmd_diskfill(short screen, int argc, char * argv[]);
extern short cmd_diskfill(short screen, int argc, const char * argv[]);
/*
* Set the label of a drive
@ -75,13 +75,13 @@ extern short cmd_diskfill(short screen, int argc, char * argv[]);
* LABEL <drive #> <label>
*
*/
extern short cmd_label(short screen, int argc, char * argv[]);
extern short cmd_label(short screen, int argc, const char * argv[]);
/*
* Format a drive
*
* FORMAT <drive #>
*/
extern short cmd_format(short screen, int argc, char * argv[]);
extern short cmd_format(short screen, int argc, const char * argv[]);
#endif

View file

@ -158,7 +158,7 @@ short cli_set_value(short channel, const char * name, const char * value) {
* Returns:
* 0 on success, any other number is an error
*/
short cli_get_value(short channel, char * name, char * buffer, short size) {
short cli_get_value(short channel, const char * name, char * buffer, short size) {
p_setting setting = cli_find_setting(name);
if (setting == 0) {
/* Setting not found... */
@ -214,7 +214,7 @@ short cli_cmd_set(short channel, int argc, const char * argv[]) {
/*
* Command to set the value of a setting
*/
short cli_cmd_get(short channel, int argc, char * argv[]) {
short cli_cmd_get(short channel, int argc, const char * argv[]) {
char buffer[128];
short result;
@ -224,7 +224,7 @@ short cli_cmd_get(short channel, int argc, char * argv[]) {
cli_set_help(channel);
} else {
result = cli_get_value(channel, argv[1], buffer, 128);
result = cli_get_value(channel, (char*)argv[1], buffer, 128);
if (result == 0) {
print(channel, buffer);
print(channel, "\n");

View file

@ -56,7 +56,7 @@ extern short cli_set_value(short channel, const char * name, const char * value)
* Returns:
* 0 on success, any other number is an error
*/
extern short cli_get_value(short channel, char * name, char * buffer, short size);
extern short cli_get_value(short channel, const char * name, char * buffer, short size);
/*
* Command to set the value of a setting
@ -66,6 +66,6 @@ extern short cli_cmd_set(short screen, int argc, const char * argv[]);
/*
* Command to set the value of a setting
*/
extern short cli_cmd_get(short screen, int argc, char * argv[]);
extern short cli_cmd_get(short screen, int argc, const char * argv[]);
#endif

View file

@ -13,7 +13,7 @@
/*
* Play a sound on the PSG
*/
short psg_test(short channel, int argc, char * argv[]) {
short psg_test(short channel, int argc, const char * argv[]) {
int i;
long target_time;
@ -94,7 +94,7 @@ const unsigned char opl3_tone_off[] = {
/*
* Play a sound on the OPL3
*/
short opl3_test(short channel, int argc, char * argv[]) {
short opl3_test(short channel, int argc, const char * argv[]) {
short i;
unsigned char reg;
unsigned char data;
@ -132,7 +132,7 @@ short opl3_test(short channel, int argc, char * argv[]) {
/*
* Perform a transmit test on the MIDI ports
*/
short midi_tx_test(short channel, int argc, char * argv[]) {
short midi_tx_test(short channel, int argc, const char * argv[]) {
#if MODEL == MODEL_FOENIX_A2560K
const char note_on[] = { 0x90, 0x3c, 0xff };
const char note_off[] = { 0x80, 0x3c, 0x00 };
@ -158,7 +158,7 @@ short midi_tx_test(short channel, int argc, char * argv[]) {
/*
* Perform a receive test on the MIDI ports
*/
short midi_rx_test(short channel, int argc, char * argv[]) {
short midi_rx_test(short channel, int argc, const char * argv[]) {
#if MODEL == MODEL_FOENIX_A2560K
char message[80];
unsigned short scancode = 0;
@ -198,7 +198,7 @@ short midi_rx_test(short channel, int argc, char * argv[]) {
/*
* Perform a loopback test on the MIDI ports
*/
short midi_loop_test(short channel, int argc, char * argv[]) {
short midi_loop_test(short channel, int argc, const char * argv[]) {
#if MODEL == MODEL_FOENIX_A2560K
char message[80];
unsigned short scancode = 0;
@ -242,7 +242,7 @@ short midi_loop_test(short channel, int argc, char * argv[]) {
/*
* Test the OPL2
*/
short opl2_test(short channel, int argc, char * argv[]) {
short opl2_test(short channel, int argc, const char * argv[]) {
unsigned char i;
OPN2_INT_BASE[OPN2_22_LFO] = 0; /* LFO off */

View file

@ -8,31 +8,31 @@
/*
* Play a sound on the PSG
*/
extern short psg_test(short channel, int argc, char * argv[]);
extern short psg_test(short channel, int argc, const char * argv[]);
/*
* Play a sound on the OPL3
*/
extern short opl3_test(short channel, int argc, char * argv[]);
extern short opl3_test(short channel, int argc, const char * argv[]);
/*
* Test the OPL2
*/
extern short opl2_test(short channel, int argc, char * argv[]);
extern short opl2_test(short channel, int argc, const char * argv[]);
/*
* Perform a transmit test on the MIDI ports
*/
extern short midi_tx_test(short channel, int argc, char * argv[]);
extern short midi_tx_test(short channel, int argc, const char * argv[]);
/*
* Perform a receive test on the MIDI ports
*/
extern short midi_rx_test(short channel, int argc, char * argv[]);
extern short midi_rx_test(short channel, int argc, const char * argv[]);
/*
* Perform a loopback test on the MIDI ports
*/
extern short midi_loop_test(short channel, int argc, char * argv[]);
extern short midi_loop_test(short channel, int argc, const char * argv[]);
#endif

View file

@ -59,7 +59,7 @@ typedef struct s_cli_test_feature {
* Tests...
*/
short cli_test_bitmap(short channel, int argc, char * argv[]) {
short cli_test_bitmap(short channel, int argc, const char * argv[]) {
int i,m,p;
unsigned char j;
unsigned short k;
@ -83,7 +83,7 @@ short cli_test_bitmap(short channel, int argc, char * argv[]) {
return 0;
}
short cli_test_uart(short channel, int argc, char * argv[]) {
short cli_test_uart(short channel, int argc, const char * argv[]) {
char c;
char buffer[80];
@ -110,7 +110,7 @@ short cli_test_uart(short channel, int argc, char * argv[]) {
return 0;
}
short cli_test_panic(short channel, int argc, char * argv[]) {
short cli_test_panic(short channel, int argc, const char * argv[]) {
volatile int x = 0;
return argc / x;
}
@ -118,7 +118,7 @@ short cli_test_panic(short channel, int argc, char * argv[]) {
/*
* Try using the RTC periodic interrupt in polled mode
*/
short cli_test_rtc(short channel, int argc, char * argv[]) {
short cli_test_rtc(short channel, int argc, const char * argv[]) {
char buffer[80];
char * spinner = "|/-\\";
short count = 0;
@ -150,7 +150,7 @@ short cli_test_rtc(short channel, int argc, char * argv[]) {
/*
* Test the memory
*/
short cli_mem_test(short channel, int argc, char * argv[]) {
short cli_mem_test(short channel, int argc, const char * argv[]) {
volatile unsigned char * memory = 0x00000000;
t_sys_info sys_info;
const long mem_start = 0x00050000;
@ -201,7 +201,7 @@ short cli_mem_test(short channel, int argc, char * argv[]) {
/*
* Test the IDE interface by reading the MBR
*/
short cli_test_ide(short screen, int argc, char * argv[]) {
short cli_test_ide(short screen, int argc, const char * argv[]) {
unsigned char buffer[512];
short i;
short scancode;
@ -230,7 +230,7 @@ short cli_test_ide(short screen, int argc, char * argv[]) {
/*
* Test file creation
*/
short cli_test_create(short screen, int argc, char * argv[]) {
short cli_test_create(short screen, int argc, const char * argv[]) {
short n;
if (argc > 1) {
@ -256,7 +256,7 @@ short cli_test_create(short screen, int argc, char * argv[]) {
}
}
short cli_test_lpt(short screen, int argc, char * argv[]) {
short cli_test_lpt(short screen, int argc, const char * argv[]) {
#if MODEL == MODEL_FOENIX_A2560K
char message[80];
unsigned char scancode;
@ -312,7 +312,7 @@ short cli_test_lpt(short screen, int argc, char * argv[]) {
return 0;
}
short cmd_test_print(short screen, int argc, char * argv[]) {
short cmd_test_print(short screen, int argc, const char * argv[]) {
#if MODEL == MODEL_FOENIX_A2560K
const char * test_pattern = "0123456789ABCDEFGHIJKLMNOPQRTSUVWZXYZ\r\n";
@ -372,7 +372,7 @@ void test_help(short screen) {
/*
* Test command
*/
short cmd_test(short screen, int argc, char * argv[]) {
short cmd_test(short screen, int argc, const char * argv[]) {
short i;
p_cli_test_feature f;

View file

@ -8,6 +8,6 @@
/*
* Test command
*/
extern short cmd_test(short channel, int argc, char * argv[]);
extern short cmd_test(short channel, int argc, const char * argv[]);
#endif

View file

@ -7,7 +7,9 @@
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "log.h"
#include "syscalls.h"
@ -731,7 +733,7 @@ short fsys_getlabel(char * path, char * label) {
* drive = drive number
* label = buffer that holds the label
*/
short fsys_setlabel(short drive, char * label) {
short fsys_setlabel(short drive, const char * label) {
FRESULT fres;
char buffer[80];

View file

@ -141,7 +141,7 @@ extern short fsys_getlabel(char * path, char * label);
* drive = drive number
* label = buffer that holds the label
*/
extern short fsys_setlabel(short drive, char * label);
extern short fsys_setlabel(short drive, const char * label);
/*
* Format a drive

View file

@ -2,7 +2,10 @@
* A logging utility
*/
#include <stdio.h>
#include <string.h>
#include "interrupt.h"
#include "log.h"
#include "simpleio.h"
#include "dev/text_screen_iii.h"
@ -242,7 +245,7 @@ void log2(short level, char * message1, char * message2) {
* message2 = the second part of the message to log
* message3 = the third part of the message to log
*/
void log3(short level, char * message1, char * message2, char * message3) {
void log3(short level, const char * message1, const char * message2, const char * message3) {
if (level <= log_level) {
print(log_channel, message1);
print(log_channel, message2);

View file

@ -72,7 +72,7 @@ extern void log2(short level, char * message1, char * message2);
* message2 = the second part of the message to log
* message3 = the third part of the message to log
*/
extern void log3(short level, char * message1, char * message2, char * message3);
extern void log3(short level, const char * message1, const char * message2, const char * message3);
/*
* Log a message with a number