1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 09:22:28 +02:00

eeshow/ (file_read, vcs_git_read): now pass 0 return from parse()

This commit is contained in:
Werner Almesberger 2016-08-05 20:42:42 -03:00
parent e5f010797d
commit dfebad4e6a
4 changed files with 12 additions and 14 deletions

View File

@ -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), bool (*parse)(const struct file *file, void *user, const char *line),
void *user) void *user)
{ {
char buf[1000]; char buf[1000];
char *nl; char *nl;
if (file->vcs) { if (file->vcs)
vcs_read(file->vcs, file, parse, user); return vcs_read(file->vcs, file, parse, user);
return;
}
while (fgets(buf, sizeof(buf), file->file)) { while (fgets(buf, sizeof(buf), file->file)) {
nl = strchr(buf, '\n'); nl = strchr(buf, '\n');
if (nl) if (nl)
*nl = 0; *nl = 0;
file->lineno++; file->lineno++;
if (!parse(file, user, buf)) if (!parse(file, user, buf))
break; return 0;
} }
return 1;
} }

View File

@ -32,7 +32,7 @@ char *file_graft_relative(const char *base, const char *name);
void file_open(struct file *file, const char *name, void file_open(struct file *file, const char *name,
const struct file *related); 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), bool (*parse)(const struct file *file, void *user, const char *line),
void *user); void *user);
void file_close(struct file *file); void file_close(struct file *file);

View File

@ -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), bool (*parse)(const struct file *file, void *user, const char *line),
void *user) void *user)
{ {
@ -467,14 +467,13 @@ void vcs_git_read(void *ctx, struct file *file,
while (p != end) { while (p != end) {
nl = memchr(p, '\n', end - p); nl = memchr(p, '\n', end - p);
file->lineno++; file->lineno++;
if (!nl) { if (!nl)
send_line(p, end - p, parse, user, file); return send_line(p, end - p, parse, user, file);
return;
}
if (!send_line(p, nl - p, parse, user, file)) if (!send_line(p, nl - p, parse, user, file))
return; return 0;
p = nl + 1; p = nl + 1;
} }
return 1;
} }

View File

@ -33,7 +33,7 @@ void vcs_git_init(void);
struct vcs_git *vcs_git_open(const char *revision, const char *name, struct vcs_git *vcs_git_open(const char *revision, const char *name,
const struct vcs_git *related); 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), bool (*parse)(const struct file *file, void *user, const char *line),
void *user); void *user);
void vcs_git_close(void *ctx); void vcs_git_close(void *ctx);