werror.c 1.24 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1 2 3 4 5 6 7 8 9
/* werror.c
 *
 */

#include "werror.h"

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

10 11 12
int debug_flag = 0;
int quiet_flag = 0;

Niels Möller's avatar
Niels Möller committed
13 14 15 16
void werror(char *format, ...) 
{
  va_list args;

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  if (!quiet_flag)
    {
      va_start(args, format);
      vfprintf(stderr, format, args);
      va_end(args);
    }
}

void debug(char *format, ...) 
{
  va_list args;

  if (debug_flag)
    {
      va_start(args, format);
      vfprintf(stderr, format, args);
      va_end(args);
    }
}

/* Escape non-printable characters. */
void werror_washed(UINT32 length, UINT8 *msg)
{
  int i;

  for(i = 0; i<lengh; i++)
    {
      switch(msg[i])
	{
	case '\\':
	  fputs("\\\\", stderr);
	  break;
	case '\r':
	  /* Ignore */
	  break;
	default:
	  if (!isprint(msg[i]))
	    {
	      fprintf("\\x%2x", msg[i]);
	      break;
	    }
	  /* Fall through */
	case '\n':
	  putc('\n', stderr);
	  break;
	}
    }
}

/* For outputting data recieved from the other end */
void werror_safe(UINT32 length, UINT8 *msg)
{
  if (!quiet_flag)
    werror_washed(length, msg);
}

void debug_safe(UINT32 length, UINT8 *msg)
{
  if (debug_flag)
    werror_washed(length, msg);
Niels Möller's avatar
Niels Möller committed
77 78 79 80 81 82 83 84 85 86 87 88
}

void fatal(char *format, ...) 
{
  va_list args;

  va_start(args, format);
  vfprintf(stderr, format, args);
  va_end(args);

  abort();
}