Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtdocbook / sgmls / tools.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: tools.h /main/3 1996/06/19 17:18:54 drk $ */
24 /* TOOLS.H: Definitions for type declarations, printing, bit handling, etc.
25 */
26
27 #if CHAR_SIGNED
28 typedef unsigned char UNCH;
29 #else
30 typedef char UNCH;
31 #endif
32
33 #if CHAR_SIGNED
34 #define ustrcmp(s1, s2) strcmp((char *)(s1), (char *)(s2))
35 #define ustrcpy(s1, s2) strcpy((char *)(s1), (char *)(s2))
36 #define ustrchr(s, c) (UNCH *)strchr((char *)(s), c)
37 #define ustrncmp(s1, s2, n) strncmp((char *)(s1), (char *)(s2), n)
38 #define ustrncpy(s1, s2, n) strncpy((char *)(s1), (char *)(s2), n)
39 #define ustrlen(s1) strlen((char *)(s1))
40 #else
41 #define ustrcmp strcmp
42 #define ustrcpy strcpy
43 #define ustrchr strchr
44 #define ustrncmp strncmp
45 #define ustrncpy strncpy
46 #define ustrlen strlen
47 #endif
48
49 #if 0
50 int ustrcmp(UNCH *, UNCH *);
51 UNCH *ustrchr(UNCH *, int);
52 int ustrncmp(UNCH *, UNCH *, UNS);
53 int ustrncpy(UNCH *, UNCH *, UNS);
54 int ustrlen(UNCH *);
55 #endif
56
57 typedef unsigned UNS;
58
59 #ifdef USE_ISASCII
60 #define ISASCII(c) isascii(c)
61 #else
62 #define ISASCII(c) (1)
63 #endif
64
65 #ifdef BSD_STRINGS
66 #define MEMZERO(s, n) bzero(s, n)
67 #else /* not BSD_STRINGS */
68 #define MEMZERO(s, n) memset(s, '\0', n)
69 #endif /* not BSD_STRINGS */
70
71 /* Macros for bit manipulation.
72 */
73 #define SET(word, bits)          ((word) |= (bits))    /* Turn bits on */
74 #define RESET(word, bits)        ((word) &= ~(bits))   /* Turn bits off */
75 #define GET(word, bits)          ((word) & (bits))     /* 1=any bit on */
76 #define BITOFF(word, bits)       (GET(word, bits)==0)  /* 1=no bits on */
77 #define BITON(word, bits)        ((word) & (bits))     /* 1=any bit on */
78
79 #define ETDCDATA (dumetd)          /* Dummy etd pointer for #PCDATA. */
80 #define ETDNULL  (dumetd + 1)      /* Dummy etd pointer for null tag. */
81 #define ETDNET   (dumetd + 2)      /* Dummy etd pointer for NET delimiter. */
82 #define BADPTR(p) \
83   ((p) == NULL || (p) == ETDCDATA || (p) == ETDNULL || (p) == ETDNET)
84 #define PTRNUM(p) ((p) == NULL ? 0 : ((p) - dumetd) + 1)
85
86 #ifdef USE_PROTOTYPES
87 #define P(parms) parms
88 #else
89 #define P(parms) ()
90 #endif
91
92 /* VP is used for prototypes of varargs functions.  You can't have a
93 prototype if the function is defined using varargs.h rather than
94 stdarg.h. */
95 #ifdef VARARGS
96 #define VP(parms) ()
97 #else
98 #define VP(parms) P(parms)
99 #endif