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