2f1349299ccd9b16eee048ebe981b1b55dfd1b81
[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.11 2000/06/03 06:29:08 kevin Exp $
6 **  $Log: kstddef.h,v $
7 **  Revision 1.11  2000/06/03 06:29:08  kevin
8 **  *** empty log message ***
9 **
10 **  Revision 1.10  2000/05/16 04:33:17  kevin
11 **  Updated documentation
12 **
13 **  Revision 1.9  2000/05/11 01:04:44  kevin
14 **  Added Microsoft Windows compatibility
15 **
16 **  Revision 1.8  2000/05/08 20:00:48  kevin
17 **  ANSI C changes
18 **
19 **  Revision 1.7  2000/05/07 12:46:19  kevin
20 **  made c++ compatible
21 **
22 **  Revision 1.6  2000/05/03 19:51:41  kevin
23 **  function renaming for phantoms and phantom elements
24 **
25 **  Revision 1.5  2000/05/02 20:00:25  kevin
26 **  *** empty log message ***
27 **
28 **  Revision 1.4  2000/04/28 18:00:55  kevin
29 **  remove unused files
30 **
31 **  Revision 1.3  2000/04/28 17:38:16  kevin
32 **  Removed unused files
33 **
34 **  Revision 1.2  2000/04/28 14:14:16  kevin
35 **  *** empty log message ***
36 **
37 **
38 **  This program is free software; you can redistribute it and/or modify
39 **  it under the terms of the GNU General Public License (version 2) as
40 **  published by the Free Software Foundation.
41 **
42 **  This program is distributed in the hope that it will be useful,
43 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
44 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45 **  GNU General Public License for more details.
46 **
47 **  You should have received a copy of the GNU General Public License
48 **  along with this program; if not, write to the Free Software
49 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
50 ******************************************************************************/
51
52 /******************************************************************************
53  *
54  * FILE IDENTIFICATION
55  *
56  *      File Name:      STDDEF.H
57  *      Author:         Kevin Rosenberg
58  *      Purpose:        Header file containing KRL standard C definitions
59  *      Date Started:   Dec. 83
60  *
61  * DESCRIPTION
62  *      Header file contains KRL standard C definitions
63  *
64  * MODIFICATION LOG
65  *
66  *****************************************************************************/
67
68 #ifndef STDDEF_H
69 #define STDDEF_H
70
71 #ifdef __cplusplus
72 extern "C" {
73 #endif /* __cplusplus */
74
75
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <string.h>
79 #include <stdarg.h>
80
81 #undef SHELL
82
83 #define STR_MAX_LEN 255
84 #define STR_SIZE    STR_MAX_LEN+1
85
86 #ifndef bool
87 typedef signed int bool;                /* Boolean variable type */
88 #endif
89
90 typedef unsigned char string[STR_SIZE];
91
92 #define TRUE    1
93 #define FALSE   0
94 #define OK      TRUE
95 #define ERROR   FALSE
96 #define YES     TRUE
97 #define NO      FALSE
98
99 /*----------------------------------------------------------------------*/
100
101 #define SHOW(var, fmt)  fprintf (stderr, "var = fmt\n", var)
102
103 /*----------------------------------------------------------------------*/
104
105 #define NEWLINE '\n'
106 #define TAB     '\t'
107 #define EOS     '\0'
108 #define BLANK   ' '
109 #define ETX     26      /* end of text signal for PC-DOS */
110
111 /*----------------------------------------------------------------------*/
112
113 #define MAXPATHNAME  65         /* max length of pathname + 1 */
114 #define MAXFILENAME  13         /* rootname(8) + '.'(1) + extension(3) + EOS */
115 #define MAXROOTNAME   8
116 #define MAXEXTNAME    3
117 #define MAXFULLNAME  MAXPATHNAME + MAXFILENAME
118
119 /*----------------------------------------------------------------------*/
120
121 #define ABS(x)    ((x) < 0 ? -(x) : (x))
122 #define SQR(x)    ((x) * (x))
123
124 #ifndef MAX
125 #define MAX(a,b)  ((a) > (b) ? (a) : (b))
126 #endif
127 #ifndef MIN
128 #define MIN(a,b)  ((a) <= (b) ? (a) : (b))
129 #endif
130 #define ISWAP(a,b) {int i; i = a; a = b; b = i;}
131
132 #define CLIP(n,lb,ub)   if (n < lb) n = lb; else if (n > ub) n = ub
133 #define STR_EQUAL(s1,s2) (strcmp (s1, s2) == 0)
134
135 /*----------------------------------------------------------------------*/
136
137 struct time_st {
138         int hour, minute, second, hs;
139 };
140
141 struct date_st {
142         int year, month, date, dow;
143 };
144
145 struct timedate_st {
146     struct time_st t;
147     struct date_st d;
148 };
149
150 typedef struct time_st TIME;
151 typedef struct date_st DATE;
152 typedef struct timedate_st TIMEDATE;
153
154 /*----------------------------------------------------------------------*/
155
156 #define ERR_WARNING     0
157 #define ERR_SEVERE      1
158 #define ERR_FATAL       2
159
160 /*----------------------------------------------------------------------*/
161
162
163 /* codes for open command */
164 #if MICROSOFT
165 #define OPEN_RDONLY  O_RDONLY                   /* other system use standard codes */
166 #define OPEN_WRONLY  O_WRONLY                   /* for binary */
167 #define OPEN_RDWR    O_RDWR
168 #else
169 #define OPEN_RDONLY  0                  /* other system use standard codes */
170 #define OPEN_WRONLY  1                  /* for binary */
171 #define OPEN_RDWR    2
172 #endif
173
174 /*----------------------------------------------------------------------*/
175
176 /* codes for input (inp_*) routines */
177
178 #define INP_ERROR   -1
179 #define INP_NO      FALSE
180 #define INP_YES     TRUE
181 #define INP_NEITHER 'b'
182 #define INP_RETURN  'r'
183 #define INP_BREAK   0x8000
184
185 #ifndef O_BINARY
186 #define O_BINARY (0)
187 #endif
188
189 #ifndef S_IWRITE
190 #define S_IWRITE S_IWUSR
191 #endif
192
193 /* allocnum.c */
194 float *alloc_float(int n);
195 double *alloc_double(int n);
196 int *alloc_int(int n);
197
198 /* fexist.c */
199 int file_exists(const char *fname);
200
201 /* kbasename.c */
202 char *kbasename(const char *filename);
203
204 /* iclip.c */
205 int iclip(int n, int lb, int ub);
206
207 /* s_head.c */
208 char *str_skip_head(const char *str, const char *charlist);
209
210 /* s_lower.c */
211 char *str_lower(char *s);
212
213 /* s_rmtail.c */
214 char *str_wrm_tail(char *str);
215 char *str_rm_tail(char *str, const char *charlist);
216
217 /* s_save.c */
218 char *str_save(const char *s);
219
220 /* s_upper.c */
221 char *str_upper(char *str);
222
223 /* sysalloc.c */
224 void *sys_alloc(const int nbytes, const char *name);
225
226 /* syserror.c */
227 void sys_error(int severity, const char *msg, ...);
228 void sys_verror(int severity, const char *msg, va_list arg);
229 void sys_error_level(int severity);
230
231 /* sysfopen.c */
232 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
233
234 /* sysfree.c */
235 void sys_free(void *ptr, const char *name);
236
237 /* timedate.c */
238 DATE *td_get_date(DATE *d);
239 TIME *td_get_time(TIME *t);
240 double td_current_sec(void);
241 double td_time_to_sec(TIME *t);
242 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
243 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
244 TIME *td_time_copy(TIME *to, const TIME *from);
245 TIME *td_time_norm(TIME *t);
246 void td_get_tmdt(TIMEDATE *td);
247 const char *td_str_tmdt(const TIMEDATE *td);
248 const char *td_str_time(const TIME *t);
249 const char *td_str_stime(const TIME *t);
250 const char *td_str_date(const DATE *d);
251 char *td_str_cdate(DATE *d);
252 char *td_month_name(int n);
253 char *td_day_name(int n);
254
255 /* netorder.c */
256 void *strreverse (void *dest, const void *src, size_t n);
257 #if SIZEOF_SHORT == 4
258 int read_n32bint (unsigned short *n, int fd);
259 int write_n32bint (unsigned short const *n, int fd);
260 #elif SIZEOF_LONG == 4
261 int read_n32bint (unsigned long *n, int fd);
262 int write_n32bint (unsigned long const *n, int fd);
263 #else
264 int read_n32bint (unsigned int *n, int fd);
265 int write_n32bint (unsigned int const *n, int fd);
266 #endif
267 int read_nfloat (float *f, int fd);
268 int write_nfloat (float const *f, int fd);
269 int read_ndouble (double *d, int fd);
270 int write_ndouble (double const *d, int fd);
271
272 #ifdef __cplusplus
273 }
274 #endif /* __cplusplus */
275
276 #endif