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