summaryrefslogtreecommitdiff
path: root/errors.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-14 14:35:56 -0400
committerpommicket <pommicket@gmail.com>2025-09-14 14:41:58 -0400
commit0cc0c89d08994e66fa4fae5c0891b8fa14960e50 (patch)
treedcff3633138512ff7c7b453e54ae12c00f69436a /errors.c
parentee7e2dbf3d6bc4ef8d4019c666a8960976c1af75 (diff)
Error translations
Diffstat (limited to 'errors.c')
-rw-r--r--errors.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/errors.c b/errors.c
new file mode 100644
index 0000000..2e83f4a
--- /dev/null
+++ b/errors.c
@@ -0,0 +1,72 @@
+#include <inttypes.h>
+#include <assert.h>
+#include <string.h>
+
+static char error_language[32];
+
+enum error_id {
+ ERROR_HEADER,
+ ERROR_OUT_OF_MEMORY,
+ ERROR_CANT_OPEN_FILE,
+ ERROR_FILE_READ,
+ ERROR_INVALID_UTF8,
+ ERROR_ASCII_CONTROL,
+ ERROR_KEY_STARTS_WITH_DOT,
+ ERROR_KEY_ENDS_WITH_DOT,
+ ERROR_KEY_DOT_DOT,
+ ERROR_KEY_INVALID_CHAR,
+ ERROR_INVALID_ESCAPE,
+ ERROR_STRAY_CHARS_AFTER_QUOTED,
+ ERROR_MISMATCHED_SQUARE_BRACKETS,
+ ERROR_INVALID_LINE,
+ ERROR_EMPTY_KEY,
+ ERROR_REDEFINITION,
+ ERROR_COUNT,
+};
+
+static const char *const error_messages_en[ERROR_COUNT] = {
+ [ERROR_HEADER] = "Error:",
+ [ERROR_OUT_OF_MEMORY] = "Out of memory.",
+ [ERROR_CANT_OPEN_FILE] = "Couldn't open file: %s",
+ [ERROR_FILE_READ] = "Couldn't read file",
+ [ERROR_INVALID_UTF8] = "Invalid UTF-8",
+ [ERROR_ASCII_CONTROL] = "Unexpected ASCII control character %d",
+ [ERROR_KEY_STARTS_WITH_DOT] = "Key %s shouldn't begin with .",
+ [ERROR_KEY_ENDS_WITH_DOT] = "Key %s shouldn't end with .",
+ [ERROR_KEY_DOT_DOT] = "Key %s shouldn't contain ..",
+ [ERROR_KEY_INVALID_CHAR] = "Invalid character in key: '%c' (ASCII %d)",
+ [ERROR_INVALID_ESCAPE] = "Invalid escape sequence: \\%.*s",
+ [ERROR_STRAY_CHARS_AFTER_QUOTED] = "Stray characters after closing %c",
+ [ERROR_MISMATCHED_SQUARE_BRACKETS] = "Line starting with [ must end with ]",
+ [ERROR_INVALID_LINE] = "Line should start with [ or contain =",
+ [ERROR_EMPTY_KEY] = "Expected key name before =",
+ [ERROR_REDEFINITION] = "Re-definition of %s (previously defined on line %" PRIu64 ")",
+};
+
+
+static const char *const error_messages_fr[ERROR_COUNT] = {
+ [ERROR_HEADER] = "Erreur:",
+ [ERROR_OUT_OF_MEMORY] = "Mémoire épuisée.",
+ [ERROR_CANT_OPEN_FILE] = "Ne peut pas ouvrir le fichier : %s",
+ [ERROR_FILE_READ] = "Ne peut pas lire le fichier",
+ [ERROR_INVALID_UTF8] = "UTF-8 invalide",
+ [ERROR_ASCII_CONTROL] = "Caractère de contrôle imprévue (ASCII %d)",
+ [ERROR_KEY_STARTS_WITH_DOT] = "Clé %s ne devrait pas commencer par .",
+ [ERROR_KEY_ENDS_WITH_DOT] = "Clé %s ne devrait pas finir en .",
+ [ERROR_KEY_DOT_DOT] = "Clé %s ne devrait pas contenir ..",
+ [ERROR_KEY_INVALID_CHAR] = "Clé clontient une caractère invalide : '%c' (ASCII %d)",
+ [ERROR_INVALID_ESCAPE] = "Séquence d'échappement invalide : \\%.*s",
+ [ERROR_STRAY_CHARS_AFTER_QUOTED] = "Caractère imprévue suivant %c fermant",
+ [ERROR_MISMATCHED_SQUARE_BRACKETS] = "Ligne commençant par [ devrait finir en ]",
+ [ERROR_INVALID_LINE] = "Ligne devrait commençant par [ ou contenir =",
+ [ERROR_EMPTY_KEY] = "Nom de clé devrait précéder =",
+ [ERROR_REDEFINITION] = "Redéfinition de %s (définition précédente à ligne %" PRIu64 ")",
+};
+
+static struct {
+ const char *lang;
+ const char *const *messages;
+} const error_messages[] = {
+ {"en", error_messages_en},
+ {"fr", error_messages_fr},
+};