update utils::expand_args
This commit is contained in:
@ -214,7 +214,7 @@ char *utils::fgets_trunc(char *buf, int size, FILE *fp)
|
||||
void utils::sfgets(const char *srcname, int srcline, char *s, int size, FILE *fp,
|
||||
const char *filename, Error *error)
|
||||
{
|
||||
constexpr int MAXPATHLENBUF=1024;
|
||||
constexpr int MAXPATHLENBUF = 1024;
|
||||
char *rv = fgets(s, size, fp);
|
||||
if (rv == nullptr) { // something went wrong
|
||||
char buf[MAXPATHLENBUF];
|
||||
@ -243,7 +243,7 @@ void utils::sfgets(const char *srcname, int srcline, char *s, int size, FILE *fp
|
||||
void utils::sfread(const char *srcname, int srcline, void *s, size_t size, size_t num, FILE *fp,
|
||||
const char *filename, Error *error)
|
||||
{
|
||||
constexpr int MAXPATHLENBUF=1024;
|
||||
constexpr int MAXPATHLENBUF = 1024;
|
||||
size_t rv = fread(s, size, num, fp);
|
||||
if (rv != num) { // something went wrong
|
||||
char buf[MAXPATHLENBUF];
|
||||
@ -543,16 +543,21 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
||||
std::string word(arg[iarg]);
|
||||
expandflag = 0;
|
||||
|
||||
// only match compute/fix reference with a '*' wildcard
|
||||
// match compute, fix, or custom property array reference with a '*' wildcard
|
||||
// number range in the first pair of square brackets
|
||||
|
||||
if (strmatch(word, "^[cf]_\\w+\\[\\d*\\*\\d*\\]")) {
|
||||
if (strmatch(word, "^[cf]_\\w+\\[\\d*\\*\\d*\\]") ||
|
||||
strmatch(word, "^[id]2_\\w+\\[\\d*\\*\\d*\\]")) {
|
||||
|
||||
// split off the compute/fix ID, the wildcard and trailing text
|
||||
// split off the compute/fix/property ID, the wildcard and trailing text
|
||||
|
||||
size_t first = word.find("[");
|
||||
size_t second = word.find("]", first + 1);
|
||||
id = word.substr(2, first - 2);
|
||||
if (word[1] == '2')
|
||||
id = word.substr(3, first - 3);
|
||||
else
|
||||
id = word.substr(2, first - 2);
|
||||
|
||||
wc = word.substr(first + 1, second - first - 1);
|
||||
tail = word.substr(second + 1);
|
||||
|
||||
@ -580,7 +585,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
||||
}
|
||||
}
|
||||
|
||||
// fix
|
||||
// fix
|
||||
|
||||
} else if (word[0] == 'f') {
|
||||
int ifix = lmp->modify->find_fix(id);
|
||||
@ -609,59 +614,20 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
||||
|
||||
// only match custom array reference with a '*' wildcard
|
||||
// number range in the first pair of square brackets
|
||||
// OLDSTYLE code
|
||||
|
||||
if (strncmp(arg[iarg],"i2_",3) == 0 || strncmp(arg[iarg],"d2_",3) == 0) {
|
||||
char *ptr1 = strchr(arg[iarg],'[');
|
||||
if (ptr1) {
|
||||
char *ptr2 = strchr(ptr1,']');
|
||||
if (ptr2) {
|
||||
*ptr2 = '\0';
|
||||
if (strchr(ptr1,'*')) {
|
||||
if ((word[0] == 'i') || (word[0] == 'd')) {
|
||||
int flag, cols;
|
||||
int icustom = lmp->atom->find_custom(id.c_str(), flag, cols);
|
||||
|
||||
if (arg[iarg][0] == 'i') {
|
||||
*ptr1 = '\0';
|
||||
int flag,cols;
|
||||
int icustom = lmp->atom->find_custom(&arg[iarg][3],flag,cols);
|
||||
*ptr1 = '[';
|
||||
if ((icustom >= 0) && (mode == 1) && (cols > 0)) {
|
||||
|
||||
// check for custom per-atom integer array
|
||||
// check for custom per-atom array
|
||||
|
||||
if (icustom >= 0) {
|
||||
if (mode == 1 && !flag && cols) {
|
||||
nmax = cols;
|
||||
expandflag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (arg[iarg][0] == 'd') {
|
||||
*ptr1 = '\0';
|
||||
int flag,cols;
|
||||
int icustom = lmp->atom->find_custom(&arg[iarg][3],flag,cols);
|
||||
*ptr1 = '[';
|
||||
|
||||
// check for custom per-atom floating point array
|
||||
|
||||
if (icustom >= 0) {
|
||||
if (mode == 1 && flag && cols) {
|
||||
nmax = cols;
|
||||
expandflag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (((word[0] == 'i') && (flag == 0)) || ((word[0] == 'i') && (flag == 1))) {
|
||||
nmax = cols;
|
||||
expandflag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// split off the array name ID, the wildcard and trailing text
|
||||
|
||||
if (expandflag) {
|
||||
size_t first = word.find("[");
|
||||
size_t second = word.find("]", first + 1);
|
||||
id = word.substr(2, first - 2);
|
||||
wc = word.substr(first + 1, second - first - 1);
|
||||
tail = word.substr(second + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// expansion will take place
|
||||
@ -678,7 +644,10 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
||||
|
||||
for (int index = nlo; index <= nhi; index++) {
|
||||
// assemble and duplicate expanded string
|
||||
earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail));
|
||||
if (word[1] == '2')
|
||||
earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail));
|
||||
else
|
||||
earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail));
|
||||
newarg++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user