1 /*****************************************************************************
4 ** File Name: kstddef.h
5 ** Author: Kevin Rosenberg
6 ** Purpose: Header file containing KRL standard C definitions
7 ** Date Started: Dec. 83
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: kstddef.h,v 1.16 2000/06/13 16:20:31 kevin Exp $
15 ** This program is free software; you can redistribute it and/or modify
16 ** it under the terms of the GNU General Public License (version 2) as
17 ** published by the Free Software Foundation.
19 ** This program is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
24 ** You should have received a copy of the GNU General Public License
25 ** along with this program; if not, write to the Free Software
26 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 ******************************************************************************/
37 #define snprintf _snprintf
40 #define STR_MAX_LEN 255
41 #define STR_SIZE STR_MAX_LEN+1
57 /*----------------------------------------------------------------------*/
59 #define SHOW(var, fmt) fprintf (stderr, "var = fmt\n", var)
61 /*----------------------------------------------------------------------*/
67 #define ETX 26 /* end of text signal for PC-DOS */
69 /*----------------------------------------------------------------------*/
71 #define MAXPATHNAME 65 /* max length of pathname + 1 */
72 #define MAXFILENAME 13 /* rootname(8) + '.'(1) + extension(3) + EOS */
75 #define MAXFULLNAME MAXPATHNAME + MAXFILENAME
77 /*----------------------------------------------------------------------*/
79 #define ABS(x) ((x) < 0 ? -(x) : (x))
80 #define SQR(x) ((x) * (x))
82 #define ISWAP(a,b) {int i; i = a; a = b; b = i;}
84 #define CLIP(n,lb,ub) if (n < lb) n = lb; else if (n > ub) n = ub
85 #define STR_EQUAL(s1,s2) (strcmp (s1, s2) == 0)
87 /*----------------------------------------------------------------------*/
90 int hour, minute, second, ms;
94 int year, month, date, dow;
102 typedef struct time_st TIME;
103 typedef struct date_st DATE;
104 typedef struct timedate_st TIMEDATE;
106 /*----------------------------------------------------------------------*/
108 #define ERR_WARNING 0
112 /*----------------------------------------------------------------------*/
115 /* codes for open command */
117 #define OPEN_RDONLY O_RDONLY /* other system use standard codes */
118 #define OPEN_WRONLY O_WRONLY /* for binary */
119 #define OPEN_RDWR O_RDWR
121 #define OPEN_RDONLY 0 /* other system use standard codes */
122 #define OPEN_WRONLY 1 /* for binary */
126 /*----------------------------------------------------------------------*/
128 /* codes for input (inp_*) routines */
133 #define INP_NEITHER 'b'
134 #define INP_RETURN 'r'
135 #define INP_BREAK 0x8000
142 #define S_IWRITE S_IWUSR
145 /*----------------------------------------------------------------------*/
147 #if defined(MICROSOFT) || ! defined(SIZEOF_INT)
149 #define SIZEOF_LONG 4
150 #define SIZEOF_SHORT 2
151 #define SIZEOF_FLOAT 4
152 #define SIZEOF_DOUBLE 8
155 typedef signed char kint8;
156 typedef unsigned char kuint8;
160 typedef unsigned int kuint32;
161 #elif SIZEOF_LONG == 4
162 typedef long int kint32;
163 typedef unsigned int kuint32;
166 #if SIZEOF_SHORT == 2
167 typedef short int kint16;
168 typedef unsigned short int kuint16;
169 #elif SIZEOF_INT == 2
171 typedef unsigned int kuint16;
174 #if SIZEOF_FLOAT == 4
175 typedef float kfloat32;
177 #if SIZEOF_DOUBLE == 8
178 typedef double kfloat64;
182 bool file_exists(const char* fname);
183 const char* fileBasename(const char* filename);
184 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
187 const char* str_skip_head(char* const str, const char* const charlist);
188 char* str_skip_head(char* str, char* charlist);
189 char *str_lower(char *s);
190 char *str_wrm_tail(char *str);
191 char *str_rm_tail(char *str, const char* const charlist);
192 char *str_upper(char *str);
195 void sys_error(int severity, const char *msg, ...);
196 void sys_verror(int severity, const char *msg, va_list arg);
197 void sys_error_level(int severity);
200 DATE *td_get_date(DATE *d);
201 TIME *td_get_time(TIME *t);
202 double td_current_sec(void);
203 double td_time_to_sec(TIME *t);
204 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
205 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
206 TIME *td_time_copy(TIME *to, const TIME *from);
207 TIME *td_time_norm(TIME *t);
208 void td_get_tmdt(TIMEDATE *td);
209 const char *td_str_tmdt(const TIMEDATE *td);
210 const char *td_str_time(const TIME *t);
211 const char *td_str_stime(const TIME *t);
212 const char *td_str_date(const DATE *d);
213 char *td_str_cdate(DATE *d);
214 char *td_month_name(int n);
215 char *td_day_name(int n);
218 void *strreverse (void *dest, const void *src, size_t n);
219 int read_nint16 (kuint16 *n, int fd);
220 int write_nint16 (kuint16 const *n, int fd);
221 int read_nint32 (kuint32 *n, int fd);
222 int write_nint32 (kuint32 const *n, int fd);
223 int read_nfloat32 (float *f, int fd);
224 int write_nfloat32 (float const *f, int fd);
225 int read_nfloat64 (double *d, int fd);
226 int write_nfloat64 (double const *d, int fd);
227 void ConvertNetworkOrder (void* buffer, size_t bytes);
228 void ConvertReverseNetworkOrder (void* buffer, size_t bytes);