Reduce the read-only data
Thanks to rofl0r for the idea!
diff --git a/include/bc.h b/include/bc.h
index b22e600..b194a84 100644
--- a/include/bc.h
+++ b/include/bc.h
@@ -45,6 +45,14 @@
#define BC_SCALE_MAX_DEF (LONG_MAX)
#define BC_STRING_MAX_DEF (INT_MAX)
+#define BC_ERR_IDX_BC (0)
+#define BC_ERR_IDX_VEC (1)
+#define BC_ERR_IDX_LEX (2)
+#define BC_ERR_IDX_PARSE (3)
+#define BC_ERR_IDX_MATH (4)
+#define BC_ERR_IDX_EXEC (5)
+#define BC_ERR_IDX_POSIX (6)
+
typedef enum BcStatus {
BC_STATUS_SUCCESS,
@@ -157,6 +165,7 @@
extern const char *bc_header;
extern const char *bc_err_types[];
+extern const char bc_err_type_indices[];
extern const char *bc_err_descs[];
#endif // BC_H
diff --git a/src/bc/bc.c b/src/bc/bc.c
index 1f9e6fe..4382562 100644
--- a/src/bc/bc.c
+++ b/src/bc/bc.c
@@ -42,7 +42,7 @@
}
fprintf(stderr, "\n%s error: %s\n\n",
- bc_err_types[st], bc_err_descs[st]);
+ bc_err_types[bc_err_type_indices[st]], bc_err_descs[st]);
}
void bc_error_file(BcStatus st, const char *file, size_t line) {
@@ -53,7 +53,7 @@
return;
}
- fprintf(stderr, "\n%s error: %s\n", bc_err_types[st],
+ fprintf(stderr, "\n%s error: %s\n", bc_err_types[bc_err_type_indices[st]],
bc_err_descs[st]);
fprintf(stderr, " %s", file);
@@ -68,7 +68,7 @@
if (!(s || w) || st < BC_STATUS_POSIX_NAME_LEN || !file)
return BC_STATUS_SUCCESS;
- fprintf(stderr, "\n%s %s: %s\n", bc_err_types[st],
+ fprintf(stderr, "\n%s %s: %s\n", bc_err_types[bc_err_type_indices[st]],
s ? "error" : "warning", bc_err_descs[st]);
if (msg) fprintf(stderr, " %s\n", msg);
diff --git a/src/bc/data.c b/src/bc/data.c
index 2f4a262..9481bf3 100644
--- a/src/bc/data.c
+++ b/src/bc/data.c
@@ -32,80 +32,92 @@
const char *bc_err_types[] = {
- NULL,
-
"bc",
- "bc",
-
- "bc",
-
- "bc",
- "bc",
-
"vector",
- "vector",
-
"Lex",
- "Lex",
- "Lex",
- "Lex",
+ "Parse",
+ "Math",
+ "Runtime",
+ "POSIX",
- "Parse",
- "Parse",
- "Parse",
- "Parse",
- "Parse",
- "Parse",
- "Parse",
- "Parse",
- "Parse",
- "Parse",
- "Parse",
+};
- "Math",
- "Math",
- "Math",
- "Math",
- "Math",
- "Math",
- "Math",
+const char bc_err_type_indices[] = {
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
- "Runtime",
+ BC_ERR_IDX_BC,
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
- "POSIX",
+ BC_ERR_IDX_BC,
+ BC_ERR_IDX_BC,
+
+ BC_ERR_IDX_BC,
+
+ BC_ERR_IDX_BC,
+ BC_ERR_IDX_BC,
+
+ BC_ERR_IDX_VEC,
+ BC_ERR_IDX_VEC,
+
+ BC_ERR_IDX_LEX,
+ BC_ERR_IDX_LEX,
+ BC_ERR_IDX_LEX,
+ BC_ERR_IDX_LEX,
+
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+ BC_ERR_IDX_PARSE,
+
+ BC_ERR_IDX_MATH,
+ BC_ERR_IDX_MATH,
+ BC_ERR_IDX_MAT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