r3: Initial revision
[ctsim.git] / include / kstddef.h
1 /******************************************************************************
2  *
3  * FILE IDENTIFICATION
4  *
5  *      File Name:      STDDEF.H
6  *      Author:         Kevin Rosenberg
7  *      Purpose:        Header file containing KRL standard C definitions
8  *      Date Started:   Dec. 83
9  *
10  * DESCRIPTION
11  *      Header file contains KRL standard C definitions
12  *
13  * MODIFICATION LOG
14  *
15  *****************************************************************************/
16
17 #ifndef STDDEF_H
18 #define STDDEF_H
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdarg.h>
24 #include "getargs.h"
25
26 #undef SHELL
27
28 #define STR_MAX_LEN 255
29 #define STR_SIZE    STR_MAX_LEN+1
30
31 #ifndef bool
32 typedef signed int bool;                /* Boolean variable type */
33 #endif
34
35 typedef unsigned char string[STR_SIZE];
36
37 #define UNSIGNLONG unsigned long int
38 #define UNSIGNCHAR unsigned char
39
40 #define TRUE    1
41 #define FALSE   0
42 #define OK      TRUE
43 #define ERROR   FALSE
44 #define YES     TRUE
45 #define NO      FALSE
46 #define ON      TRUE
47 #define OFF     FALSE
48
49 /*----------------------------------------------------------------------*/
50
51 #define SHOW(var, fmt)  fprintf (stderr, "var = fmt\n", var)
52
53 /*----------------------------------------------------------------------*/
54
55 #define INTERNAL_FUNC  static
56 #define INTERNAL_VAR   static
57
58 /*----------------------------------------------------------------------*/
59
60 #define NEWLINE '\n'
61 #define TAB     '\t'
62 #define EOS     '\0'
63 #define BLANK   ' '
64 #define ETX     26      /* end of text signal for PC-DOS */
65
66 /*----------------------------------------------------------------------*/
67
68 #define MAXPATHNAME  65         /* max length of pathname + 1 */
69 #define MAXFILENAME  13         /* rootname(8) + '.'(1) + extension(3) + EOS */
70 #define MAXROOTNAME   8
71 #define MAXEXTNAME    3
72 #define MAXFULLNAME  MAXPATHNAME + MAXFILENAME
73
74 /*----------------------------------------------------------------------*/
75
76 #define ABS(x)    ((x) < 0 ? -(x) : (x))
77 #define SQR(x)    ((x) * (x))
78
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;}
82
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)
86
87 /*----------------------------------------------------------------------*/
88
89 struct time_st {
90         int hour, minute, second, hs;
91 };
92
93 struct date_st {
94         int year, month, date, dow;
95 };
96
97 struct timedate_st {
98     struct time_st t;
99     struct date_st d;
100 };
101
102 typedef struct time_st TIME;
103 typedef struct date_st DATE;
104 typedef struct timedate_st TIMEDATE;
105
106 /*----------------------------------------------------------------------*/
107
108 #define ERR_WARNING     0
109 #define ERR_SEVERE      1
110 #define ERR_FATAL       2
111
112 /*----------------------------------------------------------------------*/
113
114 /* codes for open command */
115
116 #ifdef LATTICE
117 #define OPEN_RDONLY  0x8000             /* Lattice codes for binary i/o */
118 #define OPEN_WRONLY  0x8001
119 #define OPEN_RDWR    0x8002
120 #elif MICROSOFT
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
124 #else
125 #define OPEN_RDONLY  0                  /* other system use standard codes */
126 #define OPEN_WRONLY  1                  /* for binary */
127 #define OPEN_RDWR    2
128 #endif
129
130 /*----------------------------------------------------------------------*/
131
132 /* codes for input (inp_*) routines */
133
134 #define INP_ERROR   -1
135 #define INP_NO      FALSE
136 #define INP_YES     TRUE
137 #define INP_NEITHER 'b'
138 #define INP_RETURN  'r'
139 #define INP_BREAK   0x8000
140
141 #ifndef O_BINARY
142 #define O_BINARY (0)
143 #endif
144
145 #ifndef S_IWRITE
146 #define S_IWRITE S_IWUSR
147 #endif
148
149 /* alloc.c */
150 void *alloc(unsigned int nbytes);
151 /* allocnum.c */
152 float *alloc_float(int n);
153 double *alloc_double(int n);
154 int *alloc_int(int n);
155 /* cant.c */
156 void cant(const char *fname);
157 /* cdate.c */
158 char *td_str_cdate(DATE *d);
159 char *td_month_name(int n);
160 char *td_day_name(int n);
161 /* ctoi.c */
162 char *ctoi(const char *s, int *ival);
163 /* fexist.c */
164 int file_exists(const char *fname);
165 /* fmax.c */
166 double fmax(double a, double b);
167 /* get_yn.c */
168 int get_yn(const char *prompt);
169 /* getbits.c */
170 unsigned int getbits(unsigned int x, int p, int n);
171 /* getch.c */
172 int getch(void);
173 void ungetch(int c);
174 /* getdate.c */
175 DATE *td_get_date(DATE *d);
176 /* gettime.c */
177 TIME *td_get_time(TIME *t);
178 /* iclip.c */
179 int iclip(int n, int lb, int ub);
180 /* infofn.c */
181 int infofn(unsigned int *attrib, long int *filesize, TIMEDATE *td);
182 /* irand.c */
183 unsigned int irand(unsigned int n);
184 /* itostr.c */
185 int itostr(int n, char str[], int size);
186 /* ltostr.c */
187 int ltostr(long val, char *cp, int base);
188 /* makefnam.c */
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[]);
193 /* putdec.c */
194 void putdec(const int n, int w, FILE *fd_out);
195 /* s_clip.c */
196 char *str_clip_tail(char *str, unsigned int nclip);
197 /* s_esc.c */
198 char *str_conv_esc(const char *from, char *to);
199 /* s_esc_c.c */
200 char *s_esc_char(const char *str, char *c);
201 /* s_get.c */
202 unsigned int str_get_last_char(const char *str);
203 /* s_head.c */
204 char *str_skip_head(const char *str, const char *charlist);
205 /* s_lower.c */
206 char *str_lower(char *s);
207 /* s_make.c */
208 char *str_make(char *str, int c, const int n);
209 /* s_revers.c */
210 char *str_reverse(char *s);
211 /* s_rmhead.c */
212 char *str_wrm_head(char *str);
213 char *str_rm_head(char *str, const char *skip_str);
214 /* s_rmtail.c */
215 char *str_rm_tail(char *str, const char *charlist);
216 /* s_save.c */
217 char *str_save(const char *s);
218 /* s_upper.c */
219 char *str_upper(char *str);
220 /* s_wtail.c */
221 char *str_wrm_tail(char *str);
222 /* searchfn.c */
223 int searchfn(const char pat[], const unsigned int attrib);
224 int getfn(const char name[]);
225 /* stime.c */
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);
232 /* strncmpc.c */
233 int strncmpc(const char *s, const char *t, int n);
234 /* sysalloc.c */
235 void *sys_alloc(const int nbytes, const char *name);
236 /* syserror.c */
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);
240 /* sysfopen.c */
241 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
242 /* sysfree.c */
243 void sys_free(void *ptr, const char *name);
244 /* timedate.c */
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);
250 /* kbasename.c */
251 char *kbasename(const char *filename);
252
253 #endif