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