Project

General

Profile

Feature #246 ยป 0032-log.c-Replace-NULLs-with-nullptrs.patch

Marko Lindqvist, 02/10/2024 01:46 PM

View differences:

utility/log.c
static void log_real(enum log_level level, bool print_from_where,
const char *where, const char *msg);
static char *log_filename = NULL;
static char *log_filename = nullptr;
static log_pre_callback_fn log_pre_callback = log_real;
static log_callback_fn log_callback = NULL;
static log_prefix_fn log_prefix = NULL;
static log_callback_fn log_callback = nullptr;
static log_prefix_fn log_prefix = nullptr;
static fc_mutex logfile_mutex;
......
unsigned int max;
};
static int log_num_files = 0;
static struct log_fileinfo *log_files = NULL;
static struct log_fileinfo *log_files = nullptr;
#endif /* FREECIV_DEBUG */
static char *log_level_names[] = {
"Fatal", "Error", "Warning", "Normal", "Verbose", "Debug", NULL
"Fatal", "Error", "Warning", "Normal", "Verbose", "Debug", nullptr
};
/* A helper variable to indicate that there is no log message. The '%s' is
......
/* Global log level. */
if (!str_to_uint(level_str, &level)) {
level = LOG_DEBUG + 1;
for (ln = 0; log_level_names[ln] != NULL && level > LOG_DEBUG; ln++) {
for (ln = 0; log_level_names[ln] != nullptr && level > LOG_DEBUG; ln++) {
if (!fc_strncasecmp(level_str, log_level_names[ln], strlen(level_str))) {
level = ln;
}
......
" Use one of the levels Fatal, Error, Warning, Normal, Verbose, Debug") );
}
if (level <= max_level) {
if (NULL != ret_level) {
if (ret_level != nullptr) {
*ret_level = level;
}
return TRUE;
......
c = level_str;
level = LOG_DEBUG + 1;
if (first_len > 0) {
for (ln = 0; log_level_names[ln] != NULL && level > LOG_DEBUG; ln++) {
for (ln = 0; log_level_names[ln] != nullptr && level > LOG_DEBUG; ln++) {
if (!fc_strncasecmp(level_str, log_level_names[ln], first_len)) {
level = ln;
}
......
}
pfile->name = fc_strdup(tok);
i++;
tok = strtok(NULL, ":");
tok = strtok(nullptr, ":");
} while (tok);
if (i != log_num_files) {
......
}
/**********************************************************************//**
Initialise the log module. Either 'filename' or 'callback' may be NULL.
If both are NULL, print to stderr. If both are non-NULL, both callback,
Initialise the log module. Either 'filename' or 'callback' may be nullptr.
If both are nullptr, print to stderr. If neither is nullptr, both callback,
and fprintf to file. Pass -1 for fatal_assertions to don't raise any
signal on failed assertion.
**************************************************************************/
......
fc_log_level = initial_level;
if (log_filename) {
free(log_filename);
log_filename = NULL;
log_filename = nullptr;
}
if (filename && strlen(filename) > 0) {
log_filename = fc_strdup(filename);
} else {
log_filename = NULL;
log_filename = nullptr;
}
log_callback = callback;
log_prefix = prefix;
......
const char *log_level_name(enum log_level lvl)
{
if (lvl < LOG_FATAL || lvl > LOG_DEBUG) {
return NULL;
return nullptr;
}
return log_level_names[lvl];
......
char buf[MAX_LEN_LOG_LINE];
fc_snprintf(buf, sizeof(buf), "%s%s", where, message);
log_callback(level, buf, log_filename != NULL);
log_callback(level, buf, log_filename != nullptr);
} else {
log_callback(level, message, log_filename != NULL);
log_callback(level, message, log_filename != nullptr);
}
}
}
......
Really print a log message.
For repeat message, may wait and print instead "last message repeated ..."
at some later time.
Calls log_callback if not NULL, else prints to stderr.
Calls log_callback if not nullptr, else prints to stderr.
**************************************************************************/
static void log_real(enum log_level level, bool print_from_where,
const char *where, const char *msg)
......
by do_log_for().
For repeat message, may wait and print instead
"last message repeated ..." at some later time.
Calls log_callback if not NULL, else prints to stderr.
Calls log_callback if not nullptr, else prints to stderr.
**************************************************************************/
void do_log(const char *file, const char *function, int line,
bool print_from_where, enum log_level level,
......
{
enum log_level level = (0 <= fc_fatal_assertions ? LOG_FATAL : LOG_ERROR);
if (NULL != assertion) {
if (assertion != nullptr) {
do_log(file, function, line, TRUE, level,
"assertion '%s' failed.", assertion);
}
if (NULL != message && NOLOGMSG != message) {
if (message != nullptr && NOLOGMSG != message) {
/* Additional message. */
char buf[MAX_LEN_LOG_LINE];
va_list args;
    (1-1/1)