xref: /netbsd-src/external/bsd/less/dist/less.h (revision 838f5788460f0f133b15d706e644d692a9d4d6ec)
1*838f5788Ssimonb /*	$NetBSD: less.h,v 1.5 2023/10/06 05:49:49 simonb Exp $	*/
220006a0bStron 
320006a0bStron /*
4*838f5788Ssimonb  * Copyright (C) 1984-2023  Mark Nudelman
520006a0bStron  *
620006a0bStron  * You may distribute under the terms of either the GNU General Public
720006a0bStron  * License or the Less License, as specified in the README file.
820006a0bStron  *
9ec18bca0Stron  * For more information, see the README file.
1020006a0bStron  */
1120006a0bStron 
1220006a0bStron #define NEWBOT 1
1320006a0bStron 
1420006a0bStron /*
1520006a0bStron  * Standard include file for "less".
1620006a0bStron  */
1720006a0bStron 
1820006a0bStron /*
1920006a0bStron  * Defines for MSDOS_COMPILER.
2020006a0bStron  */
2120006a0bStron #define MSOFTC          1   /* Microsoft C */
2220006a0bStron #define BORLANDC        2   /* Borland C */
2320006a0bStron #define WIN32C          3   /* Windows (Borland C or Microsoft C) */
2420006a0bStron #define DJGPPC          4   /* DJGPP C */
2520006a0bStron 
2620006a0bStron /*
2720006a0bStron  * Include the file of compile-time options.
2820006a0bStron  * The <> make cc search for it in -I., not srcdir.
2920006a0bStron  */
3020006a0bStron #include <defines.h>
3120006a0bStron 
3220006a0bStron #ifdef _SEQUENT_
3320006a0bStron /*
3420006a0bStron  * Kludge for Sequent Dynix systems that have sigsetmask, but
3520006a0bStron  * it's not compatible with the way less calls it.
3620006a0bStron  * {{ Do other systems need this? }}
3720006a0bStron  */
3820006a0bStron #undef HAVE_SIGSETMASK
3920006a0bStron #endif
4020006a0bStron 
4120006a0bStron /*
4220006a0bStron  * Language details.
4320006a0bStron  */
4420006a0bStron #if HAVE_CONST
4520006a0bStron #define constant        const
4620006a0bStron #else
4720006a0bStron #define constant
4820006a0bStron #endif
4920006a0bStron 
5020006a0bStron #define public          /* PUBLIC FUNCTION */
5120006a0bStron 
5220006a0bStron /* Library function declarations */
5320006a0bStron 
5420006a0bStron #if HAVE_SYS_TYPES_H
5520006a0bStron #include <sys/types.h>
5620006a0bStron #endif
5720006a0bStron #if HAVE_STDIO_H
5820006a0bStron #include <stdio.h>
5920006a0bStron #endif
6020006a0bStron #if HAVE_FCNTL_H
6120006a0bStron #include <fcntl.h>
6220006a0bStron #endif
6320006a0bStron #if HAVE_UNISTD_H
6420006a0bStron #include <unistd.h>
6520006a0bStron #endif
6620006a0bStron #if HAVE_CTYPE_H
6720006a0bStron #include <ctype.h>
6820006a0bStron #endif
6920006a0bStron #if HAVE_WCTYPE_H
7020006a0bStron #include <wctype.h>
7120006a0bStron #endif
7220006a0bStron #if HAVE_LIMITS_H
7320006a0bStron #include <limits.h>
7420006a0bStron #endif
75*838f5788Ssimonb #if HAVE_STDINT_H
76*838f5788Ssimonb #include <stdint.h>
77*838f5788Ssimonb #endif
7820006a0bStron #if HAVE_STDLIB_H
7920006a0bStron #include <stdlib.h>
8020006a0bStron #endif
8120006a0bStron #if HAVE_STRING_H
8220006a0bStron #include <string.h>
8320006a0bStron #endif
8420006a0bStron 
85*838f5788Ssimonb #if HAVE_STDCKDINT_H
86*838f5788Ssimonb #include <stdckdint.h>
87*838f5788Ssimonb #else
88*838f5788Ssimonb /*
89*838f5788Ssimonb  * These substitutes for C23 stdckdint macros do not set *R on overflow,
90*838f5788Ssimonb  * and they assume A and B are nonnegative.  That is good enough for us.
91*838f5788Ssimonb  */
92*838f5788Ssimonb #define ckd_add(r, a, b) help_ckd_add(r, a, b, sizeof *(r), signed_expr(*(r)))
93*838f5788Ssimonb #define ckd_mul(r, a, b) help_ckd_mul(r, a, b, sizeof *(r), signed_expr(*(r)))
94*838f5788Ssimonb /* True if the integer expression E, after promotion, is signed.  */
95*838f5788Ssimonb #define signed_expr(e) ((TRUE ? 0 : e) - 1 < 0)
96*838f5788Ssimonb #endif
97*838f5788Ssimonb 
98*838f5788Ssimonb #if defined UINTMAX_MAX
99*838f5788Ssimonb typedef uintmax_t uintmax;
100*838f5788Ssimonb #elif defined ULLONG_MAX
101*838f5788Ssimonb typedef unsigned long long uintmax;
102*838f5788Ssimonb #else
103*838f5788Ssimonb typedef unsigned long uintmax;
104*838f5788Ssimonb #endif
105*838f5788Ssimonb 
10620006a0bStron /* OS-specific includes */
10720006a0bStron #ifdef _OSK
10820006a0bStron #include <modes.h>
10920006a0bStron #include <strings.h>
11020006a0bStron #endif
11120006a0bStron 
11220006a0bStron #ifdef __TANDEM
11320006a0bStron #include <floss.h>
11420006a0bStron #endif
11520006a0bStron 
11620006a0bStron #if MSDOS_COMPILER==WIN32C || OS2
11720006a0bStron #include <io.h>
11820006a0bStron #endif
11920006a0bStron 
12020006a0bStron #if MSDOS_COMPILER==DJGPPC
12120006a0bStron #include <io.h>
12220006a0bStron #include <sys/exceptn.h>
12320006a0bStron #include <conio.h>
12420006a0bStron #include <pc.h>
12520006a0bStron #endif
12620006a0bStron 
12720006a0bStron #if !HAVE_STDLIB_H
12820006a0bStron char *getenv();
12920006a0bStron off_t lseek();
130*838f5788Ssimonb void *calloc();
13120006a0bStron void free();
13220006a0bStron #endif
13320006a0bStron 
13420006a0bStron /*
13520006a0bStron  * Simple lowercase test which can be used during option processing
13620006a0bStron  * (before options are parsed which might tell us what charset to use).
13720006a0bStron  */
13820006a0bStron #define ASCII_IS_UPPER(c)       ((c) >= 'A' && (c) <= 'Z')
13920006a0bStron #define ASCII_IS_LOWER(c)       ((c) >= 'a' && (c) <= 'z')
14020006a0bStron #define ASCII_TO_UPPER(c)       ((c) - 'a' + 'A')
14120006a0bStron #define ASCII_TO_LOWER(c)       ((c) - 'A' + 'a')
14220006a0bStron 
14320006a0bStron #undef IS_UPPER
14420006a0bStron #undef IS_LOWER
14520006a0bStron #undef TO_UPPER
14620006a0bStron #undef TO_LOWER
14720006a0bStron #undef IS_SPACE
14820006a0bStron #undef IS_DIGIT
14920006a0bStron 
15020006a0bStron #if HAVE_WCTYPE
15120006a0bStron #define IS_UPPER(c)     iswupper(c)
15220006a0bStron #define IS_LOWER(c)     iswlower(c)
15320006a0bStron #define TO_UPPER(c)     towupper(c)
15420006a0bStron #define TO_LOWER(c)     towlower(c)
15520006a0bStron #else
15620006a0bStron #if HAVE_UPPER_LOWER
15720006a0bStron #define IS_UPPER(c)     isupper((unsigned char) (c))
15820006a0bStron #define IS_LOWER(c)     islower((unsigned char) (c))
15920006a0bStron #define TO_UPPER(c)     toupper((unsigned char) (c))
16020006a0bStron #define TO_LOWER(c)     tolower((unsigned char) (c))
16120006a0bStron #else
16220006a0bStron #define IS_UPPER(c)     ASCII_IS_UPPER(c)
16320006a0bStron #define IS_LOWER(c)     ASCII_IS_LOWER(c)
16420006a0bStron #define TO_UPPER(c)     ASCII_TO_UPPER(c)
16520006a0bStron #define TO_LOWER(c)     ASCII_TO_LOWER(c)
16620006a0bStron #endif
16720006a0bStron #endif
16820006a0bStron 
16920006a0bStron #ifdef isspace
17020006a0bStron #define IS_SPACE(c)     isspace((unsigned char)(c))
17120006a0bStron #else
17220006a0bStron #define IS_SPACE(c)     ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
17320006a0bStron #endif
17420006a0bStron 
17520006a0bStron #ifdef isdigit
17620006a0bStron #define IS_DIGIT(c)     isdigit((unsigned char)(c))
17720006a0bStron #else
17820006a0bStron #define IS_DIGIT(c)     ((c) >= '0' && (c) <= '9')
17920006a0bStron #endif
18020006a0bStron 
18120006a0bStron #define IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI))
18220006a0bStron 
18320006a0bStron #ifndef NULL
18420006a0bStron #define NULL    0
18520006a0bStron #endif
18620006a0bStron 
18720006a0bStron #ifndef TRUE
18820006a0bStron #define TRUE            1
18920006a0bStron #endif
19020006a0bStron #ifndef FALSE
19120006a0bStron #define FALSE           0
19220006a0bStron #endif
19320006a0bStron 
19420006a0bStron #define OPT_OFF         0
19520006a0bStron #define OPT_ON          1
19620006a0bStron #define OPT_ONPLUS      2
19720006a0bStron 
19820006a0bStron #if !HAVE_MEMCPY
19920006a0bStron #ifndef memcpy
20020006a0bStron #define memcpy(to,from,len)     bcopy((from),(to),(len))
20120006a0bStron #endif
20220006a0bStron #endif
20320006a0bStron 
20420006a0bStron #if HAVE_SNPRINTF
20520006a0bStron #define SNPRINTF1(str, size, fmt, v1)             snprintf((str), (size), (fmt), (v1))
20620006a0bStron #define SNPRINTF2(str, size, fmt, v1, v2)         snprintf((str), (size), (fmt), (v1), (v2))
20720006a0bStron #define SNPRINTF3(str, size, fmt, v1, v2, v3)     snprintf((str), (size), (fmt), (v1), (v2), (v3))
20820006a0bStron #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
20920006a0bStron #else
21020006a0bStron /* Use unsafe sprintf if we don't have snprintf. */
21120006a0bStron #define SNPRINTF1(str, size, fmt, v1)             sprintf((str), (fmt), (v1))
21220006a0bStron #define SNPRINTF2(str, size, fmt, v1, v2)         sprintf((str), (fmt), (v1), (v2))
21320006a0bStron #define SNPRINTF3(str, size, fmt, v1, v2, v3)     sprintf((str), (fmt), (v1), (v2), (v3))
21420006a0bStron #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
21520006a0bStron #endif
21620006a0bStron 
21720006a0bStron #define BAD_LSEEK       ((off_t)-1)
21820006a0bStron 
21920006a0bStron #ifndef SEEK_SET
22020006a0bStron #define SEEK_SET 0
22120006a0bStron #endif
22220006a0bStron #ifndef SEEK_END
22320006a0bStron #define SEEK_END 2
22420006a0bStron #endif
22520006a0bStron 
22620006a0bStron #ifndef CHAR_BIT
22720006a0bStron #define CHAR_BIT 8
22820006a0bStron #endif
22920006a0bStron 
23020006a0bStron /*
23120006a0bStron  * Upper bound on the string length of an integer converted to string.
23220006a0bStron  * 302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
23320006a0bStron  * add 1 for integer division truncation; add 1 more for a minus sign.
23420006a0bStron  */
23520006a0bStron #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
23620006a0bStron 
23720006a0bStron /*
23820006a0bStron  * Special types and constants.
23920006a0bStron  */
24020006a0bStron typedef unsigned long LWCHAR;
24120006a0bStron typedef off_t           POSITION;
24220006a0bStron typedef off_t           LINENUM;
243*838f5788Ssimonb #define MIN_LINENUM_WIDTH   7   /* Default min printing width of a line number */
244*838f5788Ssimonb #define MAX_LINENUM_WIDTH   16  /* Max width of a line number */
245*838f5788Ssimonb #define MAX_STATUSCOL_WIDTH 4   /* Max width of the status column */
24620006a0bStron #define MAX_UTF_CHAR_LEN    6   /* Max bytes in one UTF-8 char */
247*838f5788Ssimonb #define MAX_PRCHAR_LEN      31  /* Max chars in prchar() result */
24820006a0bStron 
24920006a0bStron #define NULL_POSITION   ((POSITION)(-1))
25020006a0bStron 
25120006a0bStron /*
25220006a0bStron  * Flags for open()
25320006a0bStron  */
25420006a0bStron #if MSDOS_COMPILER || OS2
25520006a0bStron #define OPEN_READ       (O_RDONLY|O_BINARY)
25620006a0bStron #else
25720006a0bStron #ifdef _OSK
25820006a0bStron #define OPEN_READ       (S_IREAD)
25920006a0bStron #else
26020006a0bStron #ifdef O_RDONLY
26120006a0bStron #define OPEN_READ       (O_RDONLY)
26220006a0bStron #else
26320006a0bStron #define OPEN_READ       (0)
26420006a0bStron #endif
26520006a0bStron #endif
26620006a0bStron #endif
26720006a0bStron 
26820006a0bStron #if defined(O_WRONLY) && defined(O_APPEND)
26920006a0bStron #define OPEN_APPEND     (O_APPEND|O_WRONLY)
27020006a0bStron #else
27120006a0bStron #ifdef _OSK
27220006a0bStron #define OPEN_APPEND     (S_IWRITE)
27320006a0bStron #else
27420006a0bStron #define OPEN_APPEND     (1)
27520006a0bStron #endif
27620006a0bStron #endif
27720006a0bStron 
27820006a0bStron /*
279*838f5788Ssimonb  * Flags for creat()
280*838f5788Ssimonb  */
281*838f5788Ssimonb #if MSDOS_COMPILER
282*838f5788Ssimonb #define CREAT_RW        (S_IREAD|S_IWRITE)
283*838f5788Ssimonb #else
284*838f5788Ssimonb #define CREAT_RW        0644
285*838f5788Ssimonb #endif
286*838f5788Ssimonb 
287*838f5788Ssimonb /*
28820006a0bStron  * Set a file descriptor to binary mode.
28920006a0bStron  */
29020006a0bStron #if MSDOS_COMPILER==MSOFTC
29120006a0bStron #define SET_BINARY(f)   _setmode(f, _O_BINARY);
29220006a0bStron #else
29320006a0bStron #if MSDOS_COMPILER || OS2
29420006a0bStron #define SET_BINARY(f)   setmode(f, O_BINARY)
29520006a0bStron #else
29620006a0bStron #define SET_BINARY(f)
29720006a0bStron #endif
29820006a0bStron #endif
29920006a0bStron 
30020006a0bStron /*
30120006a0bStron  * Does the shell treat "?" as a metacharacter?
30220006a0bStron  */
30320006a0bStron #if MSDOS_COMPILER || OS2 || _OSK
30420006a0bStron #define SHELL_META_QUEST 0
30520006a0bStron #else
30620006a0bStron #define SHELL_META_QUEST 1
30720006a0bStron #endif
30820006a0bStron 
30920006a0bStron #define SPACES_IN_FILENAMES 1
31020006a0bStron 
31120006a0bStron /*
31220006a0bStron  * An IFILE represents an input file.
31320006a0bStron  */
314*838f5788Ssimonb #define IFILE           void*
31520006a0bStron #define NULL_IFILE      ((IFILE)NULL)
31620006a0bStron 
31720006a0bStron /*
31820006a0bStron  * The structure used to represent a "screen position".
31920006a0bStron  * This consists of a file position, and a screen line number.
32020006a0bStron  * The meaning is that the line starting at the given file
32120006a0bStron  * position is displayed on the ln-th line of the screen.
32220006a0bStron  * (Screen lines before ln are empty.)
32320006a0bStron  */
32420006a0bStron struct scrpos
32520006a0bStron {
32620006a0bStron         POSITION pos;
32720006a0bStron         int ln;
32820006a0bStron };
32920006a0bStron 
33020006a0bStron typedef union parg
33120006a0bStron {
332*838f5788Ssimonb         char *p_string;
33320006a0bStron         int p_int;
33420006a0bStron         LINENUM p_linenum;
335*838f5788Ssimonb         char p_char;
33620006a0bStron } PARG;
33720006a0bStron 
33820006a0bStron #define NULL_PARG       ((PARG *)NULL)
33920006a0bStron 
34020006a0bStron struct textlist
34120006a0bStron {
34220006a0bStron         char *string;
34320006a0bStron         char *endstring;
34420006a0bStron };
34520006a0bStron 
346*838f5788Ssimonb struct wchar_range
347*838f5788Ssimonb {
348*838f5788Ssimonb         LWCHAR first, last;
349*838f5788Ssimonb };
350*838f5788Ssimonb 
351*838f5788Ssimonb struct wchar_range_table
352*838f5788Ssimonb {
353*838f5788Ssimonb         struct wchar_range *table;
354*838f5788Ssimonb         int count;
355*838f5788Ssimonb };
356*838f5788Ssimonb 
357*838f5788Ssimonb #if HAVE_POLL
358*838f5788Ssimonb typedef short POLL_EVENTS;
359*838f5788Ssimonb #endif
360*838f5788Ssimonb 
36120006a0bStron #define EOI             (-1)
36220006a0bStron 
363*838f5788Ssimonb #define READ_ERR        (-1)
36420006a0bStron #define READ_INTR       (-2)
365*838f5788Ssimonb #define READ_AGAIN      (-3)
36620006a0bStron 
367*838f5788Ssimonb /*
368*838f5788Ssimonb  * A fraction is represented by a long n; the fraction is n/NUM_FRAC_DENOM.
369*838f5788Ssimonb  * To avoid overflow problems, 0 <= n < NUM_FRAC_DENUM <= LONG_MAX/100.
370*838f5788Ssimonb  */
37120006a0bStron #define NUM_FRAC_DENOM                  1000000
37220006a0bStron #define NUM_LOG_FRAC_DENOM              6
37320006a0bStron 
37420006a0bStron /* How quiet should we be? */
37520006a0bStron #define NOT_QUIET       0       /* Ring bell at eof and for errors */
37620006a0bStron #define LITTLE_QUIET    1       /* Ring bell only for errors */
37720006a0bStron #define VERY_QUIET      2       /* Never ring bell */
37820006a0bStron 
37920006a0bStron /* How should we prompt? */
38020006a0bStron #define PR_SHORT        0       /* Prompt with colon */
38120006a0bStron #define PR_MEDIUM       1       /* Prompt with message */
38220006a0bStron #define PR_LONG         2       /* Prompt with longer message */
38320006a0bStron 
38420006a0bStron /* How should we handle backspaces? */
38520006a0bStron #define BS_SPECIAL      0       /* Do special things for underlining and bold */
38620006a0bStron #define BS_NORMAL       1       /* \b treated as normal char; actually output */
38720006a0bStron #define BS_CONTROL      2       /* \b treated as control char; prints as ^H */
38820006a0bStron 
38920006a0bStron /* How should we search? */
39020006a0bStron #define SRCH_FORW       (1 << 0)  /* Search forward from current position */
39120006a0bStron #define SRCH_BACK       (1 << 1)  /* Search backward from current position */
39220006a0bStron #define SRCH_NO_MOVE    (1 << 2)  /* Highlight, but don't move */
393*838f5788Ssimonb #define SRCH_INCR       (1 << 3)  /* Incremental search */
39420006a0bStron #define SRCH_FIND_ALL   (1 << 4)  /* Find and highlight all matches */
39520006a0bStron #define SRCH_NO_MATCH   (1 << 8)  /* Search for non-matching lines */
39620006a0bStron #define SRCH_PAST_EOF   (1 << 9)  /* Search past end-of-file, into next file */
39720006a0bStron #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
39820006a0bStron #define SRCH_NO_REGEX   (1 << 12) /* Don't use regular expressions */
39920006a0bStron #define SRCH_FILTER     (1 << 13) /* Search is for '&' (filter) command */
40020006a0bStron #define SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
401*838f5788Ssimonb #define SRCH_WRAP       (1 << 15) /* Wrap-around search (continue at BOF/EOF) */
402*838f5788Ssimonb #define SRCH_SUBSEARCH(i) (1 << (16+(i))) /* Search for subpattern */
403*838f5788Ssimonb /* {{ Depends on NUM_SEARCH_COLORS==5 }} */
404*838f5788Ssimonb #define SRCH_SUBSEARCH_ALL (SRCH_SUBSEARCH(1)|SRCH_SUBSEARCH(2)|SRCH_SUBSEARCH(3)|SRCH_SUBSEARCH(4)|SRCH_SUBSEARCH(5))
40520006a0bStron 
40620006a0bStron #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
40720006a0bStron                                 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
40820006a0bStron                                 (((t) & ~SRCH_BACK) | SRCH_FORW))
40920006a0bStron 
41020006a0bStron /* */
41120006a0bStron #define NO_MCA          0
41220006a0bStron #define MCA_DONE        1
41320006a0bStron #define MCA_MORE        2
41420006a0bStron 
41520006a0bStron #define CC_OK           0       /* Char was accepted & processed */
41620006a0bStron #define CC_QUIT         1       /* Char was a request to abort current cmd */
41720006a0bStron #define CC_ERROR        2       /* Char could not be accepted due to error */
41820006a0bStron #define CC_PASS         3       /* Char was rejected (internal) */
41920006a0bStron 
42020006a0bStron #define CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
42120006a0bStron 
42220006a0bStron /* Special char bit-flags used to tell put_line() to do something special */
42320006a0bStron #define AT_NORMAL       (0)
42420006a0bStron #define AT_UNDERLINE    (1 << 0)
42520006a0bStron #define AT_BOLD         (1 << 1)
42620006a0bStron #define AT_BLINK        (1 << 2)
42720006a0bStron #define AT_STANDOUT     (1 << 3)
42820006a0bStron #define AT_ANSI         (1 << 4)  /* Content-supplied "ANSI" escape sequence */
42920006a0bStron #define AT_BINARY       (1 << 5)  /* LESS*BINFMT representation */
43020006a0bStron #define AT_HILITE       (1 << 6)  /* Internal highlights (e.g., for search) */
43120006a0bStron 
432*838f5788Ssimonb #define AT_COLOR_SHIFT    8
433*838f5788Ssimonb #define AT_NUM_COLORS     16
434*838f5788Ssimonb #define AT_COLOR          ((AT_NUM_COLORS-1) << AT_COLOR_SHIFT)
435*838f5788Ssimonb #define AT_COLOR_ATTN     (1 << AT_COLOR_SHIFT)
436*838f5788Ssimonb #define AT_COLOR_BIN      (2 << AT_COLOR_SHIFT)
437*838f5788Ssimonb #define AT_COLOR_CTRL     (3 << AT_COLOR_SHIFT)
438*838f5788Ssimonb #define AT_COLOR_ERROR    (4 << AT_COLOR_SHIFT)
439*838f5788Ssimonb #define AT_COLOR_LINENUM  (5 << AT_COLOR_SHIFT)
440*838f5788Ssimonb #define AT_COLOR_MARK     (6 << AT_COLOR_SHIFT)
441*838f5788Ssimonb #define AT_COLOR_PROMPT   (7 << AT_COLOR_SHIFT)
442*838f5788Ssimonb #define AT_COLOR_RSCROLL  (8 << AT_COLOR_SHIFT)
443*838f5788Ssimonb #define AT_COLOR_HEADER   (9 << AT_COLOR_SHIFT)
444*838f5788Ssimonb #define AT_COLOR_SEARCH   (10 << AT_COLOR_SHIFT)
445*838f5788Ssimonb #define AT_COLOR_SUBSEARCH(i) ((10+(i)) << AT_COLOR_SHIFT)
446*838f5788Ssimonb #define NUM_SEARCH_COLORS (AT_NUM_COLORS-10-1)
447*838f5788Ssimonb 
448*838f5788Ssimonb typedef enum { CT_NULL, CT_4BIT, CT_6BIT } COLOR_TYPE;
449*838f5788Ssimonb 
450*838f5788Ssimonb typedef enum {
451*838f5788Ssimonb 	CV_BLUE     = 1,
452*838f5788Ssimonb 	CV_GREEN    = 2,
453*838f5788Ssimonb 	CV_RED      = 4,
454*838f5788Ssimonb 	CV_BRIGHT   = 8,
455*838f5788Ssimonb 	CV_NOCHANGE = -2,
456*838f5788Ssimonb 	CV_ERROR    = -1
457*838f5788Ssimonb } COLOR_VALUE;
458*838f5788Ssimonb 
459*838f5788Ssimonb /* ANSI states */
460*838f5788Ssimonb #define ANSI_MID    1
461*838f5788Ssimonb #define ANSI_ERR    2
462*838f5788Ssimonb #define ANSI_END    3
463*838f5788Ssimonb 
46420006a0bStron #if '0' == 240
46520006a0bStron #define IS_EBCDIC_HOST 1
46620006a0bStron #endif
46720006a0bStron 
46820006a0bStron #if IS_EBCDIC_HOST
46920006a0bStron /*
47020006a0bStron  * Long definition for EBCDIC.
47120006a0bStron  * Since the argument is usually a constant, this macro normally compiles
47220006a0bStron  * into a constant.
47320006a0bStron  */
47420006a0bStron #define CONTROL(c) ( \
47520006a0bStron         (c)=='[' ? '\047' : \
47620006a0bStron         (c)=='a' ? '\001' : \
47720006a0bStron         (c)=='b' ? '\002' : \
47820006a0bStron         (c)=='c' ? '\003' : \
47920006a0bStron         (c)=='d' ? '\067' : \
48020006a0bStron         (c)=='e' ? '\055' : \
48120006a0bStron         (c)=='f' ? '\056' : \
48220006a0bStron         (c)=='g' ? '\057' : \
48320006a0bStron         (c)=='h' ? '\026' : \
48420006a0bStron         (c)=='i' ? '\005' : \
48520006a0bStron         (c)=='j' ? '\025' : \
48620006a0bStron         (c)=='k' ? '\013' : \
48720006a0bStron         (c)=='l' ? '\014' : \
48820006a0bStron         (c)=='m' ? '\015' : \
48920006a0bStron         (c)=='n' ? '\016' : \
49020006a0bStron         (c)=='o' ? '\017' : \
49120006a0bStron         (c)=='p' ? '\020' : \
49220006a0bStron         (c)=='q' ? '\021' : \
49320006a0bStron         (c)=='r' ? '\022' : \
49420006a0bStron         (c)=='s' ? '\023' : \
49520006a0bStron         (c)=='t' ? '\074' : \
49620006a0bStron         (c)=='u' ? '\075' : \
49720006a0bStron         (c)=='v' ? '\062' : \
49820006a0bStron         (c)=='w' ? '\046' : \
49920006a0bStron         (c)=='x' ? '\030' : \
50020006a0bStron         (c)=='y' ? '\031' : \
50120006a0bStron         (c)=='z' ? '\077' : \
50220006a0bStron         (c)=='A' ? '\001' : \
50320006a0bStron         (c)=='B' ? '\002' : \
50420006a0bStron         (c)=='C' ? '\003' : \
50520006a0bStron         (c)=='D' ? '\067' : \
50620006a0bStron         (c)=='E' ? '\055' : \
50720006a0bStron         (c)=='F' ? '\056' : \
50820006a0bStron         (c)=='G' ? '\057' : \
50920006a0bStron         (c)=='H' ? '\026' : \
51020006a0bStron         (c)=='I' ? '\005' : \
51120006a0bStron         (c)=='J' ? '\025' : \
51220006a0bStron         (c)=='K' ? '\013' : \
51320006a0bStron         (c)=='L' ? '\014' : \
51420006a0bStron         (c)=='M' ? '\015' : \
51520006a0bStron         (c)=='N' ? '\016' : \
51620006a0bStron         (c)=='O' ? '\017' : \
51720006a0bStron         (c)=='P' ? '\020' : \
51820006a0bStron         (c)=='Q' ? '\021' : \
51920006a0bStron         (c)=='R' ? '\022' : \
52020006a0bStron         (c)=='S' ? '\023' : \
52120006a0bStron         (c)=='T' ? '\074' : \
52220006a0bStron         (c)=='U' ? '\075' : \
52320006a0bStron         (c)=='V' ? '\062' : \
52420006a0bStron         (c)=='W' ? '\046' : \
52520006a0bStron         (c)=='X' ? '\030' : \
52620006a0bStron         (c)=='Y' ? '\031' : \
52720006a0bStron         (c)=='Z' ? '\077' : \
52820006a0bStron         (c)=='|' ? '\031' : \
52920006a0bStron         (c)=='\\' ? '\034' : \
53020006a0bStron         (c)=='^' ? '\036' : \
53120006a0bStron         (c)&077)
53220006a0bStron #else
53320006a0bStron #define CONTROL(c)      ((c)&037)
53420006a0bStron #endif /* IS_EBCDIC_HOST */
53520006a0bStron 
53620006a0bStron #define ESC             CONTROL('[')
537*838f5788Ssimonb #define ESCS            "\33"
53820006a0bStron #define CSI             ((unsigned char)'\233')
539*838f5788Ssimonb #define CHAR_END_COMMAND 0x40000000
54020006a0bStron 
54120006a0bStron #if _OSK_MWC32
54220006a0bStron #define LSIGNAL(sig,func)       os9_signal(sig,func)
54320006a0bStron #else
54420006a0bStron #define LSIGNAL(sig,func)       signal(sig,func)
54520006a0bStron #endif
54620006a0bStron 
54720006a0bStron #if HAVE_SIGPROCMASK
54820006a0bStron #if HAVE_SIGSET_T
54920006a0bStron #else
55020006a0bStron #undef HAVE_SIGPROCMASK
55120006a0bStron #endif
55220006a0bStron #endif
55320006a0bStron #if HAVE_SIGPROCMASK
55420006a0bStron #if HAVE_SIGEMPTYSET
55520006a0bStron #else
55620006a0bStron #undef  sigemptyset
55720006a0bStron #define sigemptyset(mp) *(mp) = 0
55820006a0bStron #endif
55920006a0bStron #endif
56020006a0bStron 
56120006a0bStron #define S_INTERRUPT     01
56220006a0bStron #define S_STOP          02
56320006a0bStron #define S_WINCH         04
56420006a0bStron #define ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
56520006a0bStron 
566*838f5788Ssimonb #ifdef EXIT_SUCCESS
567*838f5788Ssimonb #define QUIT_OK         EXIT_SUCCESS
568*838f5788Ssimonb #else
56920006a0bStron #define QUIT_OK         0
570*838f5788Ssimonb #endif
571*838f5788Ssimonb #ifdef EXIT_FAILURE
572*838f5788Ssimonb #define QUIT_ERROR      EXIT_FAILURE
573*838f5788Ssimonb #define QUIT_INTERRUPT  (EXIT_FAILURE+1)
574*838f5788Ssimonb #else
57520006a0bStron #define QUIT_ERROR      1
57620006a0bStron #define QUIT_INTERRUPT  2
577*838f5788Ssimonb #endif
57820006a0bStron #define QUIT_SAVED_STATUS (-1)
57920006a0bStron 
58020006a0bStron #define FOLLOW_DESC     0
58120006a0bStron #define FOLLOW_NAME     1
58220006a0bStron 
58320006a0bStron /* filestate flags */
58420006a0bStron #define CH_CANSEEK      001
58520006a0bStron #define CH_KEEPOPEN     002
58620006a0bStron #define CH_POPENED      004
58720006a0bStron #define CH_HELPFILE     010
588ec18bca0Stron #define CH_NODATA       020     /* Special case for zero length files */
589ec18bca0Stron 
59020006a0bStron #define ch_zero()       ((POSITION)0)
59120006a0bStron 
59220006a0bStron #define FAKE_HELPFILE   "@/\\less/\\help/\\file/\\@"
593ec18bca0Stron #define FAKE_EMPTYFILE  "@/\\less/\\empty/\\file/\\@"
59420006a0bStron 
59520006a0bStron /* Flags for cvt_text */
59620006a0bStron #define CVT_TO_LC       01      /* Convert upper-case to lower-case */
59720006a0bStron #define CVT_BS          02      /* Do backspace processing */
59820006a0bStron #define CVT_CRLF        04      /* Remove CR after LF */
59920006a0bStron #define CVT_ANSI        010     /* Remove ANSI escape sequences */
60020006a0bStron 
601*838f5788Ssimonb #if HAVE_TIME_T
602*838f5788Ssimonb #define time_type       time_t
603*838f5788Ssimonb #else
604*838f5788Ssimonb #define time_type       long
605*838f5788Ssimonb #endif
606*838f5788Ssimonb 
607*838f5788Ssimonb /* X11 mouse reporting definitions */
608*838f5788Ssimonb #define X11MOUSE_BUTTON1    0 /* Left button press */
609*838f5788Ssimonb #define X11MOUSE_BUTTON2    1 /* Middle button press */
610*838f5788Ssimonb #define X11MOUSE_BUTTON3    2 /* Right button press */
611*838f5788Ssimonb #define X11MOUSE_BUTTON_REL 3 /* Button release */
612*838f5788Ssimonb #define X11MOUSE_WHEEL_UP   0x40 /* Wheel scroll up */
613*838f5788Ssimonb #define X11MOUSE_WHEEL_DOWN 0x41 /* Wheel scroll down */
614*838f5788Ssimonb #define X11MOUSE_OFFSET     0x20 /* Added to button & pos bytes to create a char */
615*838f5788Ssimonb 
616*838f5788Ssimonb #if LESSTEST
617*838f5788Ssimonb #define LESS_DUMP_CHAR CONTROL(']')
618*838f5788Ssimonb #endif
619*838f5788Ssimonb 
620*838f5788Ssimonb struct mlist;
621*838f5788Ssimonb struct loption;
622*838f5788Ssimonb struct hilite_tree;
623*838f5788Ssimonb struct ansi_state;
624*838f5788Ssimonb #include "pattern.h"
625*838f5788Ssimonb #include "xbuf.h"
62620006a0bStron #include "funcs.h"
62720006a0bStron 
62820006a0bStron /* Functions not included in funcs.h */
629*838f5788Ssimonb void postoa(POSITION, char*, int);
630*838f5788Ssimonb void linenumtoa(LINENUM, char*, int);
631*838f5788Ssimonb void inttoa(int, char*, int);
632*838f5788Ssimonb int lstrtoi(char*, char**, int);
633*838f5788Ssimonb POSITION lstrtopos(char*, char**, int);
634*838f5788Ssimonb unsigned long lstrtoul(char*, char**, int);
635*838f5788Ssimonb #if MSDOS_COMPILER==WIN32C
636*838f5788Ssimonb int pclose(FILE*);
637*838f5788Ssimonb #endif
638