bp/file_loader.h

39 lines
1.1 KiB
C
Raw Normal View History

//
// file_loader.h - Definitions of an API for loading files.
//
2020-09-16 19:35:43 -07:00
#ifndef FILE_LOADER__H
#define FILE_LOADER__H
#include <stdio.h>
struct allocated_op_s; // declared in types.h
2021-01-13 18:56:22 -08:00
typedef struct file_s {
struct file_s *next;
2020-09-16 19:35:43 -07:00
const char *filename;
2020-09-18 22:49:02 -07:00
char *contents, **lines, *end;
size_t nlines;
struct allocated_op_s *ops;
2020-09-16 19:35:43 -07:00
unsigned int mmapped:1;
} file_t;
__attribute__((format(printf,2,3)))
file_t *load_file(file_t **files, const char *fmt, ...);
2021-01-13 18:56:22 -08:00
__attribute__((nonnull(3), returns_nonnull))
file_t *spoof_file(file_t **files, const char *filename, const char *text);
__attribute__((nonnull))
2020-12-27 19:48:52 -08:00
void intern_file(file_t *f);
__attribute__((nonnull))
2020-09-16 19:35:43 -07:00
void destroy_file(file_t **f);
__attribute__((pure, nonnull))
2020-09-16 19:35:43 -07:00
size_t get_line_number(file_t *f, const char *p);
__attribute__((pure, nonnull))
size_t get_char_number(file_t *f, const char *p);
__attribute__((pure, nonnull))
2020-09-16 19:35:43 -07:00
const char *get_line(file_t *f, size_t line_number);
__attribute__((nonnull(1,2,3), format(printf,5,6)))
2020-09-28 21:30:43 -07:00
void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, const char *fmt, ...);
2020-09-16 19:35:43 -07:00
#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1