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