1 /*************************************************************************
2  *  TinyFugue - programmable mud client
3  *  Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2004, 2005, 2006-2007 Ken Keys
4  *
5  *  TinyFugue (aka "tf") is protected under the terms of the GNU
6  *  General Public License.  See the file "COPYING" for details.
7  ************************************************************************/
8 /* $Id: tf.h,v 35004.59 2007/01/13 23:12:39 kkeys Exp $ */
9 
10 #ifndef TF_H
11 #define TF_H
12 
13 #ifndef NCOLORS
14 # define NCOLORS 16
15 #endif
16 
17 #if SIZEOF_INT == 4
18     typedef unsigned int attr_t;
19 #elif SIZEOF_LONG == 4
20     typedef unsigned long attr_t;
21 #else
22 #   error "no 32 bit integer?"
23 #endif
24 
25 #if NCOLORS == 256 /* character attributes can't fit in 16 bits */
26 # if SIZEOF_INT == 4
27     typedef unsigned int cattr_t;
28 # elif SIZEOF_LONG == 4
29     typedef unsigned long cattr_t;
30 # else
31 #   error "no 32 bit integer?"
32 # endif
33 #else /* character attributes can fit in 16 bits */
34 # if SIZEOF_SHORT == 2
35     typedef unsigned short cattr_t;
36 # elif SIZEOF_INT == 2
37     typedef unsigned int cattr_t;
38 # else
39 #   error "no 16 bit integer?"
40 # endif
41 #endif
42 
43 /* headers needed everywhere */
44 #include <time.h>	/* may conflict with <sys/time.h> on some systems? */
45 #include <sys/time.h>	/* for struct timeval */
46 #include "malloc.h"
47 #include "dstring.h"
48 #include "globals.h"
49 
50 #if SOCKS
51 # if (SOCKS == 4)
52 #  define connect Rconnect
53 #  define select Rselect
54 # else /* (SOCKS >= 5) */
55 #  include <socks.h>
56 # endif
57 #endif
58 
59 
60 /*
61  * TinyFugue global types and variables.
62  */
63 
64 typedef struct Program Program;
65 typedef struct Screen Screen;
66 typedef struct Pattern Pattern;
67 typedef struct Macro Macro;
68 typedef struct World World;
69 
70 #define RESTRICT_SHELL  1
71 #define RESTRICT_FILE   2
72 #define RESTRICT_WORLD  3
73 
74 typedef char smallstr[65];     /* Short buffer */
75 
76 enum enum_attr {
77     /* inside the 16 low bits */
78     F_UNDERLINE   = 0x0001,
79     F_REVERSE     = 0x0002,
80     F_FLASH       = 0x0000,   /* zero - not implemented */
81     F_DIM         = 0x0000,   /* zero - not implemented */
82     F_BOLD        = 0x0004,
83     F_HILITE      = 0x0008,
84     F_NONE        = 0x0010,
85     F_EXCLUSIVE   = 0x0020,
86 
87 #if NCOLORS == 256 /* XXX ??? */
88 # define FGCOLORSHIFT 8
89     F_FGCOLORMASK = 0x0000ff00,   /* 8 bits, interpreted as an integer */
90     F_FGCOLOR     = 0x00000040,   /* flag */
91 # define BGCOLORSHIFT 16
92     F_BGCOLORMASK = 0x00ff0000,   /* 8 bits, interpreted as an integer */
93     F_BGCOLOR     = 0x00000080,   /* flag */
94 #else
95     /* inside the 16 low bits */
96 # define FGCOLORSHIFT 8
97     F_FGCOLORMASK = 0x0f00,   /* 4 bits, interpreted as an integer */
98     F_FGCOLOR     = 0x0040,   /* flag */
99 # define BGCOLORSHIFT 12
100     F_BGCOLORMASK = 0x7000,   /* 3 bits, interpreted as an integer */
101     F_BGCOLOR     = 0x0080,   /* flag */
102 #endif
103 
104     /* outside the 16 low bits */
105     F_NOACTIVITY  = 0x01000000,	    /* does not count as activity */
106     F_NOLOG       = 0x02000000,
107     F_BELL        = 0x04000000,
108     F_GAG         = 0x08000000,
109     F_NOHISTORY   = 0x10000000,
110 
111     F_TFPROMPT    = 0x20000000,	    /* is a prompt generated by tf */
112     F_SERVPROMPT  = 0x40000000,	    /* is a prompt from server */
113 
114     F_FGCOLORS    = (F_FGCOLOR | F_FGCOLORMASK),
115     F_BGCOLORS    = (F_BGCOLOR | F_BGCOLORMASK),
116     F_COLORS      = (F_FGCOLORS | F_BGCOLORS),
117     F_SIMPLE      = (F_UNDERLINE | F_REVERSE | F_FLASH | F_DIM | F_BOLD),
118     F_HWRITE      = (F_SIMPLE | F_HILITE | F_COLORS),
119     F_ENCODE      = (F_SIMPLE | F_HILITE | F_FGCOLOR | F_BGCOLOR),
120     F_ATTR        = (F_HWRITE | F_GAG | F_NOHISTORY | F_NOACTIVITY | F_NONE |
121 		    F_EXCLUSIVE)
122 };
123 
124 #define attr2fgcolor(attr)    (((attr) & F_FGCOLORMASK) >> FGCOLORSHIFT)
125 #define attr2bgcolor(attr)    (((attr) & F_BGCOLORMASK) >> BGCOLORSHIFT)
126 #define fgcolor2attr(color)   (F_FGCOLOR | ((color) << FGCOLORSHIFT))
127 #define bgcolor2attr(color)   (F_BGCOLOR | ((color) << BGCOLORSHIFT))
128 
129 # define attr2cattr(attr)    ((cattr_t)(attr & F_HWRITE))
130 
131 extern attr_t adj_attr(attr_t base, attr_t adj);
132 
133 
134 /* Macros for defining and manipulating bit vectors of arbitrary length.
135  * We use an array of long because select() does, and these macros will be
136  * used with select() on systems without the FD_* macros.
137  */
138 
139 #ifndef NBBY
140 # define NBBY 8                                   /* bits per byte */
141 #endif
142 #ifndef LONGBITS
143 # define LONGBITS  (sizeof(long) * NBBY)          /* bits per long */
144 #endif
145 
146 #define VEC_TYPEDEF(type, size) \
147     typedef struct { \
148         unsigned long bits[(((size) + LONGBITS - 1) / LONGBITS)]; \
149     } (type)
150 
151 #define VEC_SET(n,p)   ((p)->bits[(n)/LONGBITS] |= (1L << ((n) % LONGBITS)))
152 #define VEC_CLR(n,p)   ((p)->bits[(n)/LONGBITS] &= ~(1L << ((n) % LONGBITS)))
153 #define VEC_ISSET(n,p) ((p)->bits[(n)/LONGBITS] & (1L << ((n) % LONGBITS)))
154 #if HAVE_MEMCPY   /* assume memcpy implies memset and bcopy implies bzero. */
155 # define VEC_ZERO(p)   memset((char *)(p)->bits, '\0', sizeof(*(p)))
156 #else
157 # define VEC_ZERO(p)   bzero((char *)(p)->bits, sizeof(*(p)))
158 #endif
159 
160 
161 /* Define enumerated constants */
162 #define ENUMEXTERN extern
163 #define bicode(a, b)  a
164 #include "enumlist.h"
165 
166 extern conString enum_off[];
167 extern conString enum_flag[];
168 extern conString enum_sub[];
169 extern conString enum_color[];
170 
171 /* hook definitions */
172 
173 extern int do_hook(int indx, const char *fmt, const char *argfmt, ...)
174     format_printf(2, 4);
175 
176 enum Hooks {
177 #define gencode(id, type)  H_##id
178 #include "hooklist.h"
179 #undef gencode
180     NUM_HOOKS
181 };
182 
183 VEC_TYPEDEF(hookvec_t, NUM_HOOKS);
184 
185 
186 /* externs */
187 extern const char version[], sysname[], copyright[], contrib[], mods[];
188 extern int restriction, debug;
189 extern void internal_error(const char *file, int line,
190     const char *fmt, ...) format_printf(3, 4);
191 extern void internal_error2(const char *file, int line, const char *file2,
192     int line2, const char *fmt, ...) format_printf(5, 6);
193 
194 
195 #endif /* TF_H */
196