summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-12 10:49:59 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-12 14:43:28 -0300
commit35c8d87588dc80b265f6898e27140bc6f0965610 (patch)
treef747addbda3b0bf2157dbea96109ee7b2bf76bfe
parent759ce17e1c1e258bd3f113b3fc73d809ff03e764 (diff)
downloadeeshow-35c8d87588dc80b265f6898e27140bc6f0965610.tar.gz
eeshow-35c8d87588dc80b265f6898e27140bc6f0965610.tar.bz2
eeshow-35c8d87588dc80b265f6898e27140bc6f0965610.zip
eeshow/: convert "perror" to diagnostic functions
-rw-r--r--cro.c9
-rw-r--r--diag.c19
-rw-r--r--diag.h12
-rw-r--r--fig.c7
-rw-r--r--file.c4
-rw-r--r--git-file.c6
-rw-r--r--git-hist.c6
-rw-r--r--sch-parse.c6
8 files changed, 46 insertions, 23 deletions
diff --git a/cro.c b/cro.c
index 6070287..84effae 100644
--- a/cro.c
+++ b/cro.c
@@ -23,6 +23,7 @@
#include <cairo/cairo-pdf.h>
#include "util.h"
+#include "diag.h"
#include "style.h"
#include "text.h"
#include "gfx.h"
@@ -344,7 +345,7 @@ static cairo_status_t stream_to_stdout(void *closure,
wrote = write(1, data, length);
if (wrote == (ssize_t) length)
return CAIRO_STATUS_SUCCESS;
- perror("stdout");
+ diag_perror("stdout");
return CAIRO_STATUS_WRITE_ERROR;
}
@@ -373,10 +374,8 @@ static void cr_pdf_new_sheet(void *ctx)
cc->n_sheets++;
cc->sheets = realloc(cc->sheets, sizeof(struct record) * cc->n_sheets);
- if (!cc->sheets) {
- perror("realloc");
- exit(1);
- }
+ if (!cc->sheets)
+ diag_pfatal("realloc");
cc->sheets[cc->n_sheets - 1] = cc->record;
record_wipe(&cc->record);
}
diff --git a/diag.c b/diag.c
index d9bb5a5..46cc49f 100644
--- a/diag.c
+++ b/diag.c
@@ -14,6 +14,8 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+#include <errno.h>
#include "diag.h"
@@ -22,6 +24,23 @@
unsigned verbose = 0;
+/* ----- Specialized diagnostic functions ---------------------------------- */
+
+
+void diag_pfatal(const char *s)
+{
+ fatal("%s: %s\n", s, strerror(errno));
+}
+
+
+void diag_perror(const char *s)
+{
+ error("%s: %s\n", s, strerror(errno));
+}
+
+
+/* ----- General diagnostic functions -------------------------------------- */
+
void fatal(const char *fmt, ...)
{
va_list ap;
diff --git a/diag.h b/diag.h
index be152b1..bf6ee75 100644
--- a/diag.h
+++ b/diag.h
@@ -23,6 +23,18 @@
extern unsigned verbose;
+/* ----- Specialized diagnostic functions ---------------------------------- */
+
+
+/* perror, based on "fatal" or "error" */
+
+void diag_pfatal(const char *s);
+void diag_perror(const char *s);
+
+
+/* ----- General diagnostic functions -------------------------------------- */
+
+
/*
* Terminate immediately. Further execution makes no sense.
* E.g., out of memory.
diff --git a/fig.c b/fig.c
index d24f8e7..70313c7 100644
--- a/fig.c
+++ b/fig.c
@@ -20,6 +20,7 @@
#include <assert.h>
#include "util.h"
+#include "diag.h"
#include "style.h"
#include "text.h"
#include "main.h"
@@ -269,10 +270,8 @@ static void *fig_init(int argc, char *const *argv)
}
file = fopen(template, "r");
- if (!file) {
- perror(template);
- exit(1);
- }
+ if (!file)
+ diag_pfatal(template);
while (fgets(buf, sizeof(buf), file)) {
while (apply_vars(buf, n_vars, vars));
printf("%s", buf);
diff --git a/file.c b/file.c
index d927725..a0a83db 100644
--- a/file.c
+++ b/file.c
@@ -182,11 +182,11 @@ bool file_open(struct file *file, const char *name, const struct file *related)
return 1;
if (verbose)
- perror(name); /* @@@ may need changing later */
+ diag_perror(name);
if (!strchr(name, ':')) {
if (!verbose)
- perror(name);
+ diag_perror(name);
goto fail;
}
diff --git a/git-file.c b/git-file.c
index 3246fa9..4ddef3d 100644
--- a/git-file.c
+++ b/git-file.c
@@ -125,10 +125,8 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
/* identify inode of repo root */
- if (stat(repo_dir, &repo_st) < 0) {
- perror(repo_dir);
- exit(1);
- }
+ if (stat(repo_dir, &repo_st) < 0)
+ diag_pfatal(repo_dir);
if (!S_ISDIR(repo_st.st_mode))
fatal("%s: not a directory\n", repo_dir);
diff --git a/git-hist.c b/git-hist.c
index 886b0a3..03d02d4 100644
--- a/git-hist.c
+++ b/git-hist.c
@@ -49,10 +49,8 @@ static void uplink(struct hist *down, struct hist *up)
{
down->newer = realloc(down->newer,
sizeof(struct hist *) * (down->n_newer + 1));
- if (!down->newer) {
- perror("realloc");
- exit(1);
- }
+ if (!down->newer)
+ diag_pfatal("realloc");
down->newer[down->n_newer++] = up;
}
diff --git a/sch-parse.c b/sch-parse.c
index 6d63309..ac15d8c 100644
--- a/sch-parse.c
+++ b/sch-parse.c
@@ -124,10 +124,8 @@ static bool parse_field(struct sch_ctx *ctx, const char *line)
char *s;
s = realloc((void *) txt->s, len + 3);
- if (!s) {
- perror("realloc");
- exit(1);
- }
+ if (!s)
+ diag_pfatal("realloc");
if (comp->unit <= 26)
sprintf(s + len, "%c", 'A' + comp->unit - 1);
else