rename utils::fgets_trunc_nl() to utils::fgets_trunc()

This commit is contained in:
Axel Kohlmeyer
2021-04-27 18:32:51 -04:00
parent f29744b5bc
commit 7b1b57aa9b
4 changed files with 14 additions and 14 deletions

View File

@ -19,7 +19,7 @@ In that case, the functions will stop with an error message, indicating
the name of the problematic file, if possible unless the *error* argument the name of the problematic file, if possible unless the *error* argument
is a NULL pointer. is a NULL pointer.
The :cpp:func:`fgets_trunc_nl` function will work similar for ``fgets()`` The :cpp:func:`fgets_trunc` function will work similar for ``fgets()``
but it will read in a whole line (i.e. until the end of line or end but it will read in a whole line (i.e. until the end of line or end
of file), but store only as many characters as will fit into the buffer of file), but store only as many characters as will fit into the buffer
including a final newline character and the terminating NULL byte. including a final newline character and the terminating NULL byte.
@ -41,7 +41,7 @@ NULL character.
.. doxygenfunction:: sfread .. doxygenfunction:: sfread
:project: progguide :project: progguide
.. doxygenfunction:: fgets_trunc_nl .. doxygenfunction:: fgets_trunc
:project: progguide :project: progguide
.. doxygenfunction:: read_lines_from_file .. doxygenfunction:: read_lines_from_file

View File

@ -958,7 +958,7 @@ void ReadData::header(int firstpass)
// skip 1st line of file // skip 1st line of file
if (me == 0) { if (me == 0) {
char *eof = utils::fgets_trunc_nl(line,MAXLINE,fp); char *eof = utils::fgets_trunc(line,MAXLINE,fp);
if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file");
} }
@ -967,7 +967,7 @@ void ReadData::header(int firstpass)
// read a line and bcast length // read a line and bcast length
if (me == 0) { if (me == 0) {
if (utils::fgets_trunc_nl(line,MAXLINE,fp) == nullptr) n = 0; if (utils::fgets_trunc(line,MAXLINE,fp) == nullptr) n = 0;
else n = strlen(line) + 1; else n = strlen(line) + 1;
} }
MPI_Bcast(&n,1,MPI_INT,0,world); MPI_Bcast(&n,1,MPI_INT,0,world);
@ -1670,7 +1670,7 @@ void ReadData::bodies(int firstpass, AtomVec *ptr)
m = 0; m = 0;
while (nchunk < nmax && nline <= CHUNK-MAXBODY) { while (nchunk < nmax && nline <= CHUNK-MAXBODY) {
eof = utils::fgets_trunc_nl(&buffer[m],MAXLINE,fp); eof = utils::fgets_trunc(&buffer[m],MAXLINE,fp);
if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file");
rv = sscanf(&buffer[m],"%d %d %d",&tmp,&ninteger,&ndouble); rv = sscanf(&buffer[m],"%d %d %d",&tmp,&ninteger,&ndouble);
if (rv != 3) if (rv != 3)
@ -1684,7 +1684,7 @@ void ReadData::bodies(int firstpass, AtomVec *ptr)
nword = 0; nword = 0;
while (nword < ninteger) { while (nword < ninteger) {
eof = utils::fgets_trunc_nl(&buffer[m],MAXLINE,fp); eof = utils::fgets_trunc(&buffer[m],MAXLINE,fp);
if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file");
ncount = utils::trim_and_count_words(&buffer[m]); ncount = utils::trim_and_count_words(&buffer[m]);
if (ncount == 0) if (ncount == 0)
@ -1698,7 +1698,7 @@ void ReadData::bodies(int firstpass, AtomVec *ptr)
nword = 0; nword = 0;
while (nword < ndouble) { while (nword < ndouble) {
eof = utils::fgets_trunc_nl(&buffer[m],MAXLINE,fp); eof = utils::fgets_trunc(&buffer[m],MAXLINE,fp);
if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file");
ncount = utils::trim_and_count_words(&buffer[m]); ncount = utils::trim_and_count_words(&buffer[m]);
if (ncount == 0) if (ncount == 0)
@ -2002,15 +2002,15 @@ void ReadData::parse_keyword(int first)
if (me == 0) { if (me == 0) {
if (!first) { if (!first) {
if (utils::fgets_trunc_nl(line,MAXLINE,fp) == nullptr) eof = 1; if (utils::fgets_trunc(line,MAXLINE,fp) == nullptr) eof = 1;
} }
while (eof == 0 && done == 0) { while (eof == 0 && done == 0) {
int blank = strspn(line," \t\n\r"); int blank = strspn(line," \t\n\r");
if ((blank == (int)strlen(line)) || (line[blank] == '#')) { if ((blank == (int)strlen(line)) || (line[blank] == '#')) {
if (utils::fgets_trunc_nl(line,MAXLINE,fp) == nullptr) eof = 1; if (utils::fgets_trunc(line,MAXLINE,fp) == nullptr) eof = 1;
} else done = 1; } else done = 1;
} }
if (utils::fgets_trunc_nl(buffer,MAXLINE,fp) == nullptr) { if (utils::fgets_trunc(buffer,MAXLINE,fp) == nullptr) {
eof = 1; eof = 1;
buffer[0] = '\0'; buffer[0] = '\0';
} }
@ -2064,7 +2064,7 @@ void ReadData::skip_lines(bigint n)
if (me) return; if (me) return;
if (n <= 0) return; if (n <= 0) return;
char *eof = nullptr; char *eof = nullptr;
for (bigint i = 0; i < n; i++) eof = utils::fgets_trunc_nl(line,MAXLINE,fp); for (bigint i = 0; i < n; i++) eof = utils::fgets_trunc(line,MAXLINE,fp);
if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file");
} }

View File

@ -168,7 +168,7 @@ const char *utils::guesspath(char *buf, int len, FILE *fp)
// read line into buffer. if line is too long keep reading until EOL or EOF // read line into buffer. if line is too long keep reading until EOL or EOF
// but return only the first part with a newline at the end. // but return only the first part with a newline at the end.
char *utils::fgets_trunc_nl(char *buf, int size, FILE *fp) char *utils::fgets_trunc(char *buf, int size, FILE *fp)
{ {
constexpr int MAXDUMMY = 256; constexpr int MAXDUMMY = 256;
char dummy[MAXDUMMY]; char dummy[MAXDUMMY];
@ -271,7 +271,7 @@ int utils::read_lines_from_file(FILE *fp, int nlines, int nmax,
if (me == 0) { if (me == 0) {
if (fp) { if (fp) {
for (int i = 0; i < nlines; i++) { for (int i = 0; i < nlines; i++) {
ptr = fgets_trunc_nl(ptr,nmax,fp); ptr = fgets_trunc(ptr,nmax,fp);
if (!ptr) break; // EOF? if (!ptr) break; // EOF?
// advance ptr to end of string // advance ptr to end of string
ptr += strlen(ptr); ptr += strlen(ptr);

View File

@ -75,7 +75,7 @@ namespace LAMMPS_NS {
* \param size size of buffer s (max number of bytes returned) * \param size size of buffer s (max number of bytes returned)
* \param fp file pointer used by fgets() */ * \param fp file pointer used by fgets() */
char *fgets_trunc_nl(char *s, int size, FILE *fp); char *fgets_trunc(char *s, int size, FILE *fp);
/** Safe wrapper around fgets() which aborts on errors /** Safe wrapper around fgets() which aborts on errors
* or EOF and prints a suitable error message to help debugging. * or EOF and prints a suitable error message to help debugging.