| 1 |
/* |
| 2 |
* Gregorio is a program that translates gabc files to GregorioTeX |
| 3 |
* This header prototypes the message logging functions. |
| 4 |
* |
| 5 |
* Copyright (C) 2009-2025 The Gregorio Project (see CONTRIBUTORS.md) |
| 6 |
* |
| 7 |
* This file is part of Gregorio. |
| 8 |
* |
| 9 |
* Gregorio is free software: you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU General Public License as published by |
| 11 |
* the Free Software Foundation, either version 3 of the License, or |
| 12 |
* (at your option) any later version. |
| 13 |
* |
| 14 |
* Gregorio is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
* GNU General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with Gregorio. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef MESSAGES_H |
| 24 |
#define MESSAGES_H |
| 25 |
|
| 26 |
#ifndef ENABLE_NLS |
| 27 |
#define ENABLE_NLS 0 |
| 28 |
#endif |
| 29 |
#if ENABLE_NLS == 1 |
| 30 |
#include "gettext.h" |
| 31 |
#define _(str) gettext(str) |
| 32 |
#define N_(str) (str) |
| 33 |
#define ngt_(str, strtwo, count) ngettext(str, strtwo, count) |
| 34 |
#else |
| 35 |
#define _(str) (str) |
| 36 |
#define N_(str) (str) |
| 37 |
#define ngt_(str, strtwo, count) (str) |
| 38 |
#endif |
| 39 |
|
| 40 |
typedef enum gregorio_verbosity { |
| 41 |
VERBOSITY_INFO = 1, |
| 42 |
VERBOSITY_WARNING, |
| 43 |
VERBOSITY_DEPRECATION, |
| 44 |
VERBOSITY_ERROR, |
| 45 |
VERBOSITY_ASSERTION, |
| 46 |
VERBOSITY_FATAL |
| 47 |
} gregorio_verbosity; |
| 48 |
|
| 49 |
void gregorio_message(const char *string, const char *function_name, |
| 50 |
gregorio_verbosity verbosity, int line_number); |
| 51 |
void gregorio_messagef(const char *function_name, |
| 52 |
gregorio_verbosity verbosity, |
| 53 |
int line_number, const char *format, ...) |
| 54 |
__attribute__ ((__format__ (__printf__, 4, 5))); |
| 55 |
void gregorio_set_verbosity_mode(gregorio_verbosity verbosity); |
| 56 |
void gregorio_set_debug_messages(bool debug); |
| 57 |
void gregorio_set_deprecation_errors(bool deprecation_errors); |
| 58 |
int gregorio_get_return_value(void); |
| 59 |
|
| 60 |
#define gregorio_assert_only(TEST,FUNCTION,MESSAGE) \ |
| 61 |
if (!(TEST)) { \ |
| 62 |
gregorio_message(_(MESSAGE), #FUNCTION, VERBOSITY_ASSERTION, __LINE__); \ |
| 63 |
} |
| 64 |
|
| 65 |
#define gregorio_assert(TEST,FUNCTION,MESSAGE,ON_FALSE) \ |
| 66 |
if (!(TEST)) { \ |
| 67 |
gregorio_message(_(MESSAGE), #FUNCTION, VERBOSITY_ASSERTION, __LINE__); \ |
| 68 |
ON_FALSE; \ |
| 69 |
} |
| 70 |
|
| 71 |
#define gregorio_assert2(TEST,FUNCTION,FORMAT,ARG,ON_FALSE) \ |
| 72 |
if (!(TEST)) { \ |
| 73 |
gregorio_messagef(#FUNCTION, VERBOSITY_ASSERTION, __LINE__, FORMAT, ARG); \ |
| 74 |
ON_FALSE; \ |
| 75 |
} |
| 76 |
|
| 77 |
#define gregorio_not_null(VARIABLE,FUNCTION,ON_FALSE) \ |
| 78 |
gregorio_assert(VARIABLE, FUNCTION, #VARIABLE " may not be null", ON_FALSE) |
| 79 |
|
| 80 |
#define gregorio_not_null_ptr(VARIABLE,FUNCTION,ON_FALSE) \ |
| 81 |
gregorio_assert(VARIABLE && *VARIABLE, FUNCTION, #VARIABLE " may not be null", ON_FALSE) |
| 82 |
|
| 83 |
#define gregorio_fail(FUNCTION,MESSAGE) \ |
| 84 |
gregorio_message(_(MESSAGE), #FUNCTION, VERBOSITY_ASSERTION, __LINE__) |
| 85 |
|
| 86 |
#define gregorio_fail2(FUNCTION,FORMAT,ARG) \ |
| 87 |
gregorio_messagef(#FUNCTION, VERBOSITY_ASSERTION, __LINE__, FORMAT, ARG) |
| 88 |
|
| 89 |
#endif |