AcePerl

 view release on metacpan or  search on metacpan

acelib/messubs.c  view on Meta::CPAN


  /* Format the message string.                                              */
  ACEFORMATSTRING(args, format, mesg_buf, prefix, NULL, 0) ;

  if (exitRoutine)
    (*exitRoutine)(mesg_buf) ;
  else
    fprintf (stderr, "%s\n", mesg_buf) ;

#if defined(MACINTOSH)
  crashOut(mesg_buf) ;
#else
  messdump(mesg_buf) ;

  exit(EXIT_FAILURE) ;
#endif

  return ;					  /* Should never get here. */
  }


/*******************************/

/* This is the routine called by the messcrash macro (see regular.h) which   */
/* actually does the message/handling and exit.                              */
/* This routine may encounter errors itself, in which case it will attempt   */
/* to call itself to report the error. To avoid infinite recursion we limit  */
/* this to just one reporting of an internal error and then we abort.        */
/*                                                                           */
UTIL_FUNC_DEF void uMessCrash(char *format, ...)
  {
  enum {MAXERRORS = 1} ;
  static int internalErrors = 0 ;
  static char prefix[1024] ;
  int rc ;
  char *mesg_buf = NULL ;
  va_list args ;

  /* Check for recursive calls and abort if necessary.                       */
  if (internalErrors > MAXERRORS) 
    {
      fprintf (stderr, "%s : fatal internal error, abort", 
	       messageG.progname);
      abort() ;
    }
  else internalErrors++ ;

  /* Construct the message prefix, adding the program name if possible.      */
  if (messGetErrorProgram() == NULL)
       rc = sprintf(prefix, CRASH_PREFIX_FORMAT, messGetErrorFile(), messGetErrorLine()) ;
  else
       rc = sprintf(prefix, FULL_CRASH_PREFIX_FORMAT,
		    messGetErrorProgram(), messGetErrorFile(), messGetErrorLine()) ;
  if (rc < 0) messcrash("sprintf failed") ;


  /* Format the message string.                                              */
  ACEFORMATSTRING(args, format, mesg_buf, prefix, NULL, 0) ;


  if (crashJmpBuf)		/* throw back up to the function that registered it */
    longjmp(*crashJmpBuf, 1) ;

  
#if defined(MACINTOSH)
  crashOut(mesg_buf) ;
#else
  messdump(mesg_buf) ;

  if (crashRoutine)
    (*crashRoutine)(mesg_buf) ;
  else
    fprintf(stderr, "%s\n", mesg_buf) ;

  invokeDebugger() ;

  exit(EXIT_FAILURE) ;
#endif

  return ;					  /* Should never get here. */
  }





/******* interface to crash/error trapping *******/

UTIL_FUNC_DEF jmp_buf* messCatchError (jmp_buf* new)
{
  jmp_buf* old = errorJmpBuf ;
  errorJmpBuf = new ;
  return old ;
}

UTIL_FUNC_DEF jmp_buf* messCatchCrash (jmp_buf* new)
{
  jmp_buf* old = crashJmpBuf ;
  crashJmpBuf = new ;
  return old ;
}

UTIL_FUNC_DEF char* messCaughtMessage (void) { return messbuf ; }



/* Message formatting routines.                                              */
/*                                                                           */
/*                                                                           */

/* This function writes into its own buffer, note that this has finite size  */
/* see top of file: BUFSIZE, also note that subsequent calls will overwrite  */
/* this buffer.                                                              */
/*                                                                           */
UTIL_FUNC_DEF char *messprintf (char *format, ...)
  {
  static char buffer[BUFSIZE] ;
  char *mesg_buf ;
  va_list args ;

  /* Format the message string.                                              */



( run in 2.365 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )