| Close | Back |
1 /*
2 * status.h
3 *
4 *****************************************************************************
5 *
6 * Status / Error / Warning Display for C
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *****************************************************************************
9 *
10 * Author : Rajesh _ThE gReAt
11 * Built on : Sunday, January 27, 2002, 10:10:09 AM
12 * Last Modified on : Friday, February 08, 2002, 3:29:04 PM
13 *
14 * Known errors : Modifies / uses constants used by hprintf.h .
15 *
16 *****************************************************************************
17 * DISCLAIMER:
18 *****************************************************************************
19 *
20 * Programmers may incorporate any or all code into their programs,
21 * giving proper credit within the source. Publication of the
22 * source routines is permitted so long as proper credit is given
23 * to Rajesh _ThE gReAt.
24 *
25 * Copyright (C) 2002, 2003 by Rajesh _ThE gReAt. You may use this program, or
26 * code or tables extracted from it, as desired without restriction.
27 * I can not and will not be held responsible for any damage caused from
28 * the use of this software.
29 *
30 * Read license.txt from http://www.rajeshgoli.com/license.txt
31 * or http://www.rajeshgoli.com/license.htm
32 * before using / distributing / or any sort of use of my source
33 * Also read my disclaimer http://www.rajeshgoli.com/disclaimer.htm
34 *
35 * YOU AGREE TO BE BOUND BY MY DISCLAIMER AND LICENSE BY IN ANY WAY
36 * USING THIS FILE .
37 *
38 *****************************************************************************
39 * This source works with Turbo C 2.0 and Turbo C++ 3.0 and above.
40 *****************************************************************************
41 * Rajesh _ThE gReAt is a synonym of Rajesh Goli
42 * Source freely distributable
43 *****************************************************************************/
44
45 #ifndef __STATUS_H
46 #define __STATUS_H
47 #endif
48
49 #ifndef NORM_COLOR
50 #define NORM_COLOR LIGHTGRAY
51 #endif
52
53 #ifndef WARNING_COLOR
54 #define WARNING_COLOR LIGHTCYAN
55 #endif
56
57 #ifndef ERROR_COLOR
58 #define ERROR_COLOR LIGHTRED
59 #endif
60
61 #ifndef STATUS_COLOR
62 #define STATUS_COLOR LIGHTGREEN
63 #endif
64
65 #ifndef FATAL_COLOR
66 #define FATAL_COLOR LIGHTRED + BLINK
67 #endif
68
69 #ifndef FATAL_TEXT
70 #define FATAL_TEXT LIGHTRED
71 #endif
72
73 #ifndef __HPRINTF_H
74 #include "hprintf.h"
75 #endif
76
77 #ifndef __CONIO_H
78 #include "conio.h"
79 #endif
80
81 #ifndef __STRING_H
82 #include "string.h"
83 #endif
84
85 #define ENDX 80
86
87 #ifndef DOESNT_FIT
88 #define DOESNT_FIT -1
89 #endif
90
91 #ifndef SUCCESS
92 #define SUCCESS 1
93 #endif
94
95 #define ERROR 0
96 #define ER ERROR
97
98 #define STATUS 1
99 #define ST STATUS
100
101 #define WARNING 2
102 #define WR WARNING
103
104 #define FATAL 3
105 #define FT FATAL
106
107 #ifndef STATX
108 #define STATX 5
109 #endif
110
111 #ifndef STATY
112 #define STATY 23
113 #endif
114
115 #define INIT_CLEAR_LINE int sx,sy;
116 #define CLEAR_LINE sx = wherex(); sy = wherey(); while(wherex() <= ENDX - 1) printf(" "); printf(" "); gotoxy(sx,sy);
117
118 int status(char *,short ,short );
119 #if(defined(AP))
120 int astatus(char *,short ,short ,int ,int ,...);
121 #else
122 int astatus(char *,short ,short ,int ,int);
123 #endif
124
125 int status(char *msg,short err_stat,short wait)
126 {
127 int x,y,len;
128 INIT_CLEAR_LINE ;
129 x = wherex();
130 y = wherey();
131
132 gotoxy(STATX,STATY);
133 CLEAR_LINE ;
134
135 if(*msg == NULL)
136 {
137 gotoxy(x,y);
138 return SUCCESS;
139 }
140
141 if(err_stat == ERROR)
142 len = strlen("ERROR : ");
143 else if(err_stat == STATUS)
144 len = strlen("Status : ");
145 else if(err_stat == WARNING)
146 len = strlen("WARNING : ");
147 else if(err_stat == FATAL)
148 len = strlen("!FATAL! : ");
149
150 len += strlen(msg);
151
152 if(wait)
153 len += strlen(" : Hit a key to continue ...");
154
155 if( (len + STATX) > ENDX )
156 {
157 gotoxy(x,y);
158 return DOESNT_FIT;
159 }
160
161 if(err_stat == ERROR)
162 __hprintf("<ERROR> : ",NORM_COLOR,"<",">",ERROR_COLOR);
163 else if(err_stat == STATUS)
164 __hprintf("<Status> : ",NORM_COLOR,"<",">",STATUS_COLOR);
165 else if(err_stat == WARNING)
166 __hprintf("<WARNING> : ",NORM_COLOR,"<",">",WARNING_COLOR);
167 else if(err_stat == FATAL)
168 __hprintf("<!>[FATAL]<!> : ",NORM_COLOR,"<[",">]",FATAL_COLOR,FATAL_TEXT);
169 printf("%s",msg);
170
171 if(wait)
172 {
173 if(err_stat != FATAL)
174 printf(" : Hit a key to continue ...");
175 else
176 printf(" : Hit a key to halt ...");
177 getch();
178 gotoxy(STATX,STATY);
179 CLEAR_LINE ;
180 }
181 gotoxy(x,y);
182 return SUCCESS;
183 }
184
185 #ifndef __STDARG_H
186 #include <stdarg.h
187 #endif
188
189 #if(defined(AP))
190 int astatus(char *msg,short err_stat,short wait,int normcolor,int hcolor,...)
191 #else
192 int astatus(char *msg,short err_stat,short wait,int normcolor,int hcolor)
193 #endif
194 {
195 int x,y,len;
196 #if(defined(AP))
197 va_list ap;
198 #endif
199 INIT_CLEAR_LINE ;
200 x = wherex();
201 y = wherey();
202
203 #if(defined(AP))
204 va_start(ap,hcolor);
205 #endif
206 gotoxy(STATX,STATY);
207 CLEAR_LINE ;
208
209 if(*msg == NULL)
210 {
211 gotoxy(x,y);
212 return SUCCESS;
213 }
214
215 if(err_stat == ERROR)
216 len = strlen("ERROR : ");
217 else if(err_stat == STATUS)
218 len = strlen("Status : ");
219 else if(err_stat == WARNING)
220 len = strlen("WARNING : ");
221 else if(err_stat == FATAL)
222 len = strlen("!FATAL! : ");
223
224 len += strlen(msg);
225
226 if(wait)
227 len += strlen(" : Hit a key to continue ...");
228
229 if( (len + STATX) > ENDX )
230 {
231 gotoxy(x,y);
232 return DOESNT_FIT;
233 }
234
235 if(err_stat == ERROR)
236 __hprintf("<ERROR> : ",normcolor,"<",">",hcolor);
237 else if(err_stat == STATUS)
238 __hprintf("<Status> : ",normcolor,"<",">",hcolor);
239 else if(err_stat == WARNING)
240 __hprintf("<WARNING> : ",normcolor,"<",">",hcolor);
241 else if(err_stat == FATAL)
242 #if(defined(AP))
243 __hprintf("<!>[FATAL]<!> : ",normcolor,"<[",">]",va_arg(ap,int),hcolor);
244 #else
245 __hprintf("<!>[FATAL]<!> : ",normcolor,"<[",">]",hcolor + BLINK,hcolor);
246 #endif
247 printf("%s",msg);
248
249 if(wait)
250 {
251 if(err_stat != FATAL)
252 printf(" : Hit a key to continue ...");
253 else
254 printf(" : Hit a key to halt ...");
255 getch();
256 gotoxy(STATX,STATY);
257 CLEAR_LINE ;
258 }
259 gotoxy(x,y);
260 return SUCCESS;
261 }