make use of utils::strdup()

This commit is contained in:
Axel Kohlmeyer
2021-02-04 17:00:44 -05:00
parent ab697be9e7
commit 24bf1e5b0c
23 changed files with 277 additions and 517 deletions

View File

@ -60,27 +60,21 @@ FixEfield::FixEfield(LAMMPS *lmp, int narg, char **arg) :
xstr = ystr = zstr = nullptr;
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[3][2]);
xstr = utils::strdup(arg[3]+2);
} else {
ex = qe2f * utils::numeric(FLERR,arg[3],false,lmp);
xstyle = CONSTANT;
}
if (utils::strmatch(arg[4],"^v_")) {
int n = strlen(&arg[4][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[4][2]);
ystr = utils::strdup(arg[4]+2);
} else {
ey = qe2f * utils::numeric(FLERR,arg[4],false,lmp);
ystyle = CONSTANT;
}
if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[5][2]);
zstr = utils::strdup(arg[5]+2);
} else {
ez = qe2f * utils::numeric(FLERR,arg[5],false,lmp);
zstyle = CONSTANT;
@ -99,16 +93,12 @@ FixEfield::FixEfield(LAMMPS *lmp, int narg, char **arg) :
iregion = domain->find_region(arg[iarg+1]);
if (iregion == -1)
error->all(FLERR,"Region ID for fix efield does not exist");
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],"energy") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix efield command");
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
estr = new char[n];
strcpy(estr,&arg[iarg+1][2]);
estr = utils::strdup(arg[iarg+1]+2);
} else error->all(FLERR,"Illegal fix efield command");
iarg += 2;
} else error->all(FLERR,"Illegal fix efield command");

View File

@ -184,9 +184,7 @@ void PythonImpl::command(int narg, char **arg)
iarg += 2;
} else if (strcmp(arg[iarg],"format") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Invalid python command");
int n = strlen(arg[iarg+1]) + 1;
format = new char[n];
strcpy(format,arg[iarg+1]);
format = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"length") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Invalid python command");
@ -196,9 +194,7 @@ void PythonImpl::command(int narg, char **arg)
} else if (strcmp(arg[iarg],"file") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Invalid python command");
delete[] pyfile;
int n = strlen(arg[iarg+1]) + 1;
pyfile = new char[n];
strcpy(pyfile,arg[iarg+1]);
pyfile = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"here") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Invalid python command");
@ -424,9 +420,7 @@ int PythonImpl::create_entry(char *name)
nfunc++;
pfuncs = (PyFunc *)
memory->srealloc(pfuncs,nfunc*sizeof(struct PyFunc),"python:pfuncs");
int n = strlen(name) + 1;
pfuncs[ifunc].name = new char[n];
strcpy(pfuncs[ifunc].name,name);
pfuncs[ifunc].name = utils::strdup(name);
} else deallocate(ifunc);
pfuncs[ifunc].ninput = ninput;
@ -452,9 +446,7 @@ int PythonImpl::create_entry(char *name)
pfuncs[ifunc].itype[i] = INT;
if (utils::strmatch(istr[i],"^v_")) {
pfuncs[ifunc].ivarflag[i] = 1;
int n = strlen(&istr[i][2]) + 1;
pfuncs[ifunc].svalue[i] = new char[n];
strcpy(pfuncs[ifunc].svalue[i],&istr[i][2]);
pfuncs[ifunc].svalue[i] = utils::strdup(istr[i]+2);
} else {
pfuncs[ifunc].ivarflag[i] = 0;
pfuncs[ifunc].ivalue[i] = utils::inumeric(FLERR,istr[i],false,lmp);
@ -463,9 +455,7 @@ int PythonImpl::create_entry(char *name)
pfuncs[ifunc].itype[i] = DOUBLE;
if (utils::strmatch(istr[i],"^v_")) {
pfuncs[ifunc].ivarflag[i] = 1;
int n = strlen(&istr[i][2]) + 1;
pfuncs[ifunc].svalue[i] = new char[n];
strcpy(pfuncs[ifunc].svalue[i],&istr[i][2]);
pfuncs[ifunc].svalue[i] = utils::strdup(istr[i]+2);
} else {
pfuncs[ifunc].ivarflag[i] = 0;
pfuncs[ifunc].dvalue[i] = utils::numeric(FLERR,istr[i],false,lmp);
@ -474,14 +464,10 @@ int PythonImpl::create_entry(char *name)
pfuncs[ifunc].itype[i] = STRING;
if (utils::strmatch(istr[i],"^v_")) {
pfuncs[ifunc].ivarflag[i] = 1;
int n = strlen(&istr[i][2]) + 1;
pfuncs[ifunc].svalue[i] = new char[n];
strcpy(pfuncs[ifunc].svalue[i],&istr[i][2]);
pfuncs[ifunc].svalue[i] = utils::strdup(istr[i]+2);
} else {
pfuncs[ifunc].ivarflag[i] = 0;
int n = strlen(istr[i]) + 1;
pfuncs[ifunc].svalue[i] = new char[n];
strcpy(pfuncs[ifunc].svalue[i],istr[i]);
pfuncs[ifunc].svalue[i] = utils::strdup(istr[i]);
}
} else if (type == 'p') {
pfuncs[ifunc].ivarflag[i] = 0;
@ -513,9 +499,7 @@ int PythonImpl::create_entry(char *name)
}
if (strstr(ostr,"v_") != ostr) error->all(FLERR,"Invalid python command");
int n = strlen(&ostr[2]) + 1;
pfuncs[ifunc].ovarname = new char[n];
strcpy(pfuncs[ifunc].ovarname,&ostr[2]);
pfuncs[ifunc].ovarname = utils::strdup(ostr+2);
return ifunc;
}

View File

@ -502,9 +502,7 @@ FixRigid::FixRigid(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,
@ -531,9 +529,7 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg],"infile") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid command");
delete [] inpfile;
int n = strlen(arg[iarg+1]) + 1;
inpfile = new char[n];
strcpy(inpfile,arg[iarg+1]);
inpfile = utils::strdup(arg[iarg+1]);
restart_file = 1;
reinitflag = 0;
iarg += 2;
@ -548,9 +544,7 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg],"gravity") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid command");
delete [] id_gravity;
int n = strlen(arg[iarg+1]) + 1;
id_gravity = new char[n];
strcpy(id_gravity,arg[iarg+1]);
id_gravity = utils::strdup(arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal fix rigid command");

View File

@ -13,37 +13,34 @@
#include "fix_rigid_small.h"
#include <cmath>
#include <cstring>
#include <utility>
#include "math_extra.h"
#include "math_eigen.h"
#include "atom.h"
#include "atom_vec_ellipsoid.h"
#include "atom_vec_line.h"
#include "atom_vec_tri.h"
#include "molecule.h"
#include "domain.h"
#include "update.h"
#include "respa.h"
#include "modify.h"
#include "group.h"
#include "comm.h"
#include "neighbor.h"
#include "force.h"
#include "input.h"
#include "variable.h"
#include "random_mars.h"
#include "math_const.h"
#include "hashlittle.h"
#include "memory.h"
#include "domain.h"
#include "error.h"
#include "force.h"
#include "group.h"
#include "hashlittle.h"
#include "input.h"
#include "math_const.h"
#include "math_eigen.h"
#include "math_extra.h"
#include "memory.h"
#include "modify.h"
#include "molecule.h"
#include "neighbor.h"
#include "random_mars.h"
#include "respa.h"
#include "rigid_const.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -223,9 +220,7 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg],"infile") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command");
delete [] inpfile;
int n = strlen(arg[iarg+1]) + 1;
inpfile = new char[n];
strcpy(inpfile,arg[iarg+1]);
inpfile = utils::strdup(arg[iarg+1]);
restart_file = 1;
reinitflag = 0;
iarg += 2;
@ -336,9 +331,7 @@ FixRigidSmall::FixRigidSmall(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 rigid/small nvt/npt/nph dilate group ID "
@ -365,9 +358,7 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg],"gravity") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command");
delete [] id_gravity;
int n = strlen(arg[iarg+1]) + 1;
id_gravity = new char[n];
strcpy(id_gravity,arg[iarg+1]);
id_gravity = utils::strdup(arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal fix rigid/small command");

View File

@ -71,9 +71,7 @@ FixWallSRD::FixWallSRD(LAMMPS *lmp, int narg, char **arg) :
else coord0[nwall] = domain->boxhi[dim];
} else if (utils::strmatch(arg[iarg+1],"^v_")) {
wallstyle[nwall] = VARIABLE;
int n = strlen(&arg[iarg+1][2]) + 1;
varstr[nwall] = new char[n];
strcpy(varstr[nwall],&arg[iarg+1][2]);
varstr[nwall] = utils::strdup(arg[iarg+1]+2);
} else {
wallstyle[nwall] = CONSTANT;
coord0[nwall] = utils::numeric(FLERR,arg[iarg+1],false,lmp);

View File

@ -12,21 +12,22 @@
------------------------------------------------------------------------- */
#include "fix_langevin_drude.h"
#include "fix_drude.h"
#include "atom.h"
#include "comm.h"
#include "compute.h"
#include "domain.h"
#include "error.h"
#include "force.h"
#include "input.h"
#include "modify.h"
#include "random_mars.h"
#include "update.h"
#include "variable.h"
#include <cstring>
#include <cmath>
#include "fix_drude.h"
#include "atom.h"
#include "force.h"
#include "comm.h"
#include "input.h"
#include "variable.h"
#include "random_mars.h"
#include "update.h"
#include "modify.h"
#include "compute.h"
#include "error.h"
#include "domain.h"
using namespace LAMMPS_NS;
using namespace FixConst;
@ -50,9 +51,7 @@ FixLangevinDrude::FixLangevinDrude(LAMMPS *lmp, int narg, char **arg) :
// core temperature
tstr_core = nullptr;
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
tstr_core = new char[n];
strcpy(tstr_core,&arg[3][2]);
tstr_core = utils::strdup(arg[3]+2);
tstyle_core = EQUAL;
} else {
t_start_core = utils::numeric(FLERR,arg[3],false,lmp);
@ -65,9 +64,7 @@ FixLangevinDrude::FixLangevinDrude(LAMMPS *lmp, int narg, char **arg) :
// drude temperature
tstr_drude = nullptr;
if (strstr(arg[7],"v_") == arg[6]) {
int n = strlen(&arg[6][2]) + 1;
tstr_drude = new char[n];
strcpy(tstr_drude,&arg[6][2]);
tstr_drude = utils::strdup(arg[6]+2);
tstyle_drude = EQUAL;
} else {
t_start_drude = utils::numeric(FLERR,arg[6],false,lmp);
@ -184,9 +181,7 @@ int FixLangevinDrude::modify_param(int narg, char **arg)
if (strcmp(arg[0],"temp") == 0) {
if (narg < 2) error->all(FLERR,"Illegal fix_modify command");
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)

View File

@ -16,25 +16,25 @@
------------------------------------------------------------------------- */
#include "compute_fep.h"
#include <cstring>
#include <cmath>
#include "comm.h"
#include "update.h"
#include "atom.h"
#include "comm.h"
#include "domain.h"
#include "error.h"
#include "fix.h"
#include "force.h"
#include "input.h"
#include "kspace.h"
#include "memory.h"
#include "modify.h"
#include "pair.h"
#include "pair_hybrid.h"
#include "kspace.h"
#include "input.h"
#include "fix.h"
#include "modify.h"
#include "variable.h"
#include "timer.h"
#include "memory.h"
#include "error.h"
#include "update.h"
#include "variable.h"
#include <cstring>
#include <cmath>
using namespace LAMMPS_NS;
@ -89,20 +89,14 @@ ComputeFEP::ComputeFEP(LAMMPS *lmp, int narg, char **arg) :
while (iarg < narg) {
if (strcmp(arg[iarg],"pair") == 0) {
perturb[npert].which = PAIR;
int n = strlen(arg[iarg+1]) + 1;
perturb[npert].pstyle = new char[n];
strcpy(perturb[npert].pstyle,arg[iarg+1]);
n = strlen(arg[iarg+2]) + 1;
perturb[npert].pparam = new char[n];
strcpy(perturb[npert].pparam,arg[iarg+2]);
perturb[npert].pstyle = utils::strdup(arg[iarg+1]);
perturb[npert].pparam = utils::strdup(arg[iarg+2]);
utils::bounds(FLERR,arg[iarg+3],1,atom->ntypes,
perturb[npert].ilo,perturb[npert].ihi,error);
utils::bounds(FLERR,arg[iarg+4],1,atom->ntypes,
perturb[npert].jlo,perturb[npert].jhi,error);
if (utils::strmatch(arg[iarg+5],"^v_")) {
n = strlen(&arg[iarg+5][2]) + 1;
perturb[npert].var = new char[n];
strcpy(perturb[npert].var,&arg[iarg+5][2]);
perturb[npert].var = utils::strdup(arg[iarg+5]+2);
} else error->all(FLERR,"Illegal variable in compute fep");
npert++;
iarg += 6;
@ -115,9 +109,7 @@ ComputeFEP::ComputeFEP(LAMMPS *lmp, int narg, char **arg) :
utils::bounds(FLERR,arg[iarg+2],1,atom->ntypes,
perturb[npert].ilo,perturb[npert].ihi,error);
if (utils::strmatch(arg[iarg+3],"^v_")) {
int n = strlen(&arg[iarg+3][2]) + 1;
perturb[npert].var = new char[n];
strcpy(perturb[npert].var,&arg[iarg+3][2]);
perturb[npert].var = utils::strdup(arg[iarg+3]+2);
} else error->all(FLERR,"Illegal variable in compute fep");
npert++;
iarg += 4;

View File

@ -16,23 +16,24 @@
------------------------------------------------------------------------- */
#include "fix_adapt_fep.h"
#include <cstring>
#include "atom.h"
#include "update.h"
#include "group.h"
#include "modify.h"
#include "force.h"
#include "pair.h"
#include "pair_hybrid.h"
#include "kspace.h"
#include "error.h"
#include "fix_store.h"
#include "force.h"
#include "group.h"
#include "input.h"
#include "variable.h"
#include "respa.h"
#include "kspace.h"
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "modify.h"
#include "pair.h"
#include "pair_hybrid.h"
#include "respa.h"
#include "update.h"
#include "variable.h"
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -88,20 +89,14 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) :
if (strcmp(arg[iarg],"pair") == 0) {
if (iarg+6 > narg) error->all(FLERR,"Illegal fix adapt/fep command");
adapt[nadapt].which = PAIR;
int n = strlen(arg[iarg+1]) + 1;
adapt[nadapt].pstyle = new char[n];
strcpy(adapt[nadapt].pstyle,arg[iarg+1]);
n = strlen(arg[iarg+2]) + 1;
adapt[nadapt].pparam = new char[n];
strcpy(adapt[nadapt].pparam,arg[iarg+2]);
adapt[nadapt].pstyle = utils::strdup(arg[iarg+1]);
adapt[nadapt].pparam = utils::strdup(arg[iarg+2]);
utils::bounds(FLERR,arg[iarg+3],1,atom->ntypes,
adapt[nadapt].ilo,adapt[nadapt].ihi,error);
utils::bounds(FLERR,arg[iarg+4],1,atom->ntypes,
adapt[nadapt].jlo,adapt[nadapt].jhi,error);
if (utils::strmatch(arg[iarg+5],"^v_")) {
n = strlen(&arg[iarg+5][2]) + 1;
adapt[nadapt].var = new char[n];
strcpy(adapt[nadapt].var,&arg[iarg+5][2]);
adapt[nadapt].var = utils::strdup(arg[iarg+5]+2);
} else error->all(FLERR,"Illegal fix adapt/fep command");
nadapt++;
iarg += 6;
@ -109,9 +104,7 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) :
if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt/fep command");
adapt[nadapt].which = KSPACE;
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
adapt[nadapt].var = new char[n];
strcpy(adapt[nadapt].var,&arg[iarg+1][2]);
adapt[nadapt].var = utils::strdup(arg[iarg+1]+2);
} else error->all(FLERR,"Illegal fix adapt/fep command");
nadapt++;
iarg += 2;
@ -128,9 +121,7 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) :
utils::bounds(FLERR,arg[iarg+2],1,atom->ntypes,
adapt[nadapt].ilo,adapt[nadapt].ihi,error);
if (utils::strmatch(arg[iarg+3],"^v_")) {
int n = strlen(&arg[iarg+3][2]) + 1;
adapt[nadapt].var = new char[n];
strcpy(adapt[nadapt].var,&arg[iarg+3][2]);
adapt[nadapt].var = utils::strdup(arg[iarg+3]+2);
} else error->all(FLERR,"Illegal fix adapt/fep command");
nadapt++;
iarg += 4;
@ -223,20 +214,10 @@ void FixAdaptFEP::post_constructor()
id_fix_diam = nullptr;
id_fix_chg = nullptr;
char **newarg = new char*[6];
newarg[1] = group->names[igroup];
newarg[2] = (char *) "STORE";
newarg[3] = (char *) "peratom";
newarg[4] = (char *) "1";
newarg[5] = (char *) "1";
if (diamflag) {
int n = strlen(id) + strlen("_FIX_STORE_DIAM") + 1;
id_fix_diam = new char[n];
strcpy(id_fix_diam,id);
strcat(id_fix_diam,"_FIX_STORE_DIAM");
newarg[0] = id_fix_diam;
modify->add_fix(6,newarg);
auto cmd = fmt::format("{}_FIX_STORE_DIAM {} STORE peratom 1 1",
group->names[igroup]);
modify->add_fix(cmd);
fix_diam = (FixStore *) modify->fix[modify->nfix-1];
if (fix_diam->restart_reset) fix_diam->restart_reset = 0;
@ -254,12 +235,9 @@ void FixAdaptFEP::post_constructor()
}
if (chgflag) {
int n = strlen(id) + strlen("_FIX_STORE_CHG") + 1;
id_fix_chg = new char[n];
strcpy(id_fix_chg,id);
strcat(id_fix_chg,"_FIX_STORE_CHG");
newarg[0] = id_fix_chg;
modify->add_fix(6,newarg);
auto cmd = fmt::format("{}_FIX_STORE_CHG {} STORE peratom 1 1",
group->names[igroup]);
modify->add_fix(cmd);
fix_chg = (FixStore *) modify->fix[modify->nfix-1];
if (fix_chg->restart_reset) fix_chg->restart_reset = 0;
@ -275,8 +253,6 @@ void FixAdaptFEP::post_constructor()
}
}
}
delete [] newarg;
}
/* ---------------------------------------------------------------------- */

View File

@ -17,17 +17,18 @@
#include "fix_addtorque.h"
#include <cstring>
#include "atom.h"
#include "update.h"
#include "modify.h"
#include "domain.h"
#include "respa.h"
#include "input.h"
#include "variable.h"
#include "error.h"
#include "group.h"
#include "force.h"
#include "group.h"
#include "input.h"
#include "modify.h"
#include "respa.h"
#include "update.h"
#include "variable.h"
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -54,25 +55,19 @@ FixAddTorque::FixAddTorque(LAMMPS *lmp, int narg, char **arg) :
xstr = ystr = zstr = nullptr;
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[3][2]);
xstr = utils::strdup(arg[3]+2);
} else {
xvalue = utils::numeric(FLERR,arg[3],false,lmp);
xstyle = CONSTANT;
}
if (utils::strmatch(arg[4],"^v_")) {
int n = strlen(&arg[4][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[4][2]);
ystr = utils::strdup(arg[4]+2);
} else {
yvalue = utils::numeric(FLERR,arg[4],false,lmp);
ystyle = CONSTANT;
}
if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[5][2]);
zstr = utils::strdup(arg[5]+2);
} else {
zvalue = utils::numeric(FLERR,arg[5],false,lmp);
zstyle = CONSTANT;

View File

@ -17,20 +17,22 @@
------------------------------------------------------------------------- */
#include "fix_meso_move.h"
#include <cstring>
#include <cmath>
#include "atom.h"
#include "update.h"
#include "modify.h"
#include "force.h"
#include "domain.h"
#include "lattice.h"
#include "comm.h"
#include "domain.h"
#include "error.h"
#include "force.h"
#include "input.h"
#include "variable.h"
#include "lattice.h"
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "modify.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -128,39 +130,27 @@ FixMesoMove::FixMesoMove (LAMMPS *lmp, int narg, char **arg) :
mstyle = VARIABLE;
if (strcmp(arg[4],"NULL") == 0) xvarstr = nullptr;
else if (utils::strmatch(arg[4],"^v_")) {
int n = strlen(&arg[4][2]) + 1;
xvarstr = new char[n];
strcpy(xvarstr,&arg[4][2]);
xvarstr = utils::strdup(arg[4]+2);
} else error->all(FLERR,"Illegal fix meso/move command");
if (strcmp(arg[5],"NULL") == 0) yvarstr = nullptr;
else if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
yvarstr = new char[n];
strcpy(yvarstr,&arg[5][2]);
yvarstr = utils::strdup(arg[5]+2);
} else error->all(FLERR,"Illegal fix meso/move command");
if (strcmp(arg[6],"NULL") == 0) zvarstr = nullptr;
else if (utils::strmatch(arg[6],"^v_")) {
int n = strlen(&arg[6][2]) + 1;
zvarstr = new char[n];
strcpy(zvarstr,&arg[6][2]);
zvarstr = utils::strdup(arg[6]+2);
} else error->all(FLERR,"Illegal fix meso/move command");
if (strcmp(arg[7],"NULL") == 0) vxvarstr = nullptr;
else if (utils::strmatch(arg[7],"^v_")) {
int n = strlen(&arg[7][2]) + 1;
vxvarstr = new char[n];
strcpy(vxvarstr,&arg[7][2]);
vxvarstr = utils::strdup(arg[7]+2);
} else error->all(FLERR,"Illegal fix meso/move command");
if (strcmp(arg[8],"NULL") == 0) vyvarstr = nullptr;
else if (utils::strmatch(arg[8],"^v_")) {
int n = strlen(&arg[8][2]) + 1;
vyvarstr = new char[n];
strcpy(vyvarstr,&arg[8][2]);
vyvarstr = utils::strdup(arg[8]+2);
} else error->all(FLERR,"Illegal fix meso/move command");
if (strcmp(arg[9],"NULL") == 0) vzvarstr = nullptr;
else if (utils::strmatch(arg[9],"^v_")) {
int n = strlen(&arg[9][2]) + 1;
vzvarstr = new char[n];
strcpy(vzvarstr,&arg[9][2]);
vzvarstr = utils::strdup(arg[9]+2);
} else error->all(FLERR,"Illegal fix meso/move command");
} else error->all(FLERR,"Illegal fix meso/move command");

View File

@ -12,20 +12,22 @@
------------------------------------------------------------------------- */
#include "compute_property_atom.h"
#include <cmath>
#include <cstring>
#include "math_extra.h"
#include "atom.h"
#include "atom_vec.h"
#include "atom_vec_body.h"
#include "atom_vec_ellipsoid.h"
#include "atom_vec_line.h"
#include "atom_vec_tri.h"
#include "atom_vec_body.h"
#include "update.h"
#include "domain.h"
#include "comm.h"
#include "memory.h"
#include "domain.h"
#include "error.h"
#include "math_extra.h"
#include "memory.h"
#include "update.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS;

View File

@ -13,29 +13,29 @@
#include "dump_image.h"
#include "atom.h"
#include "atom_vec.h"
#include "atom_vec_body.h"
#include "atom_vec_line.h"
#include "atom_vec_tri.h"
#include "body.h"
#include "comm.h"
#include "domain.h"
#include "error.h"
#include "fix.h"
#include "force.h"
#include "image.h"
#include "input.h"
#include "math_const.h"
#include "math_extra.h"
#include "memory.h"
#include "modify.h"
#include "molecule.h"
#include "variable.h"
#include <cmath>
#include <cctype>
#include <cstring>
#include "image.h"
#include "atom.h"
#include "atom_vec.h"
#include "atom_vec_line.h"
#include "atom_vec_tri.h"
#include "atom_vec_body.h"
#include "body.h"
#include "molecule.h"
#include "domain.h"
#include "force.h"
#include "comm.h"
#include "modify.h"
#include "fix.h"
#include "input.h"
#include "variable.h"
#include "math_const.h"
#include "math_extra.h"
#include "error.h"
#include "memory.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -226,9 +226,7 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg],"view") == 0) {
if (iarg+3 > narg) error->all(FLERR,"Illegal dump image command");
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
thetastr = new char[n];
strcpy(thetastr,&arg[iarg+1][2]);
thetastr = utils::strdup(arg[iarg+1]+2);
} else {
double theta = utils::numeric(FLERR,arg[iarg+1],false,lmp);
if (theta < 0.0 || theta > 180.0)
@ -237,9 +235,7 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
image->theta = theta;
}
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
phistr = new char[n];
strcpy(phistr,&arg[iarg+2][2]);
phistr = utils::strdup(arg[iarg+2]+2);
} else {
double phi = utils::numeric(FLERR,arg[iarg+2],false,lmp);
phi *= MY_PI/180.0;
@ -253,21 +249,15 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
else if (strcmp(arg[iarg+1],"d") == 0) cflag = DYNAMIC;
else error->all(FLERR,"Illegal dump image command");
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
cxstr = new char[n];
strcpy(cxstr,&arg[iarg+2][2]);
cxstr = utils::strdup(arg[iarg+2]+2);
cflag = DYNAMIC;
} else cx = utils::numeric(FLERR,arg[iarg+2],false,lmp);
if (utils::strmatch(arg[iarg+3],"^v_")) {
int n = strlen(&arg[iarg+3][2]) + 1;
cystr = new char[n];
strcpy(cystr,&arg[iarg+3][2]);
cystr = utils::strdup(arg[iarg+3]+2);
cflag = DYNAMIC;
} else cy = utils::numeric(FLERR,arg[iarg+3],false,lmp);
if (utils::strmatch(arg[iarg+4],"^v_")) {
int n = strlen(&arg[iarg+4][2]) + 1;
czstr = new char[n];
strcpy(czstr,&arg[iarg+4][2]);
czstr = utils::strdup(arg[iarg+4]+2);
cflag = DYNAMIC;
} else cz = utils::numeric(FLERR,arg[iarg+4],false,lmp);
iarg += 5;
@ -275,28 +265,20 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg],"up") == 0) {
if (iarg+4 > narg) error->all(FLERR,"Illegal dump image command");
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
upxstr = new char[n];
strcpy(upxstr,&arg[iarg+1][2]);
upxstr = utils::strdup(arg[iarg+1]+2);
} else image->up[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp);
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
upystr = new char[n];
strcpy(upystr,&arg[iarg+2][2]);
upystr = utils::strdup(arg[iarg+2]+2);
} else image->up[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp);
if (utils::strmatch(arg[iarg+3],"^v_")) {
int n = strlen(&arg[iarg+3][2]) + 1;
upzstr = new char[n];
strcpy(upzstr,&arg[iarg+3][2]);
upzstr = utils::strdup(arg[iarg+3]+2);
} else image->up[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp);
iarg += 4;
} else if (strcmp(arg[iarg],"zoom") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal dump image command");
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
zoomstr = new char[n];
strcpy(zoomstr,&arg[iarg+1][2]);
zoomstr = utils::strdup(arg[iarg+1]+2);
} else {
double zoom = utils::numeric(FLERR,arg[iarg+1],false,lmp);
if (zoom <= 0.0) error->all(FLERR,"Illegal dump image command");

View File

@ -12,26 +12,26 @@
------------------------------------------------------------------------- */
#include "fix_adapt.h"
#include <cstring>
#include "atom.h"
#include "bond.h"
#include "domain.h"
#include "update.h"
#include "group.h"
#include "modify.h"
#include "force.h"
#include "pair.h"
#include "pair_hybrid.h"
#include "kspace.h"
#include "error.h"
#include "fix_store.h"
#include "force.h"
#include "group.h"
#include "input.h"
#include "variable.h"
#include "respa.h"
#include "kspace.h"
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "modify.h"
#include "pair.h"
#include "pair_hybrid.h"
#include "respa.h"
#include "update.h"
#include "variable.h"
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -91,21 +91,15 @@ nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr)
if (strcmp(arg[iarg],"pair") == 0) {
if (iarg+6 > narg) error->all(FLERR,"Illegal fix adapt command");
adapt[nadapt].which = PAIR;
int n = strlen(arg[iarg+1]) + 1;
adapt[nadapt].pstyle = new char[n];
strcpy(adapt[nadapt].pstyle,arg[iarg+1]);
n = strlen(arg[iarg+2]) + 1;
adapt[nadapt].pparam = new char[n];
adapt[nadapt].pair = nullptr;
strcpy(adapt[nadapt].pparam,arg[iarg+2]);
adapt[nadapt].pstyle = utils::strdup(arg[iarg+1]);
adapt[nadapt].pparam = utils::strdup(arg[iarg+2]);
utils::bounds(FLERR,arg[iarg+3],1,atom->ntypes,
adapt[nadapt].ilo,adapt[nadapt].ihi,error);
utils::bounds(FLERR,arg[iarg+4],1,atom->ntypes,
adapt[nadapt].jlo,adapt[nadapt].jhi,error);
if (utils::strmatch(arg[iarg+5],"^v_")) {
n = strlen(&arg[iarg+5][2]) + 1;
adapt[nadapt].var = new char[n];
strcpy(adapt[nadapt].var,&arg[iarg+5][2]);
adapt[nadapt].var = utils::strdup(arg[iarg+5]+2);
} else error->all(FLERR,"Illegal fix adapt command");
nadapt++;
iarg += 6;
@ -113,19 +107,13 @@ nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr)
} else if (strcmp(arg[iarg],"bond") == 0) {
if (iarg+5 > narg) error->all(FLERR, "Illegal fix adapt command");
adapt[nadapt].which = BOND;
int n = strlen(arg[iarg+1]) + 1;
adapt[nadapt].bstyle = new char[n];
strcpy(adapt[nadapt].bstyle,arg[iarg+1]);
n = strlen(arg[iarg+2]) + 1;
adapt[nadapt].bparam = new char[n];
adapt[nadapt].bond = nullptr;
strcpy(adapt[nadapt].bparam,arg[iarg+2]);
adapt[nadapt].bstyle = utils::strdup(arg[iarg+1]);
adapt[nadapt].bparam = utils::strdup(arg[iarg+2]);
utils::bounds(FLERR,arg[iarg+3],1,atom->nbondtypes,
adapt[nadapt].ilo,adapt[nadapt].ihi,error);
if (utils::strmatch(arg[iarg+4],"^v_")) {
n = strlen(&arg[iarg+4][2]) + 1;
adapt[nadapt].var = new char[n];
strcpy(adapt[nadapt].var,&arg[iarg+4][2]);
adapt[nadapt].var = utils::strdup(arg[iarg+4]+2);
} else error->all(FLERR,"Illegal fix adapt command");
nadapt++;
iarg += 5;
@ -134,9 +122,7 @@ nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr)
if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt command");
adapt[nadapt].which = KSPACE;
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
adapt[nadapt].var = new char[n];
strcpy(adapt[nadapt].var,&arg[iarg+1][2]);
adapt[nadapt].var = utils::strdup(arg[iarg+1]+2);
} else error->all(FLERR,"Illegal fix adapt command");
nadapt++;
iarg += 2;
@ -155,9 +141,7 @@ nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr)
chgflag = 1;
} else error->all(FLERR,"Illegal fix adapt command");
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
adapt[nadapt].var = new char[n];
strcpy(adapt[nadapt].var,&arg[iarg+2][2]);
adapt[nadapt].var = utils::strdup(arg[iarg+2]+2);
} else error->all(FLERR,"Illegal fix adapt command");
nadapt++;
iarg += 3;
@ -268,8 +252,7 @@ void FixAdapt::post_constructor()
if (diamflag && atom->radius_flag) {
std::string fixcmd = id + std::string("_FIX_STORE_DIAM");
id_fix_diam = new char[fixcmd.size()+1];
strcpy(id_fix_diam,fixcmd.c_str());
id_fix_diam = utils::strdup(fixcmd);
fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]);
modify->add_fix(fixcmd);
fix_diam = (FixStore *) modify->fix[modify->nfix-1];
@ -290,8 +273,7 @@ void FixAdapt::post_constructor()
if (chgflag && atom->q_flag) {
std::string fixcmd = id + std::string("_FIX_STORE_CHG");
id_fix_chg = new char[fixcmd.size()+1];
strcpy(id_fix_chg,fixcmd.c_str());
id_fix_chg = utils::strdup(fixcmd);
fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]);
modify->add_fix(fixcmd);
fix_chg = (FixStore *) modify->fix[modify->nfix-1];
@ -346,10 +328,7 @@ void FixAdapt::init()
// strip it for pstyle arg to pair_match() and set nsub = N
// this should work for appended suffixes as well
int n = strlen(ad->pstyle) + 1;
char *pstyle = new char[n];
strcpy(pstyle,ad->pstyle);
char *pstyle = strdup(ad->pstyle);
char *cptr;
int nsub = 0;
if ((cptr = strchr(pstyle,':'))) {
@ -399,10 +378,7 @@ void FixAdapt::init()
ad->bond = nullptr;
anybond = 1;
int n = strlen(ad->bstyle) + 1;
char *bstyle = new char[n];
strcpy(bstyle,ad->bstyle);
char *bstyle = utils::strdup(ad->bstyle);
if (lmp->suffix_enable) {
int len = 2 + strlen(bstyle) + strlen(lmp->suffix);
char *bsuffix = new char[len];

View File

@ -55,25 +55,19 @@ FixAddForce::FixAddForce(LAMMPS *lmp, int narg, char **arg) :
xstr = ystr = zstr = nullptr;
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[3][2]);
xstr = utils::strdup(arg[3]+2);
} else {
xvalue = utils::numeric(FLERR,arg[3],false,lmp);
xstyle = CONSTANT;
}
if (utils::strmatch(arg[4],"^v_")) {
int n = strlen(&arg[4][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[4][2]);
ystr = utils::strdup(arg[4]+2);
} else {
yvalue = utils::numeric(FLERR,arg[4],false,lmp);
ystyle = CONSTANT;
}
if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[5][2]);
zstr = utils::strdup(arg[5]+2);
} else {
zvalue = utils::numeric(FLERR,arg[5],false,lmp);
zstyle = CONSTANT;
@ -96,16 +90,12 @@ FixAddForce::FixAddForce(LAMMPS *lmp, int narg, char **arg) :
iregion = domain->find_region(arg[iarg+1]);
if (iregion == -1)
error->all(FLERR,"Region ID for fix addforce does not exist");
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],"energy") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix addforce command");
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
estr = new char[n];
strcpy(estr,&arg[iarg+1][2]);
estr = utils::strdup(arg[iarg+1]+2);
} else error->all(FLERR,"Illegal fix addforce command");
iarg += 2;
} else error->all(FLERR,"Illegal fix addforce command");

View File

@ -49,9 +49,7 @@ FixAveForce::FixAveForce(LAMMPS *lmp, int narg, char **arg) :
xstr = ystr = zstr = nullptr;
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[3][2]);
xstr = utils::strdup(arg[3]+2);
} else if (strcmp(arg[3],"NULL") == 0) {
xstyle = NONE;
} else {
@ -59,9 +57,7 @@ FixAveForce::FixAveForce(LAMMPS *lmp, int narg, char **arg) :
xstyle = CONSTANT;
}
if (utils::strmatch(arg[4],"^v_")) {
int n = strlen(&arg[4][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[4][2]);
ystr = utils::strdup(arg[4]+2);
} else if (strcmp(arg[4],"NULL") == 0) {
ystyle = NONE;
} else {
@ -69,9 +65,7 @@ FixAveForce::FixAveForce(LAMMPS *lmp, int narg, char **arg) :
ystyle = CONSTANT;
}
if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[5][2]);
zstr = utils::strdup(arg[5]+2);
} else if (strcmp(arg[5],"NULL") == 0) {
zstyle = NONE;
} else {
@ -91,9 +85,7 @@ FixAveForce::FixAveForce(LAMMPS *lmp, int narg, char **arg) :
iregion = domain->find_region(arg[iarg+1]);
if (iregion == -1)
error->all(FLERR,"Region ID for fix aveforce does not exist");
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 error->all(FLERR,"Illegal fix aveforce command");

View File

@ -53,9 +53,7 @@ FixGravity::FixGravity(LAMMPS *lmp, int narg, char **arg) :
mstyle = vstyle = pstyle = tstyle = xstyle = ystyle = zstyle = CONSTANT;
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
mstr = new char[n];
strcpy(mstr,&arg[3][2]);
mstr = utils::strdup(arg[3]+2);
mstyle = EQUAL;
} else {
magnitude = utils::numeric(FLERR,arg[3],false,lmp);
@ -68,9 +66,7 @@ FixGravity::FixGravity(LAMMPS *lmp, int narg, char **arg) :
if (narg < 6) error->all(FLERR,"Illegal fix gravity command");
style = CHUTE;
if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
vstr = new char[n];
strcpy(vstr,&arg[5][2]);
vstr = utils::strdup(arg[5]+2);
vstyle = EQUAL;
} else {
vert = utils::numeric(FLERR,arg[5],false,lmp);
@ -82,18 +78,14 @@ FixGravity::FixGravity(LAMMPS *lmp, int narg, char **arg) :
if (narg < 7) error->all(FLERR,"Illegal fix gravity command");
style = SPHERICAL;
if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
pstr = new char[n];
strcpy(pstr,&arg[5][2]);
pstr = utils::strdup(arg[5]+2);
pstyle = EQUAL;
} else {
phi = utils::numeric(FLERR,arg[5],false,lmp);
pstyle = CONSTANT;
}
if (utils::strmatch(arg[6],"^v_")) {
int n = strlen(&arg[6][2]) + 1;
tstr = new char[n];
strcpy(tstr,&arg[6][2]);
tstr = utils::strdup(arg[6]+2);
tstyle = EQUAL;
} else {
theta = utils::numeric(FLERR,arg[6],false,lmp);
@ -105,27 +97,21 @@ FixGravity::FixGravity(LAMMPS *lmp, int narg, char **arg) :
if (narg < 8) error->all(FLERR,"Illegal fix gravity command");
style = VECTOR;
if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[5][2]);
xstr = utils::strdup(arg[5]+2);
xstyle = EQUAL;
} else {
xdir = utils::numeric(FLERR,arg[5],false,lmp);
xstyle = CONSTANT;
}
if (utils::strmatch(arg[6],"^v_")) {
int n = strlen(&arg[6][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[6][2]);
ystr = utils::strdup(arg[6]+2);
ystyle = EQUAL;
} else {
ydir = utils::numeric(FLERR,arg[6],false,lmp);
ystyle = CONSTANT;
}
if (utils::strmatch(arg[7],"^v_")) {
int n = strlen(&arg[7][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[7][2]);
zstr = utils::strdup(arg[7]+2);
zstyle = EQUAL;
} else {
zdir = utils::numeric(FLERR,arg[7],false,lmp);

View File

@ -17,19 +17,20 @@
#include "fix_heat.h"
#include <cmath>
#include <cstring>
#include "atom.h"
#include "domain.h"
#include "region.h"
#include "group.h"
#include "force.h"
#include "update.h"
#include "modify.h"
#include "input.h"
#include "variable.h"
#include "memory.h"
#include "error.h"
#include "force.h"
#include "group.h"
#include "input.h"
#include "memory.h"
#include "modify.h"
#include "region.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -53,9 +54,7 @@ idregion(nullptr), hstr(nullptr), vheat(nullptr), vscale(nullptr)
hstr = nullptr;
if (utils::strmatch(arg[4],"^v_")) {
int n = strlen(&arg[4][2]) + 1;
hstr = new char[n];
strcpy(hstr,&arg[4][2]);
hstr = utils::strdup(arg[4]+2);
} else {
heat_input = utils::numeric(FLERR,arg[4],false,lmp);
hstyle = CONSTANT;
@ -72,9 +71,7 @@ idregion(nullptr), hstr(nullptr), vheat(nullptr), vscale(nullptr)
iregion = domain->find_region(arg[iarg+1]);
if (iregion == -1)
error->all(FLERR,"Region ID for fix heat does not exist");
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 error->all(FLERR,"Illegal fix heat command");
}

View File

@ -418,24 +418,16 @@ void FixIndent::options(int narg, char **arg)
if (iarg+5 > narg) error->all(FLERR,"Illegal fix indent command");
if (utils::strmatch(arg[iarg+1],"^v_")) {
int n = strlen(&arg[iarg+1][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[iarg+1][2]);
xstr = utils::strdup(arg[iarg+1]+2);
} else xvalue = utils::numeric(FLERR,arg[iarg+1],false,lmp);
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[iarg+2][2]);
ystr = utils::strdup(arg[iarg+2]+2);
} else yvalue = utils::numeric(FLERR,arg[iarg+2],false,lmp);
if (utils::strmatch(arg[iarg+3],"^v_")) {
int n = strlen(&arg[iarg+3][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[iarg+3][2]);
zstr = utils::strdup(arg[iarg+3]+2);
} else zvalue = utils::numeric(FLERR,arg[iarg+3],false,lmp);
if (utils::strmatch(arg[iarg+4],"^v_")) {
int n = strlen(&arg[iarg+4][2]) + 1;
rstr = new char[n];
strcpy(rstr,&arg[iarg+4][2]);
rstr = utils::strdup(arg[iarg+4]+2);
} else rvalue = utils::numeric(FLERR,arg[iarg+4],false,lmp);
istyle = SPHERE;
@ -447,45 +439,31 @@ void FixIndent::options(int narg, char **arg)
if (strcmp(arg[iarg+1],"x") == 0) {
cdim = 0;
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[iarg+2][2]);
ystr = utils::strdup(arg[iarg+2]+2);
} else yvalue = utils::numeric(FLERR,arg[iarg+2],false,lmp);
if (utils::strmatch(arg[iarg+3],"^v_")) {
int n = strlen(&arg[iarg+3][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[iarg+3][2]);
zstr = utils::strdup(arg[iarg+3]+2);
} else zvalue = utils::numeric(FLERR,arg[iarg+3],false,lmp);
} else if (strcmp(arg[iarg+1],"y") == 0) {
cdim = 1;
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[iarg+2][2]);
xstr = utils::strdup(arg[iarg+2]+2);
} else xvalue = utils::numeric(FLERR,arg[iarg+2],false,lmp);
if (utils::strmatch(arg[iarg+3],"^v_")) {
int n = strlen(&arg[iarg+3][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[iarg+3][2]);
zstr = utils::strdup(arg[iarg+3]+2);
} else zvalue = utils::numeric(FLERR,arg[iarg+3],false,lmp);
} else if (strcmp(arg[iarg+1],"z") == 0) {
cdim = 2;
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[iarg+2][2]);
xstr = utils::strdup(arg[iarg+2]+2);
} else xvalue = utils::numeric(FLERR,arg[iarg+2],false,lmp);
if (utils::strmatch(arg[iarg+3],"^v_")) {
int n = strlen(&arg[iarg+3][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[iarg+3][2]);
ystr = utils::strdup(arg[iarg+3]+2);
} else yvalue = utils::numeric(FLERR,arg[iarg+3],false,lmp);
} else error->all(FLERR,"Illegal fix indent command");
if (utils::strmatch(arg[iarg+4],"^v_")) {
int n = strlen(&arg[iarg+4][2]) + 1;
rstr = new char[n];
strcpy(rstr,&arg[iarg+4][2]);
rstr = utils::strdup(arg[iarg+4]+2);
} else rvalue = utils::numeric(FLERR,arg[iarg+4],false,lmp);
istyle = CYLINDER;
@ -499,9 +477,7 @@ void FixIndent::options(int narg, char **arg)
else error->all(FLERR,"Illegal fix indent command");
if (utils::strmatch(arg[iarg+2],"^v_")) {
int n = strlen(&arg[iarg+2][2]) + 1;
pstr = new char[n];
strcpy(pstr,&arg[iarg+2][2]);
pstr = utils::strdup(arg[iarg+2]+2);
} else pvalue = utils::numeric(FLERR,arg[iarg+2],false,lmp);
if (strcmp(arg[iarg+3],"lo") == 0) planeside = -1;

View File

@ -21,24 +21,24 @@
#include "fix_langevin.h"
#include <cmath>
#include <cstring>
#include "math_extra.h"
#include "atom.h"
#include "atom_vec_ellipsoid.h"
#include "force.h"
#include "update.h"
#include "modify.h"
#include "compute.h"
#include "respa.h"
#include "comm.h"
#include "input.h"
#include "variable.h"
#include "random_mars.h"
#include "memory.h"
#include "compute.h"
#include "error.h"
#include "force.h"
#include "group.h"
#include "input.h"
#include "math_extra.h"
#include "memory.h"
#include "modify.h"
#include "random_mars.h"
#include "respa.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -65,9 +65,7 @@ FixLangevin::FixLangevin(LAMMPS *lmp, int narg, char **arg) :
nevery = 1;
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
tstr = new char[n];
strcpy(tstr,&arg[3][2]);
tstr = utils::strdup(arg[3]+2);
} else {
t_start = utils::numeric(FLERR,arg[3],false,lmp);
t_target = t_start;
@ -1032,9 +1030,7 @@ int FixLangevin::modify_param(int narg, char **arg)
if (strcmp(arg[0],"temp") == 0) {
if (narg < 2) error->all(FLERR,"Illegal fix_modify command");
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)

View File

@ -12,26 +12,28 @@
------------------------------------------------------------------------- */
#include "fix_move.h"
#include <cstring>
#include <cmath>
#include "atom.h"
#include "update.h"
#include "modify.h"
#include "force.h"
#include "domain.h"
#include "lattice.h"
#include "comm.h"
#include "respa.h"
#include "input.h"
#include "variable.h"
#include "atom_vec_body.h"
#include "atom_vec_ellipsoid.h"
#include "atom_vec_line.h"
#include "atom_vec_tri.h"
#include "atom_vec_body.h"
#include "comm.h"
#include "domain.h"
#include "error.h"
#include "force.h"
#include "input.h"
#include "lattice.h"
#include "math_const.h"
#include "math_extra.h"
#include "memory.h"
#include "error.h"
#include "modify.h"
#include "respa.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -129,39 +131,27 @@ FixMove::FixMove(LAMMPS *lmp, int narg, char **arg) :
mstyle = VARIABLE;
if (strcmp(arg[4],"NULL") == 0) xvarstr = nullptr;
else if (utils::strmatch(arg[4],"^v_")) {
int n = strlen(&arg[4][2]) + 1;
xvarstr = new char[n];
strcpy(xvarstr,&arg[4][2]);
xvarstr = utils::strdup(arg[4]+2);
} else error->all(FLERR,"Illegal fix move command");
if (strcmp(arg[5],"NULL") == 0) yvarstr = nullptr;
else if (utils::strmatch(arg[5],"^v_")) {
int n = strlen(&arg[5][2]) + 1;
yvarstr = new char[n];
strcpy(yvarstr,&arg[5][2]);
yvarstr = utils::strdup(arg[5]+2);
} else error->all(FLERR,"Illegal fix move command");
if (strcmp(arg[6],"NULL") == 0) zvarstr = nullptr;
else if (utils::strmatch(arg[6],"^v_")) {
int n = strlen(&arg[6][2]) + 1;
zvarstr = new char[n];
strcpy(zvarstr,&arg[6][2]);
zvarstr = utils::strdup(arg[6]+2);
} else error->all(FLERR,"Illegal fix move command");
if (strcmp(arg[7],"NULL") == 0) vxvarstr = nullptr;
else if (utils::strmatch(arg[7],"^v_")) {
int n = strlen(&arg[7][2]) + 1;
vxvarstr = new char[n];
strcpy(vxvarstr,&arg[7][2]);
vxvarstr = utils::strdup(arg[7]+2);
} else error->all(FLERR,"Illegal fix move command");
if (strcmp(arg[8],"NULL") == 0) vyvarstr = nullptr;
else if (utils::strmatch(arg[8],"^v_")) {
int n = strlen(&arg[8][2]) + 1;
vyvarstr = new char[n];
strcpy(vyvarstr,&arg[8][2]);
vyvarstr = utils::strdup(arg[8]+2);
} else error->all(FLERR,"Illegal fix move command");
if (strcmp(arg[9],"NULL") == 0) vzvarstr = nullptr;
else if (utils::strmatch(arg[9],"^v_")) {
int n = strlen(&arg[9][2]) + 1;
vzvarstr = new char[n];
strcpy(vzvarstr,&arg[9][2]);
vzvarstr = utils::strdup(arg[9]+2);
} else error->all(FLERR,"Illegal fix move command");
} else error->all(FLERR,"Illegal fix move command");

View File

@ -33,9 +33,7 @@ FixPrint::FixPrint(LAMMPS *lmp, int narg, char **arg) :
{
if (narg < 5) error->all(FLERR,"Illegal fix print command");
if (utils::strmatch(arg[3],"^v_")) {
int n = strlen(&arg[3][2]) + 1;
var_print = new char[n];
strcpy(var_print,&arg[3][2]);
var_print = utils::strdup(arg[3]+2);
nevery = 1;
} else {
nevery = utils::inumeric(FLERR,arg[3],false,lmp);
@ -79,9 +77,7 @@ FixPrint::FixPrint(LAMMPS *lmp, int narg, char **arg) :
} else if (strcmp(arg[iarg],"title") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix print command");
delete [] title;
int n = strlen(arg[iarg+1]) + 1;
title = new char[n];
strcpy(title,arg[iarg+1]);
title = utils::strdup(arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal fix print command");
}

View File

@ -328,8 +328,7 @@ void Variable::set(int narg, char **arg)
pad[nvar] = 0;
data[nvar] = new char*[num[nvar]];
copy(1,&arg[2],data[nvar]);
data[nvar][1] = new char[VALUELENGTH];
strcpy(data[nvar][1],"(undefined)");
data[nvar][1] = utils::strdup("(undefined)");
// SCALARFILE for strings or numbers
// which = 1st value
@ -521,12 +520,9 @@ void Variable::set(int narg, char **arg)
if (replaceflag) return;
int n = strlen(arg[0]) + 1;
names[nvar] = new char[n];
strcpy(names[nvar],arg[0]);
for (int i = 0; i < n-1; i++)
if (!isalnum(names[nvar][i]) && names[nvar][i] != '_')
names[nvar] = utils::strdup(arg[0]);
for (auto c : std::string(arg[0]))
if (!isalnum(c) && (c != '_'))
error->all(FLERR,fmt::format("Variable name '{}' must have only "
"alphanumeric characters or underscores",
names[nvar]));
@ -577,8 +573,7 @@ int Variable::set_string(const char *name, const char *str)
if (ivar < 0) return -1;
if (style[ivar] != STRING) return -1;
delete [] data[ivar][0];
data[ivar][0] = new char[strlen(str)+1];
strcpy(data[ivar][0],str);
data[ivar][0] = utils::strdup(str);
return 0;
}
@ -898,11 +893,8 @@ char *Variable::retrieve(const char *name)
sprintf(padstr,"%%0%dd",pad[ivar]);
sprintf(result,padstr,which[ivar]+1);
}
int n = strlen(result) + 1;
delete [] data[ivar][0];
data[ivar][0] = new char[n];
strcpy(data[ivar][0],result);
str = data[ivar][0];
str = data[ivar][0] = utils::strdup(result);
} else if (style[ivar] == EQUAL) {
double answer = evaluate(data[ivar][0],nullptr,ivar);
sprintf(data[ivar][1],"%.15g",answer);
@ -917,13 +909,8 @@ char *Variable::retrieve(const char *name)
} else if (style[ivar] == GETENV) {
const char *result = getenv(data[ivar][0]);
if (result == nullptr) result = (const char *) "";
int n = strlen(result) + 1;
if (n > VALUELENGTH) {
delete [] data[ivar][1];
data[ivar][1] = new char[n];
}
strcpy(data[ivar][1],result);
str = data[ivar][1];
delete [] data[ivar][1];
str = data[ivar][1] = utils::strdup(result);
} else if (style[ivar] == PYTHON) {
int ifunc = python->variable_match(data[ivar][0],name,0);
if (ifunc < 0)
@ -1185,12 +1172,8 @@ void Variable::grow()
void Variable::copy(int narg, char **from, char **to)
{
int n;
for (int i = 0; i < narg; i++) {
n = strlen(from[i]) + 1;
to[i] = new char[n];
strcpy(to[i],from[i]);
}
for (int i = 0; i < narg; i++)
to[i] = utils::strdup(from[i]);
}
/* ----------------------------------------------------------------------
@ -4728,18 +4711,14 @@ double Variable::constant(char *word)
int Variable::parse_args(char *str, char **args)
{
int n;
char *ptrnext;
int narg = 0;
int narg = 0;
char *ptr = str;
while (ptr && narg < MAXFUNCARG) {
ptrnext = find_next_comma(ptr);
if (ptrnext) *ptrnext = '\0';
n = strlen(ptr) + 1;
args[narg] = new char[n];
strcpy(args[narg],ptr);
args[narg] = utils::strdup(ptr);
narg++;
ptr = ptrnext;
if (ptr) ptr++;
@ -5089,8 +5068,7 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) :
"variable unless an atom map exists");
std::string cmd = name + std::string("_VARIABLE_STORE");
id_fix = new char[cmd.size()+1];
strcpy(id_fix,cmd.c_str());
id_fix = utils::strdup(cmd);
cmd += " all STORE peratom 0 1";
modify->add_fix(cmd);

View File

@ -420,23 +420,17 @@ void Velocity::set(int /*narg*/, char **arg)
xstr = ystr = zstr = nullptr;
if (utils::strmatch(arg[0],"^v_")) {
int n = strlen(&arg[0][2]) + 1;
xstr = new char[n];
strcpy(xstr,&arg[0][2]);
xstr = utils::strdup(arg[0]+2);
} else if (strcmp(arg[0],"NULL") == 0) xstyle = NONE;
else vx = utils::numeric(FLERR,arg[0],false,lmp);
if (utils::strmatch(arg[1],"^v_")) {
int n = strlen(&arg[1][2]) + 1;
ystr = new char[n];
strcpy(ystr,&arg[1][2]);
ystr = utils::strdup(arg[1]+2);
} else if (strcmp(arg[1],"NULL") == 0) ystyle = NONE;
else vy = utils::numeric(FLERR,arg[1],false,lmp);
if (utils::strmatch(arg[2],"^v_")) {
int n = strlen(&arg[2][2]) + 1;
zstr = new char[n];
strcpy(zstr,&arg[2][2]);
zstr = utils::strdup(arg[2]+2);
} else if (strcmp(arg[2],"NULL") == 0) zstyle = NONE;
else vz = utils::numeric(FLERR,arg[2],false,lmp);