shell: swap argc and argv

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent ab5e9d532e
commit a7504ad99c
  1. 12
      include/shell.h
  2. 2
      include/shell/echo.h
  3. 24
      include/shell/mufs.h
  4. 6
      include/shell/rtc.h
  5. 2
      include/shell/version.h
  6. 8
      source/shell/cmd.c
  7. 2
      source/shell/echo.c
  8. 16
      source/shell/flash.c
  9. 6
      source/shell/ftl.c
  10. 28
      source/shell/mufs.c
  11. 6
      source/shell/rtc.c
  12. 2
      source/shell/version.c

@ -5,7 +5,7 @@ struct console;
struct cmd {
const char *cmd;
const char *desc;
void (* exec)(struct console *con, const char **argv, size_t argc);
void (* exec)(struct console *con, size_t argc, const char **argv);
};
struct shell {
@ -18,14 +18,14 @@ struct shell {
size_t count_args(const char *line);
char **parse_args(const char *line, size_t *argc);
void cmd_exec(struct cmd *cmds, struct console *con, const char **argv,
size_t argc);
void cmd_exec(struct cmd *cmds, struct console *con, size_t argc,
const char **argv);
void cmd_parse(struct cmd *cmds, struct console *con, const char *line);
int shell_init(struct shell *shell, struct cmd *cmds,
struct console *con, const char *prompt);
int shell_parse(struct shell *shell);
void do_flash_cmd(struct console *con, const char **argv, size_t argc);
void do_ftl_cmd(struct console *con, const char **argv, size_t argc);
void do_mufs_cmd(struct console *con, const char **argv, size_t argc);
void do_flash_cmd(struct console *con, size_t argc, const char **argv);
void do_ftl_cmd(struct console *con, size_t argc, const char **argv);
void do_mufs_cmd(struct console *con, size_t argc, const char **argv);

@ -1,3 +1,3 @@
#pragma once
void shell_echo(struct console *con, const char **argv, size_t argc);
void shell_echo(struct console *con, size_t argc, const char **argv);

@ -1,14 +1,14 @@
#pragma once
void shell_mount(struct console *con, const char **argv, size_t argc);
void shell_unmount(struct console *con, const char **argv, size_t argc);
void shell_format(struct console *con, const char **argv, size_t argc);
void shell_mkdir(struct console *con, const char **argv, size_t argc);
void shell_rmdir(struct console *con, const char **argv, size_t argc);
void shell_stat(struct console *con, const char **argv, size_t argc);
void shell_cat(struct console *con, const char **argv, size_t argc);
void shell_write(struct console *con, const char **argv, size_t argc);
void shell_append(struct console *con, const char **argv, size_t argc);
void shell_mv(struct console *con, const char **argv, size_t argc);
void shell_rm(struct console *con, const char **argv, size_t argc);
void shell_ls(struct console *con, const char **argv, size_t argc);
void shell_mount(struct console *con, size_t argc, const char **argv);
void shell_unmount(struct console *con, size_t argc, const char **argv);
void shell_format(struct console *con, size_t argc, const char **argv);
void shell_mkdir(struct console *con, size_t argc, const char **argv);
void shell_rmdir(struct console *con, size_t argc, const char **argv);
void shell_stat(struct console *con, size_t argc, const char **argv);
void shell_cat(struct console *con, size_t argc, const char **argv);
void shell_write(struct console *con, size_t argc, const char **argv);
void shell_append(struct console *con, size_t argc, const char **argv);
void shell_mv(struct console *con, size_t argc, const char **argv);
void shell_rm(struct console *con, size_t argc, const char **argv);
void shell_ls(struct console *con, size_t argc, const char **argv);

@ -2,6 +2,6 @@
struct console;
void shell_date(struct console *con, const char **argv, size_t argc);
void shell_time(struct console *con, const char **argv, size_t argc);
void shell_set_date(struct console *con, const char **argv, size_t argc);
void shell_date(struct console *con, size_t argc, const char **argv);
void shell_time(struct console *con, size_t argc, const char **argv);
void shell_set_date(struct console *con, size_t argc, const char **argv);

@ -1,3 +1,3 @@
#pragma once
void shell_version(struct console *con, const char **argv, size_t argc);
void shell_version(struct console *con, size_t argc, const char **argv);

@ -5,8 +5,8 @@
#include <console.h>
#include <shell.h>
void cmd_exec(struct cmd *cmds, struct console *con, const char **argv,
size_t argc)
void cmd_exec(struct cmd *cmds, struct console *con, size_t argc,
const char **argv)
{
struct cmd *cmd;
@ -15,7 +15,7 @@ void cmd_exec(struct cmd *cmds, struct console *con, const char **argv,
for (cmd = cmds; cmd->cmd; ++cmd) {
if (strcmp(cmd->cmd, argv[0]) == 0) {
cmd->exec(con, argv + 1, argc - 1);
cmd->exec(con, argc - 1, argv + 1);
break;
}
}
@ -29,7 +29,7 @@ void cmd_parse(struct cmd *cmds, struct console *con, const char *line)
if (!(argv = parse_args(line, &argc)))
return;
cmd_exec(cmds, con, (const char **)argv, argc);
cmd_exec(cmds, con, argc, (const char **)argv);
free(argv);
}

@ -4,7 +4,7 @@
#include <shell/echo.h>
void shell_echo(struct console *con, const char **argv, size_t argc)
void shell_echo(struct console *con, size_t argc, const char **argv)
{
if (argc < 1)
return;

@ -59,7 +59,7 @@ static void print_hex_ascii(FILE *fp, uint32_t offset, const char *buf, size_t l
}
}
static void do_flash_probe(struct console *con, const char **argv, size_t argc)
static void do_flash_probe(struct console *con, size_t argc, const char **argv)
{
(void)argv;
(void)argc;
@ -75,7 +75,7 @@ static void do_flash_probe(struct console *con, const char **argv, size_t argc)
}
}
static void do_flash_release(struct console *con, const char **argv, size_t argc)
static void do_flash_release(struct console *con, size_t argc, const char **argv)
{
(void)argv;
(void)argc;
@ -89,7 +89,7 @@ static void do_flash_release(struct console *con, const char **argv, size_t argc
flash = NULL;
}
static void do_flash_info(struct console *con, const char **argv, size_t argc)
static void do_flash_info(struct console *con, size_t argc, const char **argv)
{
size_t size, capacity;
@ -108,7 +108,7 @@ static void do_flash_info(struct console *con, const char **argv, size_t argc)
size, capacity, 100 * size / capacity);
}
static void do_flash_read(struct console *con, const char **argv, size_t argc)
static void do_flash_read(struct console *con, size_t argc, const char **argv)
{
char buf[256];
size_t addr, len, nbytes;
@ -150,7 +150,7 @@ static void do_flash_read(struct console *con, const char **argv, size_t argc)
}
}
static void do_flash_write(struct console *con, const char **argv, size_t argc)
static void do_flash_write(struct console *con, size_t argc, const char **argv)
{
char buf[256];
size_t addr, len, nbytes;
@ -197,7 +197,7 @@ static void do_flash_write(struct console *con, const char **argv, size_t argc)
flash_sync(flash);
}
static void do_flash_erase(struct console *con, const char **argv, size_t argc)
static void do_flash_erase(struct console *con, size_t argc, const char **argv)
{
size_t addr, len;
@ -241,12 +241,12 @@ static struct cmd flash_cmds[] = {
{ NULL, NULL, NULL },
};
void do_flash_cmd(struct console *con, const char **argv, size_t argc)
void do_flash_cmd(struct console *con, size_t argc, const char **argv)
{
if (argc < 1) {
fprintf(con->fp, "usage: flash <command>\n");
return;
}
cmd_exec(flash_cmds, con, argv, argc);
cmd_exec(flash_cmds, con, argc, argv);
}

@ -15,7 +15,7 @@
extern struct flash_dev *flash;
static void do_ftl_probe(struct console *con, const char **argv, size_t argc)
static void do_ftl_probe(struct console *con, size_t argc, const char **argv)
{
(void)argv;
(void)argc;
@ -41,12 +41,12 @@ static struct cmd ftl_cmds[] = {
{ NULL, NULL, NULL },
};
void do_ftl_cmd(struct console *con, const char **argv, size_t argc)
void do_ftl_cmd(struct console *con, size_t argc, const char **argv)
{
if (argc < 1) {
fprintf(con->fp, "usage: flash <command>\n");
return;
}
cmd_exec(ftl_cmds, con, argv, argc);
cmd_exec(ftl_cmds, con, argc, argv);
}

@ -20,7 +20,7 @@
extern struct flash_dev *flash;
struct mufs *mufs = NULL;
void shell_mount(struct console *con, const char **argv, size_t argc)
void shell_mount(struct console *con, size_t argc, const char **argv)
{
(void)argc;
(void)argv;
@ -43,7 +43,7 @@ void shell_mount(struct console *con, const char **argv, size_t argc)
flash = NULL;
}
void shell_unmount(struct console *con, const char **argv, size_t argc)
void shell_unmount(struct console *con, size_t argc, const char **argv)
{
(void)argc;
(void)argv;
@ -63,7 +63,7 @@ void shell_unmount(struct console *con, const char **argv, size_t argc)
mufs = NULL;
}
void shell_format(struct console *con, const char **argv, size_t argc)
void shell_format(struct console *con, size_t argc, const char **argv)
{
(void)argc;
(void)argv;
@ -79,7 +79,7 @@ void shell_format(struct console *con, const char **argv, size_t argc)
}
}
void shell_mkdir(struct console *con, const char **argv, size_t argc)
void shell_mkdir(struct console *con, size_t argc, const char **argv)
{
if (argc < 1) {
fprintf(con->fp, "usage: mufs mkdir <path>\n");
@ -97,7 +97,7 @@ void shell_mkdir(struct console *con, const char **argv, size_t argc)
}
}
void shell_rmdir(struct console *con, const char **argv, size_t argc)
void shell_rmdir(struct console *con, size_t argc, const char **argv)
{
if (argc < 1) {
fprintf(con->fp, "usage: mufs rmdir <path>\n");
@ -115,7 +115,7 @@ void shell_rmdir(struct console *con, const char **argv, size_t argc)
}
}
void shell_stat(struct console *con, const char **argv, size_t argc)
void shell_stat(struct console *con, size_t argc, const char **argv)
{
struct mufs_stat stat;
@ -143,7 +143,7 @@ void shell_stat(struct console *con, const char **argv, size_t argc)
printf(" file size: %" PRIu32 " bytes\n", stat.file_size);
}
void shell_cat(struct console *con, const char **argv, size_t argc)
void shell_cat(struct console *con, size_t argc, const char **argv)
{
char data[256];
struct mufs_file *file;
@ -170,7 +170,7 @@ void shell_cat(struct console *con, const char **argv, size_t argc)
mufs_close(file);
}
void shell_write(struct console *con, const char **argv, size_t argc)
void shell_write(struct console *con, size_t argc, const char **argv)
{
char data[256];
struct mufs_file *file;
@ -201,7 +201,7 @@ void shell_write(struct console *con, const char **argv, size_t argc)
mufs_close(file);
}
void shell_append(struct console *con, const char **argv, size_t argc)
void shell_append(struct console *con, size_t argc, const char **argv)
{
struct mufs_file *file;
char data[256];
@ -232,7 +232,7 @@ void shell_append(struct console *con, const char **argv, size_t argc)
mufs_close(file);
}
void shell_mv(struct console *con, const char **argv, size_t argc)
void shell_mv(struct console *con, size_t argc, const char **argv)
{
if (argc < 2) {
fprintf(con->fp, "usage: mufs mv <old> <new>\n");
@ -250,7 +250,7 @@ void shell_mv(struct console *con, const char **argv, size_t argc)
}
}
void shell_rm(struct console *con, const char **argv, size_t argc)
void shell_rm(struct console *con, size_t argc, const char **argv)
{
if (argc < 1) {
fprintf(con->fp, "usage: mufs rm <path>\n");
@ -268,7 +268,7 @@ void shell_rm(struct console *con, const char **argv, size_t argc)
}
}
void shell_ls(struct console *con, const char **argv, size_t argc)
void shell_ls(struct console *con, size_t argc, const char **argv)
{
struct mufs_dirent ent;
struct mufs_dir *dir;
@ -311,7 +311,7 @@ static struct cmd mufs_cmds[] = {
{ NULL, NULL, NULL },
};
void do_mufs_cmd(struct console *con, const char **argv, size_t argc)
void do_mufs_cmd(struct console *con, size_t argc, const char **argv)
{
cmd_exec(mufs_cmds, con, argv, argc);
cmd_exec(mufs_cmds, con, argc, argv);
}

@ -6,7 +6,7 @@
#include <shell/rtc.h>
void shell_date(struct console *con, const char **argv, size_t argc)
void shell_date(struct console *con, size_t argc, const char **argv)
{
struct tm now;
@ -20,7 +20,7 @@ void shell_date(struct console *con, const char **argv, size_t argc)
now.tm_mday, now.tm_mon + 1, now.tm_year + 1900);
}
void shell_time(struct console *con, const char **argv, size_t argc)
void shell_time(struct console *con, size_t argc, const char **argv)
{
struct tm now;
@ -32,7 +32,7 @@ void shell_time(struct console *con, const char **argv, size_t argc)
fprintf(con->fp, "%ld\n", mktime(&now));
}
void shell_set_date(struct console *con, const char **argv, size_t argc)
void shell_set_date(struct console *con, size_t argc, const char **argv)
{
struct tm now;

@ -4,7 +4,7 @@
#include <shell/version.h>
void shell_version(struct console *con, const char **argv, size_t argc)
void shell_version(struct console *con, size_t argc, const char **argv)
{
(void)argv;

Loading…
Cancel
Save