llm
Download
34 lines 1.6 KiBCModified 2026-08-26 raw
12345678910111213141516171819202122232425262728293031323334
// Definitions of an API for loading files.

#pragma once

#include <stdio.h>

#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);
// Render `file`'s source around the given span, highlighting it. `highlight_error`
// writes to stderr flush-left (what the compiler and runtime error paths want);
// `highlight_error_to` is the same renderer pointed at any stream and indented,
// so `tomo test` can show an excerpt with exactly the same shape.
int highlight_error_to(FILE *out, int indent, file_t *file, const char *start, const char *end, const char *hl_color,
                       int64_t context_lines, bool use_color);
int highlight_error(file_t *file, const char *start, const char *end, const char *hl_color, int64_t context_lines,
                    bool use_color);