correct sfgets() API to use const char for preprocessor string. whitespace cleanup
This commit is contained in:
@ -20,7 +20,7 @@
|
|||||||
/*
|
/*
|
||||||
* Mini regex-module adapted from https://github.com/kokke/tiny-regex-c
|
* Mini regex-module adapted from https://github.com/kokke/tiny-regex-c
|
||||||
* which is in the public domain.
|
* which is in the public domain.
|
||||||
*
|
*
|
||||||
* Supports:
|
* Supports:
|
||||||
* ---------
|
* ---------
|
||||||
* '.' Dot, matches any character
|
* '.' Dot, matches any character
|
||||||
@ -98,8 +98,8 @@ int utils::cfvarg(std::string mode, const char *arg, char *&cfv_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* like fgets() but aborts with an error or EOF is encountered */
|
/* like fgets() but aborts with an error or EOF is encountered */
|
||||||
void utils::sfgets(char* srcname, int srcline, char *s, int size,
|
void utils::sfgets(const char *srcname, int srcline, char *s, int size,
|
||||||
FILE *fp, std::string filename, Error *error)
|
FILE *fp, const char *filename, Error *error)
|
||||||
{
|
{
|
||||||
char *rv = fgets(s,size,fp);
|
char *rv = fgets(s,size,fp);
|
||||||
if (rv == NULL) { // something went wrong
|
if (rv == NULL) { // something went wrong
|
||||||
@ -112,7 +112,8 @@ void utils::sfgets(char* srcname, int srcline, char *s, int size,
|
|||||||
} else {
|
} else {
|
||||||
errmsg = "Unexpected short read while reading file '";
|
errmsg = "Unexpected short read while reading file '";
|
||||||
}
|
}
|
||||||
errmsg += filename + "'";
|
errmsg += filename;
|
||||||
|
errmsg += "'";
|
||||||
|
|
||||||
if (error) error->one(srcname,srcline,errmsg.c_str());
|
if (error) error->one(srcname,srcline,errmsg.c_str());
|
||||||
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
|
||||||
@ -181,11 +182,11 @@ extern "C" {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
idx += 1;
|
idx += 1;
|
||||||
|
|
||||||
if (matchpattern(pattern, text)) {
|
if (matchpattern(pattern, text)) {
|
||||||
if (text[0] == '\0')
|
if (text[0] == '\0')
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,7 +236,7 @@ extern "C" {
|
|||||||
case 's': { re_compiled[j].type = WHITESPACE; } break;
|
case 's': { re_compiled[j].type = WHITESPACE; } break;
|
||||||
case 'S': { re_compiled[j].type = NOT_WHITESPACE; } break;
|
case 'S': { re_compiled[j].type = NOT_WHITESPACE; } break;
|
||||||
|
|
||||||
/* Escaped character, e.g. '.' or '$' */
|
/* Escaped character, e.g. '.' or '$' */
|
||||||
default: {
|
default: {
|
||||||
re_compiled[j].type = CHAR;
|
re_compiled[j].type = CHAR;
|
||||||
re_compiled[j].ch = pattern[i];
|
re_compiled[j].ch = pattern[i];
|
||||||
@ -260,7 +261,7 @@ extern "C" {
|
|||||||
|
|
||||||
/* Copy characters inside [..] to buffer */
|
/* Copy characters inside [..] to buffer */
|
||||||
while ((pattern[++i] != ']') && (pattern[i] != '\0')) {
|
while ((pattern[++i] != ']') && (pattern[i] != '\0')) {
|
||||||
/* Missing ] */
|
/* Missing ] */
|
||||||
if (pattern[i] == '\\') {
|
if (pattern[i] == '\\') {
|
||||||
if (ccl_bufidx >= MAX_CHAR_CLASS_LEN - 1) {
|
if (ccl_bufidx >= MAX_CHAR_CLASS_LEN - 1) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -64,8 +64,8 @@ namespace LAMMPS_NS {
|
|||||||
* \param filename file name associated with fp (for error message)
|
* \param filename file name associated with fp (for error message)
|
||||||
* \param error pointer to Error class instance (for abort)
|
* \param error pointer to Error class instance (for abort)
|
||||||
*/
|
*/
|
||||||
void sfgets(char* srcname, int srcline, char *s, int size,
|
void sfgets(const char *srcname, int srcline, char *s, int size,
|
||||||
FILE *fp, std::string filename, Error *error);
|
FILE *fp, const char *filename, Error *error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user