r107: initial cvs import
[ctsim.git] / include / kstddef.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **      File Name:      kstddef.h
5 **      Author:         Kevin Rosenberg
6 **      Purpose:        Header file containing KRL standard C definitions
7 **      Date Started:   Dec. 83
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: kstddef.h,v 1.18 2000/06/19 18:18:13 kevin Exp $
13 **
14 **
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.
18 **
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.
23 **
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 ******************************************************************************/
28
29 #ifndef STDDEF_H
30 #define STDDEF_H
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #ifdef _WIN32
37 #define snprintf _snprintf
38 #endif
39
40 #define STR_MAX_LEN 255
41 #define STR_SIZE    STR_MAX_LEN+1
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <stdarg.h>
47
48 #define TRUE    1
49 #define FALSE   0
50 #define OK      TRUE
51 #define ERROR   FALSE
52 #define YES     TRUE
53 #define NO      FALSE
54
55 /*----------------------------------------------------------------------*/
56
57 #define SHOW(var, fmt)  { cerr << "var = " << var << endl; }
58
59 /*----------------------------------------------------------------------*/
60
61 #define NEWLINE '\n'
62 #define TAB     '\t'
63 #define EOS     '\0'
64 #define BLANK   ' '
65
66 /*----------------------------------------------------------------------*/
67
68 struct time_st {
69         int hour, minute, second, ms;
70 };
71
72 struct date_st {
73         int year, month, date, dow;
74 };
75
76 struct timedate_st {
77     struct time_st t;
78     struct date_st d;
79 };
80
81 typedef struct time_st TIME;
82 typedef struct date_st DATE;
83 typedef struct timedate_st TIMEDATE;
84
85 /*----------------------------------------------------------------------*/
86
87 #define ERR_WARNING     0
88 #define ERR_SEVERE      1
89 #define ERR_FATAL       2
90
91 /*----------------------------------------------------------------------*/
92
93
94 /* codes for open command */
95 #if MICROSOFT
96 #define OPEN_RDONLY  O_RDONLY                   /* other system use standard codes */
97 #define OPEN_WRONLY  O_WRONLY                   /* for binary */
98 #define OPEN_RDWR    O_RDWR
99 #else
100 #define OPEN_RDONLY  0                  /* other system use standard codes */
101 #define OPEN_WRONLY  1                  /* for binary */
102 #define OPEN_RDWR    2
103 #endif
104
105 /*----------------------------------------------------------------------*/
106
107 #ifndef O_BINARY
108 #define O_BINARY (0)
109 #endif
110
111 #ifndef S_IWRITE
112 #define S_IWRITE S_IWUSR
113 #endif
114
115 /*----------------------------------------------------------------------*/
116
117 #if defined(MICROSOFT) || ! defined(SIZEOF_INT)
118    #define SIZEOF_INT 4
119    #define SIZEOF_LONG 4
120    #define SIZEOF_SHORT 2
121    #define SIZEOF_FLOAT 4
122    #define SIZEOF_DOUBLE 8
123 #endif
124
125 typedef signed char kint8;
126 typedef unsigned char kuint8;
127
128 #if SIZEOF_INT == 4
129     typedef int kint32;
130     typedef unsigned int kuint32;
131 #elif SIZEOF_LONG == 4
132     typedef long int kint32;
133     typedef unsigned int kuint32;
134 #endif
135
136 #if SIZEOF_SHORT == 2
137     typedef short int kint16;
138     typedef unsigned short int kuint16;
139 #elif SIZEOF_INT == 2
140     typedef int kint16;
141     typedef unsigned int kuint16;
142 #endif
143
144 #if SIZEOF_FLOAT == 4
145     typedef float kfloat32;
146 #endif
147 #if SIZEOF_DOUBLE == 8
148     typedef double kfloat64;
149 #endif
150
151
152 /* filefuncs.cpp */
153 bool file_exists(const char* fname);
154 const char* fileBasename(const char* filename);
155 FILE *sys_fopen(const char *filename, const char *mode, const char *progname);
156
157 /* strfuncs.cpp */
158 char* str_skip_head(const char* str, const char* const charlist);
159 char* str_skip_head(const char* str, char* charlist);
160 char *str_lower(char *s);
161 char *str_wrm_tail(char *str);
162 char *str_rm_tail(char *str, const char* const charlist);
163 char *str_upper(char *str);
164
165 /* syserror.cpp */
166 void sys_error(int severity, const char *msg, ...);
167 void sys_verror(int severity, const char *msg, va_list arg);
168 void sys_error_level(int severity);
169
170 /* timedate.cpp */
171 DATE *td_get_date(DATE *d);
172 TIME *td_get_time(TIME *t);
173 double td_current_sec(void);
174 double td_time_to_sec(TIME *t);
175 TIME *td_time_sub(const TIME *t1, const TIME *t2, TIME *tdiff);
176 TIME *td_time_add(const TIME *t1, const TIME *t2, TIME *tsum);
177 TIME *td_time_copy(TIME *to, const TIME *from);
178 TIME *td_time_norm(TIME *t);
179 void td_get_tmdt(TIMEDATE *td);
180 const char *td_str_tmdt(const TIMEDATE *td);
181 const char *td_str_time(const TIME *t);
182 const char *td_str_stime(const TIME *t);
183 const char *td_str_date(const DATE *d);
184 char *td_str_cdate(DATE *d);
185 char *td_month_name(int n);
186 char *td_day_name(int n);
187
188 #endif