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