pussuw commented on code in PR #1654:
URL: https://github.com/apache/nuttx-apps/pull/1654#discussion_r1144349219


##########
nshlib/nsh_parse.c:
##########
@@ -115,6 +129,14 @@ struct nsh_memlist_s
 };
 #endif
 
+#ifdef CONFIG_NSH_ALIAS
+struct nsh_alist_s
+{
+  int nallocs;
+  FAR struct nsh_alias_s *allocs[CONFIG_NSH_ALIAS_MAX_AMOUNT];

Review Comment:
   > It's more simple to iterate all alias and clear exp directly after the end 
of expansion.
   I thought of this and decided to make the list anyway. 
   
   It is there so you don't need to traverse the whole alias list after every 
command. I for example have >50 aliases in my use case. In the normal case when 
using the terminal no alias expansion is performed.
   
   Example:
   ```
   $ alias foo1=bar
   $ alias foo2=bar
   ...
   $ alias foo50=bar
   $ ls
   ```
   Here after executing the ls command, even though no alias expansion has been 
performed you would have to go through all 50 aliases to see if they have been 
expanded. Instead now we have a "expanded aliases list" that is empty and 
nothing needs to be done.
   
   There is a purpose for the expanded alias list, the exp flag and the rem 
flag.
   1. The expanded alias list contains every expanded alias, so they can be 
cleared and if necessary, removed from the alias list after a command has been 
executed
   2. The exp flag is already explained above, an alias shall be expanded only 
once
   3. Rem field is also needed as the expanded alias string is not copied onto 
the parsed command line, simply a reference is returned and this means the 
alias data must be retained until the command has been executed. 
   
   When is the rem field relevant ? Well, some insane corner cases can appear...
   
   ```
   $ alias ua='unalias -a'
   $ ua
   ```
   Here the string behind the alias removes all aliases, but it is not safe to 
remove ua before the command unalias -a has been executed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to