1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-22 20:45:55 +02:00

eeshow/: convert "perror" to diagnostic functions

This commit is contained in:
Werner Almesberger 2016-08-12 10:49:59 -03:00
parent d1fdcaeab4
commit 5a7ddc8b95
8 changed files with 46 additions and 23 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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.

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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