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