X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fcommon.h;h=0fdad32fcd54cad9a1498fa0b2b06a44c51bb9c7;hb=4fa90f321f51af8f5bfc48eee1435e2f41d853b3;hp=6f9fb65df4bf069fbe24dc07a5ceb20784600a3f;hpb=ef267d12284b855bc52ee429a5dc12da1d1e3b95;p=babeltrace.git diff --git a/src/common/common.h b/src/common/common.h index 6f9fb65d..0fdad32f 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -33,14 +33,10 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#define __BT_IN_BABELTRACE_H +#include #include "common/assert.h" #include "common/macros.h" @@ -330,6 +326,30 @@ size_t bt_common_get_page_size(int log_level); BT_HIDDEN void bt_common_sep_digits(char *str, unsigned int digits_per_group, char sep); +/* + * This is similar to what the command `fold --spaces` does: it wraps + * the input lines of `str`, breaking at spaces, and indenting each line + * with `indent` spaces so that each line fits the total length + * `total_length`. + * + * If an original line in `str` contains a word which is >= the content + * length (`total_length - indent`), then the corresponding folded line + * is also larger than the content length. In other words, breaking at + * spaces is a best effort, but it might not be possible. + * + * The returned string, on success, is owned by the caller. + */ +BT_HIDDEN +GString *bt_common_fold(const char *str, unsigned int total_length, + unsigned int indent); + +/* + * Writes the terminal's width to `*width`, its height to `*height`, + * and returns 0 on success, or returns -1 on error. + */ +BT_HIDDEN +int bt_common_get_term_size(unsigned int *width, unsigned int *height); + /* * Wraps read() function to handle EINTR and partial reads. * On success, it returns `count` received as parameter. On error, it returns a @@ -548,26 +568,6 @@ end: return str; } -static inline -const char *bt_common_self_message_iterator_status_string( - enum bt_self_message_iterator_status status) -{ - switch (status) { - case BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN: - return "BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN"; - case BT_SELF_MESSAGE_ITERATOR_STATUS_END: - return "BT_SELF_MESSAGE_ITERATOR_STATUS_END"; - case BT_SELF_MESSAGE_ITERATOR_STATUS_OK: - return "BT_SELF_MESSAGE_ITERATOR_STATUS_OK"; - case BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR: - return "BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR"; - case BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM: - return "BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM"; - default: - return "(unknown)"; - } -}; - static inline const char *bt_common_logging_level_string( enum bt_logging_level level) @@ -579,8 +579,8 @@ const char *bt_common_logging_level_string( return "BT_LOGGING_LEVEL_DEBUG"; case BT_LOGGING_LEVEL_INFO: return "BT_LOGGING_LEVEL_INFO"; - case BT_LOGGING_LEVEL_WARN: - return "BT_LOGGING_LEVEL_WARN"; + case BT_LOGGING_LEVEL_WARNING: + return "BT_LOGGING_LEVEL_WARNING"; case BT_LOGGING_LEVEL_ERROR: return "BT_LOGGING_LEVEL_ERROR"; case BT_LOGGING_LEVEL_FATAL: @@ -593,42 +593,33 @@ const char *bt_common_logging_level_string( }; static inline -const char *bt_self_component_status_string( - enum bt_self_component_status status) +const char *bt_common_func_status_string(int status) { switch (status) { - case BT_SELF_COMPONENT_STATUS_OK: - return "BT_SELF_COMPONENT_STATUS_OK"; - case BT_SELF_COMPONENT_STATUS_END: - return "BT_SELF_COMPONENT_STATUS_END"; - case BT_SELF_COMPONENT_STATUS_AGAIN: - return "BT_SELF_COMPONENT_STATUS_AGAIN"; - case BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION: - return "BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION"; - case BT_SELF_COMPONENT_STATUS_ERROR: - return "BT_SELF_COMPONENT_STATUS_ERROR"; - case BT_SELF_COMPONENT_STATUS_NOMEM: - return "BT_SELF_COMPONENT_STATUS_NOMEM"; - default: - return "(unknown)"; - } -} - -static inline -const char *bt_message_iterator_status_string( - enum bt_message_iterator_status status) -{ - switch (status) { - case BT_MESSAGE_ITERATOR_STATUS_AGAIN: - return "BT_MESSAGE_ITERATOR_STATUS_AGAIN"; - case BT_MESSAGE_ITERATOR_STATUS_END: - return "BT_MESSAGE_ITERATOR_STATUS_END"; - case BT_MESSAGE_ITERATOR_STATUS_OK: - return "BT_MESSAGE_ITERATOR_STATUS_OK"; - case BT_MESSAGE_ITERATOR_STATUS_ERROR: - return "BT_MESSAGE_ITERATOR_STATUS_ERROR"; - case BT_MESSAGE_ITERATOR_STATUS_NOMEM: - return "BT_MESSAGE_ITERATOR_STATUS_NOMEM"; + case __BT_FUNC_STATUS_OVERFLOW: + return "OVERFLOW"; + case __BT_FUNC_STATUS_INVALID_PARAMS: + return "INVALID_PARAMS"; + case __BT_FUNC_STATUS_INVALID_OBJECT: + return "INVALID_OBJECT"; + case __BT_FUNC_STATUS_MEMORY_ERROR: + return "MEMORY_ERROR"; + case __BT_FUNC_STATUS_LOADING_ERROR: + return "LOADING_ERROR"; + case __BT_FUNC_STATUS_ERROR: + return "ERROR"; + case __BT_FUNC_STATUS_OK: + return "OK"; + case __BT_FUNC_STATUS_END: + return "END"; + case __BT_FUNC_STATUS_NOT_FOUND: + return "NOT_FOUND"; + case __BT_FUNC_STATUS_AGAIN: + return "AGAIN"; + case __BT_FUNC_STATUS_UNSUPPORTED: + return "UNSUPPORTED"; + case __BT_FUNC_STATUS_CANCELED: + return "CANCELED"; default: return "(unknown)"; } @@ -725,11 +716,4 @@ end: return ret; } -static inline -enum bt_self_message_iterator_status bt_common_message_iterator_status_to_self( - enum bt_message_iterator_status status) -{ - return (int) status; -} - #endif /* BABELTRACE_COMMON_INTERNAL_H */