1 /******************************************************************************
6 * Author: Kevin Rosenberg
7 * Purpose: Header file containing KRL standard C definitions
8 * Date Started: Dec. 83
11 * Header file contains KRL standard C definitions
15 *****************************************************************************/
28 #define STR_MAX_LEN 255
29 #define STR_SIZE STR_MAX_LEN+1
32 typedef signed int bool; /* Boolean variable type */
35 typedef unsigned char string[STR_SIZE];
37 #define UNSIGNLONG unsigned long int
38 #define UNSIGNCHAR unsigned char
49 /*----------------------------------------------------------------------*/
51 #define SHOW(var, fmt) fprintf (stderr, "var = fmt\n", var)
53 /*----------------------------------------------------------------------*/
55 #define INTERNAL_FUNC static
56 #define INTERNAL_VAR static
58 /*----------------------------------------------------------------------*/
64 #define ETX 26 /* end of text signal for PC-DOS */
66 /*----------------------------------------------------------------------*/
68 #define MAXPATHNAME 65 /* max length of pathname + 1 */
69 #define MAXFILENAME 13 /* rootname(8) + '.'(1) + extension(3) + EOS */
72 #define MAXFULLNAME MAXPATHNAME + MAXFILENAME
74 /*----------------------------------------------------------------------*/
76 #define ABS(x) ((x) < 0 ? -(x) : (x))
77 #define SQR(x) ((x) * (x))
79 #define MAX(a,b) ((a) > (b) ? (a) : (b))
80 #define MIN(a,b) ((a) <= (b) ? (a) : (b))
81 #define ISWAP(a,b) {int i; i = a; a = b; b = i;}
83 #define CLIP(n,lb,ub) if (n < lb) n = lb; else if (n > ub) n = ub
84 #define FOREVER for (;;)
85 #define STR_EQUAL(s1,s2) (strcmp (s1, s2) == 0)
87 /*----------------------------------------------------------------------*/
90 int hour, minute, second, hs;
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 /*----------------------------------------------------------------------*/
114 /* codes for open command */
117 #define OPEN_RDONLY 0x8000 /* Lattice codes for binary i/o */
118 #define OPEN_WRONLY 0x8001
119 #define OPEN_RDWR 0x8002
121 #define OPEN_RDONLY O_RDONLY /* other system use standard codes */
122 #define OPEN_WRONLY O_WRONLY /* for binary */
123 #define OPEN_RDWR O_RDWR
125 #define OPEN_RDONLY 0 /* other system use standard codes */
126 #define OPEN_WRONLY 1 /* for binary */
130 /*----------------------------------------------------------------------*/
132 /* codes for input (inp_*) routines */
137 #define INP_NEITHER 'b'
138 #define INP_RETURN 'r'
139 #define INP_BREAK 0x8000
146 #define S_IWRITE S_IWUSR
150 void *alloc(unsigned int nbytes);
152 float *alloc_float(int n);
153 double *alloc_double(int n);
154 int *alloc_int(int n);
156 void cant(const char *fname);
158 char *td_str_cdate(DATE *d);
159 char *td_month_name(int n);
160 char *td_day_name(int n);
162 char *ctoi(const char *s, int *ival);
164 int file_exists(const char *fname);
166 double fmax(double a, double b);
168 int get_yn(const char *prompt);
170 unsigned int getbits(unsigned int x, int p, int n);
175 DATE *td_get_date(DATE *d);
177 TIME *td_get_time(TIME *t);
179 int iclip(int n, int lb, int ub);
181 int infofn(unsigned int *attrib, long int *filesize, TIMEDATE *td);
183 unsigned int irand(unsigned int n);
185 int itostr(int n, char str[], int size);
187 int ltostr(long val, char *cp, int base);
189 int makefnam(const char *rawfn, const char *template_str, char *result);
190 int getfnam(const char fullname[], char pathname[], char filename[]);
191 int getexten(const char *fullname, char *exten);
192 int validfn(const char filename[]);
194 void putdec(const int n, int w, FILE *fd_out);
196 char *str_clip_tail(char *str, unsigned int nclip);
198 char *str_conv_esc(const char *from, char *to);
200 char *s_esc_char(const char *str, char *c);
202 unsigned int str_get_last_char(const char *str);
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_reverse(char *s);
212 char *str_wrm_head(char *str);
213 char *str_rm_head(char *str, const char *skip_str);
215 char *str_rm_tail(char *str, const char *charlist);
217 char *str_save(const char *s);
219 char *str_upper(char *str);
221 char *str_wrm_tail(char *str);
223 int searchfn(const char pat[], const unsigned int attrib);
224 int getfn(const char name[]);
226 double td_current_sec(void);
227 double td_time_to_sec(TIME *t);
228 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
229 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
230 TIME *td_time_copy(TIME *to, const TIME *from);
231 TIME *td_time_norm(TIME *t);
233 int strncmpc(const char *s, const char *t, int n);
235 void *sys_alloc(const int nbytes, const char *name);
237 void sys_error(int severity, const char *msg, ...);
238 void sys_verror(int severity, const char *msg, va_list arg);
239 void sys_error_level(int severity);
241 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
243 void sys_free(void *ptr, const char *name);
245 void td_get_tmdt(TIMEDATE *td);
246 const char *td_str_tmdt(const TIMEDATE *td);
247 const char *td_str_time(const TIME *t);
248 const char *td_str_stime(const TIME *t);
249 const char *td_str_date(const DATE *d);
251 char *kbasename(const char *filename);