-/* $OpenBSD: main.c,v 1.151 2015/10/10 13:20:25 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.152 2015/10/11 21:06:59 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
#include <assert.h>
#include <ctype.h>
-#include <errno.h>
+#include <err.h>
#include <fcntl.h>
#include <glob.h>
#include <signal.h>
static void usage(enum argmode) __attribute__((noreturn));
static int woptions(struct curparse *, char *);
+extern char *__progname;
+
static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
static char help_arg[] = "help";
static char *help_argv[] = {help_arg, NULL};
-static const char *progname;
static enum mandoclevel rc;
int use_pager;
int c;
- if (argc < 1)
- progname = "mandoc";
- else if ((progname = strrchr(argv[0], '/')) == NULL)
- progname = argv[0];
- else
- ++progname;
-
- if (0 == strncmp(progname, "mandocdb", 8) ||
- 0 == strncmp(progname, "makewhatis", 10))
+ if (0 == strncmp(__progname, "mandocdb", 8) ||
+ 0 == strncmp(__progname, "makewhatis", 10))
return mandocdb(argc, argv);
/* Search options. */
memset(&search, 0, sizeof(struct mansearch));
search.outkey = "Nd";
- if (strcmp(progname, "man") == 0)
+ if (strcmp(__progname, "man") == 0)
search.argmode = ARG_NAME;
- else if (strncmp(progname, "apropos", 7) == 0)
+ else if (strncmp(__progname, "apropos", 7) == 0)
search.argmode = ARG_EXPR;
- else if (strncmp(progname, "whatis", 6) == 0)
+ else if (strncmp(__progname, "whatis", 6) == 0)
search.argmode = ARG_WORD;
- else if (strncmp(progname, "help", 4) == 0)
+ else if (strncmp(__progname, "help", 4) == 0)
search.argmode = ARG_NAME;
else
search.argmode = ARG_FILE;
break;
case 'I':
if (strncmp(optarg, "os=", 3)) {
- fprintf(stderr,
- "%s: -I %s: Bad argument\n",
- progname, optarg);
+ warnx("-I %s: Bad argument", optarg);
return (int)MANDOCLEVEL_BADARG;
}
if (defos) {
- fprintf(stderr,
- "%s: -I %s: Duplicate argument\n",
- progname, optarg);
+ warnx("-I %s: Duplicate argument", optarg);
return (int)MANDOCLEVEL_BADARG;
}
defos = mandoc_strdup(optarg + 3);
*/
if (search.argmode == ARG_NAME) {
- if (*progname == 'h') {
+ if (*__progname == 'h') {
if (argc == 0) {
argv = help_argv;
argc = 1;
fs_search(&search, &conf.manpath,
argc, argv, &res, &sz);
else
- fprintf(stderr,
- "%s: nothing appropriate\n",
- progname);
+ warnx("nothing appropriate");
}
if (sz == 0) {
paths->paths[ipath], sec, name);
globres = glob(file, 0, NULL, &globinfo);
if (globres != 0 && globres != GLOB_NOMATCH)
- fprintf(stderr, "%s: %s: glob: %s\n",
- progname, file, strerror(errno));
+ warn("%s: glob", file);
free(file);
if (globres == 0)
file = mandoc_strdup(*globinfo.gl_pathv);
return 0;
found:
- fprintf(stderr, "%s: outdated mandoc.db lacks %s(%s) entry, run "
- "makewhatis %s\n", progname, name, sec, paths->paths[ipath]);
+ warnx("outdated mandoc.db lacks %s(%s) entry, run makewhatis %s",
+ name, sec, paths->paths[ipath]);
*res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage));
page = *res + (*ressz - 1);
page->file = file;
return;
}
if (*ressz == lastsz)
- fprintf(stderr,
- "%s: No entry for %s in the manual.\n",
- progname, *argv);
+ warnx("No entry for %s in the manual.", *argv);
lastsz = *ressz;
argv++;
argc--;
return;
fail:
- fprintf(stderr, "%s: %s: SYSERR: %s: %s",
- progname, file, syscall, strerror(errno));
+ warn("%s: SYSERR: %s", file, syscall);
if (rc < MANDOCLEVEL_SYSERR)
rc = MANDOCLEVEL_SYSERR;
}
} else if ( ! strcmp(arg, "us-ascii")) {
*options &= ~(MPARSE_UTF8 | MPARSE_LATIN1);
} else {
- fprintf(stderr, "%s: -K %s: Bad argument\n",
- progname, arg);
+ warnx("-K %s: Bad argument", arg);
return 0;
}
return 1;
else if (0 == strcmp(arg, "an"))
*options |= MPARSE_MAN;
else {
- fprintf(stderr, "%s: -m %s: Bad argument\n",
- progname, arg);
+ warnx("-m %s: Bad argument", arg);
return 0;
}
else if (0 == strcmp(arg, "pdf"))
curp->outtype = OUTT_PDF;
else {
- fprintf(stderr, "%s: -T %s: Bad argument\n",
- progname, arg);
+ warnx("-T %s: Bad argument", arg);
return 0;
}
curp->wlevel = MANDOCLEVEL_BADARG;
break;
default:
- fprintf(stderr, "%s: -W %s: Bad argument\n",
- progname, o);
+ warnx("-W %s: Bad argument", o);
return 0;
}
}
{
const char *mparse_msg;
- fprintf(stderr, "%s: %s:", progname, file);
+ fprintf(stderr, "%s: %s:", __progname, file);
if (line)
fprintf(stderr, "%d:%d:", line, col + 1);
switch (pager_pid = fork()) {
case -1:
- fprintf(stderr, "%s: fork: %s\n",
- progname, strerror(errno));
- exit((int)MANDOCLEVEL_SYSERR);
+ err((int)MANDOCLEVEL_SYSERR, "fork");
case 0:
break;
default:
/* The child process becomes the pager. */
- if (dup2(tag_files->ofd, STDOUT_FILENO) == -1) {
- fprintf(stderr, "pager: stdout: %s\n", strerror(errno));
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (dup2(tag_files->ofd, STDOUT_FILENO) == -1)
+ err((int)MANDOCLEVEL_SYSERR, "pager stdout");
close(tag_files->ofd);
close(tag_files->tfd);
execvp(argv[0], argv);
- fprintf(stderr, "%s: exec %s: %s\n",
- progname, argv[0], strerror(errno));
- exit((int)MANDOCLEVEL_SYSERR);
+ err((int)MANDOCLEVEL_SYSERR, "exec %s", argv[0]);
}
-/* $OpenBSD: mandoc_aux.c,v 1.5 2015/10/06 18:30:43 schwarze Exp $ */
+/* $OpenBSD: mandoc_aux.c,v 1.6 2015/10/11 21:06:59 schwarze Exp $ */
/*
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
*/
#include <sys/types.h>
+#include <err.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
ret = vasprintf(dest, fmt, ap);
va_end(ap);
- if (-1 == ret) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (ret == -1)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
return ret;
}
void *ptr;
ptr = calloc(num, size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
return ptr;
}
void *ptr;
ptr = malloc(size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
return ptr;
}
{
ptr = realloc(ptr, size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
return ptr;
}
{
ptr = reallocarray(ptr, num, size);
- if (NULL == ptr) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
return ptr;
}
char *p;
p = strdup(ptr);
- if (NULL == p) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (ptr == NULL)
+ err((int)MANDOCLEVEL_SYSERR, NULL);
return p;
}
-/* $OpenBSD: mandocdb.c,v 1.150 2015/10/06 18:30:43 schwarze Exp $ */
+/* $OpenBSD: mandocdb.c,v 1.151 2015/10/11 21:06:59 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
#include <assert.h>
#include <ctype.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <fts.h>
static int treescan(void);
static size_t utf8(unsigned int, char [7]);
+extern char *__progname;
+
static char tempfilename[32];
-static char *progname;
static int nodb; /* no database changes */
static int mparse_options; /* abort the parse early */
static int use_all; /* use all found files */
mpages_info.key_offset = offsetof(struct mpage, inodev);
mlinks_info.key_offset = offsetof(struct mlink, file);
- progname = strrchr(argv[0], '/');
- if (progname == NULL)
- progname = argv[0];
- else
- ++progname;
-
/*
* We accept a few different invocations.
* The CHECKOP macro makes sure that invocation styles don't
*/
#define CHECKOP(_op, _ch) do \
if (OP_DEFAULT != (_op)) { \
- fprintf(stderr, "%s: -%c: Conflicting option\n", \
- progname, (_ch)); \
+ warnx("-%c: Conflicting option", (_ch)); \
goto usage; \
} while (/*CONSTCOND*/0)
break;
case 'T':
if (strcmp(optarg, "utf8")) {
- fprintf(stderr, "%s: -T%s: "
- "Unsupported output format\n",
- progname, optarg);
+ warnx("-T%s: Unsupported output format",
+ optarg);
goto usage;
}
write_utf8 = 1;
argv += optind;
if (OP_CONFFILE == op && argc > 0) {
- fprintf(stderr, "%s: -C: Too many arguments\n",
- progname);
+ warnx("-C: Too many arguments");
goto usage;
}
" %s [-DnpQ] [-Tutf8] -d dir [file ...]\n"
" %s [-Dnp] -u dir [file ...]\n"
" %s [-Q] -t file ...\n",
- progname, progname, progname,
- progname, progname);
+ __progname, __progname, __progname,
+ __progname, __progname);
return (int)MANDOCLEVEL_BADARG;
}
-/* $OpenBSD: manpath.c,v 1.15 2015/05/07 12:07:29 schwarze Exp $ */
+/* $OpenBSD: manpath.c,v 1.16 2015/10/11 21:06:59 schwarze Exp $ */
/*
* Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
#include <sys/stat.h>
#include <ctype.h>
+#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
size_t i;
if (NULL == (cp = realpath(dir, buf))) {
- if (complain) {
- fputs("manpath: ", stderr);
- perror(dir);
- }
+ if (complain)
+ warn("manpath: %s", dir);
return;
}
return;
if (stat(cp, &sb) == -1) {
- if (complain) {
- fputs("manpath: ", stderr);
- perror(dir);
- }
+ if (complain)
+ warn("manpath: %s", dir);
return;
}
-/* $OpenBSD: mansearch.c,v 1.45 2015/10/06 18:30:44 schwarze Exp $ */
+/* $OpenBSD: mansearch.c,v 1.46 2015/10/11 21:06:59 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
#include <sys/types.h>
#include <assert.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#define SQL_BIND_TEXT(_db, _s, _i, _v) \
do { if (SQLITE_OK != sqlite3_bind_text \
((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \
- fprintf(stderr, "%s\n", sqlite3_errmsg((_db))); \
+ warnx("%s", sqlite3_errmsg((_db))); \
} while (0)
#define SQL_BIND_INT64(_db, _s, _i, _v) \
do { if (SQLITE_OK != sqlite3_bind_int64 \
((_s), (_i)++, (_v))) \
- fprintf(stderr, "%s\n", sqlite3_errmsg((_db))); \
+ warnx("%s", sqlite3_errmsg((_db))); \
} while (0)
#define SQL_BIND_BLOB(_db, _s, _i, _v) \
do { if (SQLITE_OK != sqlite3_bind_blob \
((_s), (_i)++, (&_v), sizeof(_v), SQLITE_STATIC)) \
- fprintf(stderr, "%s\n", sqlite3_errmsg((_db))); \
+ warnx("%s", sqlite3_errmsg((_db))); \
} while (0)
struct expr {
if (start) {
if (NULL != pagecache) {
- fprintf(stderr, "pagecache already enabled\n");
+ warnx("pagecache already enabled");
return (int)MANDOCLEVEL_BADARG;
}
if (SQLITE_OK == c)
return (int)MANDOCLEVEL_OK;
- fprintf(stderr, "pagecache: %s\n", sqlite3_errstr(c));
+ warnx("pagecache: %s", sqlite3_errstr(c));
} else if (NULL == pagecache) {
- fprintf(stderr, "pagecache missing\n");
+ warnx("pagecache missing");
return (int)MANDOCLEVEL_BADARG;
}
for (i = 0; i < paths->sz; i++) {
if (chdir_status && paths->paths[i][0] != '/') {
if ( ! getcwd_status) {
- fprintf(stderr, "%s: getcwd: %s\n",
- paths->paths[i], buf);
+ warnx("%s: getcwd: %s", paths->paths[i], buf);
continue;
} else if (chdir(buf) == -1) {
perror(buf);
SQLITE_OPEN_READONLY, NULL);
if (SQLITE_OK != c) {
- fprintf(stderr, "%s/%s: %s\n",
- paths->paths[i], MANDOC_DB, strerror(errno));
+ warn("%s/%s", paths->paths[i], MANDOC_DB);
sqlite3_close(db);
continue;
}
j = 1;
c = sqlite3_prepare_v2(db, sql, -1, &s, NULL);
if (SQLITE_OK != c)
- fprintf(stderr, "%s\n", sqlite3_errmsg(db));
+ warnx("%s", sqlite3_errmsg(db));
for (ep = e; NULL != ep; ep = ep->next) {
if (NULL == ep->substr) {
}
if (SQLITE_DONE != c)
- fprintf(stderr, "%s\n", sqlite3_errmsg(db));
+ warnx("%s", sqlite3_errmsg(db));
sqlite3_finalize(s);
"WHERE pageid=? ORDER BY sec, arch, name",
-1, &s, NULL);
if (SQLITE_OK != c)
- fprintf(stderr, "%s\n", sqlite3_errmsg(db));
+ warnx("%s", sqlite3_errmsg(db));
c = sqlite3_prepare_v2(db,
"SELECT bits, key, pageid FROM keys "
"WHERE pageid=? AND bits & ?",
-1, &s2, NULL);
if (SQLITE_OK != c)
- fprintf(stderr, "%s\n", sqlite3_errmsg(db));
+ warnx("%s", sqlite3_errmsg(db));
for (mp = ohash_first(&htab, &idx);
NULL != mp;
globfree(&globinfo);
}
if (c != SQLITE_DONE)
- fprintf(stderr, "%s\n", sqlite3_errmsg(db));
+ warnx("%s", sqlite3_errmsg(db));
sqlite3_reset(s);
/* If none of the files is usable, use the first name. */
output = newoutput;
}
if (SQLITE_DONE != c)
- fprintf(stderr, "%s\n", sqlite3_errmsg(db));
+ warnx("%s", sqlite3_errmsg(db));
sqlite3_reset(s);
return output;
}
free(val);
if (irc) {
regerror(irc, &e->regexp, errbuf, sizeof(errbuf));
- fprintf(stderr, "regcomp: %s\n", errbuf);
+ warnx("regcomp: %s", errbuf);
free(e);
return NULL;
}
-/* $OpenBSD: read.c,v 1.117 2015/10/06 18:30:44 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.118 2015/10/11 21:06:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
#include <assert.h>
#include <ctype.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
size_t off;
ssize_t ssz;
- if (-1 == fstat(fd, &st)) {
- perror(file);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (fstat(fd, &st) == -1)
+ err((int)MANDOCLEVEL_SYSERR, "%s", file);
/*
* If we're a regular file, try just reading in the whole entry
}
if (curp->gzip) {
- if ((gz = gzdopen(fd, "rb")) == NULL) {
- perror(file);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if ((gz = gzdopen(fd, "rb")) == NULL)
+ err((int)MANDOCLEVEL_SYSERR, "%s", file);
} else
gz = NULL;
fb->sz = off;
return 1;
}
- if (ssz == -1) {
- perror(file);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (ssz == -1)
+ err((int)MANDOCLEVEL_SYSERR, "%s", file);
off += (size_t)ssz;
}
-/* $OpenBSD: term_ps.c,v 1.40 2015/10/06 18:30:44 schwarze Exp $ */
+/* $OpenBSD: term_ps.c,v 1.41 2015/10/11 21:07:00 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
#include <sys/types.h>
#include <assert.h>
+#include <err.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
pagex = 216;
pagey = 356;
} else if (2 != sscanf(pp, "%ux%u", &pagex, &pagey))
- fprintf(stderr, "%s: Unknown paper\n", pp);
+ warnx("%s: Unknown paper", pp);
}
/*