1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include <inttypes.h>
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_NO_CLOSING_QUOTE,
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 ")",
[ERROR_NO_CLOSING_QUOTE] = "Missing closing %c",
};
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 ")",
[ERROR_NO_CLOSING_QUOTE] = "Aucun %c fermant",
};
static struct {
const char *lang;
const char *const *messages;
} const error_messages[] = {
{"en", error_messages_en},
{"fr", error_messages_fr},
};
|