diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-01-08 02:53:10 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-01-08 02:53:10 +0000 |
commit | f6b0c55bed3ced7da6e13acf4a92653bd0aba536 (patch) | |
tree | fc7bcb5f75b1960748b96a011dc9e0b2e249750a /usr.bin | |
parent | f416d40f7faf2c57f96c6dea877b46138d731c05 (diff) |
Simplify the mparse_open() interface.
Just return the file descriptor or -1 on error;
there is just one kind of error anyway.
Suggested by Christos Zoulas (NetBSD).
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/main.c | 14 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/mandocdb.c | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/read.c | 24 |
4 files changed, 22 insertions, 27 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index ef2fc7577fd..5d9bc632ee1 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,7 +1,7 @@ -/* $OpenBSD: main.c,v 1.168 2016/01/08 02:13:35 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.169 2016/01/08 02:53:09 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -115,7 +115,6 @@ main(int argc, char *argv[]) size_t isec, i, sz; int prio, best_prio; char sec; - enum mandoclevel rctmp; enum outmode outmode; int fd; int show_usage; @@ -418,11 +417,7 @@ main(int argc, char *argv[]) } while (argc > 0) { - rctmp = mparse_open(curp.mp, &fd, - resp != NULL ? resp->file : *argv); - if (rc < rctmp) - rc = rctmp; - + fd = mparse_open(curp.mp, resp != NULL ? resp->file : *argv); if (fd != -1) { if (use_pager) { tag_files = tag_init(); @@ -441,7 +436,8 @@ main(int argc, char *argv[]) if (argc > 1 && curp.outtype <= OUTT_UTF8) ascii_sepline(curp.outdata); - } + } else if (rc < MANDOCLEVEL_ERROR) + rc = MANDOCLEVEL_ERROR; if (MANDOCLEVEL_OK != rc && curp.wstop) break; diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index fec47f2e24e..7a733fa3d62 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,7 +1,7 @@ -/* $OpenBSD: mandoc.h,v 1.150 2015/11/07 13:57:55 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.151 2016/01/08 02:53:09 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2016 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -423,7 +423,7 @@ const char *mchars_spec2str(const char *, size_t, size_t *); struct mparse *mparse_alloc(int, enum mandoclevel, mandocmsg, const char *); void mparse_free(struct mparse *); void mparse_keep(struct mparse *); -enum mandoclevel mparse_open(struct mparse *, int *, const char *); +int mparse_open(struct mparse *, const char *); enum mandoclevel mparse_readfd(struct mparse *, int, const char *); void mparse_reset(struct mparse *); void mparse_result(struct mparse *, diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index b234f3145ee..5fea1de469a 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandocdb.c,v 1.165 2016/01/08 02:13:35 schwarze Exp $ */ +/* $OpenBSD: mandocdb.c,v 1.166 2016/01/08 02:53:09 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2016 Ingo Schwarze <schwarze@openbsd.org> @@ -1112,8 +1112,7 @@ mpages_merge(struct mparse *mp) man = NULL; sodest = NULL; - mparse_open(mp, &fd, mlink->file); - if (fd == -1) { + if ((fd = mparse_open(mp, mlink->file)) == -1) { say(mlink->file, "&open"); goto nextpage; } diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 72d9b8ed4bf..65ee258def2 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read.c,v 1.121 2016/01/08 02:13:35 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.122 2016/01/08 02:53:09 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2016 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -532,8 +532,7 @@ rerun: if (curp->secondary) curp->secondary->sz -= pos + 1; save_file = curp->file; - if (mparse_open(curp, &fd, ln.buf + of) == - MANDOCLEVEL_OK) { + if ((fd = mparse_open(curp, ln.buf + of)) != -1) { mparse_readfd(curp, fd, ln.buf + of); close(fd); curp->file = save_file; @@ -752,10 +751,11 @@ mparse_readfd(struct mparse *curp, int fd, const char *file) return curp->file_status; } -enum mandoclevel -mparse_open(struct mparse *curp, int *fd, const char *file) +int +mparse_open(struct mparse *curp, const char *file) { char *cp; + int fd; curp->file = file; cp = strrchr(file, '.'); @@ -763,8 +763,8 @@ mparse_open(struct mparse *curp, int *fd, const char *file) /* First try to use the filename as it is. */ - if ((*fd = open(file, O_RDONLY)) != -1) - return MANDOCLEVEL_OK; + if ((fd = open(file, O_RDONLY)) != -1) + return fd; /* * If that doesn't work and the filename doesn't @@ -773,18 +773,18 @@ mparse_open(struct mparse *curp, int *fd, const char *file) if ( ! curp->gzip) { mandoc_asprintf(&cp, "%s.gz", file); - *fd = open(file, O_RDONLY); + fd = open(file, O_RDONLY); free(cp); - if (*fd != -1) { + if (fd != -1) { curp->gzip = 1; - return MANDOCLEVEL_OK; + return fd; } } /* Neither worked, give up. */ mandoc_msg(MANDOCERR_FILE, curp, 0, 0, strerror(errno)); - return MANDOCLEVEL_ERROR; + return -1; } struct mparse * |