xref: /freebsd/contrib/less/less.h (revision 1b6c76a2fe091c74f08427e6c870851025a9cf67)
1 /* $FreeBSD$ */
2 /*
3  * Copyright (C) 1984-2000  Mark Nudelman
4  *
5  * You may distribute under the terms of either the GNU General Public
6  * License or the Less License, as specified in the README file.
7  *
8  * For more information about less, or for information on how to
9  * contact the author, see the README file.
10  */
11 
12 
13 /*
14  * Standard include file for "less".
15  */
16 
17 /*
18  * Defines for MSDOS_COMPILER.
19  */
20 #define	MSOFTC		1	/* Microsoft C */
21 #define	BORLANDC	2	/* Borland C */
22 #define	WIN32C		3	/* Windows (Borland C or Microsoft C) */
23 #define	DJGPPC		4	/* DJGPP C */
24 
25 /*
26  * Include the file of compile-time options.
27  * The <> make cc search for it in -I., not srcdir.
28  */
29 #include <defines.h>
30 
31 #ifdef _SEQUENT_
32 /*
33  * Kludge for Sequent Dynix systems that have sigsetmask, but
34  * it's not compatible with the way less calls it.
35  * {{ Do other systems need this? }}
36  */
37 #undef HAVE_SIGSETMASK
38 #endif
39 
40 /*
41  * Language details.
42  */
43 #if HAVE_VOID
44 #define	VOID_POINTER	void *
45 #else
46 #define	VOID_POINTER	char *
47 #define	void  int
48 #endif
49 #if HAVE_CONST
50 #define	constant	const
51 #else
52 #define	constant
53 #endif
54 
55 #define	public		/* PUBLIC FUNCTION */
56 
57 /* Library function declarations */
58 
59 #if HAVE_SYS_TYPES_H
60 #include <sys/types.h>
61 #endif
62 #if HAVE_STDIO_H
63 #include <stdio.h>
64 #endif
65 #if HAVE_FCNTL_H
66 #include <fcntl.h>
67 #endif
68 #if HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
71 #if HAVE_CTYPE_H
72 #include <ctype.h>
73 #endif
74 #if HAVE_STDLIB_H
75 #include <stdlib.h>
76 #endif
77 #if HAVE_STRING_H
78 #include <string.h>
79 #endif
80 #ifdef _OSK
81 #include <modes.h>
82 #include <strings.h>
83 #endif
84 #if MSDOS_COMPILER==WIN32C
85 #include <io.h>
86 #endif
87 #if MSDOS_COMPILER==DJGPPC
88 #include <io.h>
89 #include <sys/exceptn.h>
90 #include <conio.h>
91 #include <pc.h>
92 #endif
93 
94 #if !HAVE_STDLIB_H
95 char *getenv();
96 off_t lseek();
97 VOID_POINTER calloc();
98 void free();
99 #endif
100 
101 /*
102  * Simple lowercase test which can be used during option processing
103  * (before options are parsed which might tell us what charset to use).
104  */
105 #define SIMPLE_IS_UPPER(c)	((c) >= 'A' && (c) <= 'Z')
106 #define SIMPLE_IS_LOWER(c)	((c) >= 'a' && (c) <= 'z')
107 #define	SIMPLE_TO_UPPER(c)	((c) - 'a' + 'A')
108 #define	SIMPLE_TO_LOWER(c)	((c) - 'A' + 'a')
109 
110 #if !HAVE_UPPER_LOWER
111 #define	isupper(c)	SIMPLE_IS_UPPER(c)
112 #define	islower(c)	SIMPLE_IS_LOWER(c)
113 #define	toupper(c)	SIMPLE_TO_UPPER(c)
114 #define	tolower(c)	SIMPLE_TO_LOWER(c)
115 #endif
116 
117 #ifndef NULL
118 #define	NULL	0
119 #endif
120 
121 #ifndef TRUE
122 #define	TRUE		1
123 #endif
124 #ifndef FALSE
125 #define	FALSE		0
126 #endif
127 
128 #define	OPT_OFF		0
129 #define	OPT_ON		1
130 #define	OPT_ONPLUS	2
131 
132 #if !HAVE_MEMCPY
133 #ifndef memcpy
134 #define	memcpy(to,from,len)	bcopy((from),(to),(len))
135 #endif
136 #endif
137 
138 #define	BAD_LSEEK	((off_t)-1)
139 
140 /*
141  * Special types and constants.
142  */
143 typedef off_t		POSITION;
144 #define PR_POSITION	"%lld"
145 #define MAX_PRINT_POSITION 20
146 #define MAX_PRINT_INT      10
147 
148 #define	NULL_POSITION	((POSITION)(-1))
149 
150 /*
151  * Flags for open()
152  */
153 #if MSDOS_COMPILER || OS2
154 #define	OPEN_READ	(O_RDONLY|O_BINARY)
155 #else
156 #ifdef _OSK
157 #define	OPEN_READ	(S_IREAD)
158 #else
159 #ifdef O_RDONLY
160 #define	OPEN_READ	(O_RDONLY)
161 #else
162 #define	OPEN_READ	(0)
163 #endif
164 #endif
165 #endif
166 
167 #if defined(O_WRONLY) && defined(O_APPEND)
168 #define	OPEN_APPEND	(O_APPEND|O_WRONLY)
169 #else
170 #ifdef _OSK
171 #define OPEN_APPEND	(S_IWRITE)
172 #else
173 #define	OPEN_APPEND	(1)
174 #endif
175 #endif
176 
177 /*
178  * Set a file descriptor to binary mode.
179  */
180 #if MSDOS_COMPILER==MSOFTC
181 #define	SET_BINARY(f)	_setmode(f, _O_BINARY);
182 #else
183 #if MSDOS_COMPILER
184 #define	SET_BINARY(f)	setmode(f, O_BINARY)
185 #else
186 #define	SET_BINARY(f)
187 #endif
188 #endif
189 
190 /*
191  * Does the shell treat "?" as a metacharacter?
192  */
193 #if MSDOS_COMPILER || OS2 || _OSK
194 #define	SHELL_META_QUEST 0
195 #else
196 #define	SHELL_META_QUEST 1
197 #endif
198 
199 #define	SPACES_IN_FILENAMES 1
200 
201 /*
202  * An IFILE represents an input file.
203  */
204 #define	IFILE		VOID_POINTER
205 #define	NULL_IFILE	((IFILE)NULL)
206 
207 /*
208  * The structure used to represent a "screen position".
209  * This consists of a file position, and a screen line number.
210  * The meaning is that the line starting at the given file
211  * position is displayed on the ln-th line of the screen.
212  * (Screen lines before ln are empty.)
213  */
214 struct scrpos
215 {
216 	POSITION pos;
217 	int ln;
218 };
219 
220 typedef union parg
221 {
222 	char *p_string;
223 	int p_int;
224 } PARG;
225 
226 #define	NULL_PARG	((PARG *)NULL)
227 
228 struct textlist
229 {
230 	char *string;
231 	char *endstring;
232 };
233 
234 #define	EOI		(-1)
235 
236 #define	READ_INTR	(-2)
237 
238 /* How quiet should we be? */
239 #define	NOT_QUIET	0	/* Ring bell at eof and for errors */
240 #define	LITTLE_QUIET	1	/* Ring bell only for errors */
241 #define	VERY_QUIET	2	/* Never ring bell */
242 
243 /* How should we prompt? */
244 #define	PR_SHORT	0	/* Prompt with colon */
245 #define	PR_MEDIUM	1	/* Prompt with message */
246 #define	PR_LONG		2	/* Prompt with longer message */
247 
248 /* How should we handle backspaces? */
249 #define	BS_SPECIAL	0	/* Do special things for underlining and bold */
250 #define	BS_NORMAL	1	/* \b treated as normal char; actually output */
251 #define	BS_CONTROL	2	/* \b treated as control char; prints as ^H */
252 
253 /* How should we search? */
254 #define	SRCH_FORW	000001	/* Search forward from current position */
255 #define	SRCH_BACK	000002	/* Search backward from current position */
256 #define	SRCH_NO_MOVE	000004	/* Highlight, but don't move */
257 #define	SRCH_FIND_ALL	000010	/* Find and highlight all matches */
258 #define	SRCH_NO_MATCH	000100	/* Search for non-matching lines */
259 #define	SRCH_PAST_EOF	000200	/* Search past end-of-file, into next file */
260 #define	SRCH_FIRST_FILE	000400	/* Search starting at the first file */
261 #define	SRCH_NO_REGEX	001000	/* Don't use regular expressions */
262 
263 #define	SRCH_REVERSE(t)	(((t) & SRCH_FORW) ? \
264 				(((t) & ~SRCH_FORW) | SRCH_BACK) : \
265 				(((t) & ~SRCH_BACK) | SRCH_FORW))
266 
267 /* */
268 #define	NO_MCA		0
269 #define	MCA_DONE	1
270 #define	MCA_MORE	2
271 
272 #define	CC_OK		0	/* Char was accepted & processed */
273 #define	CC_QUIT		1	/* Char was a request to abort current cmd */
274 #define	CC_ERROR	2	/* Char could not be accepted due to error */
275 #define	CC_PASS		3	/* Char was rejected (internal) */
276 
277 #define CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
278 
279 /* Special chars used to tell put_line() to do something special */
280 #define	AT_NORMAL	(0)
281 #define	AT_UNDERLINE	(1)
282 #define	AT_BOLD		(2)
283 #define	AT_BLINK	(3)
284 #define	AT_INVIS	(4)
285 #define	AT_STANDOUT	(5)
286 
287 #if IS_EBCDIC_HOST
288 /*
289  * Long definition for EBCDIC.
290  * Since the argument is usually a constant, this macro normally compiles
291  * into a constant.
292  */
293 #define CONTROL(c) ( \
294 	(c)=='[' ? '\047' : \
295 	(c)=='a' ? '\001' : \
296 	(c)=='b' ? '\002' : \
297 	(c)=='c' ? '\003' : \
298 	(c)=='d' ? '\067' : \
299 	(c)=='e' ? '\055' : \
300 	(c)=='f' ? '\056' : \
301 	(c)=='g' ? '\057' : \
302 	(c)=='h' ? '\026' : \
303 	(c)=='i' ? '\005' : \
304 	(c)=='j' ? '\025' : \
305 	(c)=='k' ? '\013' : \
306 	(c)=='l' ? '\014' : \
307 	(c)=='m' ? '\015' : \
308 	(c)=='n' ? '\016' : \
309 	(c)=='o' ? '\017' : \
310 	(c)=='p' ? '\020' : \
311 	(c)=='q' ? '\021' : \
312 	(c)=='r' ? '\022' : \
313 	(c)=='s' ? '\023' : \
314 	(c)=='t' ? '\074' : \
315 	(c)=='u' ? '\075' : \
316 	(c)=='v' ? '\062' : \
317 	(c)=='w' ? '\046' : \
318 	(c)=='x' ? '\030' : \
319 	(c)=='y' ? '\031' : \
320 	(c)=='z' ? '\077' : \
321 	(c)=='A' ? '\001' : \
322 	(c)=='B' ? '\002' : \
323 	(c)=='C' ? '\003' : \
324 	(c)=='D' ? '\067' : \
325 	(c)=='E' ? '\055' : \
326 	(c)=='F' ? '\056' : \
327 	(c)=='G' ? '\057' : \
328 	(c)=='H' ? '\026' : \
329 	(c)=='I' ? '\005' : \
330 	(c)=='J' ? '\025' : \
331 	(c)=='K' ? '\013' : \
332 	(c)=='L' ? '\014' : \
333 	(c)=='M' ? '\015' : \
334 	(c)=='N' ? '\016' : \
335 	(c)=='O' ? '\017' : \
336 	(c)=='P' ? '\020' : \
337 	(c)=='Q' ? '\021' : \
338 	(c)=='R' ? '\022' : \
339 	(c)=='S' ? '\023' : \
340 	(c)=='T' ? '\074' : \
341 	(c)=='U' ? '\075' : \
342 	(c)=='V' ? '\062' : \
343 	(c)=='W' ? '\046' : \
344 	(c)=='X' ? '\030' : \
345 	(c)=='Y' ? '\031' : \
346 	(c)=='Z' ? '\077' : \
347 	(c)=='|' ? '\031' : \
348 	(c)=='\\' ? '\034' : \
349 	(c)=='^' ? '\036' : \
350 	(c)&077)
351 #else
352 #define	CONTROL(c)	((c)&037)
353 #endif /* IS_EBCDIC_HOST */
354 
355 #define	ESC		CONTROL('[')
356 
357 #if _OSK_MWC32
358 #define	LSIGNAL(sig,func)	os9_signal(sig,func)
359 #else
360 #define	LSIGNAL(sig,func)	signal(sig,func)
361 #endif
362 
363 #if HAVE_SIGPROCMASK
364 #if HAVE_SIGSET_T
365 #else
366 #undef HAVE_SIGPROCMASK
367 #endif
368 #endif
369 #if HAVE_SIGPROCMASK
370 #if HAVE_SIGEMPTYSET
371 #else
372 #undef  sigemptyset
373 #define sigemptyset(mp) *(mp) = 0
374 #endif
375 #endif
376 
377 #define	S_INTERRUPT	01
378 #define	S_STOP		02
379 #define S_WINCH		04
380 #define	ABORT_SIGS()	(sigs & (S_INTERRUPT|S_STOP))
381 
382 #define	QUIT_OK		0
383 #define	QUIT_ERROR	1
384 #define	QUIT_SAVED_STATUS (-1)
385 
386 /* filestate flags */
387 #define	CH_CANSEEK	001
388 #define	CH_KEEPOPEN	002
389 #define	CH_POPENED	004
390 #define	CH_HELPFILE	010
391 
392 #define	ch_zero()	((POSITION)0)
393 
394 #define	FAKE_HELPFILE	"@/\\less/\\help/\\file/\\@"
395 
396 #include "funcs.h"
397 
398