From ee2a2dfffca5bf08293c6b326f240cd120821a40 Mon Sep 17 00:00:00 2001 From: "J. Lewis Muir" Date: Wed, 11 Jan 2012 11:40:30 -0600 Subject: [PATCH] libCom/iocsh: Ignore comment lines after macro expansion The handling of comment lines is only performed before macro expansion, thus lines with macros that expand to comment lines will not be correctly handled as comment lines. By chance this kind of worked sometimes because a "#" command that does nothing is internally added to the command registry to make it show up in the help output. Relying on this is broken. Furthermore, if the line starts with '#' followed by a non-separator character (e.g. "##", "#whatever", etc.) it will not work (i.e. it will produce a command-not-found error). This fix checks to see if the first character of the line after macro expansion is '#'. If it is, it considers the line to be a comment. --- src/libCom/iocsh/iocsh.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libCom/iocsh/iocsh.cpp b/src/libCom/iocsh/iocsh.cpp index a3cbd22a1..46f8d3529 100644 --- a/src/libCom/iocsh/iocsh.cpp +++ b/src/libCom/iocsh/iocsh.cpp @@ -567,6 +567,12 @@ iocshBody (const char *pathname, const char *commandLine) if ((prompt == NULL) && *line && (commandLine == NULL)) puts(line); + /* + * Ignore lines that become comment lines after macro expansion + */ + if (*line == '#') + continue; + /* * Break line into words */