bp/files.h

43 lines
1.3 KiB
C
Raw Normal View History

//
// files.h - Definitions of an API for loading files.
//
#ifndef FILES__H
#define FILES__H
2020-09-16 19:35:43 -07:00
2021-01-18 11:53:37 -08:00
#include <stdbool.h>
2020-09-16 19:35:43 -07:00
#include <stdio.h>
2021-01-26 17:58:46 -08:00
#include <unistd.h>
#define file_err(f, ...) do { fprint_line(stderr, f, __VA_ARGS__); exit(EXIT_FAILURE); } while(false)
2020-09-16 19:35:43 -07:00
2021-07-29 12:45:37 -07:00
struct pat_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;
char *memory, **lines, *start, *end;
size_t nlines;
2021-07-29 12:45:37 -07:00
struct pat_s *pats;
2021-01-18 11:53:37 -08:00
bool mmapped:1;
2020-09-16 19:35:43 -07:00
} file_t;
__attribute__((nonnull(2)))
file_t *load_file(file_t **files, const char *filename);
__attribute__((format(printf,2,3)))
file_t *load_filef(file_t **files, const char *fmt, ...);
__attribute__((nonnull))
void slice_file(file_t *slice, file_t *src, const char *start, const char *end);
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, ssize_t len);
__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))
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