[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pdf-devel] Error module: first lines
From: |
gerel |
Subject: |
[pdf-devel] Error module: first lines |
Date: |
Fri, 14 Dec 2007 20:59:51 -0300 |
Well, I have written a few lines now. I was thinking of two things:
1. We could use pdf_error_message_count to abort exectuion after a maximum is
exceeded.
2. Do you think the "pdf_error_one_per_line" variable will be of use for us ?
Here it goes, suggestions are welcome :-)
--- pdf-error.h ---
/* Time-stamp: <2007-12-14 17:41:34 gerel> */
#ifndef PDF_ERROR_H
#define PDF_ERROR_H
#define PDF_ERROR 1
#define PDF_OK 0
enum pdf_error_t
{
/* foo module errros */
PDF_EINVCHAR = 1,
PDF_EINVSYNTAX,
PDF_EEOF,
/* memory module errors */
PDF_EOUTOFMEM,
/* general errors */
PDF_EFATAL
};
extern const char * pdf_error_errlist [];
extern enum pdf_error_t pdf_errno;
/* Print a message with `fprintf (stderr, FORMAT, ...)';
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
extern void pdf_error (int status, int errnum, const char *format, ...);
extern void pdf_perror (const char *str);
/*
* Exits the program with PDF_EFATAL.
* If 'str' is not empty prints 'str' followed by the error description.
*/
extern void pdf_abort (const char *str);
/* This variable is incremented each time `error' is called. */
extern unsigned int pdf_error_message_count;
/* Sometimes we want to have at most one error per line. This
variable controls whether this mode is selected or not. */
extern int pdf_error_one_per_line;
#endif /* PDF_ERROR_H */
--- end of pdf-error.h ---
--- pdf-error.c ---
/* Time-stamp: <2007-12-14 18:25:50 gerel> */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <pdf-error.h>
const char * pdf_error_errlist [] =
{
"invalid character",
"invalid syntax",
"end of file",
"out of memory",
"fatal error"
};
enum pdf_error_t pdf_errno = 0;
unsigned int pdf_error_message_count = 0;
int pdf_error_one_per_line = 0;
void
pdf_perror (const char *str)
{
pdf_error (0, (int) pdf_errno, str);
}
void
pdf_abort (const char *str)
{
pdf_error (1, (int) PDF_EFATAL, str);
}
void
pdf_error (int status, int errnum, const char *format, ...)
{
va_list args;
fprintf (stderr, "gnupdf: ");
if (format != NULL)
{
va_start (args, format);
vfprintf (stderr, format, args);
fprintf (stderr, ": ");
}
if (errnum)
fprintf (stderr, "%s", pdf_error_errlist[errnum-1]);
fprintf (stderr, ".\n");
fflush (stderr);
pdf_error_message_count++;
if (status)
exit (status);
}
--- end of pdf-error.c ---
-gerel
- [pdf-devel] Error module: first lines,
gerel <=
- [pdf-devel] Error module: first lines, gerel, 2007/12/15
- Re: [pdf-devel] Error module: first lines, Behdad Esfahbod, 2007/12/16
- Re: [pdf-devel] Error module: first lines, gerel, 2007/12/17
- Re: [pdf-devel] Error module: first lines, jemarch, 2007/12/17
- Re: [pdf-devel] Error module: first lines, gerel, 2007/12/17
- Re: [pdf-devel] Error module: first lines, Behdad Esfahbod, 2007/12/17
- Re: [pdf-devel] Error module: first lines, gerel, 2007/12/18
- Re: [pdf-devel] Error module: first lines, Behdad Esfahbod, 2007/12/18
- Re: [pdf-devel] Error module: first lines, jemarch, 2007/12/19