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