Uncrustify maxscale

See script directory for method. The script to run in the top level
MaxScale directory is called maxscale-uncrustify.sh, which uses
another script, list-src, from the same directory (so you need to set
your PATH). The uncrustify version was 0.66.
This commit is contained in:
Niclas Antti
2018-09-09 22:26:19 +03:00
parent fa7ec95069
commit c447e5cf15
849 changed files with 35002 additions and 27238 deletions

View File

@ -41,7 +41,7 @@ namespace
int DEFAULT_LOG_AUGMENTATION = 0;
// A message that is logged 10 times in 1 second will be suppressed for 10 seconds.
static MXB_LOG_THROTTLING DEFAULT_LOG_THROTTLING = { 10, 1000, 10000 };
static MXB_LOG_THROTTLING DEFAULT_LOG_THROTTLING = {10, 1000, 10000};
// BUFSIZ comes from the system. It equals with block size or its multiplication.
const int MAX_LOGSTRLEN = BUFSIZ;
@ -62,14 +62,26 @@ std::string get_timestamp(void)
struct tm tm;
localtime_r(&t, &tm);
static const char timestamp_formatstr[] = "%04d-%02d-%02d %02d:%02d:%02d ";
static int required = snprintf(NULL, 0, timestamp_formatstr,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec);
static int required = snprintf(NULL,
0,
timestamp_formatstr,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
char buf[required + 1];
snprintf(buf, sizeof(buf), timestamp_formatstr,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec);
snprintf(buf,
sizeof(buf),
timestamp_formatstr,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
return buf;
}
@ -84,33 +96,47 @@ std::string get_timestamp_hp(void)
int usec = tv.tv_usec / 1000;
static const char timestamp_formatstr_hp[] = "%04d-%02d-%02d %02d:%02d:%02d.%03d ";
static int required = snprintf(NULL, 0, timestamp_formatstr_hp,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, usec);
static int required = snprintf(NULL,
0,
timestamp_formatstr_hp,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
usec);
char buf[required + 1];
snprintf(buf, sizeof(buf), timestamp_formatstr_hp,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, usec);
snprintf(buf,
sizeof(buf),
timestamp_formatstr_hp,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
usec);
return buf;
}
struct LOG_PREFIX
{
const char* text; // The prefix, e.g. "error: "
int len; // The length of the prefix without the trailing NULL.
const char* text; // The prefix, e.g. "error: "
int len; // The length of the prefix without the trailing NULL.
};
const char PREFIX_EMERG[] = "emerg : ";
const char PREFIX_ALERT[] = "alert : ";
const char PREFIX_CRIT[] = "crit : ";
const char PREFIX_ERROR[] = "error : ";
const char PREFIX_EMERG[] = "emerg : ";
const char PREFIX_ALERT[] = "alert : ";
const char PREFIX_CRIT[] = "crit : ";
const char PREFIX_ERROR[] = "error : ";
const char PREFIX_WARNING[] = "warning: ";
const char PREFIX_NOTICE[] = "notice : ";
const char PREFIX_INFO[] = "info : ";
const char PREFIX_DEBUG[] = "debug : ";
const char PREFIX_NOTICE[] = "notice : ";
const char PREFIX_INFO[] = "info : ";
const char PREFIX_DEBUG[] = "debug : ";
LOG_PREFIX level_to_prefix(int level)
{
@ -167,16 +193,16 @@ LOG_PREFIX level_to_prefix(int level)
break;
}
--prefix.len; // Remove trailing NULL.
--prefix.len; // Remove trailing NULL.
return prefix;
}
enum message_suppression_t
{
MESSAGE_NOT_SUPPRESSED, // Message is not suppressed.
MESSAGE_SUPPRESSED, // Message is suppressed for the first time (for this round)
MESSAGE_STILL_SUPPRESSED // Message is still suppressed (for this round)
MESSAGE_NOT_SUPPRESSED, // Message is not suppressed.
MESSAGE_SUPPRESSED, // Message is suppressed for the first time (for this round)
MESSAGE_STILL_SUPPRESSED // Message is still suppressed (for this round)
};
class MessageRegistryKey
@ -200,9 +226,8 @@ public:
bool eq(const MessageRegistryKey& other) const
{
return
filename == other.filename && // Yes, we compare the pointer values and not the strings.
linenumber == other.linenumber;
return filename == other.filename // Yes, we compare the pointer values and not the strings.
&& linenumber == other.linenumber;
}
size_t hash() const
@ -212,7 +237,7 @@ public:
* https://en.wikipedia.org/wiki/Jenkins_hash_function
*/
uint64_t key1 = (uint64_t)filename;
uint16_t key2 = (uint16_t)linenumber; // The first 48 bits are likely to be 0.
uint16_t key2 = (uint16_t)linenumber; // The first 48 bits are likely to be 0.
uint32_t hash_value = 0;
size_t i;
@ -313,11 +338,10 @@ public:
private:
std::mutex m_lock;
uint64_t m_first_ms; /** The time when the error was logged the first time in this window. */
uint64_t m_last_ms; /** The time when the error was logged the last time. */
size_t m_count; /** How many times the error has been reported within this window. */
uint64_t m_first_ms; /** The time when the error was logged the first time in this window. */
uint64_t m_last_ms; /** The time when the error was logged the last time. */
size_t m_count; /** How many times the error has been reported within this window. */
};
}
namespace std
@ -347,7 +371,6 @@ struct equal_to<MessageRegistryKey>
return lhs.eq(rhs);
}
};
}
namespace
@ -357,21 +380,21 @@ class MessageRegistry;
struct this_unit
{
int augmentation; // Can change during the lifetime of log_manager.
bool do_highprecision; // Can change during the lifetime of log_manager.
bool do_syslog; // Can change during the lifetime of log_manager.
bool do_maxlog; // Can change during the lifetime of log_manager.
MXB_LOG_THROTTLING throttling; // Can change during the lifetime of log_manager.
int augmentation; // Can change during the lifetime of log_manager.
bool do_highprecision; // Can change during the lifetime of log_manager.
bool do_syslog; // Can change during the lifetime of log_manager.
bool do_maxlog; // Can change during the lifetime of log_manager.
MXB_LOG_THROTTLING throttling; // Can change during the lifetime of log_manager.
std::unique_ptr<mxb::Logger> sLogger;
std::unique_ptr<MessageRegistry> sMessage_registry;
size_t (*context_provider)(char* buffer, size_t len);
size_t (* context_provider)(char* buffer, size_t len);
} this_unit =
{
DEFAULT_LOG_AUGMENTATION, // augmentation
false, // do_highprecision
true, // do_syslog
true, // do_maxlog
DEFAULT_LOG_THROTTLING, // throttling
DEFAULT_LOG_AUGMENTATION, // augmentation
false, // do_highprecision
true, // do_syslog
true, // do_maxlog
DEFAULT_LOG_THROTTLING, // throttling
};
class MessageRegistry
@ -417,7 +440,6 @@ private:
std::mutex m_lock;
std::unordered_map<Key, Stats> m_registry;
};
}
bool mxb_log_init(const char* ident,
@ -457,22 +479,22 @@ bool mxb_log_init(const char* ident,
filepath = std::string(logdir) + "/" + suffix;
}
this_unit.sMessage_registry.reset(new (std::nothrow) MessageRegistry);
this_unit.sMessage_registry.reset(new( std::nothrow) MessageRegistry);
switch (target)
{
case MXB_LOG_TARGET_FS:
case MXB_LOG_TARGET_DEFAULT:
this_unit.sLogger = mxb::FileLogger::create(filepath);
break;
case MXB_LOG_TARGET_FS:
case MXB_LOG_TARGET_DEFAULT:
this_unit.sLogger = mxb::FileLogger::create(filepath);
break;
case MXB_LOG_TARGET_STDOUT:
this_unit.sLogger = mxb::StdoutLogger::create(filepath);
break;
case MXB_LOG_TARGET_STDOUT:
this_unit.sLogger = mxb::StdoutLogger::create(filepath);
break;
default:
assert(!true);
break;
default:
assert(!true);
break;
}
if (this_unit.sLogger && this_unit.sMessage_registry)
@ -552,9 +574,9 @@ void mxb_log_set_throttling(const MXB_LOG_THROTTLING* throttling)
// is used right when its values are modified.
this_unit.throttling = *throttling;
if ((this_unit.throttling.count == 0) ||
(this_unit.throttling.window_ms == 0) ||
(this_unit.throttling.suppress_ms == 0))
if ((this_unit.throttling.count == 0)
|| (this_unit.throttling.window_ms == 0)
|| (this_unit.throttling.suppress_ms == 0))
{
MXB_NOTICE("Log throttling has been disabled.");
}
@ -592,20 +614,28 @@ static const char* level_to_string(int level)
{
case LOG_EMERG:
return "emergency";
case LOG_ALERT:
return "alert";
case LOG_CRIT:
return "critical";
case LOG_ERR:
return "error";
case LOG_WARNING:
return "warning";
case LOG_NOTICE:
return "notice";
case LOG_INFO:
return "informational";
case LOG_DEBUG:
return "debug";
default:
assert(!true);
return "unknown";
@ -643,8 +673,11 @@ bool mxb_log_set_priority_enabled(int level, bool enable)
int mxb_log_message(int priority,
const char* modname,
const char* file, int line, const char* function,
const char* format, ...)
const char* file,
int line,
const char* function,
const char* format,
...)
{
int err = 0;
@ -653,7 +686,7 @@ int mxb_log_message(int priority,
int level = priority & LOG_PRIMASK;
if ((priority & ~(LOG_PRIMASK | LOG_FACMASK)) == 0) // Check that the priority is ok,
if ((priority & ~(LOG_PRIMASK | LOG_FACMASK)) == 0) // Check that the priority is ok,
{
message_suppression_t status = MESSAGE_NOT_SUPPRESSED;
@ -671,7 +704,7 @@ int mxb_log_message(int priority,
{
va_list valist;
char context[32]; // The documentation will guarantee a buffer of at least 32 bytes.
char context[32]; // The documentation will guarantee a buffer of at least 32 bytes.
int context_len = 0;
if (this_unit.context_provider)
@ -680,21 +713,21 @@ int mxb_log_message(int priority,
if (context_len != 0)
{
context_len += 3; // The added "() "
context_len += 3; // The added "() "
}
}
int modname_len = modname ? strlen(modname) + 3 : 0; // +3 due to "[...] "
int modname_len = modname ? strlen(modname) + 3 : 0; // +3 due to "[...] "
static const char SUPPRESSION[] =
" (subsequent similar messages suppressed for %lu milliseconds)";
static const char SUPPRESSION[]
= " (subsequent similar messages suppressed for %lu milliseconds)";
int suppression_len = 0;
size_t suppress_ms = this_unit.throttling.suppress_ms;
if (status == MESSAGE_SUPPRESSED)
{
suppression_len += sizeof(SUPPRESSION) - 1; // Remove trailing NULL
suppression_len -= 3; // Remove the %lu
suppression_len -= 3; // Remove the %lu
suppression_len += UINTLEN(suppress_ms);
}
@ -719,7 +752,7 @@ int mxb_log_message(int priority,
{
case MXB_LOG_AUGMENT_WITH_FUNCTION:
augmentation_len = sizeof(FORMAT_FUNCTION) - 1; // Remove trailing 0
augmentation_len -= 2; // Remove the %s
augmentation_len -= 2; // Remove the %s
augmentation_len += strlen(function);
break;
@ -740,18 +773,18 @@ int mxb_log_message(int priority,
message_len -= (buffer_len - MAX_LOGSTRLEN);
buffer_len = MAX_LOGSTRLEN;
assert(prefix.len + context_len + modname_len +
augmentation_len + message_len + suppression_len == buffer_len);
assert(prefix.len + context_len + modname_len
+ augmentation_len + message_len + suppression_len == buffer_len);
}
char buffer[buffer_len + 1];
char *prefix_text = buffer;
char *context_text = prefix_text + prefix.len;
char *modname_text = context_text + context_len;
char *augmentation_text = modname_text + modname_len;
char *message_text = augmentation_text + augmentation_len;
char *suppression_text = message_text + message_len;
char* prefix_text = buffer;
char* context_text = prefix_text + prefix.len;
char* modname_text = context_text + context_len;
char* augmentation_text = modname_text + modname_len;
char* message_text = augmentation_text + augmentation_len;
char* suppression_text = message_text + message_len;
strcpy(prefix_text, prefix.text);