r90: Convert MPI structure to C++ class
[ctsim.git] / include / kstddef.h
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: kstddef.h,v 1.15 2000/06/09 01:35:33 kevin Exp $
6 **  $Log: kstddef.h,v $
7 **  Revision 1.15  2000/06/09 01:35:33  kevin
8 **  Convert MPI structure to C++ class
9 **
10 **  Revision 1.14  2000/06/07 03:49:54  kevin
11 **  *** empty log message ***
12 **
13 **  Revision 1.13  2000/06/07 00:59:38  kevin
14 **  added imagefiles
15 **
16 **  Revision 1.12  2000/06/05 01:32:45  kevin
17 **  Added C++ compatibility
18 **
19 **  Revision 1.11  2000/06/03 06:29:08  kevin
20 **  *** empty log message ***
21 **
22 **  Revision 1.10  2000/05/16 04:33:17  kevin
23 **  Updated documentation
24 **
25 **  Revision 1.9  2000/05/11 01:04:44  kevin
26 **  Added Microsoft Windows compatibility
27 **
28 **  Revision 1.8  2000/05/08 20:00:48  kevin
29 **  ANSI C changes
30 **
31 **  Revision 1.7  2000/05/07 12:46:19  kevin
32 **  made c++ compatible
33 **
34 **  Revision 1.6  2000/05/03 19:51:41  kevin
35 **  function renaming for phantoms and phantom elements
36 **
37 **  Revision 1.5  2000/05/02 20:00:25  kevin
38 **  *** empty log message ***
39 **
40 **  Revision 1.4  2000/04/28 18:00:55  kevin
41 **  remove unused files
42 **
43 **  Revision 1.3  2000/04/28 17:38:16  kevin
44 **  Removed unused files
45 **
46 **  Revision 1.2  2000/04/28 14:14:16  kevin
47 **  *** empty log message ***
48 **
49 **
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.
53 **
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.
58 **
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 ******************************************************************************/
63
64 /******************************************************************************
65  *
66  * FILE IDENTIFICATION
67  *
68  *      File Name:      STDDEF.H
69  *      Author:         Kevin Rosenberg
70  *      Purpose:        Header file containing KRL standard C definitions
71  *      Date Started:   Dec. 83
72  *
73  * DESCRIPTION
74  *      Header file contains KRL standard C definitions
75  *
76  * MODIFICATION LOG
77  *
78  *****************************************************************************/
79
80 #ifndef STDDEF_H
81 #define STDDEF_H
82
83 #ifdef HAVE_CONFIG_H
84 #include "config.h"
85 #endif
86
87 #ifdef _WIN32
88 #define snprintf _snprintf
89 #endif
90
91 #if !defined(bool) && !defined(__cplusplus)
92 typedef int bool;               /* Boolean variable type */
93 #endif
94
95 #define STR_MAX_LEN 255
96 #define STR_SIZE    STR_MAX_LEN+1
97
98 #if !defined(__cplusplus)
99 typedef unsigned char string[STR_SIZE];
100 #endif
101
102 #include <stdio.h>
103 #include <stdlib.h>
104 #include <string.h>
105 #include <stdarg.h>
106
107 #undef SHELL
108
109 #define TRUE    1
110 #define FALSE   0
111 #define OK      TRUE
112 #define ERROR   FALSE
113 #define YES     TRUE
114 #define NO      FALSE
115
116 /*----------------------------------------------------------------------*/
117
118 #define SHOW(var, fmt)  fprintf (stderr, "var = fmt\n", var)
119
120 /*----------------------------------------------------------------------*/
121
122 #define NEWLINE '\n'
123 #define TAB     '\t'
124 #define EOS     '\0'
125 #define BLANK   ' '
126 #define ETX     26      /* end of text signal for PC-DOS */
127
128 /*----------------------------------------------------------------------*/
129
130 #define MAXPATHNAME  65         /* max length of pathname + 1 */
131 #define MAXFILENAME  13         /* rootname(8) + '.'(1) + extension(3) + EOS */
132 #define MAXROOTNAME   8
133 #define MAXEXTNAME    3
134 #define MAXFULLNAME  MAXPATHNAME + MAXFILENAME
135
136 /*----------------------------------------------------------------------*/
137
138 #define ABS(x)    ((x) < 0 ? -(x) : (x))
139 #define SQR(x)    ((x) * (x))
140
141 #ifndef MAX
142 #define MAX(a,b)  ((a) > (b) ? (a) : (b))
143 #endif
144 #ifndef MIN
145 #define MIN(a,b)  ((a) <= (b) ? (a) : (b))
146 #endif
147 #define ISWAP(a,b) {int i; i = a; a = b; b = i;}
148
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)
151
152 /*----------------------------------------------------------------------*/
153
154 struct time_st {
155         int hour, minute, second, ms;
156 };
157
158 struct date_st {
159         int year, month, date, dow;
160 };
161
162 struct timedate_st {
163     struct time_st t;
164     struct date_st d;
165 };
166
167 typedef struct time_st TIME;
168 typedef struct date_st DATE;
169 typedef struct timedate_st TIMEDATE;
170
171 /*----------------------------------------------------------------------*/
172
173 #define ERR_WARNING     0
174 #define ERR_SEVERE      1
175 #define ERR_FATAL       2
176
177 /*----------------------------------------------------------------------*/
178
179
180 /* codes for open command */
181 #if MICROSOFT
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
185 #else
186 #define OPEN_RDONLY  0                  /* other system use standard codes */
187 #define OPEN_WRONLY  1                  /* for binary */
188 #define OPEN_RDWR    2
189 #endif
190
191 /*----------------------------------------------------------------------*/
192
193 /* codes for input (inp_*) routines */
194
195 #define INP_ERROR   -1
196 #define INP_NO      FALSE
197 #define INP_YES     TRUE
198 #define INP_NEITHER 'b'
199 #define INP_RETURN  'r'
200 #define INP_BREAK   0x8000
201
202 #ifndef O_BINARY
203 #define O_BINARY (0)
204 #endif
205
206 #ifndef S_IWRITE
207 #define S_IWRITE S_IWUSR
208 #endif
209
210 /*----------------------------------------------------------------------*/
211
212 #if defined(MICROSOFT) || ! defined(SIZEOF_INT)
213    #define SIZEOF_INT 4
214    #define SIZEOF_LONG 4
215    #define SIZEOF_SHORT 2
216    #define SIZEOF_FLOAT 4
217    #define SIZEOF_DOUBLE 8
218 #endif
219
220 typedef signed char kint8;
221 typedef unsigned char kuint8;
222
223 #if SIZEOF_INT == 4
224     typedef int kint32;
225     typedef unsigned int kuint32;
226 #elif SIZEOF_LONG == 4
227     typedef long int kint32;
228     typedef unsigned int kuint32;
229 #endif
230
231 #if SIZEOF_SHORT == 2
232     typedef short int kint16;
233     typedef unsigned short int kuint16;
234 #elif SIZEOF_INT == 2
235     typedef int kint16;
236     typedef unsigned int kuint16;
237 #endif
238
239 #if SIZEOF_FLOAT == 4
240     typedef float kfloat32;
241 #endif
242 #if SIZEOF_DOUBLE == 8
243     typedef double kfloat64;
244 #endif
245
246 #ifdef __cplusplus
247 extern "C" {
248 #endif /* __cplusplus */
249
250
251 /* allocnum.c */
252 float *alloc_float(int n);
253 double *alloc_double(int n);
254 int *alloc_int(int n);
255
256 /* fexist.c */
257 int file_exists(const char *fname);
258
259 /* kbasename.c */
260 char *kbasename(const char *filename);
261
262 /* iclip.c */
263 int iclip(int n, int lb, int ub);
264
265 /* s_head.c */
266 char *str_skip_head(const char *str, const char *charlist);
267
268 /* s_lower.c */
269 char *str_lower(char *s);
270
271 /* s_rmtail.c */
272 char *str_wrm_tail(char *str);
273 char *str_rm_tail(char *str, const char *charlist);
274
275 /* s_save.c */
276 char *str_save(const char *s);
277
278 /* s_upper.c */
279 char *str_upper(char *str);
280
281 /* sysalloc.c */
282 void *sys_alloc(const int nbytes, const char *name);
283
284 /* syserror.c */
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);
288
289 /* sysfopen.c */
290 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
291
292 /* sysfree.c */
293 void sys_free(void *ptr, const char *name);
294
295 /* timedate.c */
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);
312
313 /* netorder.c */
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);
325
326 #ifdef __cplusplus
327 }
328 #endif /* __cplusplus */
329
330 #endif