xref: /freebsd/contrib/less/less.h (revision dafba19e42e78cd3d7c9264ece49ddd3d7d70da5)
1 /*
2  * Copyright (C) 1984-2025  Mark Nudelman
3  *
4  * You may distribute under the terms of either the GNU General Public
5  * License or the Less License, as specified in the README file.
6  *
7  * For more information, see the README file.
8  */
9 
10 /*
11  * Standard include file for "less".
12  */
13 
14 /*
15  * Defines for MSDOS_COMPILER.
16  */
17 #define MSOFTC          1   /* Microsoft C */
18 #define BORLANDC        2   /* Borland C */
19 #define WIN32C          3   /* Windows (Borland C or Microsoft C) */
20 #define DJGPPC          4   /* DJGPP C */
21 
22 /*
23  * Include the file of compile-time options.
24  * The <> make cc search for it in -I., not srcdir.
25  */
26 #include <defines.h>
27 
28 #ifdef _SEQUENT_
29 /*
30  * Kludge for Sequent Dynix systems that have sigsetmask, but
31  * it's not compatible with the way less calls it.
32  * {{ Do other systems need this? }}
33  */
34 #undef HAVE_SIGSETMASK
35 #endif
36 
37 
38 /* Library function declarations */
39 
40 #if HAVE_SYS_TYPES_H
41 #include <sys/types.h>
42 #endif
43 #if HAVE_STDIO_H
44 #include <stdio.h>
45 #endif
46 #if HAVE_FCNTL_H
47 #include <fcntl.h>
48 #endif
49 #if HAVE_UNISTD_H
50 #include <unistd.h>
51 #endif
52 #if HAVE_CTYPE_H
53 #include <ctype.h>
54 #endif
55 #if HAVE_LIMITS_H
56 #include <limits.h>
57 #endif
58 #if HAVE_STDINT_H
59 #include <stdint.h>
60 #endif
61 #if HAVE_STDLIB_H
62 #include <stdlib.h>
63 #endif
64 #if HAVE_STRING_H
65 #include <string.h>
66 #endif
67 
68 #if HAVE_STDCKDINT_H
69 #include <stdckdint.h>
70 #else
71 /*
72  * These substitutes for C23 stdckdint macros do not set *R on overflow,
73  * and they assume A and B are nonnegative.  That is good enough for us.
74  */
75 #define ckd_add(r, a, b) help_ckd_add(r, (uintmax)(a), (uintmax)(b), sizeof *(r), signed_expr(*(r)))
76 #define ckd_mul(r, a, b) help_ckd_mul(r, (uintmax)(a), (uintmax)(b), sizeof *(r), signed_expr(*(r)))
77 /* True if the integer expression E, after promotion, is signed.  */
78 #define signed_expr(e) ((TRUE ? 0 : e) - 1 < 0)
79 #endif
80 #define muldiv(val,num,den) umuldiv((uintmax)(val), (uintmax)(num), (uintmax)(den))
81 
82 #include "lang.h"
83 
84 #if defined UINTMAX_MAX
85 typedef uintmax_t uintmax;
86 #elif defined ULLONG_MAX
87 typedef unsigned long long uintmax;
88 #else
89 typedef unsigned long uintmax;
90 #endif
91 
92 /* OS-specific includes */
93 #ifdef _OSK
94 #include <modes.h>
95 #include <strings.h>
96 #endif
97 
98 #ifdef __TANDEM
99 #include <floss.h>
100 #endif
101 
102 #if MSDOS_COMPILER==WIN32C || OS2
103 #include <io.h>
104 #endif
105 
106 #if MSDOS_COMPILER==DJGPPC
107 #include <io.h>
108 #include <sys/exceptn.h>
109 #include <conio.h>
110 #include <pc.h>
111 #endif
112 
113 #if !HAVE_STDLIB_H
114 char *getenv();
115 off_t lseek();
116 void *calloc();
117 void free();
118 #endif
119 
120 /*
121  * Simple lowercase test which can be used during option processing
122  * (before options are parsed which might tell us what charset to use).
123  */
124 #define ASCII_IS_UPPER(c)       ((c) >= 'A' && (c) <= 'Z')
125 #define ASCII_IS_LOWER(c)       ((c) >= 'a' && (c) <= 'z')
126 #define ASCII_TO_UPPER(c)       ((c) - 'a' + 'A')
127 #define ASCII_TO_LOWER(c)       ((c) - 'A' + 'a')
128 
129 #undef IS_UPPER
130 #undef IS_LOWER
131 #undef TO_UPPER
132 #undef TO_LOWER
133 #undef IS_SPACE
134 #undef IS_DIGIT
135 
136 #if HAVE_WCTYPE
137 #define IS_UPPER(c)     iswupper((wint_t) (c))
138 #define IS_LOWER(c)     iswlower((wint_t) (c))
139 #define TO_UPPER(c)     towupper((wint_t) (c))
140 #define TO_LOWER(c)     towlower((wint_t) (c))
141 #else
142 #if HAVE_UPPER_LOWER
143 #define IS_UPPER(c)     (is_ascii_char(c) && isupper((unsigned char) (c)))
144 #define IS_LOWER(c)     (is_ascii_char(c) && islower((unsigned char) (c)))
145 #define TO_UPPER(c)     (is_ascii_char(c) ? toupper((unsigned char) (c)) : (c))
146 #define TO_LOWER(c)     (is_ascii_char(c) ? tolower((unsigned char) (c)) : (c))
147 #else
148 #define IS_UPPER(c)     (is_ascii_char(c) && ASCII_IS_UPPER(c))
149 #define IS_LOWER(c)     (is_ascii_char(c) && ASCII_IS_LOWER(c))
150 #define TO_UPPER(c)     (is_ascii_char(c) ? ASCII_TO_UPPER(c) : (c))
151 #define TO_LOWER(c)     (is_ascii_char(c) ? ASCII_TO_LOWER(c) : (c))
152 #endif
153 #endif
154 
155 #ifdef isspace
156 #define IS_SPACE(c)     isspace((unsigned char)(c))
157 #else
158 #define IS_SPACE(c)     ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
159 #endif
160 
161 #ifdef isdigit
162 #define IS_DIGIT(c)     isdigit((unsigned char)(c))
163 #else
164 #define IS_DIGIT(c)     ((c) >= '0' && (c) <= '9')
165 #endif
166 
167 #define IS_CSI_START(c) (control_char(c) && (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI)))
168 
169 #define OPT_OFF         0
170 #define OPT_ON          1
171 #define OPT_ONPLUS      2
172 
173 #if !HAVE_MEMCPY
174 #ifndef memcpy
175 #define memcpy(to,from,len)     bcopy((from),(to),(len))
176 #endif
177 #endif
178 
179 #if HAVE_SNPRINTF
180 #define SNPRINTF1(str, size, fmt, v1)             snprintf((str), (size), (fmt), (v1))
181 #define SNPRINTF2(str, size, fmt, v1, v2)         snprintf((str), (size), (fmt), (v1), (v2))
182 #define SNPRINTF3(str, size, fmt, v1, v2, v3)     snprintf((str), (size), (fmt), (v1), (v2), (v3))
183 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
184 #else
185 /* Use unsafe sprintf if we don't have snprintf. */
186 #define SNPRINTF1(str, size, fmt, v1)             sprintf((str), (fmt), (v1))
187 #define SNPRINTF2(str, size, fmt, v1, v2)         sprintf((str), (fmt), (v1), (v2))
188 #define SNPRINTF3(str, size, fmt, v1, v2, v3)     sprintf((str), (fmt), (v1), (v2), (v3))
189 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
190 #endif
191 
192 #define BAD_LSEEK       ((off_t)-1)
193 
194 #ifndef SEEK_SET
195 #define SEEK_SET 0
196 #endif
197 #ifndef SEEK_END
198 #define SEEK_END 2
199 #endif
200 
201 #ifndef CHAR_BIT
202 #define CHAR_BIT 8
203 #endif
204 
205 /*
206  * Upper bound on the string length of an integer converted to string.
207  * 302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
208  * add 1 for integer division truncation; add 1 more for a minus sign.
209  */
210 #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
211 
212 /*
213  * Special types and constants.
214  */
215 typedef unsigned long LWCHAR;
216 #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER >= 1500)
217 typedef long long less_off_t;  /* __int64 */
218 typedef struct _stat64 less_stat_t;
219 #define less_fstat _fstat64
220 #define less_stat _stat64
221 #define less_lseek _lseeki64
222 #else
223 typedef off_t less_off_t;
224 typedef struct stat less_stat_t;
225 #define less_fstat fstat
226 #define less_stat stat
227 #define less_lseek lseek
228 #endif
229 typedef less_off_t      POSITION;
230 typedef off_t           LINENUM;
231 #define MIN_LINENUM_WIDTH   7   /* Default min printing width of a line number */
232 #define MAX_LINENUM_WIDTH   16  /* Max width of a line number */
233 #define MAX_STATUSCOL_WIDTH 4   /* Max width of the status column */
234 #define MAX_UTF_CHAR_LEN    6   /* Max bytes in one UTF-8 char */
235 #define MAX_PRCHAR_LEN      31  /* Max chars in prchar() result */
236 
237 #define NULL_POSITION   ((POSITION)(-1))
238 
239 /*
240  * Flags for open()
241  */
242 #if MSDOS_COMPILER || OS2
243 #define OPEN_READ       (O_RDONLY|O_BINARY)
244 #else
245 #ifdef _OSK
246 #define OPEN_READ       (S_IREAD)
247 #else
248 #ifdef O_RDONLY
249 #define OPEN_READ       (O_RDONLY)
250 #else
251 #define OPEN_READ       (0)
252 #endif
253 #endif
254 #endif
255 
256 #if defined(O_WRONLY) && defined(O_APPEND)
257 #define OPEN_APPEND     (O_APPEND|O_WRONLY)
258 #else
259 #ifdef _OSK
260 #define OPEN_APPEND     (S_IWRITE)
261 #else
262 #define OPEN_APPEND     (1)
263 #endif
264 #endif
265 
266 /* Use iread() to read tty? */
267 #if !MSDOS_COMPILER || MSDOS_COMPILER == DJGPPC
268 #define LESS_IREAD_TTY 1
269 #endif
270 
271 /*
272  * Flags for creat()
273  */
274 #if MSDOS_COMPILER
275 #define CREAT_RW        (S_IREAD|S_IWRITE)
276 #else
277 #define CREAT_RW        0644
278 #endif
279 
280 /*
281  * Set a file descriptor to binary mode.
282  */
283 #if MSDOS_COMPILER==MSOFTC
284 #define SET_BINARY(f)   _setmode(f, _O_BINARY);
285 #else
286 #if MSDOS_COMPILER || OS2
287 #define SET_BINARY(f)   setmode(f, O_BINARY)
288 #else
289 #define SET_BINARY(f)
290 #endif
291 #endif
292 
293 #define SPACES_IN_FILENAMES 1
294 
295 /*
296  * An IFILE represents an input file.
297  */
298 #define IFILE           void*
299 #define NULL_IFILE      ((IFILE)NULL)
300 
301 /*
302  * The structure used to represent a "screen position".
303  * This consists of a file position, and a screen line number.
304  * The meaning is that the line starting at the given file
305  * position is displayed on the ln-th line of the screen.
306  * (Screen lines before ln are empty.)
307  */
308 struct scrpos
309 {
310         POSITION pos;
311         int ln;
312 };
313 
314 typedef union parg
315 {
316         constant char *p_string;
317         int p_int;
318         LINENUM p_linenum;
319         char p_char;
320 } PARG;
321 
322 #define NULL_PARG       ((PARG *)NULL)
323 
324 struct textlist
325 {
326         char *string;
327         char *endstring;
328 };
329 
330 struct wchar_range
331 {
332         LWCHAR first, last;
333 };
334 
335 struct wchar_range_table
336 {
337 	struct wchar_range *table;
338 	unsigned int count;
339 };
340 
341 #if HAVE_POLL
342 typedef short POLL_EVENTS;
343 #endif
344 
345 #define EOI             (-1)
346 
347 #define READ_ERR        (-1)
348 #define READ_INTR       (-2)
349 #define READ_AGAIN      (-3)
350 
351 /*
352  * A fraction is represented by a long n; the fraction is n/NUM_FRAC_DENOM.
353  * To avoid overflow problems, 0 <= n < NUM_FRAC_DENUM <= LONG_MAX/100.
354  */
355 #define NUM_FRAC_DENOM                  1000000
356 #define NUM_LOG_FRAC_DENOM              6
357 
358 /*
359  * Max expected reasonable duration of a paste.
360  * Increasing this value avoids accidentally reenabling unwanted paste input
361  * in the middle of a very long paste but risks apparently frozen UI if the
362  * end bracket is missing.
363  */
364 #define MAX_PASTE_IGNORE_SEC            5
365 
366 /* How quiet should we be? */
367 #define NOT_QUIET       0       /* Ring bell at eof and for errors */
368 #define LITTLE_QUIET    1       /* Ring bell only for errors */
369 #define VERY_QUIET      2       /* Never ring bell */
370 
371 /* How should we prompt? */
372 #define PR_SHORT        0       /* Prompt with colon */
373 #define PR_MEDIUM       1       /* Prompt with message */
374 #define PR_LONG         2       /* Prompt with longer message */
375 
376 /* How should we handle backspaces? */
377 #define BS_SPECIAL      0       /* Do special things for underlining and bold */
378 #define BS_NORMAL       1       /* \b treated as normal char; actually output */
379 #define BS_CONTROL      2       /* \b treated as control char; prints as ^H */
380 
381 /* How should we search? */
382 #define SRCH_FORW       (1 << 0)  /* Search forward from current position */
383 #define SRCH_BACK       (1 << 1)  /* Search backward from current position */
384 #define SRCH_NO_MOVE    (1 << 2)  /* Highlight, but don't move */
385 #define SRCH_INCR       (1 << 3)  /* Incremental search */
386 #define SRCH_FIND_ALL   (1 << 4)  /* Find and highlight all matches */
387 #define SRCH_NO_MATCH   (1 << 8)  /* Search for non-matching lines */
388 #define SRCH_PAST_EOF   (1 << 9)  /* Search past end-of-file, into next file */
389 #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
390 #define SRCH_NO_REGEX   (1 << 12) /* Don't use regular expressions */
391 #define SRCH_FILTER     (1 << 13) /* Search is for '&' (filter) command */
392 #define SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
393 #define SRCH_WRAP       (1 << 15) /* Wrap-around search (continue at BOF/EOF) */
394 #if OSC8_LINK
395 #define SRCH_OSC8       (1 << 16) /* */
396 #endif
397 #define SRCH_SUBSEARCH(i) (1 << (17+(i))) /* Search for subpattern */
398 /* {{ Depends on NUM_SEARCH_COLORS==5 }} */
399 #define SRCH_SUBSEARCH_ALL (SRCH_SUBSEARCH(1)|SRCH_SUBSEARCH(2)|SRCH_SUBSEARCH(3)|SRCH_SUBSEARCH(4)|SRCH_SUBSEARCH(5))
400 
401 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
402                                 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
403                                 (((t) & ~SRCH_BACK) | SRCH_FORW))
404 /* Parsing position in an OSC8 link: "\e]8;PARAMS;URI\e\\" (final "\e\\" may be "\7") */
405 typedef enum osc8_state {
406 	OSC_START,    /* Waiting for initial \e */
407 	OSC_INTRO,    /* Waiting for intro char, usually ']' */
408 	OSC_TYPENUM,  /* Reading OS command type */
409 	OSC_STRING,   /* Reading OS command string */
410 	OSC_END_CSI,  /* Waiting for backslash after the final ESC. */
411 	OSC_END,      /* At end */
412 
413 	OSC8_PARAMS,  /* In the OSC8 parameters */
414 	OSC8_URI,     /* In the OSC8 URI */
415 	OSC8_NOT,     /* This is not an OSC8 link */
416 } osc8_state;
417 
418 /* */
419 #define NO_MCA          0
420 #define MCA_DONE        1
421 #define MCA_MORE        2
422 
423 #define CC_OK           0       /* Char was accepted & processed */
424 #define CC_QUIT         1       /* Char was a request to abort current cmd */
425 #define CC_ERROR        2       /* Char could not be accepted due to error */
426 #define CC_PASS         3       /* Char was rejected (internal) */
427 
428 #define CF_QUIT_ON_ERASE (1<<0) /* Abort cmd if its entirely erased */
429 #define CF_OPTION        (1<<1) /* A_OPT_TOGGLE */
430 
431 /* Special char bit-flags used to tell put_line() to do something special */
432 #define AT_NORMAL       (0)
433 #define AT_UNDERLINE    (1 << 0)
434 #define AT_BOLD         (1 << 1)
435 #define AT_BLINK        (1 << 2)
436 #define AT_STANDOUT     (1 << 3)
437 #define AT_ANSI         (1 << 4)  /* Content-supplied "ANSI" escape sequence */
438 #define AT_BINARY       (1 << 5)  /* LESS*BINFMT representation */
439 #define AT_HILITE       (1 << 6)  /* Internal highlights (e.g., for search) */
440 #define AT_PLACEHOLDER  (1 << 7)  /* Placeholder for half of double-wide char */
441 
442 #define AT_COLOR_SHIFT    8
443 #define AT_NUM_COLORS     16
444 #define AT_COLOR          ((AT_NUM_COLORS-1) << AT_COLOR_SHIFT)
445 #define AT_COLOR_ATTN     (1 << AT_COLOR_SHIFT)
446 #define AT_COLOR_BIN      (2 << AT_COLOR_SHIFT)
447 #define AT_COLOR_CTRL     (3 << AT_COLOR_SHIFT)
448 #define AT_COLOR_ERROR    (4 << AT_COLOR_SHIFT)
449 #define AT_COLOR_LINENUM  (5 << AT_COLOR_SHIFT)
450 #define AT_COLOR_MARK     (6 << AT_COLOR_SHIFT)
451 #define AT_COLOR_PROMPT   (7 << AT_COLOR_SHIFT)
452 #define AT_COLOR_RSCROLL  (8 << AT_COLOR_SHIFT)
453 #define AT_COLOR_HEADER   (9 << AT_COLOR_SHIFT)
454 #define AT_COLOR_SEARCH   (10 << AT_COLOR_SHIFT)
455 #define AT_COLOR_SUBSEARCH(i) ((10+(i)) << AT_COLOR_SHIFT)
456 #define NUM_SEARCH_COLORS (AT_NUM_COLORS-10-1)
457 
458 typedef enum { CT_NULL, CT_4BIT, CT_6BIT } COLOR_TYPE;
459 
460 typedef enum {
461 	CV_BLUE     = 1,
462 	CV_GREEN    = 2,
463 	CV_RED      = 4,
464 	CV_BRIGHT   = 8,
465 	CV_NOCHANGE = -2,
466 	CV_ERROR    = -1
467 } COLOR_VALUE;
468 
469 typedef enum {
470 	CATTR_NULL       = 0,
471 	CATTR_STANDOUT   = (1 << 0),
472 	CATTR_BOLD       = (1 << 1),
473 	CATTR_UNDERLINE  = (1 << 2),
474 	CATTR_BLINK      = (1 << 3),
475 } CHAR_ATTR;
476 
477 /* ANSI states */
478 typedef enum {
479 	ANSI_NULL,
480 	ANSI_MID,
481 	ANSI_ERR,
482 	ANSI_END,
483 } ansi_state;
484 
485 #if '0' == 240
486 #define IS_EBCDIC_HOST 1
487 #endif
488 
489 #if IS_EBCDIC_HOST
490 /*
491  * Long definition for EBCDIC.
492  * Since the argument is usually a constant, this macro normally compiles
493  * into a constant.
494  */
495 #define CONTROL(c) ( \
496         (c)=='[' ? '\047' : \
497         (c)=='a' ? '\001' : \
498         (c)=='b' ? '\002' : \
499         (c)=='c' ? '\003' : \
500         (c)=='d' ? '\067' : \
501         (c)=='e' ? '\055' : \
502         (c)=='f' ? '\056' : \
503         (c)=='g' ? '\057' : \
504         (c)=='h' ? '\026' : \
505         (c)=='i' ? '\005' : \
506         (c)=='j' ? '\025' : \
507         (c)=='k' ? '\013' : \
508         (c)=='l' ? '\014' : \
509         (c)=='m' ? '\015' : \
510         (c)=='n' ? '\016' : \
511         (c)=='o' ? '\017' : \
512         (c)=='p' ? '\020' : \
513         (c)=='q' ? '\021' : \
514         (c)=='r' ? '\022' : \
515         (c)=='s' ? '\023' : \
516         (c)=='t' ? '\074' : \
517         (c)=='u' ? '\075' : \
518         (c)=='v' ? '\062' : \
519         (c)=='w' ? '\046' : \
520         (c)=='x' ? '\030' : \
521         (c)=='y' ? '\031' : \
522         (c)=='z' ? '\077' : \
523         (c)=='A' ? '\001' : \
524         (c)=='B' ? '\002' : \
525         (c)=='C' ? '\003' : \
526         (c)=='D' ? '\067' : \
527         (c)=='E' ? '\055' : \
528         (c)=='F' ? '\056' : \
529         (c)=='G' ? '\057' : \
530         (c)=='H' ? '\026' : \
531         (c)=='I' ? '\005' : \
532         (c)=='J' ? '\025' : \
533         (c)=='K' ? '\013' : \
534         (c)=='L' ? '\014' : \
535         (c)=='M' ? '\015' : \
536         (c)=='N' ? '\016' : \
537         (c)=='O' ? '\017' : \
538         (c)=='P' ? '\020' : \
539         (c)=='Q' ? '\021' : \
540         (c)=='R' ? '\022' : \
541         (c)=='S' ? '\023' : \
542         (c)=='T' ? '\074' : \
543         (c)=='U' ? '\075' : \
544         (c)=='V' ? '\062' : \
545         (c)=='W' ? '\046' : \
546         (c)=='X' ? '\030' : \
547         (c)=='Y' ? '\031' : \
548         (c)=='Z' ? '\077' : \
549         (c)=='|' ? '\031' : \
550         (c)=='\\' ? '\034' : \
551         (c)=='^' ? '\036' : \
552         (c)&077)
553 #else
554 #define CONTROL(c)      ((c)&037)
555 #endif /* IS_EBCDIC_HOST */
556 
557 #define ESC             CONTROL('[')
558 #define ESCS            "\33"
559 #define CSI             ((unsigned char)'\233')
560 #define VARSEL_15       ((LWCHAR)0xFE0E)  /* VARIATION SELECTOR 15 */
561 #define VARSEL_16       ((LWCHAR)0xFE0F)  /* VARIATION SELECTOR 16 */
562 
563 #if _OSK_MWC32
564 #define LSIGNAL(sig,func)       os9_signal(sig,func)
565 #else
566 #define LSIGNAL(sig,func)       signal(sig,func)
567 #endif
568 
569 #if HAVE_SIGPROCMASK
570 #if HAVE_SIGSET_T
571 #else
572 #undef HAVE_SIGPROCMASK
573 #endif
574 #endif
575 #if HAVE_SIGPROCMASK
576 #if HAVE_SIGEMPTYSET
577 #else
578 #undef  sigemptyset
579 #define sigemptyset(mp) *(mp) = 0
580 #endif
581 #endif
582 
583 #define S_INTERRUPT     (1<<0)
584 #define S_SWINTERRUPT   (1<<1)
585 #define S_STOP          (1<<2)
586 #define S_WINCH         (1<<3)
587 #define ABORT_SIGS()    (sigs & (S_INTERRUPT|S_SWINTERRUPT|S_STOP))
588 
589 #ifdef EXIT_SUCCESS
590 #define QUIT_OK         EXIT_SUCCESS
591 #else
592 #define QUIT_OK         0
593 #endif
594 #ifdef EXIT_FAILURE
595 #define QUIT_ERROR      EXIT_FAILURE
596 #define QUIT_INTERRUPT  (EXIT_FAILURE+1)
597 #else
598 #define QUIT_ERROR      1
599 #define QUIT_INTERRUPT  2
600 #endif
601 #define QUIT_SAVED_STATUS (-1)
602 
603 #define FOLLOW_DESC     0
604 #define FOLLOW_NAME     1
605 
606 /* filestate flags */
607 #define CH_CANSEEK      001
608 #define CH_KEEPOPEN     002
609 #define CH_POPENED      004
610 #define CH_HELPFILE     010
611 #define CH_NODATA       020     /* Special case for zero length files */
612 #define CH_NOTRUSTSIZE  040     /* For files that claim 0 length size falsely */
613 
614 #define ch_zero()       ((POSITION)0)
615 
616 #define FAKE_HELPFILE   "@/\\less/\\help/\\file/\\@"
617 #define FAKE_EMPTYFILE  "@/\\less/\\empty/\\file/\\@"
618 
619 /* Flags for cvt_text */
620 #define CVT_TO_LC       01      /* Convert upper-case to lower-case */
621 #define CVT_BS          02      /* Do backspace processing */
622 #define CVT_CRLF        04      /* Remove CR after LF */
623 #define CVT_ANSI        010     /* Remove ANSI escape sequences */
624 
625 #if HAVE_TIME_T
626 #define time_type       time_t
627 #else
628 #define time_type       long
629 #endif
630 
631 /* X11 mouse reporting definitions */
632 #define X11MOUSE_BUTTON1    0 /* Left button press */
633 #define X11MOUSE_BUTTON2    1 /* Middle button press */
634 #define X11MOUSE_BUTTON3    2 /* Right button press */
635 #define X11MOUSE_BUTTON_REL 3 /* Button release */
636 #define X11MOUSE_DRAG       0x20 /* Drag with button down */
637 #define X11MOUSE_WHEEL_UP   0x40 /* Wheel scroll up */
638 #define X11MOUSE_WHEEL_DOWN 0x41 /* Wheel scroll down */
639 #define X11MOUSE_OFFSET     0x20 /* Added to button & pos bytes to create a char */
640 
641 /* Security features. */
642 #define SF_EDIT             (1<<1)  /* Edit file (v) */
643 #define SF_EXAMINE          (1<<2)  /* Examine file (:e) */
644 #define SF_GLOB             (1<<3)  /* Expand file pattern */
645 #define SF_HISTORY          (1<<4)  /* History file */
646 #define SF_LESSKEY          (1<<5)  /* Lesskey files */
647 #define SF_LESSOPEN         (1<<6)  /* LESSOPEN */
648 #define SF_LOGFILE          (1<<7)  /* Log file (s, -o) */
649 #define SF_PIPE             (1<<8)  /* Pipe (|) */
650 #define SF_SHELL            (1<<9)  /* Shell command (!) */
651 #define SF_STOP             (1<<10) /* Stop signal */
652 #define SF_TAGS             (1<<11) /* Tags */
653 #define SF_OSC8_OPEN        (1<<12) /* OSC8 open */
654 
655 #if LESSTEST
656 #define LESS_DUMP_CHAR CONTROL(']')
657 #endif
658 
659 struct mlist;
660 struct loption;
661 struct hilite_tree;
662 struct ansi_state;
663 #include "pattern.h"
664 #include "xbuf.h"
665 #include "funcs.h"
666 
667 /* Functions not included in funcs.h */
668 void postoa(POSITION, char*, int);
669 void linenumtoa(LINENUM, char*, int);
670 void inttoa(int, char*, int);
671 int lstrtoi(char*, char**, int);
672 POSITION lstrtopos(char*, char**, int);
673 unsigned long lstrtoul(char*, char**, int);
674 int lstrtoic(constant char*, constant char**, int);
675 POSITION lstrtoposc(constant char*, constant char**, int);
676 unsigned long lstrtoulc(constant char*, constant char**, int);
677 #if MSDOS_COMPILER==WIN32C
678 int pclose(FILE*);
679 #endif
680 #if !HAVE_STRCHR
681 char * strchr(char *s, char c);
682 #endif
683 #if !HAVE_MEMCPY
684 void * memcpy(void *dst, constant void *src, size_t len);
685 #endif
686 #if !HAVE_STRSTR
687 char * strstr(constant char *haystack, constant char *needle);
688 #endif
689