2016-08-02 17:00:08 +03:00
|
|
|
/*
|
|
|
|
* file.h - Open and read a file
|
|
|
|
*
|
|
|
|
* Written 2016 by Werner Almesberger
|
|
|
|
* Copyright 2016 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FILE_H
|
|
|
|
#define FILE_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2016-08-02 21:36:18 +03:00
|
|
|
#include <stdio.h>
|
2016-08-02 17:00:08 +03:00
|
|
|
|
2016-08-02 21:36:18 +03:00
|
|
|
|
|
|
|
struct file {
|
|
|
|
FILE *file; /* NULL if using a version control system */
|
|
|
|
void *vcs; /* VCS descriptor or NULL */
|
|
|
|
const char *name; /* name/designator given to file_open */
|
|
|
|
unsigned lineno;
|
|
|
|
const struct file *related; /* NULL if not related to anything */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool file_cat(const struct file *file, void *user, const char *line);
|
|
|
|
|
2016-08-03 01:13:28 +03:00
|
|
|
char *file_graft_relative(const char *base, const char *name);
|
|
|
|
|
2016-08-06 03:02:57 +03:00
|
|
|
bool file_open(struct file *file, const char *name,
|
2016-08-02 21:36:18 +03:00
|
|
|
const struct file *related);
|
2016-08-06 07:15:49 +03:00
|
|
|
bool file_open_revision(struct file *file, const char *rev, const char *name,
|
|
|
|
const struct file *related);
|
2016-08-06 02:42:42 +03:00
|
|
|
bool file_read(struct file *file,
|
2016-08-02 21:36:18 +03:00
|
|
|
bool (*parse)(const struct file *file, void *user, const char *line),
|
2016-08-02 17:00:08 +03:00
|
|
|
void *user);
|
2016-08-02 21:36:18 +03:00
|
|
|
void file_close(struct file *file);
|
2016-08-02 17:00:08 +03:00
|
|
|
|
|
|
|
#endif /* !FILE_H */
|