with the refactored include handling we can allow include in if/then/else

This commit is contained in:
Axel Kohlmeyer
2019-07-02 01:30:11 -04:00
parent 7547e1dae6
commit 6fc5810bb4
3 changed files with 9 additions and 23 deletions

View File

@ -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.

View File

@ -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++;

View File

@ -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