pdf-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pdf-devel] Error module implementation


From: gerel
Subject: [pdf-devel] Error module implementation
Date: Sat, 23 Feb 2008 13:04:41 -0300

Well, here I have a first version of the API.  As for the error predefined
messages (pdf_error_stlist), I'm not sure if they are of use to the client.


--- pdf-error.h ---
/* Time-stamp: <2008-02-23 12:24:52 gerel> */

#ifndef PDF_ERROR_H
#define PDF_ERROR_H

#ifdef HAVE_DEBUG_BASE
#define PDF_DEBUG_BASE(message, ...) do{ \
  pdf_error (0, stderr, "***DEBUG BASE***:%s:%d: " message, \
  __FILE__, __LINE__, __VA_ARGS__); \
  } while (0)
#else
#define PDF_DEBUG_BASE ""
#endif /* HAVE_DEBUG_BASE */

#ifdef HAVE_DEBUG_OBJECT
#define PDF_DEBUG_OBJECT(message, ...) do{ \
  pdf_error (0, stderr, "***DEBUG OBJECT***:%s:%d: " message, \
  __FILE__, __LINE__, __VA_ARGS__); \
  } while (0)
#else
#define PDF_DEBUG_OBJECT ""
#endif /* HAVE_DEBUG_OBJECT */

#ifdef HAVE_DEBUG_DOCUMENT
#define PDF_DEBUG_DOCUMENT(message, ...) do{ \
  pdf_error (0, stderr, "***DEBUG DOCUMENT***:%s:%d: " message, \
  __FILE__, __LINE__, __VA_ARGS__); \
  } while (0)
#else
#define PDF_DEBUG_DOCUMENT ""
#endif /* HAVE_DEBUG_DOCUMENT */

#ifdef HAVE_DEBUG_PAGE
#define PDF_DEBUG_PAGE(message, ...) do{ \
  pdf_error (0, stderr, "***DEBUG PAGE***:%s:%d: " message, \
  __FILE__, __LINE__, __VA_ARGS__); \
  } while (0)
#else
#define PDF_DEBUG_PAGE ""
#endif /* HAVE_DEBUG_PAGE */


/* TODO: add missing status codes */
typedef enum 
{
        PDF_OK = 0,
        PDF_ERROR,
        PDF_EBADDATA,
        PDF_ENOMEM,
        PDF_EEOF,
        PDF_EDIVBYZERO,
        PDF_ENONODE,
        PDF_EINVRANGE,
        PDF_ETEXTENC,
        PDF_ENOMATCH,
        PDF_STATUS_ITEMS
} pdf_status_t;

extern const char * pdf_error_stlist [];

/* Print a message with `fprintf (fd, FORMAT, ...)';
   if status is nonzero, print the corresponding message. */
extern void pdf_error (pdf_status_t status, FILE * fd, const char *format, ...);

/* Print the message corresponding to 'status' to stderr
 * followed by 'str'.
 */
extern void pdf_perror (pdf_status_t status, const char *str);

/* 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 */

--- EOF pdf-error.h ---


--- pdf-error.c ---
/* Time-stamp: <2008-02-23 12:21:26 gerel> */

#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include <pdf-error.h>

/* Update this list according to pdf_status_t. */
const char * pdf_error_stlist [] =
  {
          "serious error",
          "invalid or bad arguments",
          "insufficient memory",
          "end of file",
          "divison by zero",
          "no node found",
          "invalid range",
          "error in text encoding",
          "no matching found"
  };

int pdf_error_one_per_line = 1;

void
pdf_perror (pdf_status_t status, const char *str)
{ 
  pdf_error ((int) status, stderr, str);
}


void
pdf_error (pdf_status_t status, FILE * fd, const char *format, ...)
{
  va_list args;
  int errnum;

  errnum = (int) status;
  
  fprintf (fd, "GNU PDF");

  if (format != NULL)
    {
      fprintf (fd, ": ");
      va_start (args, format);
      vfprintf (fd, format, args);
    }

  if (errnum >  0 && errnum < PDF_STATUS_ITEMS)
    fprintf (fd, ": %s", pdf_error_stlist[errnum-1]);
  
  fprintf (fd, pdf_error_one_per_line ? ".\n" : ". ");
  fflush (fd);

}

--- EOF pdf-error.c ---


Comments are welcome.

BTW we said we won't abort the program by any way, although PDF_ENOMEM
comes to my mind :-/

cheers

-gerel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]