forked from lijiext/lammps
simplify using utils::strdup()
This commit is contained in:
parent
1710fb86d3
commit
a5563e8d04
14
src/fix.cpp
14
src/fix.cpp
|
@ -42,21 +42,15 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) :
|
|||
// fix ID, group, and style
|
||||
// ID must be all alphanumeric chars or underscores
|
||||
|
||||
int n = strlen(arg[0]) + 1;
|
||||
id = new char[n];
|
||||
strcpy(id,arg[0]);
|
||||
|
||||
for (int i = 0; i < n-1; i++)
|
||||
if (!isalnum(id[i]) && id[i] != '_')
|
||||
error->all(FLERR,"Fix ID must be alphanumeric or underscore characters");
|
||||
id = utils::strdup(arg[0]);
|
||||
if (!utils::is_id(id))
|
||||
error->all(FLERR,"Fix ID must be alphanumeric or underscore characters");
|
||||
|
||||
igroup = group->find(arg[1]);
|
||||
if (igroup == -1) error->all(FLERR,"Could not find fix group ID");
|
||||
groupbit = group->bitmask[igroup];
|
||||
|
||||
n = strlen(arg[2]) + 1;
|
||||
style = new char[n];
|
||||
strcpy(style,arg[2]);
|
||||
style = utils::strdup(arg[2]);
|
||||
|
||||
restart_global = restart_peratom = restart_file = 0;
|
||||
force_reneighbor = 0;
|
||||
|
|
|
@ -57,9 +57,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
|||
nrepeat = utils::inumeric(FLERR,arg[4],false,lmp);
|
||||
nfreq = utils::inumeric(FLERR,arg[5],false,lmp);
|
||||
|
||||
int n = strlen(arg[6]) + 1;
|
||||
idchunk = new char[n];
|
||||
strcpy(idchunk,arg[6]);
|
||||
idchunk = utils::strdup(arg[6]);
|
||||
|
||||
global_freq = nfreq;
|
||||
no_change_box = 1;
|
||||
|
@ -190,9 +188,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
|||
if (iarg+2 > narg)
|
||||
error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
biasflag = 1;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
id_bias = new char[n];
|
||||
strcpy(id_bias,arg[iarg+1]);
|
||||
id_bias = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"adof") == 0) {
|
||||
if (iarg+2 > narg)
|
||||
|
@ -220,31 +216,23 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
|||
} else if (strcmp(arg[iarg],"format") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
delete [] format_user;
|
||||
int n = strlen(arg[iarg+1]) + 2;
|
||||
format_user = new char[n];
|
||||
sprintf(format_user," %s",arg[iarg+1]);
|
||||
format_user = utils::strdup(arg[iarg+1]);
|
||||
format = format_user;
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title1") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
delete [] title1;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title1 = new char[n];
|
||||
strcpy(title1,arg[iarg+1]);
|
||||
title1 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title2") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
delete [] title2;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title2 = new char[n];
|
||||
strcpy(title2,arg[iarg+1]);
|
||||
title2 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title3") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
delete [] title3;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title3 = new char[n];
|
||||
strcpy(title3,arg[iarg+1]);
|
||||
title3 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
}
|
||||
|
|
|
@ -139,23 +139,17 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg):
|
|||
} else if (strcmp(arg[iarg],"title1") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command");
|
||||
delete [] title1;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title1 = new char[n];
|
||||
strcpy(title1,arg[iarg+1]);
|
||||
title1 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title2") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command");
|
||||
delete [] title2;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title2 = new char[n];
|
||||
strcpy(title2,arg[iarg+1]);
|
||||
title2 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title3") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command");
|
||||
delete [] title3;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title3 = new char[n];
|
||||
strcpy(title3,arg[iarg+1]);
|
||||
title3 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal fix ave/correlate command");
|
||||
}
|
||||
|
|
|
@ -993,23 +993,17 @@ void FixAveHisto::options(int iarg, int narg, char **arg)
|
|||
} else if (strcmp(arg[iarg],"title1") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command");
|
||||
delete [] title1;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title1 = new char[n];
|
||||
strcpy(title1,arg[iarg+1]);
|
||||
title1 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title2") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command");
|
||||
delete [] title2;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title2 = new char[n];
|
||||
strcpy(title2,arg[iarg+1]);
|
||||
title2 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title3") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command");
|
||||
delete [] title3;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title3 = new char[n];
|
||||
strcpy(title3,arg[iarg+1]);
|
||||
title3 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal fix ave/histo command");
|
||||
}
|
||||
|
|
|
@ -1067,31 +1067,23 @@ void FixAveTime::options(int iarg, int narg, char **arg)
|
|||
} else if (strcmp(arg[iarg],"format") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/time command");
|
||||
delete [] format_user;
|
||||
int n = strlen(arg[iarg+1]) + 2;
|
||||
format_user = new char[n];
|
||||
sprintf(format_user," %s",arg[iarg+1]);
|
||||
format_user = utils::strdup(arg[iarg+1]);
|
||||
format = format_user;
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title1") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command");
|
||||
delete [] title1;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title1 = new char[n];
|
||||
strcpy(title1,arg[iarg+1]);
|
||||
title1 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title2") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command");
|
||||
delete [] title2;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title2 = new char[n];
|
||||
strcpy(title2,arg[iarg+1]);
|
||||
title2 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title3") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command");
|
||||
delete [] title3;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
title3 = new char[n];
|
||||
strcpy(title3,arg[iarg+1]);
|
||||
title3 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal fix ave/time command");
|
||||
}
|
||||
|
|
|
@ -761,9 +761,7 @@ int FixBoxRelax::modify_param(int narg, char **arg)
|
|||
tflag = 0;
|
||||
}
|
||||
delete [] id_temp;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_temp = new char[n];
|
||||
strcpy(id_temp,arg[1]);
|
||||
id_temp = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(arg[1]);
|
||||
if (icompute < 0)
|
||||
|
@ -792,9 +790,7 @@ int FixBoxRelax::modify_param(int narg, char **arg)
|
|||
pflag = 0;
|
||||
}
|
||||
delete [] id_press;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_press = new char[n];
|
||||
strcpy(id_press,arg[1]);
|
||||
id_press = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(arg[1]);
|
||||
if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID");
|
||||
|
|
|
@ -67,9 +67,7 @@ FixController::FixController(LAMMPS *lmp, int narg, char **arg) :
|
|||
|
||||
// control variable arg
|
||||
|
||||
int n = strlen(arg[iarg]) + 1;
|
||||
cvID = new char[n];
|
||||
strcpy(cvID,arg[iarg]);
|
||||
cvID = utils::strdup(arg[iarg]);
|
||||
|
||||
// error check
|
||||
|
||||
|
|
|
@ -126,12 +126,8 @@ rfix(nullptr), irregular(nullptr), set(nullptr)
|
|||
error->all(FLERR,"Illegal fix deform command");
|
||||
delete [] set[index].hstr;
|
||||
delete [] set[index].hratestr;
|
||||
int n = strlen(&arg[iarg+2][2]) + 1;
|
||||
set[index].hstr = new char[n];
|
||||
strcpy(set[index].hstr,&arg[iarg+2][2]);
|
||||
n = strlen(&arg[iarg+3][2]) + 1;
|
||||
set[index].hratestr = new char[n];
|
||||
strcpy(set[index].hratestr,&arg[iarg+3][2]);
|
||||
set[index].hstr = utils::strdup(&arg[iarg+2][2]);
|
||||
set[index].hratestr = utils::strdup(&arg[iarg+3][2]);
|
||||
iarg += 4;
|
||||
} else error->all(FLERR,"Illegal fix deform command");
|
||||
|
||||
|
@ -188,12 +184,8 @@ rfix(nullptr), irregular(nullptr), set(nullptr)
|
|||
error->all(FLERR,"Illegal fix deform command");
|
||||
delete [] set[index].hstr;
|
||||
delete [] set[index].hratestr;
|
||||
int n = strlen(&arg[iarg+2][2]) + 1;
|
||||
set[index].hstr = new char[n];
|
||||
strcpy(set[index].hstr,&arg[iarg+2][2]);
|
||||
n = strlen(&arg[iarg+3][2]) + 1;
|
||||
set[index].hratestr = new char[n];
|
||||
strcpy(set[index].hratestr,&arg[iarg+3][2]);
|
||||
set[index].hstr = utils::strdup(&arg[iarg+2][2]);
|
||||
set[index].hratestr = utils::strdup(&arg[iarg+3][2]);
|
||||
iarg += 4;
|
||||
} else error->all(FLERR,"Illegal fix deform command");
|
||||
|
||||
|
|
|
@ -39,12 +39,9 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr)
|
|||
// dgroupbit = bitmask of dynamic group
|
||||
// group ID is last part of fix ID
|
||||
|
||||
int n = strlen(id) - strlen("GROUP_") + 1;
|
||||
char *dgroup = new char[n];
|
||||
strcpy(dgroup,&id[strlen("GROUP_")]);
|
||||
gbit = group->bitmask[group->find(dgroup)];
|
||||
gbitinverse = group->inversemask[group->find(dgroup)];
|
||||
delete [] dgroup;
|
||||
auto dgroupid = std::string(id).substr(strlen("GROUP_"));
|
||||
gbit = group->bitmask[group->find(dgroupid)];
|
||||
gbitinverse = group->inversemask[group->find(dgroupid)];
|
||||
|
||||
// process optional args
|
||||
|
||||
|
@ -61,9 +58,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr)
|
|||
error->all(FLERR,"Region ID for group dynamic does not exist");
|
||||
regionflag = 1;
|
||||
delete [] idregion;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
idregion = new char[n];
|
||||
strcpy(idregion,arg[iarg+1]);
|
||||
idregion = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"var") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal group command");
|
||||
|
@ -71,9 +66,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr)
|
|||
error->all(FLERR,"Variable name for group dynamic does not exist");
|
||||
varflag = 1;
|
||||
delete [] idvar;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
idvar = new char[n];
|
||||
strcpy(idvar,arg[iarg+1]);
|
||||
idvar = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"property") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal group command");
|
||||
|
@ -81,9 +74,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr)
|
|||
error->all(FLERR,"Per atom property for group dynamic does not exist");
|
||||
propflag = 1;
|
||||
delete [] idprop;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
idprop = new char[n];
|
||||
strcpy(idprop,arg[iarg+1]);
|
||||
idprop = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"every") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal group command");
|
||||
|
@ -123,7 +114,7 @@ void FixGroup::init()
|
|||
if (group->dynamic[igroup])
|
||||
error->all(FLERR,"Group dynamic parent group cannot be dynamic");
|
||||
|
||||
if (strstr(update->integrate_style,"respa"))
|
||||
if (utils::strmatch(update->integrate_style,"^respa"))
|
||||
nlevels_respa = ((Respa *) update->integrate)->nlevels;
|
||||
|
||||
// set current indices for region and variable
|
||||
|
|
|
@ -275,9 +275,7 @@ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) :
|
|||
else {
|
||||
allremap = 0;
|
||||
delete [] id_dilate;
|
||||
int n = strlen(arg[iarg+1]) + 1;
|
||||
id_dilate = new char[n];
|
||||
strcpy(id_dilate,arg[iarg+1]);
|
||||
id_dilate = utils::strdup(arg[iarg+1]);
|
||||
int idilate = group->find(id_dilate);
|
||||
if (idilate == -1)
|
||||
error->all(FLERR,"Fix nvt/npt/nph dilate group ID does not exist");
|
||||
|
@ -1414,9 +1412,7 @@ int FixNH::modify_param(int narg, char **arg)
|
|||
tcomputeflag = 0;
|
||||
}
|
||||
delete [] id_temp;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_temp = new char[n];
|
||||
strcpy(id_temp,arg[1]);
|
||||
id_temp = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(arg[1]);
|
||||
if (icompute < 0)
|
||||
|
@ -1448,9 +1444,7 @@ int FixNH::modify_param(int narg, char **arg)
|
|||
pcomputeflag = 0;
|
||||
}
|
||||
delete [] id_press;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_press = new char[n];
|
||||
strcpy(id_press,arg[1]);
|
||||
id_press = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(arg[1]);
|
||||
if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID");
|
||||
|
|
|
@ -467,9 +467,7 @@ int FixPressBerendsen::modify_param(int narg, char **arg)
|
|||
tflag = 0;
|
||||
}
|
||||
delete [] id_temp;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_temp = new char[n];
|
||||
strcpy(id_temp,arg[1]);
|
||||
id_temp = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(arg[1]);
|
||||
if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID");
|
||||
|
@ -496,9 +494,7 @@ int FixPressBerendsen::modify_param(int narg, char **arg)
|
|||
pflag = 0;
|
||||
}
|
||||
delete [] id_press;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_press = new char[n];
|
||||
strcpy(id_press,arg[1]);
|
||||
id_press = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(arg[1]);
|
||||
if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID");
|
||||
|
|
|
@ -70,9 +70,7 @@ FixSpring::FixSpring(LAMMPS *lmp, int narg, char **arg) :
|
|||
if (narg != 10) error->all(FLERR,"Illegal fix spring command");
|
||||
styleflag = COUPLE;
|
||||
|
||||
int n = strlen(arg[4]) + 1;
|
||||
group2 = new char[n];
|
||||
strcpy(group2,arg[4]);
|
||||
group2 = utils::strdup(arg[4]);
|
||||
igroup2 = group->find(arg[4]);
|
||||
if (igroup2 == -1)
|
||||
error->all(FLERR,"Fix spring couple group ID does not exist");
|
||||
|
|
|
@ -49,13 +49,8 @@ FixSpringChunk::FixSpringChunk(LAMMPS *lmp, int narg, char **arg) :
|
|||
|
||||
k_spring = utils::numeric(FLERR,arg[3],false,lmp);
|
||||
|
||||
int n = strlen(arg[4]) + 1;
|
||||
idchunk = new char[n];
|
||||
strcpy(idchunk,arg[4]);
|
||||
|
||||
n = strlen(arg[5]) + 1;
|
||||
idcom = new char[n];
|
||||
strcpy(idcom,arg[5]);
|
||||
idchunk = utils::strdup(arg[4]);
|
||||
idcom = utils::strdup(arg[5]);
|
||||
|
||||
esprings = 0.0;
|
||||
nchunk = 0;
|
||||
|
|
|
@ -205,9 +205,7 @@ int FixTempBerendsen::modify_param(int narg, char **arg)
|
|||
tflag = 0;
|
||||
}
|
||||
delete [] id_temp;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_temp = new char[n];
|
||||
strcpy(id_temp,arg[1]);
|
||||
id_temp = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(id_temp);
|
||||
if (icompute < 0)
|
||||
|
|
|
@ -261,9 +261,7 @@ int FixTempCSLD::modify_param(int narg, char **arg)
|
|||
tflag = 0;
|
||||
}
|
||||
delete [] id_temp;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_temp = new char[n];
|
||||
strcpy(id_temp,arg[1]);
|
||||
id_temp = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(id_temp);
|
||||
if (icompute < 0)
|
||||
|
|
|
@ -216,9 +216,7 @@ int FixTempCSVR::modify_param(int narg, char **arg)
|
|||
tflag = 0;
|
||||
}
|
||||
delete [] id_temp;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_temp = new char[n];
|
||||
strcpy(id_temp,arg[1]);
|
||||
id_temp = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(id_temp);
|
||||
if (icompute < 0)
|
||||
|
|
|
@ -202,9 +202,7 @@ int FixTempRescale::modify_param(int narg, char **arg)
|
|||
tflag = 0;
|
||||
}
|
||||
delete [] id_temp;
|
||||
int n = strlen(arg[1]) + 1;
|
||||
id_temp = new char[n];
|
||||
strcpy(id_temp,arg[1]);
|
||||
id_temp = utils::strdup(arg[1]);
|
||||
|
||||
int icompute = modify->find_compute(id_temp);
|
||||
if (icompute < 0)
|
||||
|
|
|
@ -54,9 +54,7 @@ FixWallRegion::FixWallRegion(LAMMPS *lmp, int narg, char **arg) :
|
|||
iregion = domain->find_region(arg[3]);
|
||||
if (iregion == -1)
|
||||
error->all(FLERR,"Region ID for fix wall/region does not exist");
|
||||
int n = strlen(arg[3]) + 1;
|
||||
idregion = new char[n];
|
||||
strcpy(idregion,arg[3]);
|
||||
idregion = utils::strdup(arg[3]);
|
||||
|
||||
if (strcmp(arg[4],"lj93") == 0) style = LJ93;
|
||||
else if (strcmp(arg[4],"lj126") == 0) style = LJ126;
|
||||
|
|
Loading…
Reference in New Issue