aboutsummaryrefslogtreecommitdiff
path: root/stdlib/files.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-13 20:18:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-13 20:18:08 -0400
commitc455e7b67d2e55e6ed03e3449203d4e307f5a7dd (patch)
tree27d9d4c77193f7aa1fe3a3c6fe5631d0ccfd59e2 /stdlib/files.h
parent816aa29b799132acb8c71d4968df6c4619fb2b1d (diff)
Rename builtins/ -> stdlib/
Diffstat (limited to 'stdlib/files.h')
-rw-r--r--stdlib/files.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/stdlib/files.h b/stdlib/files.h
new file mode 100644
index 00000000..f650f78e
--- /dev/null
+++ b/stdlib/files.h
@@ -0,0 +1,35 @@
+//
+// files.h - Definitions of an API for loading files.
+//
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <unistd.h>
+
+typedef struct {
+ const char *filename, *relative_filename;
+ const char *text;
+ int64_t len;
+ int64_t num_lines, line_capacity;
+ int64_t *line_offsets;
+} file_t;
+
+char *resolve_path(const char *path, const char *relative_to, const char *system_path);
+__attribute__((pure, nonnull))
+char *file_base_name(const char *path);
+__attribute__((nonnull))
+file_t *load_file(const char *filename);
+__attribute__((nonnull, returns_nonnull))
+file_t *spoof_file(const char *filename, const char *text);
+__attribute__((pure, nonnull))
+int64_t get_line_number(file_t *f, const char *p);
+__attribute__((pure, nonnull))
+int64_t get_line_column(file_t *f, const char *p);
+__attribute__((pure, nonnull))
+const char *get_line(file_t *f, int64_t line_number);
+__attribute__((pure, nonnull))
+const char *get_file_pos(file_t *f, const char *p);
+int highlight_error(file_t *file, const char *start, const char *end, const char *hl_color, int64_t context_lines, bool use_color);
+
+// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0