File: z_error.cpp

package info (click to toggle)
glhack 1.2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,744 kB
  • sloc: ansic: 208,571; cpp: 13,139; yacc: 2,005; makefile: 1,152; lex: 377; sh: 121; awk: 89; sed: 11
file content (81 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
77
78
79
80
81
//----------------------------------------------------------------------------
//  ERROR and debugging
//----------------------------------------------------------------------------
//
//  Z C++ Lib (C) 2001-2002 Andrew Apted
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//------------------------------------------------------------------------

using namespace std;

#include "z_config.h"
#include "z_error.h"

//
// Fatal
//
// Terminates the program, reporting the error.
//
void Z_Error::Fatal(const char *str, ...)
{
  char buffer[2048];

  // create message
  va_list args;

  va_start(args, str);
  vsprintf(buffer, str, args);
  va_end(args);

  if (buffer[0] == 0 || buffer[strlen(buffer)-1] != '\n')
    strcat(buffer, "\n");

  fprintf(stderr, "\n\n*** FATAL ERROR ***\n\n%s\n", buffer);
      
  exit(10);
}

//
// Debug
//
// FIXME: this code is platform specific (and hack-ish).
//
void Z_Error::Debug(const char *str, ...)
{
#ifndef NDEBUG
  static FILE *debug_fp = 0;

  if (! debug_fp)
  {
    debug_fp = fopen("/tmp/debug.txt", "w");

    if (! debug_fp)
    {
      Z_Error::Fatal("Unable to open: /tmp/debug.txt\n");
    }
  }

  char buffer[2048];

  // create message
  va_list args;

  va_start(args, str);
  vsprintf(buffer, str, args);
  va_end(args);

  fprintf(debug_fp, "%s", buffer);
#else
  (void) str;
#endif
}