1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: kstddef.h,v 1.3 2000/04/28 17:38:16 kevin Exp $
7 ** Revision 1.3 2000/04/28 17:38:16 kevin
8 ** Removed unused files
10 ** Revision 1.2 2000/04/28 14:14:16 kevin
11 ** *** empty log message ***
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.
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.
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 /******************************************************************************
32 * Author: Kevin Rosenberg
33 * Purpose: Header file containing KRL standard C definitions
34 * Date Started: Dec. 83
37 * Header file contains KRL standard C definitions
41 *****************************************************************************/
53 #define STR_MAX_LEN 255
54 #define STR_SIZE STR_MAX_LEN+1
57 typedef signed int bool; /* Boolean variable type */
60 typedef unsigned char string[STR_SIZE];
62 #define UNSIGNLONG unsigned long int
63 #define UNSIGNCHAR unsigned char
74 /*----------------------------------------------------------------------*/
76 #define SHOW(var, fmt) fprintf (stderr, "var = fmt\n", var)
78 /*----------------------------------------------------------------------*/
80 #define INTERNAL_FUNC static
81 #define INTERNAL_VAR static
83 /*----------------------------------------------------------------------*/
89 #define ETX 26 /* end of text signal for PC-DOS */
91 /*----------------------------------------------------------------------*/
93 #define MAXPATHNAME 65 /* max length of pathname + 1 */
94 #define MAXFILENAME 13 /* rootname(8) + '.'(1) + extension(3) + EOS */
97 #define MAXFULLNAME MAXPATHNAME + MAXFILENAME
99 /*----------------------------------------------------------------------*/
101 #define ABS(x) ((x) < 0 ? -(x) : (x))
102 #define SQR(x) ((x) * (x))
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;}
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)
112 /*----------------------------------------------------------------------*/
115 int hour, minute, second, hs;
119 int year, month, date, dow;
127 typedef struct time_st TIME;
128 typedef struct date_st DATE;
129 typedef struct timedate_st TIMEDATE;
131 /*----------------------------------------------------------------------*/
133 #define ERR_WARNING 0
137 /*----------------------------------------------------------------------*/
139 /* codes for open command */
142 #define OPEN_RDONLY 0x8000 /* Lattice codes for binary i/o */
143 #define OPEN_WRONLY 0x8001
144 #define OPEN_RDWR 0x8002
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
150 #define OPEN_RDONLY 0 /* other system use standard codes */
151 #define OPEN_WRONLY 1 /* for binary */
155 /*----------------------------------------------------------------------*/
157 /* codes for input (inp_*) routines */
162 #define INP_NEITHER 'b'
163 #define INP_RETURN 'r'
164 #define INP_BREAK 0x8000
171 #define S_IWRITE S_IWUSR
175 void *alloc(unsigned int nbytes);
177 float *alloc_float(int n);
178 double *alloc_double(int n);
179 int *alloc_int(int n);
181 char *td_str_cdate(DATE *d);
182 char *td_month_name(int n);
183 char *td_day_name(int n);
185 char *ctoi(const char *s, int *ival);
187 int file_exists(const char *fname);
189 double fmax(double a, double b);
191 int get_yn(const char *prompt);
196 int iclip(int n, int lb, int ub);
198 unsigned int irand(unsigned int n);
200 int ltostr(long val, char *cp, int base);
202 char *str_clip_tail(char *str, unsigned int nclip);
204 char *str_skip_head(const char *str, const char *charlist);
206 char *str_lower(char *s);
208 char *str_make(char *str, int c, const int n);
210 char *str_wrm_head(char *str);
211 char *str_rm_head(char *str, const char *skip_str);
213 char *str_rm_tail(char *str, const char *charlist);
215 char *str_save(const char *s);
217 char *str_upper(char *str);
219 char *str_wrm_tail(char *str);
221 int strncmpc(const char *s, const char *t, int n);
223 void *sys_alloc(const int nbytes, const char *name);
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);
229 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
231 void sys_free(void *ptr, const char *name);
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);
247 char *kbasename(const char *filename);