From 6fc5810bb4d4b0d0042204926bf04d29259db063 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 2 Jul 2019 01:30:11 -0400 Subject: [PATCH] with the refactored include handling we can allow include in if/then/else --- doc/src/if.txt | 3 +-- src/input.cpp | 28 ++++++++-------------------- src/input.h | 1 - 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/doc/src/if.txt b/doc/src/if.txt index 20caf1a1ef..ceec8f55db 100644 --- a/doc/src/if.txt +++ b/doc/src/if.txt @@ -57,8 +57,7 @@ Boolean expression is FALSE, then no commands are executed. The syntax for Boolean expressions is described below. Each command (t1, f1, e1, etc) can be any valid LAMMPS input script -command, except an "include"_include.html command, which is not -allowed. If the command is more than one word, it must enclosed in +command. If the command is more than one word, it must enclosed in quotes, so it will be treated as a single argument, as in the examples above. diff --git a/src/input.cpp b/src/input.cpp index 9e0ad78d9e..390ca37bf3 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -82,7 +82,6 @@ Input::Input(LAMMPS *lmp, int argc, char **argv) : Pointers(lmp) label_active = 0; labelstr = NULL; jump_skip = 0; - ifthenelse_flag = 0; if (me == 0) { nfile = maxfile = 1; @@ -962,11 +961,10 @@ void Input::ifthenelse() ncommands++; } - ifthenelse_flag = 1; - for (int i = 0; i < ncommands; i++) one(commands[i]); - ifthenelse_flag = 0; - - for (int i = 0; i < ncommands; i++) delete [] commands[i]; + for (int i = 0; i < ncommands; i++) { + one(commands[i]); + delete [] commands[i]; + } delete [] commands; return; @@ -1018,13 +1016,10 @@ void Input::ifthenelse() // execute the list of commands - ifthenelse_flag = 1; - for (int i = 0; i < ncommands; i++) one(commands[i]); - ifthenelse_flag = 0; - - // clean up - - for (int i = 0; i < ncommands; i++) delete [] commands[i]; + for (int i = 0; i < ncommands; i++) { + one(commands[i]); + delete [] commands[i]; + } delete [] commands; return; @@ -1037,13 +1032,6 @@ void Input::include() { if (narg != 1) error->all(FLERR,"Illegal include command"); - // do not allow include inside an if command - // NOTE: this check will fail if a 2nd if command was inside the if command - // and came before the include - - if (ifthenelse_flag) - error->all(FLERR,"Cannot use include command within an if command"); - if (me == 0) { if (nfile == maxfile) { maxfile++; diff --git a/src/input.h b/src/input.h index 33e83bfb06..7b6e55c2ba 100644 --- a/src/input.h +++ b/src/input.h @@ -54,7 +54,6 @@ class Input : protected Pointers { int label_active; // 0 = no label, 1 = looking for label char *labelstr; // label string being looked for int jump_skip; // 1 if skipping next jump, 0 otherwise - int ifthenelse_flag; // 1 if executing commands inside an if-then-else FILE **infiles; // list of open input files