1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: kstddef.h,v 1.15 2000/06/09 01:35:33 kevin Exp $
7 ** Revision 1.15 2000/06/09 01:35:33 kevin
8 ** Convert MPI structure to C++ class
10 ** Revision 1.14 2000/06/07 03:49:54 kevin
11 ** *** empty log message ***
13 ** Revision 1.13 2000/06/07 00:59:38 kevin
16 ** Revision 1.12 2000/06/05 01:32:45 kevin
17 ** Added C++ compatibility
19 ** Revision 1.11 2000/06/03 06:29:08 kevin
20 ** *** empty log message ***
22 ** Revision 1.10 2000/05/16 04:33:17 kevin
23 ** Updated documentation
25 ** Revision 1.9 2000/05/11 01:04:44 kevin
26 ** Added Microsoft Windows compatibility
28 ** Revision 1.8 2000/05/08 20:00:48 kevin
31 ** Revision 1.7 2000/05/07 12:46:19 kevin
32 ** made c++ compatible
34 ** Revision 1.6 2000/05/03 19:51:41 kevin
35 ** function renaming for phantoms and phantom elements
37 ** Revision 1.5 2000/05/02 20:00:25 kevin
38 ** *** empty log message ***
40 ** Revision 1.4 2000/04/28 18:00:55 kevin
41 ** remove unused files
43 ** Revision 1.3 2000/04/28 17:38:16 kevin
44 ** Removed unused files
46 ** Revision 1.2 2000/04/28 14:14:16 kevin
47 ** *** empty log message ***
50 ** This program is free software; you can redistribute it and/or modify
51 ** it under the terms of the GNU General Public License (version 2) as
52 ** published by the Free Software Foundation.
54 ** This program is distributed in the hope that it will be useful,
55 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
56 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 ** GNU General Public License for more details.
59 ** You should have received a copy of the GNU General Public License
60 ** along with this program; if not, write to the Free Software
61 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
62 ******************************************************************************/
64 /******************************************************************************
69 * Author: Kevin Rosenberg
70 * Purpose: Header file containing KRL standard C definitions
71 * Date Started: Dec. 83
74 * Header file contains KRL standard C definitions
78 *****************************************************************************/
88 #define snprintf _snprintf
91 #if !defined(bool) && !defined(__cplusplus)
92 typedef int bool; /* Boolean variable type */
95 #define STR_MAX_LEN 255
96 #define STR_SIZE STR_MAX_LEN+1
98 #if !defined(__cplusplus)
99 typedef unsigned char string[STR_SIZE];
116 /*----------------------------------------------------------------------*/
118 #define SHOW(var, fmt) fprintf (stderr, "var = fmt\n", var)
120 /*----------------------------------------------------------------------*/
126 #define ETX 26 /* end of text signal for PC-DOS */
128 /*----------------------------------------------------------------------*/
130 #define MAXPATHNAME 65 /* max length of pathname + 1 */
131 #define MAXFILENAME 13 /* rootname(8) + '.'(1) + extension(3) + EOS */
132 #define MAXROOTNAME 8
134 #define MAXFULLNAME MAXPATHNAME + MAXFILENAME
136 /*----------------------------------------------------------------------*/
138 #define ABS(x) ((x) < 0 ? -(x) : (x))
139 #define SQR(x) ((x) * (x))
142 #define MAX(a,b) ((a) > (b) ? (a) : (b))
145 #define MIN(a,b) ((a) <= (b) ? (a) : (b))
147 #define ISWAP(a,b) {int i; i = a; a = b; b = i;}
149 #define CLIP(n,lb,ub) if (n < lb) n = lb; else if (n > ub) n = ub
150 #define STR_EQUAL(s1,s2) (strcmp (s1, s2) == 0)
152 /*----------------------------------------------------------------------*/
155 int hour, minute, second, ms;
159 int year, month, date, dow;
167 typedef struct time_st TIME;
168 typedef struct date_st DATE;
169 typedef struct timedate_st TIMEDATE;
171 /*----------------------------------------------------------------------*/
173 #define ERR_WARNING 0
177 /*----------------------------------------------------------------------*/
180 /* codes for open command */
182 #define OPEN_RDONLY O_RDONLY /* other system use standard codes */
183 #define OPEN_WRONLY O_WRONLY /* for binary */
184 #define OPEN_RDWR O_RDWR
186 #define OPEN_RDONLY 0 /* other system use standard codes */
187 #define OPEN_WRONLY 1 /* for binary */
191 /*----------------------------------------------------------------------*/
193 /* codes for input (inp_*) routines */
198 #define INP_NEITHER 'b'
199 #define INP_RETURN 'r'
200 #define INP_BREAK 0x8000
207 #define S_IWRITE S_IWUSR
210 /*----------------------------------------------------------------------*/
212 #if defined(MICROSOFT) || ! defined(SIZEOF_INT)
214 #define SIZEOF_LONG 4
215 #define SIZEOF_SHORT 2
216 #define SIZEOF_FLOAT 4
217 #define SIZEOF_DOUBLE 8
220 typedef signed char kint8;
221 typedef unsigned char kuint8;
225 typedef unsigned int kuint32;
226 #elif SIZEOF_LONG == 4
227 typedef long int kint32;
228 typedef unsigned int kuint32;
231 #if SIZEOF_SHORT == 2
232 typedef short int kint16;
233 typedef unsigned short int kuint16;
234 #elif SIZEOF_INT == 2
236 typedef unsigned int kuint16;
239 #if SIZEOF_FLOAT == 4
240 typedef float kfloat32;
242 #if SIZEOF_DOUBLE == 8
243 typedef double kfloat64;
248 #endif /* __cplusplus */
252 float *alloc_float(int n);
253 double *alloc_double(int n);
254 int *alloc_int(int n);
257 int file_exists(const char *fname);
260 char *kbasename(const char *filename);
263 int iclip(int n, int lb, int ub);
266 char *str_skip_head(const char *str, const char *charlist);
269 char *str_lower(char *s);
272 char *str_wrm_tail(char *str);
273 char *str_rm_tail(char *str, const char *charlist);
276 char *str_save(const char *s);
279 char *str_upper(char *str);
282 void *sys_alloc(const int nbytes, const char *name);
285 void sys_error(int severity, const char *msg, ...);
286 void sys_verror(int severity, const char *msg, va_list arg);
287 void sys_error_level(int severity);
290 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
293 void sys_free(void *ptr, const char *name);
296 DATE *td_get_date(DATE *d);
297 TIME *td_get_time(TIME *t);
298 double td_current_sec(void);
299 double td_time_to_sec(TIME *t);
300 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
301 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
302 TIME *td_time_copy(TIME *to, const TIME *from);
303 TIME *td_time_norm(TIME *t);
304 void td_get_tmdt(TIMEDATE *td);
305 const char *td_str_tmdt(const TIMEDATE *td);
306 const char *td_str_time(const TIME *t);
307 const char *td_str_stime(const TIME *t);
308 const char *td_str_date(const DATE *d);
309 char *td_str_cdate(DATE *d);
310 char *td_month_name(int n);
311 char *td_day_name(int n);
314 void *strreverse (void *dest, const void *src, size_t n);
315 int read_nint16 (kuint16 *n, int fd);
316 int write_nint16 (kuint16 const *n, int fd);
317 int read_nint32 (kuint32 *n, int fd);
318 int write_nint32 (kuint32 const *n, int fd);
319 int read_nfloat32 (float *f, int fd);
320 int write_nfloat32 (float const *f, int fd);
321 int read_nfloat64 (double *d, int fd);
322 int write_nfloat64 (double const *d, int fd);
323 void ConvertNetworkOrder (void* buffer, size_t bytes);
324 void ConvertReverseNetworkOrder (void* buffer, size_t bytes);
328 #endif /* __cplusplus */