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