Variable style 'string' substitutes variables in definition

This commit is contained in:
Sebastian Hütter
2018-06-14 13:10:08 +02:00
parent 29e555213c
commit 3e79296dcf
3 changed files with 18 additions and 6 deletions

View File

@ -284,12 +284,21 @@ void Variable::set(int narg, char **arg)
} else if (strcmp(arg[1],"string") == 0) {
if (narg != 3) error->all(FLERR,"Illegal variable command");
int maxcopy = strlen(arg[2]) + 1;
int maxwork = maxcopy;
char *scopy = new char[maxcopy];
char *work = new char[maxwork];
strcpy(scopy,arg[2]);
input->substitute(scopy,work,maxcopy,maxwork,1);
delete [] work;
int ivar = find(arg[0]);
if (ivar >= 0) {
if (style[ivar] != STRING)
error->all(FLERR,"Cannot redefine variable as a different style");
delete [] data[ivar][0];
copy(1,&arg[2],data[ivar]);
copy(1,&scopy,data[ivar]);
replaceflag = 1;
} else {
if (nvar == maxvar) grow();
@ -298,8 +307,9 @@ void Variable::set(int narg, char **arg)
which[nvar] = 0;
pad[nvar] = 0;
data[nvar] = new char*[num[nvar]];
copy(1,&arg[2],data[nvar]);
copy(1,&scopy,data[nvar]);
}
delete [] scopy;
// GETENV
// remove pre-existing var if also style GETENV (allows it to be reset)