CardSight 0.1.0
C API reference for the CardSight firmware and application
Loading...
Searching...
No Matches
shell.h File Reference

The command line on the console: commands are registered in a linker section, the shell splits a line and calls the matching one. More...

Go to the source code of this file.

Data Structures

struct  shell_cmd
 One command registered in the .shell_cmd linker section. More...

Macros

#define SHELL_CMD(name, help, fn)
 Register a shell command.

Functions

int shell_exec (char *line)
 Run a command line.

Detailed Description

The command line on the console: commands are registered in a linker section, the shell splits a line and calls the matching one.

Macro Definition Documentation

◆ SHELL_CMD

#define SHELL_CMD ( name,
help,
fn )
Value:
static const struct shell_cmd __shell_cmd_##name \
__attribute__((used, section(".shell_cmd"))) = { #name, help, fn }
One command registered in the .shell_cmd linker section.
Definition shell.h:14

Register a shell command.

Places a static struct shell_cmd in the .shell_cmd section, keeps it despite not being referenced, and uses name both as the command word and as the symbol suffix.

Parameters
nameCommand word, e.g. mycmd.
helpOne-line description shown by the help command.
fnHandler with the signature int fn(int argc, char **argv).

Function Documentation

◆ shell_exec()

int shell_exec ( char * line)

Run a command line.

Splits line at spaces and tabs in place, at most eight words, then calls the command whose name matches the first word. An unknown command prints a hint and returns -1.

Parameters
[in,out]lineNUL-terminated line; modified by the splitting.
Returns
What the command returned, -1 for an unknown command, or 0 for an empty line.