2021-01-12 21:04:43 -08:00
|
|
|
//
|
2021-01-15 19:27:25 -08:00
|
|
|
// files.h - Definitions of an API for loading files.
|
2021-01-12 21:04:43 -08:00
|
|
|
//
|
2021-01-15 19:27:25 -08:00
|
|
|
#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 01:48:36 -08:00
|
|
|
|
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;
|
2021-05-20 18:31:28 -07:00
|
|
|
char *memory, **lines, *start, *end;
|
2020-12-17 19:49:56 -08:00
|
|
|
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;
|
|
|
|
|
2021-01-17 18:06:00 -08:00
|
|
|
__attribute__((nonnull(2)))
|
|
|
|
file_t *load_file(file_t **files, const char *filename);
|
2021-01-15 02:05:17 -08:00
|
|
|
__attribute__((format(printf,2,3)))
|
2021-01-17 18:06:00 -08:00
|
|
|
file_t *load_filef(file_t **files, const char *fmt, ...);
|
2021-05-20 18:31:28 -07:00
|
|
|
__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))
|
2021-03-03 17:24:23 -08:00
|
|
|
file_t *spoof_file(file_t **files, const char *filename, const char *text, ssize_t len);
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((nonnull))
|
2020-09-16 19:35:43 -07:00
|
|
|
void destroy_file(file_t **f);
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((pure, nonnull))
|
2020-09-16 19:35:43 -07:00
|
|
|
size_t get_line_number(file_t *f, const char *p);
|
2020-09-23 22:37:28 -07:00
|
|
|
__attribute__((pure, nonnull))
|
2020-09-16 19:35:43 -07:00
|
|
|
const char *get_line(file_t *f, size_t line_number);
|
2021-01-15 02:05:17 -08:00
|
|
|
__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
|
2020-12-17 19:49:56 -08:00
|
|
|
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
|