AcePerl

 view release on metacpan or  search on metacpan

acelib/messubs.c  view on Meta::CPAN

va_end(FORMAT_ARGS) ;

static char *uMessFormat(va_list args, char *format, char *prefix,
			 char *buffer, unsigned int buflen) ;


/* Some standard defines for titles/text for messages:                       */
/*                                                                           */
#define ERROR_PREFIX "ERROR: "
#define EXIT_PREFIX "EXIT: "
#define CRASH_PREFIX_FORMAT "FATAL ERROR reported by %s at line %d: "
#define FULL_CRASH_PREFIX_FORMAT "FATAL ERROR reported by program %s, in file %s, at line %d: "
#if defined(MACINTOSH)
#define SYSERR_FORMAT "system error %d"
#else
#define SYSERR_FORMAT "system error %d - %s"
#endif
#define PROGNAME "The program"

/* messcrash now reports the file/line no. where the messcrash was issued    */
/* as an aid to debugging. We do this using a static structure which holds   */
/* the information and a macro version of messcrash (see regular.h), the     */
/* structure elements are retrieved using access functions.                  */
typedef struct _MessErrorInfo
  {
  char *progname ;				  /* Name of executable reporting error. */
  char *filename ;				  /* Filename where error reported */
  int line_num ;				  /* Line number of file where error
						     reported. */
  } MessErrorInfo ;

static MessErrorInfo messageG = {NULL, NULL, 0} ;

static int messGetErrorLine() ;
static char *messGetErrorFile() ;


/* Keeps a running total of errors so far (incremented whenever messerror is */
/* called).                                                                  */
static int errorCount_G = 0 ;


/* Function pointers for application supplied routines that are called when  */
/* ever messerror or messcrash are called, enables application to take       */
/* action on all such errors.                                                */
static jmp_buf *errorJmpBuf = 0 ;
static jmp_buf *crashJmpBuf = 0 ;



/***************************************************************/
/********* call backs and functions to register them ***********/

static VoidRoutine	  beepRoutine = 0 ;
static OutRoutine	  outRoutine = 0 ;
static OutRoutine	  dumpRoutine = 0 ;
static OutRoutine	  errorRoutine = 0 ;
static OutRoutine	  exitRoutine = 0 ;
static OutRoutine	  crashRoutine = 0 ;
static QueryRoutine	  queryRoutine = 0 ;
static PromptRoutine	  promptRoutine = 0 ;
static IsInterruptRoutine isInterruptRoutine = 0 ;

UTIL_FUNC_DEF VoidRoutine messBeepRegister (VoidRoutine func)
{ VoidRoutine old = beepRoutine ; beepRoutine = func ; return old ; }

UTIL_FUNC_DEF OutRoutine messOutRegister (OutRoutine func)
{ OutRoutine old = outRoutine ; outRoutine = func ; return old ; }

UTIL_FUNC_DEF OutRoutine messDumpRegister (OutRoutine func)
{ OutRoutine old = dumpRoutine ; dumpRoutine = func ; return old ; }

UTIL_FUNC_DEF OutRoutine messErrorRegister (OutRoutine func)
{ OutRoutine old = errorRoutine ; errorRoutine = func ; return old ; }

UTIL_FUNC_DEF OutRoutine messExitRegister (OutRoutine func)
{ OutRoutine old = exitRoutine ; exitRoutine = func ; return old ; }

UTIL_FUNC_DEF OutRoutine messCrashRegister (OutRoutine func)
{ OutRoutine old = crashRoutine ; crashRoutine = func ; return old ; }

UTIL_FUNC_DEF QueryRoutine messQueryRegister (QueryRoutine func)
{ QueryRoutine old = queryRoutine ; queryRoutine = func ; return old ; }

UTIL_FUNC_DEF PromptRoutine messPromptRegister (PromptRoutine func)
{ PromptRoutine old = promptRoutine ; promptRoutine = func ; return old ; }

UTIL_FUNC_DEF IsInterruptRoutine messIsInterruptRegister (IsInterruptRoutine func)
{ IsInterruptRoutine old = isInterruptRoutine ; isInterruptRoutine = func ; return old ; }



/***************************************************/
UTIL_FUNC_DEF BOOL messIsInterruptCalled (void)
{
  if (isInterruptRoutine)
    return (*isInterruptRoutine)() ;

  /* unless a routine is registered, we assume no interrupt
     (e.g. F4 keypress in graph-window) has been called */
  return FALSE;
}


/* The message output routines.                                              */
/*                                                                           */
/*                                                                           */


/***************************************************/
UTIL_FUNC_DEF void messbeep (void)
{
  if (beepRoutine)
    (*beepRoutine)() ;
  else
    { freeOutf ("%c",0x07) ;  /* bell character, I hope */
      fflush (stdout) ;	/* added by fw 02.Feb 1994 */
    }
}


/*******************************/
UTIL_FUNC_DEF void messout (char *format,...)
{
  va_list args ;
  char *mesg_buf ;

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

  if (outRoutine)
    (*outRoutine)(mesg_buf) ;
  else
    fprintf (stdout, "//!! %s\n", mesg_buf) ;

}

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

UTIL_FUNC_DEF BOOL messPrompt (char *prompt, char *dfault, char *fmt)
{ 
  BOOL answer ;
  
  if (promptRoutine)
    answer = (*promptRoutine)(prompt, dfault, fmt) ;
  else
    answer = freeprompt (prompt, dfault, fmt) ;

  return answer ;
}

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

UTIL_FUNC_DEF BOOL messQuery (char *format,...)
{ 
  BOOL answer ;
  char *mesg_buf = NULL ;
  va_list args ;

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

  if (queryRoutine)
    answer = (*queryRoutine)(mesg_buf) ;
  else
    answer = freequery (mesg_buf) ;

  return answer ;
}

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

UTIL_FUNC_DEF void messdump (char *format,...)
{
  static char dumpbuf[BUFSIZE] ;		  /* BEWARE limited buffer size. */
  char *mesg_buf ;
  va_list args ;

  /* Format the message string.                                              */
  ACEFORMATSTRING(args, format, mesg_buf, NULL, &dumpbuf[0], BUFSIZE)

  strcat (mesg_buf, "\n") ;			  /* assume we are writing to a file */

  if (dumpRoutine)
    (*dumpRoutine)(mesg_buf) ;
}


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


/* Access function for returning running error total.                        */
UTIL_FUNC_DEF int messErrorCount (void) { return errorCount_G ; }


/* Output a non-fatal error message, for all messages a call to messdump is  */
/* made which may result in the message being logged. The single error count */
/* is also incremented so that functions can use this to check how many      */
/* errors have been recorded so far.                                         */
UTIL_FUNC_DEF void messerror (char *format, ...)
{
  char *prefix = ERROR_PREFIX ;
  char *mesg_buf = NULL ;
  va_list args ;

  /* always increment the error count.                                       */
  ++errorCount_G ;



( run in 0.714 second using v1.01-cache-2.11-cpan-6aa56a78535 )