-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.c
More file actions
139 lines (118 loc) · 3.64 KB
/
Copy patherror.c
File metadata and controls
139 lines (118 loc) · 3.64 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
** Copyright 1998-2008, Pete J. Jensen
** All Rights Reserved.
**
** This is UNPUBLISHED PROPRIETARY SOURCE CODE of the authors
** the contents of this file may not be disclosed to third parties, copied or
** duplicated in any form, in whole or in part, without the prior written
** permission of the authors.
**
** RESTRICTED RIGHTS LEGEND:
** Use, duplication or disclosure by the Government is subject to restrictions
** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
** rights reserved under the Copyright Laws of the United States.
**
** ______
** /_____/\
** /_____\\ \ FILE: error.c
** /_____\ \\ / AUTHOR: Pete Jensen
** /_____/ \/ / /
** /_____/ / \//\ VERSION: 1.0.0
** \_____\//\ / /
** \_____/ / /\ /
** \_____/ \\ \
** \_____\ \\
** \_____\/
**/
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <dir.h>
#include <alloc.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <io.h>
#include <limits.h>
#include "error.h"
#include "graph.h"
#include "globals.h"
/*
* Function: errorHandler
* Purpose : To handler errors for the program; and log all erorrs to the
* errorLog file as defined in the header file.
* Inputs : The error message.
* Returns : Void
* Modifies: errorlog.
* Error Checking : Failed closing file.
* Failed logging error.
* Sample Call : errorHandler("Could not go to sleep");
*/
void errorHandlerLvl(char *message, int level)
{
FILE *fp;
if ((fp = fopen(ERRORLOG, "a")) != NULL)
{
fprintf(fp, "\nERROR: %s\n", message);
fprintf(stderr, "\n\nERROR: %s\n", message);
if (fclose(fp) == EOF)
fprintf(stderr, "\n\nFailed to close file.");
}
else
{
/* Display Errors To StdErr since we could not log to a file. */
fprintf(stderr, "\a\nERROR *** : %s\n", message);
fprintf(stderr, "\n\nFATAL ERROR: Failed logging Error\n");
}
if (level == ERROR_SEVERE){
/* This Happens Weather we logged the error or not. */
fprintf(stderr, "(press any key to continue)\n");
getch();
// End the graphics mode
endGraphicsMode();
// Clear the screen
clrscr();
exit(EXIT_FAILURE);
}
}
/*
* Function: errorHandler
* Purpose : To handler errors for the program; and log all erorrs to the
* errorLog file as defined in the header file.
* Inputs : The error message.
* Returns : Void
* Modifies: errorlog.
* Error Checking : Failed closing file.
* Failed logging error.
* Sample Call : errorHandler("Could not go to sleep");
*/
void errorHandler(char *message)
{
FILE *fp;
// End the graphics mode
endGraphicsMode();
// Clear the screen
clrscr();
if ((fp = fopen(ERRORLOG, "a")) != NULL)
{
fprintf(fp, "\nERROR: %s\n", message);
fprintf(stderr, "\n\nERROR: %s\n", message);
if (fclose(fp) == EOF)
fprintf(stderr, "\n\nFailed to close file.");
}
else
{
/* Display Errors To StdErr since we could not log to a file. */
fprintf(stderr, "\a\nERROR *** : %s\n", message);
fprintf(stderr, "\n\nFATAL ERROR: Failed logging Error\n");
}
/* This Happens Weather we logged the error or not. */
fprintf(stderr, "(press any key to continue)\n");
getch();
exit(EXIT_FAILURE);
}