simplify using std::string

This commit is contained in:
Axel Kohlmeyer
2021-03-16 09:39:28 -04:00
parent b7759b0cdb
commit 1ef1a7d865

View File

@ -445,26 +445,14 @@ is passed to :cpp:func:`lammps_commands_string` for processing.
void lammps_commands_list(void *handle, int ncmd, const char **cmds)
{
LAMMPS *lmp = (LAMMPS *) handle;
int n = ncmd+1;
for (int i = 0; i < ncmd; i++) n += strlen(cmds[i]);
char *str = (char *) lmp->memory->smalloc(n,"lib/commands/list:str");
str[0] = '\0';
n = 0;
std::string allcmds;
for (int i = 0; i < ncmd; i++) {
strcpy(&str[n],cmds[i]);
n += strlen(cmds[i]);
if (str[n-1] != '\n') {
str[n] = '\n';
str[n+1] = '\0';
n++;
}
allcmds.append(cmds[i]);
if (allcmds.back() != '\n') allcmds.append(1,'\n');
}
lammps_commands_string(handle,str);
lmp->memory->sfree(str);
lammps_commands_string(handle,allcmds.c_str());
}
/* ---------------------------------------------------------------------- */