summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-08-21 20:42:16 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-08-21 20:42:16 -0400
commitd63a28aa4d227544b912b3edc2479de622d18a32 (patch)
tree42aac6845611365d4243dcc7f9b36214da3dcd09 /util
parent1c214758924bbfcd0cbafb6a4240210f057de007 (diff)
started identification
Diffstat (limited to 'util')
-rw-r--r--util/arr.c5
-rw-r--r--util/err.c44
2 files changed, 37 insertions, 12 deletions
diff --git a/util/arr.c b/util/arr.c
index aeeeb92..6cbf9eb 100644
--- a/util/arr.c
+++ b/util/arr.c
@@ -29,6 +29,11 @@ void *arr_add(Array *arr) {
return item;
}
+void arr_remove_last(Array *arr) {
+ arr->len--;
+ /* OPTIM (memory): Shorten array. */
+}
+
void arr_free(Array *arr) {
free(arr->data);
}
diff --git a/util/err.c b/util/err.c
index 5385cf1..6eaa191 100644
--- a/util/err.c
+++ b/util/err.c
@@ -2,14 +2,21 @@
#if USE_COLORED_TEXT
#define TEXT_ERROR(x) "\x1b[91m" x "\x1b[0m"
+#define TEXT_INFO(x) "\x1b[94m" x "\x1b[0m"
#define TEXT_IMPORTANT(x) "\x1b[1m" x "\x1b[0m"
#else
#define TEXT_ERROR(x) x
+#define TEXT_INFO(x) x
#define TEXT_IMPORTANT(x) x
#endif
typedef uint32_t LineNo;
+typedef struct {
+ LineNo line;
+ char *code;
+} Location;
+
/* file name of file being processed */
static const char *err_filename;
@@ -33,6 +40,10 @@ static void err_print_header_(LineNo line) {
err_fprint(TEXT_ERROR("error:") " at line %lu of %s:\n", (unsigned long)line, err_filename);
}
+static void info_print_header_(LineNo line) {
+ err_fprint(TEXT_INFO("info:") " at line %lu of %s:\n", (unsigned long)line, err_filename);
+}
+
static void err_print_footer_(const char *context) {
err_fprint("\n\there --> ");
const char *end = strchr(context, '\n');
@@ -48,21 +59,30 @@ static void err_print_footer_(const char *context) {
/* Write nicely-formatted errors to the error file */
-/* static void err_print(LineNo line, const char *context, const char *fmt, ...) { */
-/* err_print_header_(line); */
-/* va_list args; */
-/* va_start(args, fmt); */
-/* err_vfprint(fmt, args); */
-/* va_end(args); */
-/* err_print_footer_(context); */
-/* } */
-
-static void err_vprint(LineNo line, const char *context, const char *fmt, va_list args) {
- err_print_header_(line);
+
+static void err_vprint(Location where, const char *fmt, va_list args) {
+ err_print_header_(where.line);
+ err_vfprint(fmt, args);
+ err_print_footer_(where.code);
+}
+
+static void err_print(Location where, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ err_vprint(where, fmt, args);
+ va_end(args);
+}
+
+static void info_print(Location where, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ info_print_header_(where.line);
err_vfprint(fmt, args);
- err_print_footer_(context);
+ err_print_footer_(where.code);
+ va_end(args);
}
+
static void *err_malloc(size_t size) {
void *ret = malloc(size);
if (!ret) {