nsh/nshlib: Add alias support for nsh

This adds support for string aliases into nsh. There are some nuances that
are not handled correctly yet:

- Reserved words can be overloaded, which is a clear POSIX violation
This commit is contained in:
Ville Juven
2023-02-22 18:19:59 +02:00
committed by Petro Karashchenko
parent bf40833d2e
commit f9dfb51001
7 changed files with 683 additions and 36 deletions

View File

@@ -715,6 +715,25 @@ struct nsh_parser_s
#endif
};
#ifdef CONFIG_NSH_ALIAS
struct nsh_alias_s
{
FAR struct nsh_alias_s *next; /* Single link list for traversing */
FAR char *name; /* Name of the alias */
FAR char *value; /* Value behind the name */
union
{
struct
{
uint8_t exp : 1; /* Already expanded ? */
uint8_t rem : 1; /* Marked for deletion */
};
uint8_t flags; /* Raw value */
};
};
#endif
/* This is the general form of a command handler */
struct nsh_vtbl_s; /* Defined in nsh_console.h */
@@ -793,6 +812,13 @@ int nsh_usbconsole(void);
# define nsh_usbconsole() (-ENOSYS)
#endif
#ifdef CONFIG_NSH_ALIAS
FAR struct nsh_alias_s *nsh_aliasfind(FAR struct nsh_vtbl_s *vtbl,
FAR const char *token);
void nsh_aliasfree(FAR struct nsh_vtbl_s *vtbl,
FAR struct nsh_alias_s *alias);
#endif
#ifndef CONFIG_NSH_DISABLESCRIPT
int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
FAR const char *path, bool log);
@@ -1193,6 +1219,11 @@ int cmd_pmconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
# endif
#endif
#ifdef CONFIG_NSH_ALIAS
int cmd_alias(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
int cmd_unalias(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
#endif
/****************************************************************************
* Name: nsh_extmatch_count
*