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