1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: kstddef.h,v 1.2 2000/04/28 14:14:16 kevin Exp $
7 ** Revision 1.2 2000/04/28 14:14:16 kevin
8 ** *** empty log message ***
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.
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.
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 /******************************************************************************
29 * Author: Kevin Rosenberg
30 * Purpose: Header file containing KRL standard C definitions
31 * Date Started: Dec. 83
34 * Header file contains KRL standard C definitions
38 *****************************************************************************/
50 #define STR_MAX_LEN 255
51 #define STR_SIZE STR_MAX_LEN+1
54 typedef signed int bool; /* Boolean variable type */
57 typedef unsigned char string[STR_SIZE];
59 #define UNSIGNLONG unsigned long int
60 #define UNSIGNCHAR unsigned char
71 /*----------------------------------------------------------------------*/
73 #define SHOW(var, fmt) fprintf (stderr, "var = fmt\n", var)
75 /*----------------------------------------------------------------------*/
77 #define INTERNAL_FUNC static
78 #define INTERNAL_VAR static
80 /*----------------------------------------------------------------------*/
86 #define ETX 26 /* end of text signal for PC-DOS */
88 /*----------------------------------------------------------------------*/
90 #define MAXPATHNAME 65 /* max length of pathname + 1 */
91 #define MAXFILENAME 13 /* rootname(8) + '.'(1) + extension(3) + EOS */
94 #define MAXFULLNAME MAXPATHNAME + MAXFILENAME
96 /*----------------------------------------------------------------------*/
98 #define ABS(x) ((x) < 0 ? -(x) : (x))
99 #define SQR(x) ((x) * (x))
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;}
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)
109 /*----------------------------------------------------------------------*/
112 int hour, minute, second, hs;
116 int year, month, date, dow;
124 typedef struct time_st TIME;
125 typedef struct date_st DATE;
126 typedef struct timedate_st TIMEDATE;
128 /*----------------------------------------------------------------------*/
130 #define ERR_WARNING 0
134 /*----------------------------------------------------------------------*/
136 /* codes for open command */
139 #define OPEN_RDONLY 0x8000 /* Lattice codes for binary i/o */
140 #define OPEN_WRONLY 0x8001
141 #define OPEN_RDWR 0x8002
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
147 #define OPEN_RDONLY 0 /* other system use standard codes */
148 #define OPEN_WRONLY 1 /* for binary */
152 /*----------------------------------------------------------------------*/
154 /* codes for input (inp_*) routines */
159 #define INP_NEITHER 'b'
160 #define INP_RETURN 'r'
161 #define INP_BREAK 0x8000
168 #define S_IWRITE S_IWUSR
172 void *alloc(unsigned int nbytes);
174 float *alloc_float(int n);
175 double *alloc_double(int n);
176 int *alloc_int(int n);
178 void cant(const char *fname);
180 char *td_str_cdate(DATE *d);
181 char *td_month_name(int n);
182 char *td_day_name(int n);
184 char *ctoi(const char *s, int *ival);
186 int file_exists(const char *fname);
188 double fmax(double a, double b);
190 int get_yn(const char *prompt);
192 unsigned int getbits(unsigned int x, int p, int n);
197 DATE *td_get_date(DATE *d);
199 TIME *td_get_time(TIME *t);
201 int iclip(int n, int lb, int ub);
203 int infofn(unsigned int *attrib, long int *filesize, TIMEDATE *td);
205 unsigned int irand(unsigned int n);
207 int itostr(int n, char str[], int size);
209 int ltostr(long val, char *cp, int base);
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[]);
216 void putdec(const int n, int w, FILE *fd_out);
218 char *str_clip_tail(char *str, unsigned int nclip);
220 char *str_conv_esc(const char *from, char *to);
222 char *s_esc_char(const char *str, char *c);
224 unsigned int str_get_last_char(const char *str);
226 char *str_skip_head(const char *str, const char *charlist);
228 char *str_lower(char *s);
230 char *str_make(char *str, int c, const int n);
232 char *str_reverse(char *s);
234 char *str_wrm_head(char *str);
235 char *str_rm_head(char *str, const char *skip_str);
237 char *str_rm_tail(char *str, const char *charlist);
239 char *str_save(const char *s);
241 char *str_upper(char *str);
243 char *str_wrm_tail(char *str);
245 int searchfn(const char pat[], const unsigned int attrib);
246 int getfn(const char name[]);
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);
255 int strncmpc(const char *s, const char *t, int n);
257 void *sys_alloc(const int nbytes, const char *name);
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);
263 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
265 void sys_free(void *ptr, const char *name);
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);
273 char *kbasename(const char *filename);