[nos-bbs] Command & configuratin line comments

Barry Siegfried k2mf at nnj.k2mf.ampr.org
Tue Sep 19 15:42:46 EDT 2006


["(Skip) K8RRA" <k8rra at ameritech.net> wrote]:

> This is a "toss up"...
>
> Can anyone confirm or deny the "#" MAY be inserted in any character
> position to begin a command or configuration comment?

It may NOT.

> Documentation I have seen is ambiguous.  More specific documentation
> may exist.

It likely does not.  And the person(s) who wrote the original ambiguous
documentation about this probably didn't read the code.

> I have ALWAYS been successful with "#" in position 1 of autoexec.nos.
> I have sometimes been unsuccessful with "#" in position  >1 in
> autoexec.nos.

This is a correct observation.

> I have not tested all other configuration files used for jnos2.0x
> but would like to know the answer.

> What facts and opinions are available?

I will give you some facts.  You may form your own opinions about
them.  :)

JNOS considers the command to reside in the first non-whitespace
field on a command line.  All that means is that you can indent
your command lines with whitespace and JNOS won't care.  Other
NOSs won't care about that either.

Given the above, if JNOS finds the first character position of
the first non-whitespace field on a command line to be the '#'
character, then it considers the remainder of the line to be a
comment and the line is discarded.  At least one other NOS variant
has added the ';' character as a comment delimeter in this character
position as well.

Now we have all seen autoexec.nos and other config files to contain
commands and arguments and then sometimes a comment beginning with
the '#' character.  In nearly all cases, the '#' character provides
a simple visual clue to the reader that a comment is following
because the '#' character is NOT actually parsed by JNOS as a
comment delimeter in any other position other than when it is in
the first character position of the first non-whitespace field on
a command line.

So then why does it "seem" to work MOST of the time when it precedes
comments at the ends of command lines?  Simply put, it is really
because of the way in which JNOS parses its commands and their
arguments.

JNOS commands are parsed with code knowing how many required
arguments there are for every given command and then how many
optional arguments are following the required arguments.  Most
commands don't have a very large number of optional arguments
(if any at all), so all of the possible arguments have been
parsed and processed before the '#' character is ever encountered
on the command line.  In these cases, the existence of the '#'
character actually means absolutely nothing, because at that
point on the command line, any remaining non-whitespace fields
following the last possible argument may be considered to be a
comment (which simply means that the parsing code doesn't care
about it).  On these lines, you can precede your comments with
any character, or in fact not precede them with any character
at all.  It makes absolutely no difference.  JNOS has just simply
stopped parsing the line because all of the possible arguments to
the command have been exhausted.

If you're with me so far, then the reason that the '#' character
is not ALWAYS "parsed" as a comment following a command and its
arguments should become obvious.  Simply put, this will happen on
lines which have many possible optional arguments and they have
not all been exhausted before the '#' character is encountered.
Putting a '#' character after the last argument parsed (but not
necessarily the last possible optional argument a particular
command is expecting) will cause the parsing code to think that
it is the *next* argument.  So this gives the false impression
that it "doesn't work" as a comment delimeter, when in fact it
is NEVER actually parsed as a comment delimeter and only "seems"
to work most of the time because all of the possible arguments
for a given command have been exhausted before the '#' character
is encountered.

In fact, there are only a relatively few commands where putting
comments on command lines gets in the way of the proper parsing
of a command:

1) 'start,stop <server> [<port>]' commands where a '#' character
   is interpreted as the <port> if the port number isn't given,

2) /alias file conversions in expandalias() where one email username
   is broken out to a number of aliases on a single line and a '#'
   character is interpreted as the "next" alias on that line,

3) 'route add[private] <dest ip addr>[/<bits>] <interface>
   [<next ip gateway>,direct [<metric>]]' commands where a '#'
   character is interpreted as one of the last optional arguments
   on the command line from <next ip gateway> on.

At least one other NOS variant has added specific checks for the
'#' and ';' comment-delimeting characters to avoid this confusion
once the beginning of the optional arguments part of the parsing
code for the above commands has been reached.  This removes the
ambiguity encountered when this occurs.

I am quite confident that most of the times the '#' character
has "failed" as a comment-delimeter for Skip has been in one of
the kinds of commands above.  But the reality is, it is never
actually used as a comment delimeter except in the first character
position of the first non-whitespace field on a command line.

If I've missed a command where a trailing comment often gets
confused by the argument parsing code, please let me know!

> If "#" may be inserted anywhere on any command line to begin a
> comment, that would be compatible with bash and a good thing.
> (perhaps only in my opinion...)

This *can* be done but several sections of the code would have to
be modified in order to make it work right.  You would have to
make sure that all possibilities (where '#' or ';' characters are
intended to be parts of quoted arguments) are accounted for and
not handled incorrectly.  This goes for hidden Net/Rom nodes which
begin with the '#' character as well.  There are other cases where
'#' or ';' characters might be significant.  I just can't think of
any more at the moment.

It's never as easy as it first looks.

73, de Barry, K2MF >>
           o
          <|>      Barry Siegfried
+---------/-\---------------------------+
| Internet | bgs at mfnos.net              |
| HomePage | http://www.mfnos.net/~bgs  |
+----------+----------------------------+
| Amprnet  | k2mf at nnj.k2mf.ampr.org     |
| PBBS     | k2mf at k2ge.#cnj.nj.usa.noam |
+----------+----------------------------+




More information about the nos-bbs mailing list