Bug in print command(?)

I have discovered a bug/unanticipated feature in the print command. For
example, the following script produces an error:
   print "hello"
   print "______...again"
   print " ...again"
The first two lines work fine, but any quoted string starting with a space
(such as the last line) produces
   ERROR: Illegal print command (input.cpp:783)

This error is, of course, easy to circumvent by starting the string with a
non-whitespace character, as in the second line.

Karl D. Hammond
University of Tennessee, Knoxville
[email protected]...

"You can never know everything, and part of what you know is always
   wrong. A portion of wisdom lies in knowing that. A portion of courage
   lies in going on anyway."
"Nothing ever goes as you expect. Expect nothing, and you will not be
   surprised."

hi karl,

I have discovered a bug/unanticipated feature in the print command. For
example, the following script produces an error:
print "hello"
print "______...again"
print " ...again"
The first two lines work fine, but any quoted string starting with a space
(such as the last line) produces
ERROR: Illegal print command (input.cpp:783)

This error is, of course, easy to circumvent by starting the string with a
non-whitespace character, as in the second line.

yes. i would call this a bug. i've dug for the source and
it originates in the fact that and how lammps uses the
strtok() function to tokenize the input. strtok() is ignorant
about quoted strings and thus messes up the string buffer
in the scenario. the solution is to avoid strtok() and replace
it with a set of utility functions that don't zero terminate
tokens while parsing.

please find attached a copy of input.cpp with a
correspondingly rewritten Input::parse.cpp method.
please let us know, if this fixes the problem and
doesn't break other parts of your input. since this
is a key routine in lammps, issues should show
up fairly quickly, i hope.

cheers,
    axel.

input.cpp.gz (7.71 KB)

of course, right after i sent out the mail (and despite
running quite a few tests) i found a bug in the rewrite
when running the very next input.

please try the updated version instead.

thanks,
    axel.

input.cpp.gz (7.71 KB)

Thank you as always for your speedy and thorough responses. The fix
passes all my (admittedly non-exhaustive) tests, including the one that
tripped it in the first place, which was something like,
   variable energy equal etotal
   variable procnum uloop 7
   print "DEBUG: energy = \{energy\}"    print " : procnum = {procnum}"

Looks good.

Karl D. Hammond
University of Tennessee, Knoxville
[email protected]...

"You can never know everything, and part of what you know is always
   wrong. A portion of wisdom lies in knowing that. A portion of courage
   lies in going on anyway."
"Nothing ever goes as you expect. Expect nothing, and you will not be
   surprised."

yes, the logic with strtok() didn't expect
a quoted string to start with whitespace ...
I'll patch this when I'm back in the office.

Steve