diff --git a/eeshow/file.c b/eeshow/file.c index 386149a..2d6aa17 100644 --- a/eeshow/file.c +++ b/eeshow/file.c @@ -178,25 +178,24 @@ void file_open(struct file *file, const char *name, const struct file *related) } -void file_read(struct file *file, +bool file_read(struct file *file, bool (*parse)(const struct file *file, void *user, const char *line), void *user) { char buf[1000]; char *nl; - if (file->vcs) { - vcs_read(file->vcs, file, parse, user); - return; - } + if (file->vcs) + return vcs_read(file->vcs, file, parse, user); while (fgets(buf, sizeof(buf), file->file)) { nl = strchr(buf, '\n'); if (nl) *nl = 0; file->lineno++; if (!parse(file, user, buf)) - break; + return 0; } + return 1; } diff --git a/eeshow/file.h b/eeshow/file.h index ff28d92..b77e99c 100644 --- a/eeshow/file.h +++ b/eeshow/file.h @@ -32,7 +32,7 @@ char *file_graft_relative(const char *base, const char *name); void file_open(struct file *file, const char *name, const struct file *related); -void file_read(struct file *file, +bool file_read(struct file *file, bool (*parse)(const struct file *file, void *user, const char *line), void *user); void file_close(struct file *file); diff --git a/eeshow/git-file.c b/eeshow/git-file.c index 21810c0..1828d84 100644 --- a/eeshow/git-file.c +++ b/eeshow/git-file.c @@ -455,7 +455,7 @@ struct vcs_git *vcs_git_open(const char *revision, const char *name, } -void vcs_git_read(void *ctx, struct file *file, +bool vcs_git_read(void *ctx, struct file *file, bool (*parse)(const struct file *file, void *user, const char *line), void *user) { @@ -467,14 +467,13 @@ void vcs_git_read(void *ctx, struct file *file, while (p != end) { nl = memchr(p, '\n', end - p); file->lineno++; - if (!nl) { - send_line(p, end - p, parse, user, file); - return; - } + if (!nl) + return send_line(p, end - p, parse, user, file); if (!send_line(p, nl - p, parse, user, file)) - return; + return 0; p = nl + 1; } + return 1; } diff --git a/eeshow/git-file.h b/eeshow/git-file.h index 7d1b637..220b9fc 100644 --- a/eeshow/git-file.h +++ b/eeshow/git-file.h @@ -33,7 +33,7 @@ void vcs_git_init(void); struct vcs_git *vcs_git_open(const char *revision, const char *name, const struct vcs_git *related); -void vcs_git_read(void *ctx, struct file *file, +bool vcs_git_read(void *ctx, struct file *file, bool (*parse)(const struct file *file, void *user, const char *line), void *user); void vcs_git_close(void *ctx);