r28: *** empty log message ***
[ctsim.git] / include / kstddef.h
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: kstddef.h,v 1.5 2000/05/02 20:00:25 kevin Exp $
6 **  $Log: kstddef.h,v $
7 **  Revision 1.5  2000/05/02 20:00:25  kevin
8 **  *** empty log message ***
9 **
10 **  Revision 1.4  2000/04/28 18:00:55  kevin
11 **  remove unused files
12 **
13 **  Revision 1.3  2000/04/28 17:38:16  kevin
14 **  Removed unused files
15 **
16 **  Revision 1.2  2000/04/28 14:14:16  kevin
17 **  *** empty log message ***
18 **
19 **
20 **  This program is free software; you can redistribute it and/or modify
21 **  it under the terms of the GNU General Public License (version 2) as
22 **  published by the Free Software Foundation.
23 **
24 **  This program is distributed in the hope that it will be useful,
25 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
26 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 **  GNU General Public License for more details.
28 **
29 **  You should have received a copy of the GNU General Public License
30 **  along with this program; if not, write to the Free Software
31 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32 ******************************************************************************/
33 /******************************************************************************
34  *
35  * FILE IDENTIFICATION
36  *
37  *      File Name:      STDDEF.H
38  *      Author:         Kevin Rosenberg
39  *      Purpose:        Header file containing KRL standard C definitions
40  *      Date Started:   Dec. 83
41  *
42  * DESCRIPTION
43  *      Header file contains KRL standard C definitions
44  *
45  * MODIFICATION LOG
46  *
47  *****************************************************************************/
48
49 #ifndef STDDEF_H
50 #define STDDEF_H
51
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <stdarg.h>
56
57 #undef SHELL
58
59 #define STR_MAX_LEN 255
60 #define STR_SIZE    STR_MAX_LEN+1
61
62 #ifndef bool
63 typedef signed int bool;                /* Boolean variable type */
64 #endif
65
66 typedef unsigned char string[STR_SIZE];
67
68 #define UNSIGNLONG unsigned long int
69 #define UNSIGNCHAR unsigned char
70
71 #define TRUE    1
72 #define FALSE   0
73 #define OK      TRUE
74 #define ERROR   FALSE
75 #define YES     TRUE
76 #define NO      FALSE
77 #define ON      TRUE
78 #define OFF     FALSE
79
80 /*----------------------------------------------------------------------*/
81
82 #define SHOW(var, fmt)  fprintf (stderr, "var = fmt\n", var)
83
84 /*----------------------------------------------------------------------*/
85
86 #define INTERNAL_FUNC  static
87 #define INTERNAL_VAR   static
88
89 /*----------------------------------------------------------------------*/
90
91 #define NEWLINE '\n'
92 #define TAB     '\t'
93 #define EOS     '\0'
94 #define BLANK   ' '
95 #define ETX     26      /* end of text signal for PC-DOS */
96
97 /*----------------------------------------------------------------------*/
98
99 #define MAXPATHNAME  65         /* max length of pathname + 1 */
100 #define MAXFILENAME  13         /* rootname(8) + '.'(1) + extension(3) + EOS */
101 #define MAXROOTNAME   8
102 #define MAXEXTNAME    3
103 #define MAXFULLNAME  MAXPATHNAME + MAXFILENAME
104
105 /*----------------------------------------------------------------------*/
106
107 #define ABS(x)    ((x) < 0 ? -(x) : (x))
108 #define SQR(x)    ((x) * (x))
109
110 #define MAX(a,b)  ((a) > (b) ? (a) : (b))
111 #define MIN(a,b)  ((a) <= (b) ? (a) : (b))
112 #define ISWAP(a,b) {int i; i = a; a = b; b = i;}
113
114 #define CLIP(n,lb,ub)   if (n < lb) n = lb; else if (n > ub) n = ub
115 #define FOREVER         for (;;)
116 #define STR_EQUAL(s1,s2) (strcmp (s1, s2) == 0)
117
118 /*----------------------------------------------------------------------*/
119
120 struct time_st {
121         int hour, minute, second, hs;
122 };
123
124 struct date_st {
125         int year, month, date, dow;
126 };
127
128 struct timedate_st {
129     struct time_st t;
130     struct date_st d;
131 };
132
133 typedef struct time_st TIME;
134 typedef struct date_st DATE;
135 typedef struct timedate_st TIMEDATE;
136
137 /*----------------------------------------------------------------------*/
138
139 #define ERR_WARNING     0
140 #define ERR_SEVERE      1
141 #define ERR_FATAL       2
142
143 /*----------------------------------------------------------------------*/
144
145 /* codes for open command */
146
147 #ifdef LATTICE
148 #define OPEN_RDONLY  0x8000             /* Lattice codes for binary i/o */
149 #define OPEN_WRONLY  0x8001
150 #define OPEN_RDWR    0x8002
151 #elif MICROSOFT
152 #define OPEN_RDONLY  O_RDONLY                   /* other system use standard codes */
153 #define OPEN_WRONLY  O_WRONLY                   /* for binary */
154 #define OPEN_RDWR    O_RDWR
155 #else
156 #define OPEN_RDONLY  0                  /* other system use standard codes */
157 #define OPEN_WRONLY  1                  /* for binary */
158 #define OPEN_RDWR    2
159 #endif
160
161 /*----------------------------------------------------------------------*/
162
163 /* codes for input (inp_*) routines */
164
165 #define INP_ERROR   -1
166 #define INP_NO      FALSE
167 #define INP_YES     TRUE
168 #define INP_NEITHER 'b'
169 #define INP_RETURN  'r'
170 #define INP_BREAK   0x8000
171
172 #ifndef O_BINARY
173 #define O_BINARY (0)
174 #endif
175
176 #ifndef S_IWRITE
177 #define S_IWRITE S_IWUSR
178 #endif
179
180 /* allocnum.c */
181 float *alloc_float(int n);
182 double *alloc_double(int n);
183 int *alloc_int(int n);
184 /* fexist.c */
185 int file_exists(const char *fname);
186 /* kbasename.c */
187 char *kbasename(const char *filename);
188 /* iclip.c */
189 int iclip(int n, int lb, int ub);
190 /* s_head.c */
191 char *str_skip_head(const char *str, const char *charlist);
192 /* s_lower.c */
193 char *str_lower(char *s);
194 /* s_rmtail.c */
195 char *str_wrm_tail(char *str);
196 char *str_rm_tail(char *str, const char *charlist);
197 /* s_save.c */
198 char *str_save(const char *s);
199 /* s_upper.c */
200 char *str_upper(char *str);
201 /* sysalloc.c */
202 void *sys_alloc(const int nbytes, const char *name);
203 /* syserror.c */
204 void sys_error(int severity, const char *msg, ...);
205 void sys_verror(int severity, const char *msg, va_list arg);
206 void sys_error_level(int severity);
207 /* sysfopen.c */
208 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
209 /* sysfree.c */
210 void sys_free(void *ptr, const char *name);
211 /* timedate.c */
212 DATE *td_get_date(DATE *d);
213 TIME *td_get_time(TIME *t);
214 double td_current_sec(void);
215 double td_time_to_sec(TIME *t);
216 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
217 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
218 TIME *td_time_copy(TIME *to, const TIME *from);
219 TIME *td_time_norm(TIME *t);
220 void td_get_tmdt(TIMEDATE *td);
221 const char *td_str_tmdt(const TIMEDATE *td);
222 const char *td_str_time(const TIME *t);
223 const char *td_str_stime(const TIME *t);
224 const char *td_str_date(const DATE *d);
225 char *td_str_cdate(DATE *d);
226 char *td_month_name(int n);
227 char *td_day_name(int n);
228
229 #endif