API

The application interfaces of MicroShell are really simple. Basically, you need to use only two functions such as microshell_init and microshell_getline. For the porting to a embdded system, it needs only two serial I/O interface functions (read and write).

The core functions

microshell

typedef void (*MICROSHELL_UART_PUTC)(char c);
typedef char (*MICROSHELL_UART_GETC)(void);
typedef void (*MICROSHELL_ACTION_HOOK)(MSCORE_ACTION action);
void microshell_init(MICROSHELL *handle, MICROSHELL_UART_PUTC uart_putc, MICROSHELL_UART_GETC uart_getc, MICROSHELL_ACTION_HOOK action_hook);
char *microshell_getline(MICROSHELL *handle, char *buf, int siz);

The util functions

mscmd

typedef int MSCMD_USER_RESULT;
typedef void * MSCMD_USER_OBJECT;
typedef MSCMD_USER_RESULT (*MSCMD_FUNC)(MSOPT *msopt, MSCMD_USER_OBJECT usrobj);
typedef struct {
    char *argv0;
    MSCMD_FUNC func;
} MSCMD_COMMAND_TABLE;

typedef struct {
    MSCMD_COMMAND_TABLE *command_table;
    int command_count;
    MSCMD_USER_OBJECT usrobj;
} MSCMD;
int mscmd_init(MSCMD *handle, MSCMD_COMMAND_TABLE *command_table, int command_count, MSCMD_USER_OBJECT usrobj);
int mscmd_execute(MSCMD *handle, char *text, MSCMD_USER_RESULT *result);

msopt

typedef enum {
    MSOPT_RESULT_OK = 0,
    MSOPT_RESULT_ERROR_ILLEGAL_OBJECT,
    MSOPT_RESULT_ERROR_ILLEGAL_INDEX_NUMBER,
    MSOPT_RESULT_ERROR_TOO_MUCH_ARGUMENTS,
    MSOPT_RESULT_ERROR_BUFFER_SIZE,
} MSOPT_RESULT;
MSOPT_RESULT msopt_init(MSOPT *handle, char *text);
MSOPT_RESULT msopt_get_argc(MSOPT *handle, int *argc);
MSOPT_RESULT msopt_get_argv(MSOPT *handle, int index, char *bufptr, int bufsiz);