1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: kstddef.h,v 1.13 2000/06/07 00:59:38 kevin Exp $
7 ** Revision 1.13 2000/06/07 00:59:38 kevin
10 ** Revision 1.12 2000/06/05 01:32:45 kevin
11 ** Added C++ compatibility
13 ** Revision 1.11 2000/06/03 06:29:08 kevin
14 ** *** empty log message ***
16 ** Revision 1.10 2000/05/16 04:33:17 kevin
17 ** Updated documentation
19 ** Revision 1.9 2000/05/11 01:04:44 kevin
20 ** Added Microsoft Windows compatibility
22 ** Revision 1.8 2000/05/08 20:00:48 kevin
25 ** Revision 1.7 2000/05/07 12:46:19 kevin
26 ** made c++ compatible
28 ** Revision 1.6 2000/05/03 19:51:41 kevin
29 ** function renaming for phantoms and phantom elements
31 ** Revision 1.5 2000/05/02 20:00:25 kevin
32 ** *** empty log message ***
34 ** Revision 1.4 2000/04/28 18:00:55 kevin
35 ** remove unused files
37 ** Revision 1.3 2000/04/28 17:38:16 kevin
38 ** Removed unused files
40 ** Revision 1.2 2000/04/28 14:14:16 kevin
41 ** *** empty log message ***
44 ** This program is free software; you can redistribute it and/or modify
45 ** it under the terms of the GNU General Public License (version 2) as
46 ** published by the Free Software Foundation.
48 ** This program is distributed in the hope that it will be useful,
49 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
50 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 ** GNU General Public License for more details.
53 ** You should have received a copy of the GNU General Public License
54 ** along with this program; if not, write to the Free Software
55 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56 ******************************************************************************/
58 /******************************************************************************
63 * Author: Kevin Rosenberg
64 * Purpose: Header file containing KRL standard C definitions
65 * Date Started: Dec. 83
68 * Header file contains KRL standard C definitions
72 *****************************************************************************/
82 #define snprintf _snprintf
85 #if !defined(bool) && !defined(__cplusplus)
86 typedef int bool; /* Boolean variable type */
89 #define STR_MAX_LEN 255
90 #define STR_SIZE STR_MAX_LEN+1
92 #if !defined(__cplusplus)
93 typedef unsigned char string[STR_SIZE];
110 /*----------------------------------------------------------------------*/
112 #define SHOW(var, fmt) fprintf (stderr, "var = fmt\n", var)
114 /*----------------------------------------------------------------------*/
120 #define ETX 26 /* end of text signal for PC-DOS */
122 /*----------------------------------------------------------------------*/
124 #define MAXPATHNAME 65 /* max length of pathname + 1 */
125 #define MAXFILENAME 13 /* rootname(8) + '.'(1) + extension(3) + EOS */
126 #define MAXROOTNAME 8
128 #define MAXFULLNAME MAXPATHNAME + MAXFILENAME
130 /*----------------------------------------------------------------------*/
132 #define ABS(x) ((x) < 0 ? -(x) : (x))
133 #define SQR(x) ((x) * (x))
136 #define MAX(a,b) ((a) > (b) ? (a) : (b))
139 #define MIN(a,b) ((a) <= (b) ? (a) : (b))
141 #define ISWAP(a,b) {int i; i = a; a = b; b = i;}
143 #define CLIP(n,lb,ub) if (n < lb) n = lb; else if (n > ub) n = ub
144 #define STR_EQUAL(s1,s2) (strcmp (s1, s2) == 0)
146 /*----------------------------------------------------------------------*/
149 int hour, minute, second, ms;
153 int year, month, date, dow;
161 typedef struct time_st TIME;
162 typedef struct date_st DATE;
163 typedef struct timedate_st TIMEDATE;
165 /*----------------------------------------------------------------------*/
167 #define ERR_WARNING 0
171 /*----------------------------------------------------------------------*/
174 /* codes for open command */
176 #define OPEN_RDONLY O_RDONLY /* other system use standard codes */
177 #define OPEN_WRONLY O_WRONLY /* for binary */
178 #define OPEN_RDWR O_RDWR
180 #define OPEN_RDONLY 0 /* other system use standard codes */
181 #define OPEN_WRONLY 1 /* for binary */
185 /*----------------------------------------------------------------------*/
187 /* codes for input (inp_*) routines */
192 #define INP_NEITHER 'b'
193 #define INP_RETURN 'r'
194 #define INP_BREAK 0x8000
201 #define S_IWRITE S_IWUSR
204 /*----------------------------------------------------------------------*/
206 #if defined(MICROSOFT) || ! defined(SIZEOF_INT)
208 #define SIZEOF_LONG 4
209 #define SIZEOF_SHORT 2
210 #define SIZEOF_FLOAT 4
211 #define SIZEOF_DOUBLE 8
214 typedef signed char kint8;
215 typedef unsigned char kuint8;
219 typedef unsigned int kuint32;
220 #elif SIZEOF_LONG == 4
221 typedef long int kint32;
222 typedef unsigned int kuint32;
225 #if SIZEOF_SHORT == 2
226 typedef short int kint16;
227 typedef unsigned short int kuint16;
228 #elif SIZEOF_INT == 2
230 typedef unsigned int kuint16;
233 #if SIZEOF_FLOAT == 4
234 typedef float kfloat32;
236 #if SIZEOF_DOUBLE == 8
237 typedef double kfloat64;
242 #endif /* __cplusplus */
246 float *alloc_float(int n);
247 double *alloc_double(int n);
248 int *alloc_int(int n);
251 int file_exists(const char *fname);
254 char *kbasename(const char *filename);
257 int iclip(int n, int lb, int ub);
260 char *str_skip_head(const char *str, const char *charlist);
263 char *str_lower(char *s);
266 char *str_wrm_tail(char *str);
267 char *str_rm_tail(char *str, const char *charlist);
270 char *str_save(const char *s);
273 char *str_upper(char *str);
276 void *sys_alloc(const int nbytes, const char *name);
279 void sys_error(int severity, const char *msg, ...);
280 void sys_verror(int severity, const char *msg, va_list arg);
281 void sys_error_level(int severity);
284 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
287 void sys_free(void *ptr, const char *name);
290 DATE *td_get_date(DATE *d);
291 TIME *td_get_time(TIME *t);
292 double td_current_sec(void);
293 double td_time_to_sec(TIME *t);
294 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
295 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
296 TIME *td_time_copy(TIME *to, const TIME *from);
297 TIME *td_time_norm(TIME *t);
298 void td_get_tmdt(TIMEDATE *td);
299 const char *td_str_tmdt(const TIMEDATE *td);
300 const char *td_str_time(const TIME *t);
301 const char *td_str_stime(const TIME *t);
302 const char *td_str_date(const DATE *d);
303 char *td_str_cdate(DATE *d);
304 char *td_month_name(int n);
305 char *td_day_name(int n);
308 void *strreverse (void *dest, const void *src, size_t n);
309 int read_nint16 (kuint16 *n, int fd);
310 int write_nint16 (kuint16 const *n, int fd);
311 int read_nint32 (kuint32 *n, int fd);
312 int write_nint32 (kuint32 const *n, int fd);
313 int read_nfloat32 (float *f, int fd);
314 int write_nfloat32 (float const *f, int fd);
315 int read_nfloat64 (double *d, int fd);
316 int write_nfloat64 (double const *d, int fd);
320 #endif /* __cplusplus */