1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: kstddef.h,v 1.14 2000/06/07 03:49:54 kevin Exp $
7 ** Revision 1.14 2000/06/07 03:49:54 kevin
8 ** *** empty log message ***
10 ** Revision 1.13 2000/06/07 00:59:38 kevin
13 ** Revision 1.12 2000/06/05 01:32:45 kevin
14 ** Added C++ compatibility
16 ** Revision 1.11 2000/06/03 06:29:08 kevin
17 ** *** empty log message ***
19 ** Revision 1.10 2000/05/16 04:33:17 kevin
20 ** Updated documentation
22 ** Revision 1.9 2000/05/11 01:04:44 kevin
23 ** Added Microsoft Windows compatibility
25 ** Revision 1.8 2000/05/08 20:00:48 kevin
28 ** Revision 1.7 2000/05/07 12:46:19 kevin
29 ** made c++ compatible
31 ** Revision 1.6 2000/05/03 19:51:41 kevin
32 ** function renaming for phantoms and phantom elements
34 ** Revision 1.5 2000/05/02 20:00:25 kevin
35 ** *** empty log message ***
37 ** Revision 1.4 2000/04/28 18:00:55 kevin
38 ** remove unused files
40 ** Revision 1.3 2000/04/28 17:38:16 kevin
41 ** Removed unused files
43 ** Revision 1.2 2000/04/28 14:14:16 kevin
44 ** *** empty log message ***
47 ** This program is free software; you can redistribute it and/or modify
48 ** it under the terms of the GNU General Public License (version 2) as
49 ** published by the Free Software Foundation.
51 ** This program is distributed in the hope that it will be useful,
52 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
53 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54 ** GNU General Public License for more details.
56 ** You should have received a copy of the GNU General Public License
57 ** along with this program; if not, write to the Free Software
58 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
59 ******************************************************************************/
61 /******************************************************************************
66 * Author: Kevin Rosenberg
67 * Purpose: Header file containing KRL standard C definitions
68 * Date Started: Dec. 83
71 * Header file contains KRL standard C definitions
75 *****************************************************************************/
85 #define snprintf _snprintf
88 #if !defined(bool) && !defined(__cplusplus)
89 typedef int bool; /* Boolean variable type */
92 #define STR_MAX_LEN 255
93 #define STR_SIZE STR_MAX_LEN+1
95 #if !defined(__cplusplus)
96 typedef unsigned char string[STR_SIZE];
113 /*----------------------------------------------------------------------*/
115 #define SHOW(var, fmt) fprintf (stderr, "var = fmt\n", var)
117 /*----------------------------------------------------------------------*/
123 #define ETX 26 /* end of text signal for PC-DOS */
125 /*----------------------------------------------------------------------*/
127 #define MAXPATHNAME 65 /* max length of pathname + 1 */
128 #define MAXFILENAME 13 /* rootname(8) + '.'(1) + extension(3) + EOS */
129 #define MAXROOTNAME 8
131 #define MAXFULLNAME MAXPATHNAME + MAXFILENAME
133 /*----------------------------------------------------------------------*/
135 #define ABS(x) ((x) < 0 ? -(x) : (x))
136 #define SQR(x) ((x) * (x))
139 #define MAX(a,b) ((a) > (b) ? (a) : (b))
142 #define MIN(a,b) ((a) <= (b) ? (a) : (b))
144 #define ISWAP(a,b) {int i; i = a; a = b; b = i;}
146 #define CLIP(n,lb,ub) if (n < lb) n = lb; else if (n > ub) n = ub
147 #define STR_EQUAL(s1,s2) (strcmp (s1, s2) == 0)
149 /*----------------------------------------------------------------------*/
152 int hour, minute, second, ms;
156 int year, month, date, dow;
164 typedef struct time_st TIME;
165 typedef struct date_st DATE;
166 typedef struct timedate_st TIMEDATE;
168 /*----------------------------------------------------------------------*/
170 #define ERR_WARNING 0
174 /*----------------------------------------------------------------------*/
177 /* codes for open command */
179 #define OPEN_RDONLY O_RDONLY /* other system use standard codes */
180 #define OPEN_WRONLY O_WRONLY /* for binary */
181 #define OPEN_RDWR O_RDWR
183 #define OPEN_RDONLY 0 /* other system use standard codes */
184 #define OPEN_WRONLY 1 /* for binary */
188 /*----------------------------------------------------------------------*/
190 /* codes for input (inp_*) routines */
195 #define INP_NEITHER 'b'
196 #define INP_RETURN 'r'
197 #define INP_BREAK 0x8000
204 #define S_IWRITE S_IWUSR
207 /*----------------------------------------------------------------------*/
209 #if defined(MICROSOFT) || ! defined(SIZEOF_INT)
211 #define SIZEOF_LONG 4
212 #define SIZEOF_SHORT 2
213 #define SIZEOF_FLOAT 4
214 #define SIZEOF_DOUBLE 8
217 typedef signed char kint8;
218 typedef unsigned char kuint8;
222 typedef unsigned int kuint32;
223 #elif SIZEOF_LONG == 4
224 typedef long int kint32;
225 typedef unsigned int kuint32;
228 #if SIZEOF_SHORT == 2
229 typedef short int kint16;
230 typedef unsigned short int kuint16;
231 #elif SIZEOF_INT == 2
233 typedef unsigned int kuint16;
236 #if SIZEOF_FLOAT == 4
237 typedef float kfloat32;
239 #if SIZEOF_DOUBLE == 8
240 typedef double kfloat64;
245 #endif /* __cplusplus */
249 float *alloc_float(int n);
250 double *alloc_double(int n);
251 int *alloc_int(int n);
254 int file_exists(const char *fname);
257 char *kbasename(const char *filename);
260 int iclip(int n, int lb, int ub);
263 char *str_skip_head(const char *str, const char *charlist);
266 char *str_lower(char *s);
269 char *str_wrm_tail(char *str);
270 char *str_rm_tail(char *str, const char *charlist);
273 char *str_save(const char *s);
276 char *str_upper(char *str);
279 void *sys_alloc(const int nbytes, const char *name);
282 void sys_error(int severity, const char *msg, ...);
283 void sys_verror(int severity, const char *msg, va_list arg);
284 void sys_error_level(int severity);
287 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
290 void sys_free(void *ptr, const char *name);
293 DATE *td_get_date(DATE *d);
294 TIME *td_get_time(TIME *t);
295 double td_current_sec(void);
296 double td_time_to_sec(TIME *t);
297 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
298 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
299 TIME *td_time_copy(TIME *to, const TIME *from);
300 TIME *td_time_norm(TIME *t);
301 void td_get_tmdt(TIMEDATE *td);
302 const char *td_str_tmdt(const TIMEDATE *td);
303 const char *td_str_time(const TIME *t);
304 const char *td_str_stime(const TIME *t);
305 const char *td_str_date(const DATE *d);
306 char *td_str_cdate(DATE *d);
307 char *td_month_name(int n);
308 char *td_day_name(int n);
311 void *strreverse (void *dest, const void *src, size_t n);
312 int read_nint16 (kuint16 *n, int fd);
313 int write_nint16 (kuint16 const *n, int fd);
314 int read_nint32 (kuint32 *n, int fd);
315 int write_nint32 (kuint32 const *n, int fd);
316 int read_nfloat32 (float *f, int fd);
317 int write_nfloat32 (float const *f, int fd);
318 int read_nfloat64 (double *d, int fd);
319 int write_nfloat64 (double const *d, int fd);
320 void ConvertNetworkOrder (void* buffer, size_t bytes);
324 #endif /* __cplusplus */