simplify by using utils::strdup()
This commit is contained in:
@ -278,14 +278,8 @@ void ReadData::command(int narg, char **arg)
|
|||||||
if (fix_index[nfix] < 0)
|
if (fix_index[nfix] < 0)
|
||||||
error->all(FLERR,"Fix ID for read_data does not exist");
|
error->all(FLERR,"Fix ID for read_data does not exist");
|
||||||
if (strcmp(arg[iarg+2],"NULL") == 0) fix_header[nfix] = nullptr;
|
if (strcmp(arg[iarg+2],"NULL") == 0) fix_header[nfix] = nullptr;
|
||||||
else {
|
else fix_header[nfix] = utils::strdup(arg[iarg+2]);
|
||||||
int n = strlen(arg[iarg+2]) + 1;
|
fix_section[nfix] = utils::strdup(arg[iarg+3]);
|
||||||
fix_header[nfix] = new char[n];
|
|
||||||
strcpy(fix_header[nfix],arg[iarg+2]);
|
|
||||||
}
|
|
||||||
int n = strlen(arg[iarg+3]) + 1;
|
|
||||||
fix_section[nfix] = new char[n];
|
|
||||||
strcpy(fix_section[nfix],arg[iarg+3]);
|
|
||||||
nfix++;
|
nfix++;
|
||||||
iarg += 4;
|
iarg += 4;
|
||||||
|
|
||||||
|
|||||||
@ -64,9 +64,7 @@ ReadDump::ReadDump(LAMMPS *lmp) : Pointers(lmp)
|
|||||||
fields = nullptr;
|
fields = nullptr;
|
||||||
buf = nullptr;
|
buf = nullptr;
|
||||||
|
|
||||||
int n = strlen("native") + 1;
|
readerstyle = utils::strdup("native");
|
||||||
readerstyle = new char[n];
|
|
||||||
strcpy(readerstyle,"native");
|
|
||||||
|
|
||||||
nreader = 0;
|
nreader = 0;
|
||||||
readers = nullptr;
|
readers = nullptr;
|
||||||
@ -182,9 +180,7 @@ void ReadDump::store_files(int nstr, char **str)
|
|||||||
// either all or none of files must have '%' wild-card
|
// either all or none of files must have '%' wild-card
|
||||||
|
|
||||||
for (int i = 0; i < nfile; i++) {
|
for (int i = 0; i < nfile; i++) {
|
||||||
int n = strlen(str[i]) + 1;
|
files[i] = utils::strdup(str[i]);
|
||||||
files[i] = new char[n];
|
|
||||||
strcpy(files[i],str[i]);
|
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
if (strchr(files[i],'%')) multiproc = 1;
|
if (strchr(files[i],'%')) multiproc = 1;
|
||||||
@ -1258,9 +1254,7 @@ int ReadDump::fields_and_keywords(int narg, char **arg)
|
|||||||
for (i = 0; i < nfield; i++)
|
for (i = 0; i < nfield; i++)
|
||||||
if (type == fieldtype[i]) break;
|
if (type == fieldtype[i]) break;
|
||||||
if (i == nfield) error->all(FLERR,"Illegal read_dump command");
|
if (i == nfield) error->all(FLERR,"Illegal read_dump command");
|
||||||
int n = strlen(arg[iarg+2]) + 1;
|
fieldlabel[i] = utils::strdup(arg[iarg+2]);
|
||||||
fieldlabel[i] = new char[n];
|
|
||||||
strcpy(fieldlabel[i],arg[iarg+2]);
|
|
||||||
iarg += 3;
|
iarg += 3;
|
||||||
} else if (strcmp(arg[iarg],"scaled") == 0) {
|
} else if (strcmp(arg[iarg],"scaled") == 0) {
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal read_dump command");
|
if (iarg+2 > narg) error->all(FLERR,"Illegal read_dump command");
|
||||||
@ -1277,9 +1271,7 @@ int ReadDump::fields_and_keywords(int narg, char **arg)
|
|||||||
} else if (strcmp(arg[iarg],"format") == 0) {
|
} else if (strcmp(arg[iarg],"format") == 0) {
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal read_dump command");
|
if (iarg+2 > narg) error->all(FLERR,"Illegal read_dump command");
|
||||||
delete [] readerstyle;
|
delete [] readerstyle;
|
||||||
int n = strlen(arg[iarg+1]) + 1;
|
readerstyle = utils::strdup(arg[iarg+1]);
|
||||||
readerstyle = new char[n];
|
|
||||||
strcpy(readerstyle,arg[iarg+1]);
|
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
break;
|
break;
|
||||||
} else error->all(FLERR,"Illegal read_dump command");
|
} else error->all(FLERR,"Illegal read_dump command");
|
||||||
|
|||||||
@ -33,13 +33,8 @@ Region::Region(LAMMPS *lmp, int /*narg*/, char **arg) :
|
|||||||
id(nullptr), style(nullptr), contact(nullptr), list(nullptr),
|
id(nullptr), style(nullptr), contact(nullptr), list(nullptr),
|
||||||
xstr(nullptr), ystr(nullptr), zstr(nullptr), tstr(nullptr)
|
xstr(nullptr), ystr(nullptr), zstr(nullptr), tstr(nullptr)
|
||||||
{
|
{
|
||||||
int n = strlen(arg[0]) + 1;
|
id = utils::strdup(arg[0]);
|
||||||
id = new char[n];
|
style = utils::strdup(arg[1]);
|
||||||
strcpy(id,arg[0]);
|
|
||||||
|
|
||||||
n = strlen(arg[1]) + 1;
|
|
||||||
style = new char[n];
|
|
||||||
strcpy(style,arg[1]);
|
|
||||||
|
|
||||||
varshape = 0;
|
varshape = 0;
|
||||||
xstr = ystr = zstr = tstr = nullptr;
|
xstr = ystr = zstr = tstr = nullptr;
|
||||||
@ -338,23 +333,17 @@ void Region::options(int narg, char **arg)
|
|||||||
if (strcmp(arg[iarg+1],"NULL") != 0) {
|
if (strcmp(arg[iarg+1],"NULL") != 0) {
|
||||||
if (strstr(arg[iarg+1],"v_") != arg[iarg+1])
|
if (strstr(arg[iarg+1],"v_") != arg[iarg+1])
|
||||||
error->all(FLERR,"Illegal region command");
|
error->all(FLERR,"Illegal region command");
|
||||||
int n = strlen(&arg[iarg+1][2]) + 1;
|
xstr = utils::strdup(&arg[iarg+1][2]);
|
||||||
xstr = new char[n];
|
|
||||||
strcpy(xstr,&arg[iarg+1][2]);
|
|
||||||
}
|
}
|
||||||
if (strcmp(arg[iarg+2],"NULL") != 0) {
|
if (strcmp(arg[iarg+2],"NULL") != 0) {
|
||||||
if (strstr(arg[iarg+2],"v_") != arg[iarg+2])
|
if (strstr(arg[iarg+2],"v_") != arg[iarg+2])
|
||||||
error->all(FLERR,"Illegal region command");
|
error->all(FLERR,"Illegal region command");
|
||||||
int n = strlen(&arg[iarg+2][2]) + 1;
|
ystr = utils::strdup(&arg[iarg+2][2]);
|
||||||
ystr = new char[n];
|
|
||||||
strcpy(ystr,&arg[iarg+2][2]);
|
|
||||||
}
|
}
|
||||||
if (strcmp(arg[iarg+3],"NULL") != 0) {
|
if (strcmp(arg[iarg+3],"NULL") != 0) {
|
||||||
if (strstr(arg[iarg+3],"v_") != arg[iarg+3])
|
if (strstr(arg[iarg+3],"v_") != arg[iarg+3])
|
||||||
error->all(FLERR,"Illegal region command");
|
error->all(FLERR,"Illegal region command");
|
||||||
int n = strlen(&arg[iarg+3][2]) + 1;
|
zstr = utils::strdup(&arg[iarg+3][2]);
|
||||||
zstr = new char[n];
|
|
||||||
strcpy(zstr,&arg[iarg+3][2]);
|
|
||||||
}
|
}
|
||||||
moveflag = 1;
|
moveflag = 1;
|
||||||
iarg += 4;
|
iarg += 4;
|
||||||
@ -363,9 +352,7 @@ void Region::options(int narg, char **arg)
|
|||||||
if (iarg+8 > narg) error->all(FLERR,"Illegal region command");
|
if (iarg+8 > narg) error->all(FLERR,"Illegal region command");
|
||||||
if (strstr(arg[iarg+1],"v_") != arg[iarg+1])
|
if (strstr(arg[iarg+1],"v_") != arg[iarg+1])
|
||||||
error->all(FLERR,"Illegal region command");
|
error->all(FLERR,"Illegal region command");
|
||||||
int n = strlen(&arg[iarg+1][2]) + 1;
|
tstr = utils::strdup(&arg[iarg+1][2]);
|
||||||
tstr = new char[n];
|
|
||||||
strcpy(tstr,&arg[iarg+1][2]);
|
|
||||||
point[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp);
|
point[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp);
|
||||||
point[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp);
|
point[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp);
|
||||||
point[2] = utils::numeric(FLERR,arg[iarg+4],false,lmp);
|
point[2] = utils::numeric(FLERR,arg[iarg+4],false,lmp);
|
||||||
|
|||||||
@ -39,12 +39,9 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
list = new int[n];
|
list = new int[n];
|
||||||
nregion = 0;
|
nregion = 0;
|
||||||
|
|
||||||
int m,iregion;
|
|
||||||
for (int iarg = 0; iarg < n; iarg++) {
|
for (int iarg = 0; iarg < n; iarg++) {
|
||||||
m = strlen(arg[iarg+3]) + 1;
|
idsub[nregion] = utils::strdup(arg[iarg+3]);
|
||||||
idsub[nregion] = new char[m];
|
int iregion = domain->find_region(idsub[nregion]);
|
||||||
strcpy(idsub[nregion],arg[iarg+3]);
|
|
||||||
iregion = domain->find_region(idsub[nregion]);
|
|
||||||
if (iregion == -1)
|
if (iregion == -1)
|
||||||
error->all(FLERR,"Region intersect region ID does not exist");
|
error->all(FLERR,"Region intersect region ID does not exist");
|
||||||
list[nregion++] = iregion;
|
list[nregion++] = iregion;
|
||||||
@ -123,9 +120,8 @@ void RegIntersect::init()
|
|||||||
// re-build list of sub-regions in case other regions were deleted
|
// re-build list of sub-regions in case other regions were deleted
|
||||||
// error if a sub-region was deleted
|
// error if a sub-region was deleted
|
||||||
|
|
||||||
int iregion;
|
|
||||||
for (int ilist = 0; ilist < nregion; ilist++) {
|
for (int ilist = 0; ilist < nregion; ilist++) {
|
||||||
iregion = domain->find_region(idsub[ilist]);
|
int iregion = domain->find_region(idsub[ilist]);
|
||||||
if (iregion == -1)
|
if (iregion == -1)
|
||||||
error->all(FLERR,"Region union region ID does not exist");
|
error->all(FLERR,"Region union region ID does not exist");
|
||||||
list[ilist] = iregion;
|
list[ilist] = iregion;
|
||||||
|
|||||||
@ -40,12 +40,9 @@ RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg),
|
|||||||
list = new int[n];
|
list = new int[n];
|
||||||
nregion = 0;
|
nregion = 0;
|
||||||
|
|
||||||
int m,iregion;
|
|
||||||
for (int iarg = 0; iarg < n; iarg++) {
|
for (int iarg = 0; iarg < n; iarg++) {
|
||||||
m = strlen(arg[iarg+3]) + 1;
|
idsub[nregion] = utils::strdup(arg[iarg+3]);
|
||||||
idsub[nregion] = new char[m];
|
int iregion = domain->find_region(idsub[nregion]);
|
||||||
strcpy(idsub[nregion],arg[iarg+3]);
|
|
||||||
iregion = domain->find_region(idsub[nregion]);
|
|
||||||
if (iregion == -1)
|
if (iregion == -1)
|
||||||
error->all(FLERR,"Region union region ID does not exist");
|
error->all(FLERR,"Region union region ID does not exist");
|
||||||
list[nregion++] = iregion;
|
list[nregion++] = iregion;
|
||||||
@ -117,9 +114,8 @@ void RegUnion::init()
|
|||||||
// re-build list of sub-regions in case other regions were deleted
|
// re-build list of sub-regions in case other regions were deleted
|
||||||
// error if a sub-region was deleted
|
// error if a sub-region was deleted
|
||||||
|
|
||||||
int iregion;
|
|
||||||
for (int ilist = 0; ilist < nregion; ilist++) {
|
for (int ilist = 0; ilist < nregion; ilist++) {
|
||||||
iregion = domain->find_region(idsub[ilist]);
|
int iregion = domain->find_region(idsub[ilist]);
|
||||||
if (iregion == -1)
|
if (iregion == -1)
|
||||||
error->all(FLERR,"Region union region ID does not exist");
|
error->all(FLERR,"Region union region ID does not exist");
|
||||||
list[ilist] = iregion;
|
list[ilist] = iregion;
|
||||||
|
|||||||
@ -96,10 +96,7 @@ char *TextFileReader::next_line(int nparams) {
|
|||||||
if (ignore_comments && (ptr = strchr(line, '#'))) *ptr = '\0';
|
if (ignore_comments && (ptr = strchr(line, '#'))) *ptr = '\0';
|
||||||
|
|
||||||
nwords = utils::count_words(line);
|
nwords = utils::count_words(line);
|
||||||
|
if (nwords > 0) n = strlen(line);
|
||||||
if (nwords > 0) {
|
|
||||||
n = strlen(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (nwords == 0 || nwords < nparams) {
|
while (nwords == 0 || nwords < nparams) {
|
||||||
char *ptr = fgets(&line[n], MAXLINE - n, fp);
|
char *ptr = fgets(&line[n], MAXLINE - n, fp);
|
||||||
|
|||||||
Reference in New Issue
Block a user