1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: kstddef.h,v 1.12 2000/06/05 01:32:45 kevin Exp $
7 ** Revision 1.12 2000/06/05 01:32:45 kevin
8 ** Added C++ compatibility
10 ** Revision 1.11 2000/06/03 06:29:08 kevin
11 ** *** empty log message ***
13 ** Revision 1.10 2000/05/16 04:33:17 kevin
14 ** Updated documentation
16 ** Revision 1.9 2000/05/11 01:04:44 kevin
17 ** Added Microsoft Windows compatibility
19 ** Revision 1.8 2000/05/08 20:00:48 kevin
22 ** Revision 1.7 2000/05/07 12:46:19 kevin
23 ** made c++ compatible
25 ** Revision 1.6 2000/05/03 19:51:41 kevin
26 ** function renaming for phantoms and phantom elements
28 ** Revision 1.5 2000/05/02 20:00:25 kevin
29 ** *** empty log message ***
31 ** Revision 1.4 2000/04/28 18:00:55 kevin
32 ** remove unused files
34 ** Revision 1.3 2000/04/28 17:38:16 kevin
35 ** Removed unused files
37 ** Revision 1.2 2000/04/28 14:14:16 kevin
38 ** *** empty log message ***
41 ** This program is free software; you can redistribute it and/or modify
42 ** it under the terms of the GNU General Public License (version 2) as
43 ** published by the Free Software Foundation.
45 ** This program is distributed in the hope that it will be useful,
46 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
47 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 ** GNU General Public License for more details.
50 ** You should have received a copy of the GNU General Public License
51 ** along with this program; if not, write to the Free Software
52 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53 ******************************************************************************/
55 /******************************************************************************
60 * Author: Kevin Rosenberg
61 * Purpose: Header file containing KRL standard C definitions
62 * Date Started: Dec. 83
65 * Header file contains KRL standard C definitions
69 *****************************************************************************/
79 #define snprintf _snprintf
82 #if !defined(bool) && !defined(__cplusplus)
83 typedef int bool; /* Boolean variable type */
86 #define STR_MAX_LEN 255
87 #define STR_SIZE STR_MAX_LEN+1
89 typedef unsigned char string[STR_SIZE];
93 #endif /* __cplusplus */
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
216 typedef unsigned int kuint32;
217 #elif SIZEOF_LONG == 4
218 typedef long int kint32;
219 typedef unsigned int kuint32;
222 #if SIZEOF_SHORT == 2
223 typedef short int kint16;
224 typedef unsigned short int kuint16;
225 #elif SIZEOF_INT == 2
227 typedef unsigned int kuint16;
230 #if SIZEOF_FLOAT == 4
231 typedef float kfloat32;
233 #if SIZEOF_DOUBLE == 8
234 typedef double kfloat64;
238 float *alloc_float(int n);
239 double *alloc_double(int n);
240 int *alloc_int(int n);
243 int file_exists(const char *fname);
246 char *kbasename(const char *filename);
249 int iclip(int n, int lb, int ub);
252 char *str_skip_head(const char *str, const char *charlist);
255 char *str_lower(char *s);
258 char *str_wrm_tail(char *str);
259 char *str_rm_tail(char *str, const char *charlist);
262 char *str_save(const char *s);
265 char *str_upper(char *str);
268 void *sys_alloc(const int nbytes, const char *name);
271 void sys_error(int severity, const char *msg, ...);
272 void sys_verror(int severity, const char *msg, va_list arg);
273 void sys_error_level(int severity);
276 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
279 void sys_free(void *ptr, const char *name);
282 DATE *td_get_date(DATE *d);
283 TIME *td_get_time(TIME *t);
284 double td_current_sec(void);
285 double td_time_to_sec(TIME *t);
286 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
287 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
288 TIME *td_time_copy(TIME *to, const TIME *from);
289 TIME *td_time_norm(TIME *t);
290 void td_get_tmdt(TIMEDATE *td);
291 const char *td_str_tmdt(const TIMEDATE *td);
292 const char *td_str_time(const TIME *t);
293 const char *td_str_stime(const TIME *t);
294 const char *td_str_date(const DATE *d);
295 char *td_str_cdate(DATE *d);
296 char *td_month_name(int n);
297 char *td_day_name(int n);
300 void *strreverse (void *dest, const void *src, size_t n);
301 int read_n32bint (kuint32 *n, int fd);
302 int write_n32bint (kuint32 const *n, int fd);
303 int read_nfloat32 (float *f, int fd);
304 int write_nfloat32 (float const *f, int fd);
305 int read_nfloat64 (double *d, int fd);
306 int write_nfloat64 (double const *d, int fd);
310 #endif /* __cplusplus */