Remove more c_str()

This commit is contained in:
Richard Berger
2020-06-05 12:13:41 -04:00
parent 7df387f7d5
commit a42a86c0d2
6 changed files with 30 additions and 31 deletions

View File

@ -3378,7 +3378,7 @@ void PairAIREBO::read_file(char *filename)
break; break;
default: default:
error->one(FLERR, fmt::format("Unknown REBO style variant %d",variant).c_str()); error->one(FLERR, fmt::format("Unknown REBO style variant %d",variant));
} }
PotentialFileReader reader(lmp, filename, potential_name); PotentialFileReader reader(lmp, filename, potential_name);
@ -3390,7 +3390,7 @@ void PairAIREBO::read_file(char *filename)
char * line = reader.next_line(); char * line = reader.next_line();
if (std::string(line).find(header) == std::string::npos) { if (std::string(line).find(header) == std::string::npos) {
error->one(FLERR,fmt::format("Potential file does not match AIREBO/REBO style variant: {}: {}", header, line).c_str()); error->one(FLERR, fmt::format("Potential file does not match AIREBO/REBO style variant: {}: {}", header, line));
} }
// skip remaining comments // skip remaining comments

View File

@ -29,6 +29,7 @@
#include "utils.h" #include "utils.h"
#include "tokenizer.h" #include "tokenizer.h"
#include "potential_file_reader.h" #include "potential_file_reader.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -1059,9 +1060,7 @@ EIMPotentialFileReader::EIMPotentialFileReader(LAMMPS * lmp, const std::string &
FILE * fp = force->open_potential(filename.c_str()); FILE * fp = force->open_potential(filename.c_str());
if (fp == NULL) { if (fp == NULL) {
char str[128]; error->one(FLERR, fmt::format("cannot open EIM potential file {}", filename));
snprintf(str, 128, "cannot open EIM potential file %s", filename.c_str());
error->one(FLERR, str);
} }
parse(fp); parse(fp);

View File

@ -380,7 +380,7 @@ void BondTable::read_table(Table *tb, char *file, char *keyword)
if (ferror) { if (ferror) {
std::string str = fmt::format("%d of %d force values in table are inconsistent with -dE/dr.\n" std::string str = fmt::format("%d of %d force values in table are inconsistent with -dE/dr.\n"
" Should only be flagged at inflection points",ferror,tb->ninput); " Should only be flagged at inflection points",ferror,tb->ninput);
error->warning(FLERR,str.c_str()); error->warning(FLERR, str);
} }
// warn if data was read incompletely, e.g. columns were missing // warn if data was read incompletely, e.g. columns were missing

View File

@ -832,13 +832,13 @@ void DihedralTable::coeff(int narg, char **arg)
string err_msg; string err_msg;
err_msg = string("Invalid dihedral table length (") err_msg = string("Invalid dihedral table length (")
+ string(arg[2]) + string(")."); + string(arg[2]) + string(").");
error->one(FLERR,err_msg.c_str()); error->one(FLERR,err_msg);
} }
else if ((tb->ninput == 2) && (tabstyle == SPLINE)) { else if ((tb->ninput == 2) && (tabstyle == SPLINE)) {
string err_msg; string err_msg;
err_msg = string("Invalid dihedral spline table length. (Try linear)\n (") err_msg = string("Invalid dihedral spline table length. (Try linear)\n (")
+ string(arg[2]) + string(")."); + string(arg[2]) + string(").");
error->one(FLERR,err_msg.c_str()); error->one(FLERR,err_msg);
} }
// check for monotonicity // check for monotonicity
@ -851,7 +851,7 @@ void DihedralTable::coeff(int narg, char **arg)
string(arg[2]) + string(", ")+i_str.str()+string("th entry)"); string(arg[2]) + string(", ")+i_str.str()+string("th entry)");
if (i==0) if (i==0)
err_msg += string("\n(This is probably a mistake with your table format.)\n"); err_msg += string("\n(This is probably a mistake with your table format.)\n");
error->all(FLERR,err_msg.c_str()); error->all(FLERR,err_msg);
} }
} }
@ -863,7 +863,7 @@ void DihedralTable::coeff(int narg, char **arg)
string err_msg; string err_msg;
err_msg = string("Dihedral table angle range must be < 360 degrees (") err_msg = string("Dihedral table angle range must be < 360 degrees (")
+string(arg[2]) + string(")."); +string(arg[2]) + string(").");
error->all(FLERR,err_msg.c_str()); error->all(FLERR,err_msg);
} }
} }
else { else {
@ -871,7 +871,7 @@ void DihedralTable::coeff(int narg, char **arg)
string err_msg; string err_msg;
err_msg = string("Dihedral table angle range must be < 2*PI radians (") err_msg = string("Dihedral table angle range must be < 2*PI radians (")
+ string(arg[2]) + string(")."); + string(arg[2]) + string(").");
error->all(FLERR,err_msg.c_str()); error->all(FLERR,err_msg);
} }
} }
@ -1214,7 +1214,7 @@ void DihedralTable::spline_table(Table *tb)
if ((num_disagreements > tb->ninput/2) && (num_disagreements > 2)) { if ((num_disagreements > tb->ninput/2) && (num_disagreements > 2)) {
string msg("Dihedral table has inconsistent forces and energies. (Try \"NOF\".)\n"); string msg("Dihedral table has inconsistent forces and energies. (Try \"NOF\".)\n");
error->all(FLERR,msg.c_str()); error->all(FLERR, msg);
} }
} // check for consistency if (! tb->f_unspecified) } // check for consistency if (! tb->f_unspecified)
@ -1344,7 +1344,7 @@ void DihedralTable::param_extract(Table *tb, char *line)
//} //}
else { else {
string err_msg = fmt::format("Invalid keyword in dihedral angle table parameters ({})", word); string err_msg = fmt::format("Invalid keyword in dihedral angle table parameters ({})", word);
error->one(FLERR,err_msg.c_str()); error->one(FLERR,err_msg);
} }
} }
} catch (TokenizerException & e) { } catch (TokenizerException & e) {

View File

@ -824,13 +824,13 @@ void DihedralTableCut::coeff(int narg, char **arg)
string err_msg; string err_msg;
err_msg = string("Invalid dihedral table length (") err_msg = string("Invalid dihedral table length (")
+ string(arg[5]) + string(")."); + string(arg[5]) + string(").");
error->one(FLERR,err_msg.c_str()); error->one(FLERR,err_msg);
} }
else if ((tb->ninput == 2) && (tabstyle == SPLINE)) { else if ((tb->ninput == 2) && (tabstyle == SPLINE)) {
string err_msg; string err_msg;
err_msg = string("Invalid dihedral spline table length. (Try linear)\n (") err_msg = string("Invalid dihedral spline table length. (Try linear)\n (")
+ string(arg[5]) + string(")."); + string(arg[5]) + string(").");
error->one(FLERR,err_msg.c_str()); error->one(FLERR,err_msg);
} }
// check for monotonicity // check for monotonicity
@ -843,7 +843,7 @@ void DihedralTableCut::coeff(int narg, char **arg)
string(arg[5]) + string(", ")+i_str.str()+string("th entry)"); string(arg[5]) + string(", ")+i_str.str()+string("th entry)");
if (i==0) if (i==0)
err_msg += string("\n(This is probably a mistake with your table format.)\n"); err_msg += string("\n(This is probably a mistake with your table format.)\n");
error->all(FLERR,err_msg.c_str()); error->all(FLERR,err_msg);
} }
} }
@ -855,7 +855,7 @@ void DihedralTableCut::coeff(int narg, char **arg)
string err_msg; string err_msg;
err_msg = string("Dihedral table angle range must be < 360 degrees (") err_msg = string("Dihedral table angle range must be < 360 degrees (")
+string(arg[5]) + string(")."); +string(arg[5]) + string(").");
error->all(FLERR,err_msg.c_str()); error->all(FLERR,err_msg);
} }
} }
else { else {
@ -863,7 +863,7 @@ void DihedralTableCut::coeff(int narg, char **arg)
string err_msg; string err_msg;
err_msg = string("Dihedral table angle range must be < 2*PI radians (") err_msg = string("Dihedral table angle range must be < 2*PI radians (")
+ string(arg[5]) + string(")."); + string(arg[5]) + string(").");
error->all(FLERR,err_msg.c_str()); error->all(FLERR,err_msg);
} }
} }
@ -1081,7 +1081,7 @@ void DihedralTableCut::read_table(Table *tb, char *file, char *keyword)
FILE *fp = force->open_potential(file); FILE *fp = force->open_potential(file);
if (fp == NULL) { if (fp == NULL) {
string err_msg = string("Cannot open file ") + string(file); string err_msg = string("Cannot open file ") + string(file);
error->one(FLERR,err_msg.c_str()); error->one(FLERR,err_msg);
} }
// loop until section found with matching keyword // loop until section found with matching keyword
@ -1090,7 +1090,7 @@ void DihedralTableCut::read_table(Table *tb, char *file, char *keyword)
if (fgets(line,MAXLINE,fp) == NULL) { if (fgets(line,MAXLINE,fp) == NULL) {
string err_msg=string("Did not find keyword \"") string err_msg=string("Did not find keyword \"")
+string(keyword)+string("\" in dihedral table file."); +string(keyword)+string("\" in dihedral table file.");
error->one(FLERR, err_msg.c_str()); error->one(FLERR, err_msg);
} }
if (strspn(line," \t\n\r") == strlen(line)) continue; // blank line if (strspn(line," \t\n\r") == strlen(line)) continue; // blank line
if (line[0] == '#') continue; // comment if (line[0] == '#') continue; // comment
@ -1376,7 +1376,7 @@ void DihedralTableCut::param_extract(Table *tb, char *line)
else { else {
string err_msg("Invalid keyword in dihedral angle table parameters"); string err_msg("Invalid keyword in dihedral angle table parameters");
err_msg += string(" (") + string(word) + string(")"); err_msg += string(" (") + string(word) + string(")");
error->one(FLERR,err_msg.c_str()); error->one(FLERR, err_msg);
} }
word = strtok(NULL," \t\n\r\f"); word = strtok(NULL," \t\n\r\f");
} }

View File

@ -156,7 +156,7 @@ void utils::sfgets(const char *srcname, int srcline, char *s, int size,
errmsg += filename; errmsg += filename;
errmsg += "'"; errmsg += "'";
if (error) error->one(srcname,srcline,errmsg.c_str()); if (error) error->one(srcname,srcline,errmsg);
if (s) *s = '\0'; // truncate string to empty in case error is NULL if (s) *s = '\0'; // truncate string to empty in case error is NULL
} }
return; return;
@ -185,7 +185,7 @@ void utils::sfread(const char *srcname, int srcline, void *s, size_t size,
errmsg += filename; errmsg += filename;
errmsg += "'"; errmsg += "'";
if (error) error->one(srcname,srcline,errmsg.c_str()); if (error) error->one(srcname,srcline,errmsg);
} }
return; return;
} }
@ -239,9 +239,9 @@ double utils::numeric(const char *file, int line, const char *str,
msg += str; msg += str;
msg += "' in input script or data file"; msg += "' in input script or data file";
if (do_abort) if (do_abort)
lmp->error->one(file,line,msg.c_str()); lmp->error->one(file,line,msg);
else else
lmp->error->all(file,line,msg.c_str()); lmp->error->all(file,line,msg);
} }
return atof(str); return atof(str);
@ -274,9 +274,9 @@ int utils::inumeric(const char *file, int line, const char *str,
msg += str; msg += str;
msg += "' in input script or data file"; msg += "' in input script or data file";
if (do_abort) if (do_abort)
lmp->error->one(file,line,msg.c_str()); lmp->error->one(file,line,msg);
else else
lmp->error->all(file,line,msg.c_str()); lmp->error->all(file,line,msg);
} }
return atoi(str); return atoi(str);
@ -309,9 +309,9 @@ bigint utils::bnumeric(const char *file, int line, const char *str,
msg += str; msg += str;
msg += "' in input script or data file"; msg += "' in input script or data file";
if (do_abort) if (do_abort)
lmp->error->one(file,line,msg.c_str()); lmp->error->one(file,line,msg);
else else
lmp->error->all(file,line,msg.c_str()); lmp->error->all(file,line,msg);
} }
return ATOBIGINT(str); return ATOBIGINT(str);
@ -344,9 +344,9 @@ tagint utils::tnumeric(const char *file, int line, const char *str,
msg += str; msg += str;
msg += "' in input script or data file"; msg += "' in input script or data file";
if (do_abort) if (do_abort)
lmp->error->one(file,line,msg.c_str()); lmp->error->one(file,line,msg);
else else
lmp->error->all(file,line,msg.c_str()); lmp->error->all(file,line,msg);
} }
return ATOTAGINT(str); return ATOTAGINT(str);