summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-04-12 15:18:11 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-04-12 15:18:11 -0400
commit3f80b6f659fe7480e537246ea79fbf6a0ec43031 (patch)
tree1d2bb4e4a75845071f690016522144f2f917c63f
parent17da3317f2725e454f5dfdcec307b59e57f4df4f (diff)
fixed could not open file error message
-rw-r--r--data_structures.c2
-rw-r--r--err.c30
-rw-r--r--types.h5
3 files changed, 19 insertions, 18 deletions
diff --git a/data_structures.c b/data_structures.c
index 06bbc90..9bab854 100644
--- a/data_structures.c
+++ b/data_structures.c
@@ -111,7 +111,7 @@ static void arr_set_lena_(void **arr, size_t n, size_t item_sz, Allocator *a) {
static void *arr_add_(void **arr, size_t item_sz) {
ArrHeader *hdr;
if (*arr == NULL) {
- arr_resv_(arr, 10, item_sz);
+ arr_resv_(arr, 1, item_sz);
hdr = arr_hdr(*arr);
} else {
hdr = arr_hdr(*arr);
diff --git a/err.c b/err.c
index 48fefca..9fada7b 100644
--- a/err.c
+++ b/err.c
@@ -69,11 +69,26 @@ static void print_pos_highlight(FILE *out, ErrCtx *ctx, File *file, U32 start_po
fprintf(out, "\n");
}
+static FILE *err_ctx_file(ErrCtx *ctx) {
+ (void)ctx;
+ return stderr;
+}
+
+
+static void err_fprint(ErrCtx *ctx, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vfprintf(err_ctx_file(ctx), fmt, args);
+ va_end(args);
+}
+
static void print_location_highlight(FILE *out, Location where) {
File *f = where.file;
ErrCtx *ctx = f->ctx;
+ if (where.start == 0 && where.end == 0) { err_fprint(ctx, "\n"); return; } /* null location */
Token *first = &f->tokens[where.start];
Token *last = &f->tokens[where.end-1];
+
print_pos_highlight(out, ctx, f, first->pos.start, last->pos.end);
}
@@ -98,18 +113,6 @@ static inline const char *ordinals(size_t x) {
}
}
-static FILE *err_ctx_file(ErrCtx *ctx) {
- (void)ctx;
- return stderr;
-}
-
-static void err_fprint(ErrCtx *ctx, const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- vfprintf(err_ctx_file(ctx), fmt, args);
- va_end(args);
-}
-
static void err_text_err(ErrCtx *ctx, const char *s) {
if (ctx->color_enabled)
err_fprint(ctx, TEXT_ERR_START "%s" TEXT_ERR_END, s);
@@ -150,18 +153,21 @@ static void err_print_line_file(Location where) {
static void err_print_header_(Location where) {
ErrCtx *ctx = where.file->ctx;
err_text_err(ctx, "error");
+ if (where.start == 0 && where.end == 0) { err_fprint(ctx, ": "); return; }
err_print_line_file(where);
}
static void info_print_header_(Location where) {
ErrCtx *ctx = where.file->ctx;
err_text_info(ctx, "info");
+ if (where.start == 0 && where.end == 0) { err_fprint(ctx, ": "); return; }
err_print_line_file(where);
}
static void warn_print_header_(Location where) {
ErrCtx *ctx = where.file->ctx;
err_text_warn(ctx, "warning");
+ if (where.start == 0 && where.end == 0) { err_fprint(ctx, ": "); return; }
err_print_line_file(where);
}
diff --git a/types.h b/types.h
index d9fc550..1a61450 100644
--- a/types.h
+++ b/types.h
@@ -130,11 +130,6 @@ typedef struct Allocator {
Page *last;
} Allocator;
-typedef struct ArrBlock {
- void *data;
- size_t n; /* number of things in this block so far */
-} ArrBlock;
-
/* initialize to 0 */
typedef struct HashTable {
void *data;