get rid of local buffers and snprinf()

This commit is contained in:
Axel Kohlmeyer
2020-06-04 16:25:09 -04:00
parent 4b58e33b1e
commit 62ee8d41f3
8 changed files with 76 additions and 124 deletions

View File

@ -251,11 +251,9 @@ void Input::file(const char *filename)
error->one(FLERR,"Too many nested levels of input scripts");
infile = fopen(filename,"r");
if (infile == NULL) {
char str[128];
snprintf(str,128,"Cannot open input script %s",filename);
error->one(FLERR,str);
}
if (infile == NULL)
error->one(FLERR,fmt::format("Cannot open input script {}",filename));
infiles[nfile++] = infile;
}
@ -545,11 +543,10 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
value = variable->retrieve(var);
}
if (value == NULL) {
char str[128];
snprintf(str,128,"Substitution for illegal variable %s",var);
error->one(FLERR,str);
}
if (value == NULL)
error->one(FLERR,fmt::format("Substitution for illegal "
"variable {}",var));
// check if storage in str2 needs to be expanded
// re-initialize ptr and ptr2 to the point beyond the variable.
@ -1038,11 +1035,9 @@ void Input::include()
error->one(FLERR,"Too many nested levels of input scripts");
infile = fopen(arg[0],"r");
if (infile == NULL) {
char str[128];
snprintf(str,128,"Cannot open input script %s",arg[0]);
error->one(FLERR,str);
}
if (infile == NULL)
error->one(FLERR,fmt::format("Cannot open input script {}",arg[0]));
infiles[nfile++] = infile;
}
@ -1073,11 +1068,9 @@ void Input::jump()
else {
if (infile && infile != stdin) fclose(infile);
infile = fopen(arg[0],"r");
if (infile == NULL) {
char str[128];
snprintf(str,128,"Cannot open input script %s",arg[0]);
error->one(FLERR,str);
}
if (infile == NULL)
error->one(FLERR,fmt::format("Cannot open input script {}",arg[0]));
infiles[nfile-1] = infile;
}
}
@ -1118,11 +1111,9 @@ void Input::log()
if (appendflag) logfile = fopen(arg[0],"a");
else logfile = fopen(arg[0],"w");
if (logfile == NULL) {
char str[128];
snprintf(str,128,"Cannot open logfile %s",arg[0]);
error->one(FLERR,str);
}
if (logfile == NULL)
error->one(FLERR,fmt::format("Cannot open logfile {}",arg[0]));
}
if (universe->nworlds == 1) universe->ulogfile = logfile;
}
@ -1197,11 +1188,9 @@ void Input::print()
if (fp != NULL) fclose(fp);
if (strcmp(arg[iarg],"file") == 0) fp = fopen(arg[iarg+1],"w");
else fp = fopen(arg[iarg+1],"a");
if (fp == NULL) {
char str[128];
snprintf(str,128,"Cannot open print file %s",arg[iarg+1]);
error->one(FLERR,str);
}
if (fp == NULL)
error->one(FLERR,fmt::format("Cannot open print file {}",
arg[iarg+1]));
}
iarg += 2;
} else if (strcmp(arg[iarg],"screen") == 0) {
@ -1810,18 +1799,15 @@ void Input::pair_style()
{
if (narg < 1) error->all(FLERR,"Illegal pair_style command");
if (force->pair) {
std::string style = arg[0];
int match = 0;
if (strcmp(arg[0],force->pair_style) == 0) match = 1;
if (style == force->pair_style) match = 1;
if (!match && lmp->suffix_enable) {
char estyle[256];
if (lmp->suffix) {
snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix);
if (strcmp(estyle,force->pair_style) == 0) match = 1;
}
if (lmp->suffix2) {
snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix2);
if (strcmp(estyle,force->pair_style) == 0) match = 1;
}
if (lmp->suffix)
if (style + "/" + lmp->suffix == force->pair_style) match = 1;
if (lmp->suffix2)
if (style + "/" + lmp->suffix2 == force->pair_style) match = 1;
}
if (match) {
force->pair->settings(narg-1,&arg[1]);