-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha_err.cpp
126 lines (103 loc) · 2.86 KB
/
a_err.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// ****************************************************************
// * PCP *
// * Copyright (C)1999 Dark Nova Software (DNS) *
// * All Rights Reserved. *
// * *
// * File: a_err.c *
// * Author: vecna *
// * Portability: All systems *
// * Description: Error reporting / Logfile routines *
// * *
// * Note: The memory for each node in the Shutdown linked list *
// * is allocated with qvalloc. It will not show up on *
// * memory allocation lists. If there seems to be bugs *
// * related to the shutdown routines, it might be a good *
// * idea to use valloc() with PARANOID and check for chunk *
// * corruption. *
// ****************************************************************
#include "pcp.h"
#define LOGFILE "verge.log"
// ***************************** Data *****************************
typedef struct shutdownType
{
char name[50];
void (*Funcptr) (void);
struct shutdownType *next;
} ShutdownType;
struct shutdownType *shutdown_top;
FILE *logf;
// ***************************** Code *****************************
void InitErrorSystem(void)
{
remove(LOGFILE);
shutdown_top = 0;
}
void AddShutdownProc(void (*FuncPtr) (void), const char *name)
{
ShutdownType *n;
n = (ShutdownType *) malloc(sizeof(ShutdownType));
vstrncpy(n -> name, name, 50);
n -> Funcptr = FuncPtr;
n -> next = shutdown_top;
shutdown_top = n;
}
void err_Shutdown()
{
ShutdownType *n;
n = shutdown_top;
while (n)
{
n -> Funcptr();
n = n -> next;
}
}
void err(const char *s, ...)
{
va_list argptr;
char msg[256];
va_start(argptr,s);
vsprintf(msg,s,argptr);
va_end(argptr);
err_Shutdown();
vExit(msg);
}
void Log(const char *text, ...)
{
va_list argptr;
char msg[256];
va_start(argptr, text);
vsprintf(msg, text, argptr);
va_end(argptr);
logf=fopen(LOGFILE,"aw");
fprintf(logf,"%s\n",msg);
fflush(logf);
fclose(logf);
}
void Logp(char *text, ...)
{
va_list argptr;
char msg[256];
va_start(argptr, text);
vsprintf(msg, text, argptr);
va_end(argptr);
logf=fopen(LOGFILE,"aw");
fprintf(logf,"%s",msg);
fflush(logf);
fclose(logf);
}
void LogDone(void)
{
logf=fopen(LOGFILE,"aw");
fprintf(logf," ... OK \n");
fflush(logf);
fclose(logf);
}
char *va(char* format, ...)
{
va_list argptr;
static char string[1024];
va_start(argptr, format);
vsprintf(string, format, argptr);
va_end(argptr);
return string;
}