diff --git a/twander.py b/twander.py index 9e2f868..84cf800 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ # For Updates See: http://www.tundraware.com/Software/twander PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.25 2002/12/18 21:44:36 tundra Exp $" +RCSID = "$Id: twander.py,v 2.26 2002/12/18 22:38:20 tundra Exp $" VERSION = RCSID.split()[2] @@ -214,7 +214,7 @@ ASSIGN = "=" # Assignment for variable definitions CONF = "" # Config file user selected with -c option -COMMENT = r"//" # Comment introducer string +COMMENT = r"#" # Comment introducer string ENVVBL = r'$' # Symbol denoting an environment variable MAXNESTING = 32 # Maximum depth of nested variable definitions QUOTECHAR = '\"' # Character to use when quoting builtin substitutions @@ -420,13 +420,7 @@ for line in cf.read().splitlines(): linenum += 1 - # Lex for comment token and discard until EOL. - - idx = line.find(COMMENT) - if idx > -1: - line = line[:idx] - - # Parse whatever is left on non-blank lines + # Parse this line if line: ParseLine(line, linenum) @@ -482,6 +476,32 @@ if line[-1] == '\n': line = line[:-1] + # Split configuration line into separate fields + fields = line.split() + + # Process Comments. This is tricky because we want to *allow* the + # comment string as a part of Command Definitions and chop it + # to EOL everywhere else. Lines which meet the following + # critera are considered Command Definitions and have no + # comment processing applied: + # + # Line must contain at least 3 fields + # + # 1st field must be one character long + # + # 1st field cannot be "#" + # (or many comments would look like Command Definitions) + + if (len(fields) >= 3) and (len(fields[0]) == 1) and (fields[0] != COMMENT): + pass + + # Not a Command Definition, strip from comment introducer to EOL + else: + idx = line.find(COMMENT) + if idx > -1: + line = line[:idx] + + # Split what's left into separate fields again fields = line.split() # Make a copy of the fields guaranteed to have