aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2022-11-03 12:55:01 -0400
committerBruce Hill <bruce@bruce-hill.com>2022-11-03 12:55:01 -0400
commit372eb2647f04c8789679a7fd80a0e91a65e47941 (patch)
treee293f1dae67fcc25f20943a341b4a3bb0ef5571d
parent611cf8441a7bd6bf1740914103198967ddab26bb (diff)
Added a column getter
-rw-r--r--files.c9
-rw-r--r--files.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/files.c b/files.c
index 22eaed1..0231f21 100644
--- a/files.c
+++ b/files.c
@@ -198,6 +198,15 @@ size_t get_line_number(file_t *f, const char *p)
}
//
+// Given a pointer, determine which line column it points to.
+//
+size_t get_line_column(file_t *f, const char *p)
+{
+ size_t line_no = get_line_number(f, p);
+ return 1 + (size_t)(p - f->lines[line_no]);
+}
+
+//
// Return a pointer to the line with the specified line number.
//
const char *get_line(file_t *f, size_t line_number)
diff --git a/files.h b/files.h
index b32d5a4..358fcd8 100644
--- a/files.h
+++ b/files.h
@@ -28,6 +28,8 @@ void destroy_file(file_t **f);
__attribute__((pure, nonnull))
size_t get_line_number(file_t *f, const char *p);
__attribute__((pure, nonnull))
+size_t get_line_column(file_t *f, const char *p);
+__attribute__((pure, nonnull))
const char *get_line(file_t *f, size_t line_number);
#endif