Debian Codegraph @

jove.h

raw
1 /**************************************************************************
2 * This program is Copyright (C) 1986-2002 by Jonathan Payne. JOVE is *
3 * provided by Jonathan and Jovehacks without charge and without *
4 * warranty. You may copy, modify, and/or distribute JOVE, provided that *
5 * this notice is included in all the source files and documentation. *
6 **************************************************************************/
7
8 /* jove.h header file to be included by EVERYONE */
9
10 #ifndef TUNED
11 # include "tune.h" /* must include first since it controls everything else */
12 #endif
13
14 #include <time.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <stdlib.h>
18 #include <stdarg.h>
19 #include <limits.h> /* for CHAR_BIT */
20 #include <stdio.h> /* for EOF, NULL */
21 #include <setjmp.h>
22 #include <sys/types.h> /* defines off_t, pid_t, maybe FD_SET for select.h */
23
24 /*
25 * NO_EXTERNS leaves this out when building setmaps.c since externs.h is for the
26 * target, not the cross-compile host
27 */
28 #ifndef NO_EXTERNS
29 # include "externs.h"
30 #endif
31
32 #ifndef NCHARS
33 # define NCHARS 0400
34 #endif
35
36 #define NULL_DADDR ((daddr) 0)
37 #define DDIRTY ((daddr)1 << (sizeof(daddr)*CHAR_BIT - 1)) /* daddr dirty flag */
38
39 #define private static
40
41 typedef int jbool;
42 #define NO 0
43 #define YES 1
44
45 #define elemsof(a) (sizeof(a) / sizeof(*(a))) /* number of array elements */
46
47 #define byte_copy(from, to, count) memcpy((void *)(to), (const void *)(from), (size_t)(count))
48 #define byte_move(from, to, count) memmove((void *)(to), (const void *)(from), (size_t)(count))
49 #define byte_zero(s, n) memset((void *)(s), 0, (size_t)(n))
50
51 /* Safe-where-possible signal handling.
52 *
53 * SIGHANDLERTYPE: the type of a pointer to a signal handler
54 * setsighandler: the best way to establish a signal handler
55 * resetsighandler: the best way to re-establish a signal handler
56 */
57
58 typedef SIGRESTYPE (*SIGHANDLERTYPE)(int);
59
60 #ifdef POSIX_SIGS
61 extern SIGHANDLERTYPE setsighandler(int, SIGHANDLERTYPE);
62 # define resetsighandler(signo, handler) /* nothing */
63 #else /* !POSIX_SIGS */
64 # ifdef USE_SIGSET
65 # define setsighandler(signo, handler) sigset((signo), (handler))
66 # define resetsighandler(signo, handler) /* nothing */
67 # else /* !USE_SIGSET */
68 /* BSD_SIGS or default: use signal() */
69 # define setsighandler(signo, handler) signal((signo), (handler))
70 # endif /* !USE_SIGSET */
71 #endif /* !POSIX_SIGS */
72
73 #ifndef resetsighandler
74 /* On some systems, the signal handler is left established,
75 * but this is not the case with original UNIX signals.
76 * This code adjusts to the system at hand, at fairly low cost.
77 * This code is even used for BSD_SIGS, even though it should not
78 * be needed: it compensates for mis-configuration.
79 * Note: this routine will only work if every execution of a particular
80 * call is for the same handler. Furthermore, all executions should
81 * be due to the handler being invoked by a signal. These restrictions
82 * ensure that the setting of the static variable indicates whether
83 * signal handlers need to be re-established.
84 */
85 # define resetsighandler(signo, handler) { \
86 static SIGHANDLERTYPE reset_handler; \
87 \
88 if (reset_handler != (handler)) \
89 reset_handler = setsighandler((signo), (handler)); \
90 }
91 #endif
92
93 /* Principles of character representation in JOVE:
94 *
95 * - Only legal characters (excluding NUL) may be stored in the buffer.
96 *
97 * - Only legal characters will be found in the input stream, as
98 * delivered by getch and kbd_getch (the meta-key feature
99 * may cause invalid characters to be read, but they will be
100 * confined within kbd_getch).
101 *
102 * - Bad characters from a file should be discarded. Perhaps a message
103 * should be generated. NUL should be considered one of these bad
104 * characters. [The elimination of these characters is the duty of
105 * callers of jgetc.]
106 *
107 * - The type of a string (ignoring const or volatile) should be "char *".
108 * This is the standard type specified by the ANSI/ISO C standard.
109 * As such, it is the type expected by the standard library.
110 *
111 * - In general, it is reasonable to use a plain char type
112 * to represent an individual character, avoiding the expense and
113 * fuss of widening.
114 *
115 * + The character must be known not to be an EOF.
116 *
117 * + The character must only be used in ways in which sign extension
118 * is known to not cause problems:
119 *
120 * * The value is coerced into a char type (the most common example
121 * is assignment to a char; another is the search character in a
122 * call to strchr). Of course, EOF must not appear in these
123 * contexts.
124 *
125 * * The value is used for equality or inequality comparison where
126 * all operands are subject to identical char widening. A
127 * special case of this is 7-bit ASCII char literals:
128 * they can be safely compared for equality or inequality with
129 * chars widened explicitly or implicitly.
130 *
131 * - ZXchar is the type for a character that has been widened without
132 * sign extension. It can represent EOF distinctly from characters.
133 * The ZXC and ZXRC functions should be used to do the widening.
134 *
135 * - DAPchar is the type that results from the "default argument promotions"
136 * applied to the char type. Since most of our function definitions are
137 * in the old style, formals declared in these definitions to be of type
138 * char should be declared to be of type DAPchar in any prototype (this is
139 * an arcane ANSI C rule). The widening involved might be sign-extension
140 * or it might not, but we don't care because it will be immediately
141 * narrowed. A C implementation can legally make the type "unsigned int",
142 * but this is highly unlikely. By extension, a value of this type may be
143 * used anywhere a char is needed.
144 *
145 * The following functions widen char type to an int, without sign
146 * extension. There are two kinds:
147 *
148 * ZXC(c): zero-extend an internal char. It is presumed that
149 * the character is clean, but we may have to prevent sign extension.
150 *
151 * ZXRC(c): zero-extend a external (raw) char. The purpose is to prevent
152 * sign extension, even if the char is invalid.
153 */
154
155 typedef int ZXchar; /* type for expanded char (possibly EOF) */
156
157 #ifndef DAPchar
158 # define DAPchar int /* DefaultArgPromotion(char) */
159 #endif
160
161 #ifndef UCHAR_ROOF
162 # define UCHAR_ROOF 256 /* better be true! */
163 #endif
164
165 #if NCHARS == 128
166 # ifndef ZXC
167 # define ZXC(c) (c) /* identity op -- sign bit must be off */
168 # endif
169 #else
170 # if NCHARS == UCHAR_ROOF
171 # ifndef ZXC
172 # define ZXC(c) ((ZXchar) (unsigned char) (c))
173 # endif
174 # else
175 /* ??? */
176 # endif
177 #endif
178
179 #ifndef ZXRC
180 # define ZXRC(c) ((ZXchar) (unsigned char) (c))
181 #endif
182
183 /* Pervasive exports of other modules */
184
185 /* disp.c */
186 extern volatile jbool UpdModLine; /* Does the mode line need to be updated? */
187
188 /* term.c: universal termcap-like declarations */
189
190 extern int
191 SG, /* number of magic cookies left by SO and SE */
192 LI, /* number of lines */
193 ILI, /* number of internal lines (LI - 1) */
194 CO; /* number of columns (CO <= MAXCOLS) */
195
196 extern jbool
197 TABS; /* terminal supports tabs */
198
199 /* typedef pervasive structure definitions */
200
201 typedef struct window Window; /* wind.h */
202 typedef struct position Bufpos; /* buf.h */
203 typedef struct mark Mark; /* buf.h (not mark.h!) */
204 typedef struct buffer Buffer; /* buf.h */
205 #ifdef FAR_LINES
206 typedef struct line _far *LinePtr; /* buf.h */
207 #else
208 typedef struct line *LinePtr; /* buf.h */
209 #endif
210 typedef struct FileStruct File; /* fp.h */
211
212 #include "buf.h"
213 #include "io.h"
214 #include "dataobj.h"
215 #include "keymaps.h"
216 #include "argcount.h"
217 #include "util.h"
218
219 #define FORWARD 1
220 #define BACKWARD (-1)
221
222 /* jove.c exports: */
223
224 /* paths */
225
226 extern char
227 ShareDir[FILESIZE], /* VAR: directory path of machine-independent support files */
228 LibDir[FILESIZE], /* VAR: directory path of machine-dependent support programs */
229 TmpDir[FILESIZE]; /* VAR: directory path to store tmp files, must exist */
230
231 #ifdef SUBSHELL
232 extern char
233 Shell[FILESIZE], /* VAR: shell to use */
234 ShFlags[16]; /* VAR: flags to shell */
235 #endif
236
237
238 /* setjmp/longjmp args for DoKeys() mainjmp */
239 #define JMP_ERROR 1
240 #define JMP_COMPLAIN 2 /* do the error without a getDOT */
241 #define JMP_QUIT 3 /* leave this level of recursion */
242
243 extern jmp_buf mainjmp;
244
245 #define IDX(c) ((c)-'a')
246 #define IDXSZ (IDX('z')+1)
247
248 extern char NullStr[];
249
250 extern ZXchar
251 peekchar, /* holds pushed-back getch output */
252 LastKeyStruck; /* used by SelfInsert and friends */
253
254 extern int
255 RecDepth, /* recursion depth (used by disp.c for modeline) */
256 SlowCmd; /* depth of nesting of slow commands */
257
258 extern jbool
259 TOabort, /* flag set by Typeout() */
260 stickymsg, /* the last message should stick around */
261 InputPending, /* is there input waiting to be processed? */
262 Interactive;
263
264 #ifdef UNIX
265 extern jbool
266 InSlowRead; /* Can we do a redisplay in a signal handler? */
267 #endif
268
269 extern char *Inputp;
270
271 #ifdef WINRESIZE
272 # define PreEmptOutput() (ResizePending || (SlowCmd == 0 && charp()))
273 # define CheapPreEmptOutput() (ResizePending || (SlowCmd == 0 && InputPending))
274 #else
275 # define PreEmptOutput() (SlowCmd == 0 && charp())
276 # define CheapPreEmptOutput() (SlowCmd == 0 && InputPending)
277 #endif
278
279 #ifdef SUBSHELL
280 extern void jcloseall(void);
281 #endif
282
283 extern SIGRESTYPE
284 finish(int code) NEVER_RETURNS, /* doesn't return at all! */
285 win_reshape(int UNUSED(junk));
286
287 extern jbool
288 charp(void);
289
290 extern ZXchar
291 getch(void),
292 kbd_getch(void),
293 peek_or_mac_getch(void),
294 waitchar(void),
295 ask_ks(void);
296
297 extern void
298 cmd_sync(void),
299 add_stroke(ZXchar),
300 error(const char *, ...) NEVER_RETURNS,
301 complain(const char *, ...) NEVER_RETURNS,
302 raw_complain(const char *, ...),
303 confirm(const char *, ...),
304 SitFor(int delay),
305 pp_key_strokes(char *buffer, size_t size),
306 tty_adjust(void),
307 Ungetc(ZXchar c),
308 kbd_ungetch(ZXchar c),
309 dispatch_macros(void);
310
311 /* Commands: */
312
313 extern void
314 #ifdef JOB_CONTROL
315 PauseJove(void),
316 #endif
317 #ifdef SUBSHELL
318 Push(void),
319 #endif
320 Recur(void),
321 TeachJove(void),
322 ShowVersion(void);
323
324 /* Variables: */
325
326 extern jbool MetaKey; /* VAR: this terminal has a meta key */
327 extern jbool TimeDisplayed; /* is time actually displayed in modeline? */
328 extern char JoveFeatures[MAXCOLS]; /* VAR: list of compiled-in features */
329
330 #if defined(UNIX) || defined(MINGW)
331 extern char JoveCompiled[MAXCOLS]; /* VAR: compile flags used to build this */
332 extern char JoveLinked[MAXCOLS]; /* VAR: link flags used to build this */
333 #endif /* UNIX || MINGW */
334
335 #ifdef UNIX
336 extern int UpdFreq; /* VAR: how often to update modeline */
337 extern void SetClockAlarm(jbool unset);
338 #endif /* UNIX */
339
340 extern jbool SaveOnExit; /* VAR: offer to save buffers on exit */