summaryrefslogtreecommitdiff
path: root/src/tet3/inc/dtmac.h
blob: 87527806b0f3f1abb7d3c216974b6c39db2c00c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
 *      SCCS:  @(#)dtmac.h	1.14 (98/08/28) 
 *
 *	UniSoft Ltd., London, England
 *
 * (C) Copyright 1992 X/Open Company Limited
 * (C) Copyright 1994 UniSoft Limited
 *
 * All rights reserved.  No part of this source code may be reproduced,
 * stored in a retrieval system, or transmitted, in any form or by any
 * means, electronic, mechanical, photocopying, recording or otherwise,
 * except as stated in the end-user licence agreement, without the prior
 * permission of the copyright owners.
 *
 * X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
 * the UK and other countries.
 */

/************************************************************************

SCCS:   	@(#)dtmac.h	1.14 98/08/28 TETware release 3.3
NAME:		dtmac.h
PRODUCT:	TETware
AUTHOR:		Andrew Dingwall, UniSoft Ltd.
DATE CREATED:	April 1992

DESCRIPTION:
	useful macros used in various parts of the system
	macros that interface to the trace subsystem

MODIFICATIONS:
	Andrew Dingwall, UniSoft Ltd., December 1993
	moved most of the non-posix band-aid stuff from individual
	source files to here

	Andrew Dingwall, UniSoft Ltd., September 1996
	added compatibility macros for the NT port

	Andrew Dingwall, UniSoft Ltd., March 1997
	added support for (WIN32-specific) tet_unlink()

	Andrew Dingwall, UniSoft Ltd., July 1997
	added support the MT DLL version of the C runtime support library
	on Win32 systems

	Andrew Dingwall, UniSoft Ltd., March 1998
	removed references to sys_errlist[] and sys_nerr since these
	symbols are no longer in the Single Unix Specification

	Andrew Dingwall, UniSoft Ltd., July 1998
	Added support for shared API libraries.
	Changed MAX() and MIN() to TET_MAX() and TET_MIN().

	Aaron Plattner, April 2010
	Fixed warnings when compiled with GCC's -Wall option.

************************************************************************/

/*
**	macros that might be system-dependent
*/

/* SIG_T is the type for the return value of signal(),
   SIG_FUNC_T is the type for the function argument to signal() */
#ifdef SVR2
#  define SIG_T		int
#  define SIG_FUNC_T	void
#else
#  if defined(BSD42) || defined(BSD43)
#    define SIG_T	int
#    define SIG_FUNC_T	int
#  else
#    define SIG_T	void
#    define SIG_FUNC_T	void
# endif /* BSD */
#endif /* SVR2 */

/* define NOMKDIR if the system does not have the mkdir() and rmdir() system
	calls - see dtetlib/mkdir.c */
#ifdef SVR2
#  define NOMKDIR
#endif

/*
** decide what type of directory access method to use;
** these defines determine which include files are used
*/
#ifdef SVR2
#  define NDIR		/* include <ndir.h> */
#else
#  if defined(BSD42) || defined(BSD43) || defined(ultrix)
#    define SYSDIR	/* include <sys/dir.h> */
#  else
#      define DIRENT	/* default - include <dirent.h> */
#  endif /* BSD */
#endif /* SVR2 */

/* choose whether to include function declaration files (like <stdlib.h>)
	or declare non-int functions locally in each file */
#if defined(SVR2) || defined(BSD42) || defined(BSD43)
#  define LOCAL_FUNCTION_DECL
#endif

/*
**	function prototypes
**
**	we define PROTOTYPES if the compiler understands ANSI-style
**	function prototypes
**
**	if PROTOTYPES is defined, we assume that system header files
**	are protected against multiple inclusion as well
*/

#if defined(__STDC__) || defined(__cplusplus)
#  ifndef PROTOTYPES
#    define PROTOTYPES
#  endif
#endif

/* function prototype macro */
#ifdef PROTOTYPES
#  define PROTOLIST(list)	list
#else
#  define PROTOLIST(list)	()
#  define const
#endif

/*
**	macros to provide access to UNIX-like system calls and library routines
**
**	each macro provides access to a function which is not part of
**	ANSI C, and thus may not be available on all platforms
**
**	a set of macros appears here for each API to which TETware is ported;
**	each set of compatibility macros also defines TET_COMPAT_MACROS
**	which is used to ensure that exactly one set of compatibility macros
**	is defined
**
**	note that the macros which appear here should only be used internally
**	by TETware and (in some cases) only provide sufficient functionality
**	for use by TETware routines
*/



/*
** UNIX-like systems - the default
**
** most of these functions are declared in <unistd.h>
*/
#ifndef TET_COMPAT_MACROS

#  define TET_COMPAT_MACROS

#  define ACCESS(A, B)		access((A), (B))
#  define CHDIR(A)		chdir((A))
#  define CHMOD(A, B)		chmod((A), (B))
#  define CLOSE(A)		close((A))
#  define CLOSEDIR(A)		closedir((A))
#  define ENVIRON		environ
#  define FCNTL_F_DUPFD(A, B)	fcntl((A), F_DUPFD, (B))
#  define FDOPEN(A, B)		fdopen((A), (B))
#  define FILENO(A)		fileno((A))
#  define FSTAT(A, B)		fstat((A), (B))
#  define GETCWD(A, B)		getcwd((A), (B))
#  define GETOPT(A, B, C)	getopt((A), (B), (C))
#  define GETPID()		getpid()
#  define KILL(A, B)		kill((A), (B))
#  define OPEN(A, B, C)		open((A), (B), (C))
#  define OPENDIR(A)		opendir((A))
#  define READ(A, B, C)		read((A), (B), (C))
#  define READDIR(A)		readdir((A))
#  define SLEEP(A)		((void) sleep(A))
#  define STAT(A, B)		stat((A), (B))
#  define STAT_ST		stat
#  define UNLINK(A)		unlink((A))
#  define WRITE(A, B, C)	write((A), (B), (C))

   /* extra help for the OPEN() macro */
#  ifndef O_TEXT
#    define O_TEXT		0
#  endif
#  ifndef O_BINARY
#    define O_BINARY		0
#  endif
#  ifndef O_NOINHERIT
#    define O_NOINHERIT		0
#  endif

   /* extra help for the socket interface */
   typedef int SOCKET;
#  define INVALID_SOCKET	-1
#  define SOCKET_ERROR		-1
#  define SOCKET_ERRNO		errno
#  define CLEAR_SOCKET_ERRNO	errno = 0
#  define SOCKET_CLOSE(A)	close((A))
#  define SOCKET_FIOCLEX(A)	tet_fioclex((A))
#  define SOCKET_IOCTL(A, B, C)	ioctl((A), (B), (C))
#  define SOCKET_ECONNRESET	ECONNRESET
#  define SOCKET_EINPROGRESS	EINPROGRESS
#  define SOCKET_EINTR		EINTR
#  define SOCKET_EWOULDBLOCK	EWOULDBLOCK

#endif /* TET_COMPAT_MACROS */


/*
**	Band-aid to enable a Win32 DLL to behave more like
**	a UNIX shared library, and for shared library implementations
**	that need import and export lists to be generated.
*/

/*
** When a shared API library is built, the API library has two parts;
** a SHARED part (libapi_s) and a STATIC part (libtcm_s).
** The static part mostly consists of the TCM object files that go in
** libapi when the static API library is built.
**
** If TET_SHLIB is defined it means that we are building a shared API library.
** If TET_SHLIB_SOURCE is defined it means that we are compiling code
** that goes in the a shared API library.
**
** TET_SHLIB is defined in the tcm*shlib makefiles.
** TET_SHLIB_SOURCE is defined in the api*shlib makefiles.
**
** TET_SHLIB_SOURCE implies TET_SHLIB
*/
#if defined(TET_SHLIB_SOURCE) && !defined(TET_SHLIB)
#  define TET_SHLIB
#endif


   /* not using shared libraries on a Win32 system */
#  define TET_IMPORT
#  define TET_EXPORT


#if !defined(TET_SHLIB_BUILD_SCRIPT) && !defined(TET_DYNLINK_SOURCE) && !defined(TET_DLCHECK_SOURCE)
#  define TET_EXPORT_FUNC(TYPE, NAME, ARGS) \
	TET_EXPORT extern TYPE NAME ARGS
#  define TET_EXPORT_FUNC_PTR(TYPE, NAME, ARGS) \
	TET_EXPORT extern TYPE (*NAME) ARGS
#  define TET_EXPORT_DATA(TYPE, NAME) \
	TET_EXPORT extern TYPE NAME
#  define TET_EXPORT_ARRAY(TYPE, NAME, DIM) \
	TET_EXPORT extern TYPE NAME DIM
#endif

#ifndef TET_SHLIB_BUILD_SCRIPT
#  define TET_IMPORT_FUNC(TYPE, NAME, ARGS) \
	TET_IMPORT extern TYPE NAME ARGS
#  define TET_IMPORT_FUNC_PTR(TYPE, NAME, ARGS) \
	TET_IMPORT extern TYPE (*NAME) ARGS
#  define TET_IMPORT_DATA(TYPE, NAME) \
	TET_IMPORT extern TYPE NAME
#  define TET_IMPORT_ARRAY(TYPE, NAME, DIM) \
	TET_IMPORT extern TYPE NAME DIM
#endif


/*
**	macros to classify path names
*/

/* macros to identify a directory separator character */
#define ispcdirsep(x)		((x) == '/' || (x) == '\\')
#define isunixdirsep(x)		((x) == '/')

#  define isdirsep(x)		isunixdirsep(x)

/*
** macros to clasify path names on PC platforms
**
** these valid on all platforms
*/

/* path starts with a drive specifier */
#define isdrvspec(x)	(isalpha(*(x)) && *((x) + 1) == ':')

/* path is an absolute path name on the current drive */
#define isabsoncur(x)	ispcdirsep(*(x))

/* path is an absolute path name on a specified drive */
#define isabsondrv(x)	(isdrvspec(x) && isabsoncur((x) + 2))

/* these valid on PCs */


/* macro to identify an absolute path name on the local machine */
#  define isabspathloc(x)	isunixdirsep(*(x))

/*
** macro to identify an absolute path name on a remote machine which 
** could be a UNIX or a PC platform
*/
#define isabspathrem(x)		(isabsondrv(x) || isunixdirsep(*(x)))



/*
**	macros that are common to all systems
*/

/* define TESTING here if it's not on the cc command line */
#ifndef TESTING
#  define TESTING 0
#endif

/* maximimum and minimum macros */
#define TET_MAX(a, b)	((a) > (b) ? (a) : (b))
#define TET_MIN(a, b)	((a) < (b) ? (a) : (b))

/* maximum length for a path name - needs to be system-independent */
#define MAXPATH		1024

/* maximum length for a system name as found in the DTET systems file */
#define SNAMELEN	32


/*
**	band-aid for non-posix systems
*/

#if defined(SVR2) || defined(BSD42) || defined(BSD43)
   typedef int mode_t;
   typedef int size_t;
   typedef int pid_t;
   typedef int uid_t;
#endif /* SVR2 || BSD4x */

#ifdef S_IFMT	/* non-posix <sys/stat.h> is included */
#  ifndef S_IRUSR
#    define S_IRUSR	0400
#    define S_IWUSR 0200
#    define S_IXUSR 0100
#    define S_IRGRP	040
#    define S_IWGRP	020
#    define S_IXGRP	010
#    define S_IROTH	04
#    define S_IWOTH	02
#    define S_IXOTH	01
#    define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
#    define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
#    define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
#  endif /* S_IRUSR */
#  ifndef S_ISDIR
#    define S_ISDIR(m)	(((m) & S_IFMT) == (S_IFDIR))
#  endif /* S_ISDIR */
#  ifndef S_ISREG
#    define S_ISREG(m)	(((m) & S_IFMT) == (S_IFREG))
#  endif /* S_ISREG */
#  ifndef S_ISFIFO
#    define S_ISFIFO(m)	(((m) & S_IFMT) == (S_IFIFO))
#  endif /* S_ISFIFO */
#endif /* S_IFMT */

#if defined(stdout) && !defined(SEEK_SET)	/* non-posix <stdio.h> */
#  define SEEK_SET	0
#  define SEEK_CUR	1
#  define SEEK_END	2
#endif

/*
**	trace macros
*/

#ifdef NOTRACE

#  define TRACE1(flag, level, s1)
#  define TRACE2(flag, level, s1, s2)
#  define TRACE3(flag, level, s1, s2, s3)
#  define TRACE4(flag, level, s1, s2, s3, s4)
#  define TRACE5(flag, level, s1, s2, s3, s4, s5)
#  define TRACE6(flag, level, s1, s2, s3, s4, s5, s6)
#  define TDUMP(flag, level, from, count, title)
#  define BUFCHK(bpp, lp, newlen)	tet_bufchk(bpp, lp, newlen)

#else /* NOTRACE */

#  define TRACE1(flag, level, s1)	\
	TRACE2(flag, level, s1, (char *) 0)

#  define TRACE2(flag, level, s1, s2) \
	TRACE3(flag, level, s1, s2, (char *) 0)

#  define TRACE3(flag, level, s1, s2, s3) \
	TRACE4(flag, level, s1, s2, s3, (char *) 0)

#  define TRACE4(flag, level, s1, s2, s3, s4) \
	TRACE5(flag, level, s1, s2, s3, s4, (char *) 0)

#  define TRACE5(flag, level, s1, s2, s3, s4, s5) \
	TRACE6(flag, level, s1, s2, s3, s4, s5, (char *) 0)

#  define TRACE6(flag, level, s1, s2, s3, s4, s5, s6) \
	if ((flag) >= (level)) tet_trace(s1, s2, s3, s4, s5, s6); else

#  define TDUMP(flag, level, from, count, title) \
	if ((flag) >= (level)) tet_tdump(from, count, title); else

#  define BUFCHK(bpp, lp, newlen) \
	tet_buftrace(bpp, lp, newlen, __FILE__, __LINE__)

   /*
   **	declarations of extern functions and data items
   */

   /* trace flag declarations */
   TET_IMPORT_DATA(int, tet_Tbuf);
   TET_IMPORT_DATA(int, tet_Ttcm);
   extern int tet_Ttcc, tet_Ttrace, tet_Tscen, tet_Texec;
#  ifndef TET_LITE	/* -START-LITE-CUT- */
      extern int tet_Tio, tet_Tloop, tet_Tserv, tet_Tsyncd, tet_Ttccd,
	tet_Txresd;
#  endif /* !TET_LITE */	/* -END-LITE-CUT- */

   /* trace subsystem function definitions */
   extern void tet_tdump PROTOLIST((char *, int, char *));
   TET_IMPORT_FUNC(void, tet_tfclear, PROTOLIST((void)));
   TET_IMPORT_FUNC(void, tet_trace,
        PROTOLIST((const char *, const char *, const char *, const char *,
                   const char *, const char *)));
   extern char **tet_traceargs PROTOLIST((int, char **));
   TET_IMPORT_FUNC(void, tet_traceinit, PROTOLIST((int, char **)));

#endif	/* NOTRACE */