xref: /freebsd/contrib/less/less.h (revision fa0dc4f0f96a1b77d4be7bcdbf965897cda14521)
1 /*
2  * Copyright (C) 1984-2026  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 struct csl_bitmap_def
342 {
343 	constant char *bit_name;
344 	int bit_value;
345 };
346 
347 #if HAVE_POLL
348 typedef short POLL_EVENTS;
349 #endif
350 
351 #define EOI             (-1)
352 
353 #define READ_ERR        (-1)
354 #define READ_INTR       (-2)
355 #define READ_AGAIN      (-3)
356 
357 /*
358  * A fraction is represented by a long n; the fraction is n/NUM_FRAC_DENOM.
359  * To avoid overflow problems, 0 <= n < NUM_FRAC_DENUM <= LONG_MAX/100.
360  */
361 #define NUM_FRAC_DENOM                  1000000
362 #define NUM_LOG_FRAC_DENOM              6
363 
364 /*
365  * Max expected reasonable duration of a paste.
366  * Increasing this value avoids accidentally reenabling unwanted paste input
367  * in the middle of a very long paste but risks apparently frozen UI if the
368  * end bracket is missing.
369  */
370 #define MAX_PASTE_IGNORE_SEC            5
371 
372 /* How quiet should we be? */
373 #define NOT_QUIET       0       /* Ring bell at eof and for errors */
374 #define LITTLE_QUIET    1       /* Ring bell only for errors */
375 #define VERY_QUIET      2       /* Never ring bell */
376 
377 /* How should we prompt? */
378 #define PR_SHORT        0       /* Prompt with colon */
379 #define PR_MEDIUM       1       /* Prompt with message */
380 #define PR_LONG         2       /* Prompt with longer message */
381 
382 /* How should we handle backspaces? */
383 #define BS_SPECIAL      0       /* Do special things for underlining and bold */
384 #define BS_NORMAL       1       /* \b treated as normal char; actually output */
385 #define BS_CONTROL      2       /* \b treated as control char; prints as ^H */
386 
387 /* How should we search? */
388 #define SRCH_FORW       (1 << 0)  /* Search forward from current position */
389 #define SRCH_BACK       (1 << 1)  /* Search backward from current position */
390 #define SRCH_NO_MOVE    (1 << 2)  /* Highlight, but don't move */
391 #define SRCH_INCR       (1 << 3)  /* Incremental search */
392 #define SRCH_FIND_ALL   (1 << 4)  /* Find and highlight all matches */
393 #define SRCH_NO_MATCH   (1 << 8)  /* Search for non-matching lines */
394 #define SRCH_PAST_EOF   (1 << 9)  /* Search past end-of-file, into next file */
395 #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
396 #define SRCH_NO_REGEX   (1 << 12) /* Don't use regular expressions */
397 #define SRCH_FILTER     (1 << 13) /* Search is for '&' (filter) command */
398 #define SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
399 #define SRCH_WRAP       (1 << 15) /* Wrap-around search (continue at BOF/EOF) */
400 #if OSC8_LINK
401 #define SRCH_OSC8       (1 << 16) /* */
402 #endif
403 #define SRCH_SUBSEARCH(i) (1 << (17+(i))) /* Search for subpattern */
404 /* {{ Depends on NUM_SEARCH_COLORS==5 }} */
405 #define SRCH_SUBSEARCH_ALL (SRCH_SUBSEARCH(1)|SRCH_SUBSEARCH(2)|SRCH_SUBSEARCH(3)|SRCH_SUBSEARCH(4)|SRCH_SUBSEARCH(5))
406 
407 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
408                                 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
409                                 (((t) & ~SRCH_BACK) | SRCH_FORW))
410 /* Parsing position in an OSC8 link: "\e]8;PARAMS;URI\e\\" (final "\e\\" may be "\7") */
411 typedef enum osc8_state {
412 	OSC_START,    /* Waiting for initial \e */
413 	OSC_INTRO,    /* Waiting for intro char, usually ']' */
414 	OSC_TYPENUM,  /* Reading OS command type */
415 	OSC_STRING,   /* Reading OS command string */
416 	OSC_END_CSI,  /* Waiting for backslash after the final ESC. */
417 	OSC_END,      /* At end */
418 
419 	OSC8_PARAMS,  /* In the OSC8 parameters */
420 	OSC8_URI,     /* In the OSC8 URI */
421 	OSC8_NOT,     /* This is not an OSC8 link */
422 } osc8_state;
423 
424 /* */
425 #define NO_MCA          0
426 #define MCA_DONE        1
427 #define MCA_MORE        2
428 
429 #define CC_OK           0       /* Char was accepted & processed */
430 #define CC_QUIT         1       /* Char was a request to abort current cmd */
431 #define CC_ERROR        2       /* Char could not be accepted due to error */
432 #define CC_PASS         3       /* Char was rejected (internal) */
433 
434 #define CF_QUIT_ON_ERASE (1<<0) /* Abort cmd if its entirely erased */
435 #define CF_OPTION        (1<<1) /* A_OPT_TOGGLE */
436 
437 /* Special char bit-flags used to tell put_line() to do something special */
438 #define AT_NORMAL       (0)
439 #define AT_UNDERLINE    (1 << 0)
440 #define AT_BOLD         (1 << 1)
441 #define AT_BLINK        (1 << 2)
442 #define AT_STANDOUT     (1 << 3)
443 #define AT_ANSI         (1 << 4)  /* Content-supplied "ANSI" escape sequence */
444 #define AT_BINARY       (1 << 5)  /* LESS*BINFMT representation */
445 #define AT_HILITE       (1 << 6)  /* Internal highlights (e.g., for search) */
446 #define AT_PLACEHOLDER  (1 << 7)  /* Placeholder for half of double-wide char */
447 
448 #define AT_COLOR_SHIFT    8
449 #define AT_COLOR          ((~(unsigned)0) << AT_COLOR_SHIFT)
450 #define AT_COLOR_ATTN     (1 << AT_COLOR_SHIFT)
451 #define AT_COLOR_BIN      (2 << AT_COLOR_SHIFT)
452 #define AT_COLOR_CTRL     (3 << AT_COLOR_SHIFT)
453 #define AT_COLOR_ERROR    (4 << AT_COLOR_SHIFT)
454 #define AT_COLOR_LINENUM  (5 << AT_COLOR_SHIFT)
455 #define AT_COLOR_MARK     (6 << AT_COLOR_SHIFT)
456 #define AT_COLOR_PROMPT   (7 << AT_COLOR_SHIFT)
457 #define AT_COLOR_RSCROLL  (8 << AT_COLOR_SHIFT)
458 #define AT_COLOR_HEADER   (9 << AT_COLOR_SHIFT)
459 #define AT_COLOR_SEARCH   (10 << AT_COLOR_SHIFT)
460 #define AT_COLOR_TILDE    (11 << AT_COLOR_SHIFT)
461 #define AT_COLOR_TARGET   (12 << AT_COLOR_SHIFT)
462 #define AT_COLOR_SS_OFFSET 13  /* largest AT_COLOR_* value + 1 */
463 #define NUM_SEARCH_COLORS  5
464 #define AT_NUM_COLORS      (AT_COLOR_SS_OFFSET + NUM_SEARCH_COLORS)
465 #define AT_COLOR_SUBSEARCH(i) ((AT_COLOR_SS_OFFSET+(i)-1) << AT_COLOR_SHIFT)
466 
467 typedef enum { CT_NULL, CT_4BIT, CT_6BIT } COLOR_TYPE;
468 
469 typedef enum {
470 	CV_BLUE     = 1,
471 	CV_GREEN    = 2,
472 	CV_RED      = 4,
473 	CV_BRIGHT   = 8,
474 	CV_NOCHANGE = -2,
475 	CV_ERROR    = -1
476 } COLOR_VALUE;
477 
478 typedef enum {
479 	CATTR_NULL       = 0,
480 	CATTR_STANDOUT   = (1 << 0),
481 	CATTR_BOLD       = (1 << 1),
482 	CATTR_UNDERLINE  = (1 << 2),
483 	CATTR_BLINK      = (1 << 3),
484 } CHAR_ATTR;
485 
486 /* ANSI states */
487 typedef enum {
488 	ANSI_NULL,
489 	ANSI_MID,
490 	ANSI_ERR,
491 	ANSI_END,
492 } ansi_state;
493 
494 #if '0' == 240
495 #define IS_EBCDIC_HOST 1
496 #endif
497 
498 #if IS_EBCDIC_HOST
499 /*
500  * Long definition for EBCDIC.
501  * Since the argument is usually a constant, this macro normally compiles
502  * into a constant.
503  */
504 #define CONTROL(c) ( \
505         (c)=='[' ? '\047' : \
506         (c)=='a' ? '\001' : \
507         (c)=='b' ? '\002' : \
508         (c)=='c' ? '\003' : \
509         (c)=='d' ? '\067' : \
510         (c)=='e' ? '\055' : \
511         (c)=='f' ? '\056' : \
512         (c)=='g' ? '\057' : \
513         (c)=='h' ? '\026' : \
514         (c)=='i' ? '\005' : \
515         (c)=='j' ? '\025' : \
516         (c)=='k' ? '\013' : \
517         (c)=='l' ? '\014' : \
518         (c)=='m' ? '\015' : \
519         (c)=='n' ? '\016' : \
520         (c)=='o' ? '\017' : \
521         (c)=='p' ? '\020' : \
522         (c)=='q' ? '\021' : \
523         (c)=='r' ? '\022' : \
524         (c)=='s' ? '\023' : \
525         (c)=='t' ? '\074' : \
526         (c)=='u' ? '\075' : \
527         (c)=='v' ? '\062' : \
528         (c)=='w' ? '\046' : \
529         (c)=='x' ? '\030' : \
530         (c)=='y' ? '\031' : \
531         (c)=='z' ? '\077' : \
532         (c)=='A' ? '\001' : \
533         (c)=='B' ? '\002' : \
534         (c)=='C' ? '\003' : \
535         (c)=='D' ? '\067' : \
536         (c)=='E' ? '\055' : \
537         (c)=='F' ? '\056' : \
538         (c)=='G' ? '\057' : \
539         (c)=='H' ? '\026' : \
540         (c)=='I' ? '\005' : \
541         (c)=='J' ? '\025' : \
542         (c)=='K' ? '\013' : \
543         (c)=='L' ? '\014' : \
544         (c)=='M' ? '\015' : \
545         (c)=='N' ? '\016' : \
546         (c)=='O' ? '\017' : \
547         (c)=='P' ? '\020' : \
548         (c)=='Q' ? '\021' : \
549         (c)=='R' ? '\022' : \
550         (c)=='S' ? '\023' : \
551         (c)=='T' ? '\074' : \
552         (c)=='U' ? '\075' : \
553         (c)=='V' ? '\062' : \
554         (c)=='W' ? '\046' : \
555         (c)=='X' ? '\030' : \
556         (c)=='Y' ? '\031' : \
557         (c)=='Z' ? '\077' : \
558         (c)=='|' ? '\031' : \
559         (c)=='\\' ? '\034' : \
560         (c)=='^' ? '\036' : \
561         (c)&077)
562 #else
563 #define CONTROL(c)      ((c)&037)
564 #endif /* IS_EBCDIC_HOST */
565 
566 #define ESC             CONTROL('[')
567 #define ESCS            "\33"
568 #define CSI             ((unsigned char)'\233')
569 #define VARSEL_15       ((LWCHAR)0xFE0E)  /* VARIATION SELECTOR 15 */
570 #define VARSEL_16       ((LWCHAR)0xFE0F)  /* VARIATION SELECTOR 16 */
571 
572 #if _OSK_MWC32
573 #define LSIGNAL(sig,func)       os9_signal(sig,func)
574 #else
575 #define LSIGNAL(sig,func)       signal(sig,func)
576 #endif
577 
578 #if HAVE_SIGPROCMASK
579 #if HAVE_SIGSET_T
580 #else
581 #undef HAVE_SIGPROCMASK
582 #endif
583 #endif
584 #if HAVE_SIGPROCMASK
585 #if HAVE_SIGEMPTYSET
586 #else
587 #undef  sigemptyset
588 #define sigemptyset(mp) *(mp) = 0
589 #endif
590 #endif
591 
592 #define S_INTERRUPT     (1<<0)
593 #define S_SWINTERRUPT   (1<<1)
594 #define S_STOP          (1<<2)
595 #define S_WINCH         (1<<3)
596 #define ABORT_SIGS()    (sigs & (S_INTERRUPT|S_SWINTERRUPT|S_STOP))
597 
598 #ifdef EXIT_SUCCESS
599 #define QUIT_OK         EXIT_SUCCESS
600 #else
601 #define QUIT_OK         0
602 #endif
603 #ifdef EXIT_FAILURE
604 #define QUIT_ERROR      EXIT_FAILURE
605 #define QUIT_INTERRUPT  (EXIT_FAILURE+1)
606 #else
607 #define QUIT_ERROR      1
608 #define QUIT_INTERRUPT  2
609 #endif
610 #define QUIT_SAVED_STATUS (-1)
611 
612 #define FOLLOW_DESC     0
613 #define FOLLOW_NAME     1
614 
615 /* filestate flags */
616 #define CH_CANSEEK      001
617 #define CH_KEEPOPEN     002
618 #define CH_POPENED      004
619 #define CH_HELPFILE     010
620 #define CH_NODATA       020     /* Special case for zero length files */
621 #define CH_NOTRUSTSIZE  040     /* For files that claim 0 length size falsely */
622 
623 #define ch_zero()       ((POSITION)0)
624 
625 #define FAKE_HELPFILE   "@/\\less/\\help/\\file/\\@"
626 #define FAKE_EMPTYFILE  "@/\\less/\\empty/\\file/\\@"
627 
628 /* Flags for cvt_text */
629 #define CVT_TO_LC       01      /* Convert upper-case to lower-case */
630 #define CVT_BS          02      /* Do backspace processing */
631 #define CVT_CRLF        04      /* Remove CR after LF */
632 #define CVT_ANSI        010     /* Remove ANSI escape sequences */
633 
634 #if HAVE_TIME_T
635 #define time_type       time_t
636 #else
637 #define time_type       long
638 #endif
639 
640 /* X11 mouse reporting definitions */
641 #define X11MOUSE_BUTTON1     0 /* Left button press */
642 #define X11MOUSE_BUTTON2     1 /* Middle button press */
643 #define X11MOUSE_BUTTON3     2 /* Right button press */
644 #define X11MOUSE_BUTTON_REL  3 /* Button release */
645 #define X11MOUSE_DRAG        0x20 /* Drag with button down */
646 #define X11MOUSE_WHEEL_UP    0x40 /* Wheel scroll up */
647 #define X11MOUSE_WHEEL_DOWN  0x41 /* Wheel scroll down */
648 #define X11MOUSE_WHEEL_LEFT  0x42 /* Wheel scroll left */
649 #define X11MOUSE_WHEEL_RIGHT 0x43 /* Wheel scroll right */
650 #define X11MOUSE_OFFSET      0x20 /* Added to button & pos bytes to create a char */
651 
652 /* Mouse features */
653 #define EMOUSE_HSCROLL      (1<<0) /* Horizontal scroll */
654 #define EMOUSE_VSCROLL      (1<<1) /* Vertical scroll */
655 #define EMOUSE_HDRAG        (1<<2) /* Horizontal drag */
656 #define EMOUSE_VDRAG        (1<<3) /* Vertical drag */
657 #define EMOUSE_LCLICK       (1<<4) /* Left click */
658 #define EMOUSE_RCLICK       (1<<5) /* Right click */
659 #define EMOUSE_COUNT        6
660 
661 /* Security features. */
662 #define SF_EDIT             (1<<1)  /* Edit file (v) */
663 #define SF_EXAMINE          (1<<2)  /* Examine file (:e) */
664 #define SF_GLOB             (1<<3)  /* Expand file pattern */
665 #define SF_HISTORY          (1<<4)  /* History file */
666 #define SF_LESSKEY          (1<<5)  /* Lesskey files */
667 #define SF_LESSOPEN         (1<<6)  /* LESSOPEN */
668 #define SF_LOGFILE          (1<<7)  /* Log file (s, -o) */
669 #define SF_PIPE             (1<<8)  /* Pipe (|) */
670 #define SF_SHELL            (1<<9)  /* Shell command (!) */
671 #define SF_STOP             (1<<10) /* Stop signal */
672 #define SF_TAGS             (1<<11) /* Tags */
673 #define SF_OSC8_OPEN        (1<<12) /* OSC8 open */
674 
675 #if LESSTEST
676 #define LESS_DUMP_CHAR CONTROL(']')
677 #endif
678 
679 struct mlist;
680 struct loption;
681 struct hilite_tree;
682 struct ansi_state;
683 #include "pattern.h"
684 #include "xbuf.h"
685 #include "funcs.h"
686 
687 /* Functions not included in funcs.h */
688 void postoa(POSITION, char*, int);
689 void linenumtoa(LINENUM, char*, int);
690 void inttoa(int, char*, int);
691 int lstrtoi(char*, char**, int);
692 POSITION lstrtopos(char*, char**, int);
693 unsigned long lstrtoul(char*, char**, int);
694 int lstrtoic(constant char*, constant char**, int);
695 POSITION lstrtoposc(constant char*, constant char**, int);
696 unsigned long lstrtoulc(constant char*, constant char**, int);
697 #if MSDOS_COMPILER==WIN32C
698 int pclose(FILE*);
699 #endif
700 #if !HAVE_STRCHR
701 char * strchr(char *s, char c);
702 #endif
703 #if !HAVE_MEMCPY
704 void * memcpy(void *dst, constant void *src, size_t len);
705 #endif
706 #if !HAVE_STRSTR
707 char * strstr(constant char *haystack, constant char *needle);
708 #endif
709