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