home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / jpegsrc.v3.lzh / jerror.c < prev    next >
Text File  |  1992-07-02  |  2KB  |  73 lines

  1. /*
  2.  * jerror.c
  3.  *
  4.  * Copyright (C) 1991, 1992, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains simple error-reporting and trace-message routines.
  9.  * These are suitable for Unix-like systems and others where writing to
  10.  * stderr is the right thing to do.  If the JPEG software is integrated
  11.  * into a larger application, you may well need to replace these.
  12.  *
  13.  * The error_exit() routine should not return to its caller.  Within a
  14.  * larger application, you might want to have it do a longjmp() to return
  15.  * control to the outer user interface routine.  This should work since
  16.  * the portable JPEG code doesn't use setjmp/longjmp.  You should make sure
  17.  * that free_all is called either within error_exit or after the return to
  18.  * the outer-level routine.
  19.  *
  20.  * These routines are used by both the compression and decompression code.
  21.  */
  22.  
  23. #include "jinclude.h"
  24. #ifdef INCLUDES_ARE_ANSI
  25. #include <stdlib.h>        /* to declare exit() */
  26. #endif
  27.  
  28. #ifndef EXIT_FAILURE        /* define exit() codes if not provided */
  29. #define EXIT_FAILURE  1
  30. #endif
  31.  
  32.  
  33. static external_methods_ptr methods; /* saved for access to message_parm, free_all */
  34.  
  35.  
  36. METHODDEF void
  37. trace_message (const char *msgtext)
  38. {
  39.   fprintf(stderr, msgtext,
  40.       methods->message_parm[0], methods->message_parm[1],
  41.       methods->message_parm[2], methods->message_parm[3],
  42.       methods->message_parm[4], methods->message_parm[5],
  43.       methods->message_parm[6], methods->message_parm[7]);
  44.   fprintf(stderr, "\n");
  45. }
  46.  
  47.  
  48. METHODDEF void
  49. error_exit (const char *msgtext)
  50. {
  51.   trace_message(msgtext);
  52.   (*methods->free_all) ();    /* clean up memory allocation */
  53.   exit(EXIT_FAILURE);
  54. }
  55.  
  56.  
  57. /*
  58.  * The method selection routine for simple error handling.
  59.  * The system-dependent setup routine should call this routine
  60.  * to install the necessary method pointers in the supplied struct.
  61.  */
  62.  
  63. GLOBAL void
  64. jselerror (external_methods_ptr emethods)
  65. {
  66.   methods = emethods;        /* save struct addr for later access */
  67.  
  68.   emethods->error_exit = error_exit;
  69.   emethods->trace_message = trace_message;
  70.  
  71.   emethods->trace_level = 0;    /* default = no tracing */
  72. }
  73.