From 372eb2647f04c8789679a7fd80a0e91a65e47941 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 3 Nov 2022 12:55:01 -0400 Subject: Added a column getter --- files.c | 9 +++++++++ files.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/files.c b/files.c index 22eaed1..0231f21 100644 --- a/files.c +++ b/files.c @@ -197,6 +197,15 @@ size_t get_line_number(file_t *f, const char *p) return lo; // Return the line number whose line starts closest before 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. // 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 -- cgit v1.2.3