[BACK]Return to less.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Annotation of src/usr.bin/less/less.h, Revision 1.13

1.1       etheisen    1: /*
1.9       shadchin    2:  * Copyright (C) 1984-2012  Mark Nudelman
1.13    ! nicm        3:  * Modified for use with illumos by Garrett D'Amore.
        !             4:  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
1.1       etheisen    5:  *
1.4       millert     6:  * You may distribute under the terms of either the GNU General Public
                      7:  * License or the Less License, as specified in the README file.
1.1       etheisen    8:  *
1.9       shadchin    9:  * For more information, see the README file.
1.1       etheisen   10:  */
                     11:
                     12: /*
1.10      nicm       13:  * Standard include file for "less".
1.4       millert    14:  */
                     15:
                     16: /*
1.1       etheisen   17:  * Include the file of compile-time options.
                     18:  * The <> make cc search for it in -I., not srcdir.
                     19:  */
                     20: #include <defines.h>
                     21:
                     22: /* Library function declarations */
                     23:
                     24: #include <sys/types.h>
                     25: #include <stdio.h>
                     26: #include <fcntl.h>
                     27: #include <unistd.h>
                     28: #include <ctype.h>
1.7       shadchin   29: #include <wctype.h>
1.4       millert    30: #include <limits.h>
1.1       etheisen   31: #include <stdlib.h>
                     32: #include <string.h>
1.10      nicm       33: #include <libgen.h>
1.8       millert    34: #include <signal.h>
1.7       shadchin   35:
1.4       millert    36: /*
                     37:  * Simple lowercase test which can be used during option processing
                     38:  * (before options are parsed which might tell us what charset to use).
                     39:  */
1.7       shadchin   40:
                     41: #undef IS_UPPER
                     42: #undef IS_LOWER
                     43: #undef TO_UPPER
                     44: #undef TO_LOWER
                     45: #undef IS_SPACE
                     46: #undef IS_DIGIT
                     47:
                     48: #define        IS_UPPER(c)     iswupper(c)
                     49: #define        IS_LOWER(c)     iswlower(c)
                     50: #define        TO_UPPER(c)     towupper(c)
                     51: #define        TO_LOWER(c)     towlower(c)
                     52:
1.10      nicm       53: #define        IS_SPACE(c)     isspace((unsigned char)(c))
                     54: #define        IS_DIGIT(c)     isdigit((unsigned char)(c))
1.7       shadchin   55:
1.10      nicm       56: #define        IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI))
1.1       etheisen   57:
                     58: #ifndef TRUE
                     59: #define        TRUE            1
                     60: #endif
                     61: #ifndef FALSE
                     62: #define        FALSE           0
                     63: #endif
                     64:
                     65: #define        OPT_OFF         0
                     66: #define        OPT_ON          1
                     67: #define        OPT_ONPLUS      2
                     68:
                     69: #define        BAD_LSEEK       ((off_t)-1)
                     70:
1.4       millert    71: #ifndef CHAR_BIT
1.10      nicm       72: #define        CHAR_BIT 8
1.4       millert    73: #endif
                     74:
                     75: /*
                     76:  * Upper bound on the string length of an integer converted to string.
                     77:  * 302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
                     78:  * add 1 for integer division truncation; add 1 more for a minus sign.
                     79:  */
1.10      nicm       80: #define        INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
1.4       millert    81:
1.1       etheisen   82: /*
                     83:  * Special types and constants.
                     84:  */
1.7       shadchin   85: typedef unsigned long LWCHAR;
1.4       millert    86: typedef off_t          LINENUM;
1.10      nicm       87: #define        MIN_LINENUM_WIDTH  7    /* Min printing width of a line number */
                     88: #define        MAX_UTF_CHAR_LEN   6    /* Max bytes in one UTF-8 char */
1.1       etheisen   89:
                     90: /*
                     91:  * Flags for open()
                     92:  */
1.4       millert    93: #define        OPEN_READ       (O_RDONLY)
1.1       etheisen   94: #define        OPEN_APPEND     (O_APPEND|O_WRONLY)
                     95:
1.4       millert    96: #define        SHELL_META_QUEST 1
1.1       etheisen   97:
1.4       millert    98: #define        SPACES_IN_FILENAMES 1
                     99:
1.1       etheisen  100: /*
                    101:  * An IFILE represents an input file.
                    102:  */
1.10      nicm      103: #define        IFILE           void *
                    104: #define        NULL_IFILE      (NULL)
1.1       etheisen  105:
                    106: /*
                    107:  * The structure used to represent a "screen position".
                    108:  * This consists of a file position, and a screen line number.
                    109:  * The meaning is that the line starting at the given file
                    110:  * position is displayed on the ln-th line of the screen.
                    111:  * (Screen lines before ln are empty.)
                    112:  */
1.10      nicm      113: struct scrpos {
                    114:        off_t pos;
1.1       etheisen  115:        int ln;
                    116: };
                    117:
                    118: typedef union parg
                    119: {
                    120:        char *p_string;
                    121:        int p_int;
1.4       millert   122:        LINENUM p_linenum;
1.1       etheisen  123: } PARG;
                    124:
                    125: #define        NULL_PARG       ((PARG *)NULL)
                    126:
                    127: struct textlist
                    128: {
                    129:        char *string;
                    130:        char *endstring;
                    131: };
                    132:
                    133: #define        EOI             (-1)
                    134:
                    135: #define        READ_INTR       (-2)
                    136:
1.7       shadchin  137: /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
1.10      nicm      138: #define        NUM_FRAC_DENOM                  1000000
                    139: #define        NUM_LOG_FRAC_DENOM              6
1.7       shadchin  140:
1.1       etheisen  141: /* How quiet should we be? */
                    142: #define        NOT_QUIET       0       /* Ring bell at eof and for errors */
                    143: #define        LITTLE_QUIET    1       /* Ring bell only for errors */
                    144: #define        VERY_QUIET      2       /* Never ring bell */
                    145:
                    146: /* How should we prompt? */
                    147: #define        PR_SHORT        0       /* Prompt with colon */
                    148: #define        PR_MEDIUM       1       /* Prompt with message */
                    149: #define        PR_LONG         2       /* Prompt with longer message */
                    150:
                    151: /* How should we handle backspaces? */
                    152: #define        BS_SPECIAL      0       /* Do special things for underlining and bold */
                    153: #define        BS_NORMAL       1       /* \b treated as normal char; actually output */
                    154: #define        BS_CONTROL      2       /* \b treated as control char; prints as ^H */
                    155:
                    156: /* How should we search? */
1.10      nicm      157: #define        SRCH_FORW       (1 << 0)  /* Search forward from current position */
                    158: #define        SRCH_BACK       (1 << 1)  /* Search backward from current position */
                    159: #define        SRCH_NO_MOVE    (1 << 2)  /* Highlight, but don't move */
                    160: #define        SRCH_FIND_ALL   (1 << 4)  /* Find and highlight all matches */
                    161: #define        SRCH_NO_MATCH   (1 << 8)  /* Search for non-matching lines */
                    162: #define        SRCH_PAST_EOF   (1 << 9)  /* Search past end-of-file, into next file */
                    163: #define        SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
                    164: #define        SRCH_NO_REGEX   (1 << 12) /* Don't use regular expressions */
                    165: #define        SRCH_FILTER     (1 << 13) /* Search is for '&' (filter) command */
                    166: #define        SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
1.1       etheisen  167:
                    168: #define        SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
                    169:                                (((t) & ~SRCH_FORW) | SRCH_BACK) : \
                    170:                                (((t) & ~SRCH_BACK) | SRCH_FORW))
                    171:
                    172: /* */
                    173: #define        NO_MCA          0
                    174: #define        MCA_DONE        1
                    175: #define        MCA_MORE        2
                    176:
                    177: #define        CC_OK           0       /* Char was accepted & processed */
                    178: #define        CC_QUIT         1       /* Char was a request to abort current cmd */
                    179: #define        CC_ERROR        2       /* Char could not be accepted due to error */
                    180: #define        CC_PASS         3       /* Char was rejected (internal) */
                    181:
1.10      nicm      182: #define        CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
1.4       millert   183:
1.7       shadchin  184: /* Special char bit-flags used to tell put_line() to do something special */
1.1       etheisen  185: #define        AT_NORMAL       (0)
1.7       shadchin  186: #define        AT_UNDERLINE    (1 << 0)
                    187: #define        AT_BOLD         (1 << 1)
                    188: #define        AT_BLINK        (1 << 2)
                    189: #define        AT_STANDOUT     (1 << 3)
                    190: #define        AT_ANSI         (1 << 4)  /* Content-supplied "ANSI" escape sequence */
                    191: #define        AT_BINARY       (1 << 5)  /* LESS*BINFMT representation */
                    192: #define        AT_HILITE       (1 << 6)  /* Internal highlights (e.g., for search) */
1.1       etheisen  193:
                    194: #define        CONTROL(c)      ((c)&037)
1.4       millert   195:
1.1       etheisen  196: #define        ESC             CONTROL('[')
1.7       shadchin  197: #define        CSI             ((unsigned char)'\233')
1.1       etheisen  198:
                    199: #define        S_INTERRUPT     01
                    200: #define        S_STOP          02
1.10      nicm      201: #define        S_WINCH         04
1.1       etheisen  202: #define        ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
                    203:
                    204: #define        QUIT_OK         0
                    205: #define        QUIT_ERROR      1
1.7       shadchin  206: #define        QUIT_INTERRUPT  2
1.1       etheisen  207: #define        QUIT_SAVED_STATUS (-1)
                    208:
1.10      nicm      209: #define        FOLLOW_DESC     0
                    210: #define        FOLLOW_NAME     1
1.7       shadchin  211:
1.1       etheisen  212: /* filestate flags */
                    213: #define        CH_CANSEEK      001
                    214: #define        CH_KEEPOPEN     002
                    215: #define        CH_POPENED      004
1.7       shadchin  216: #define        CH_HELPFILE     010
1.11      deraadt   217: #define        CH_NODATA       020     /* Special case for zero length files */
1.9       shadchin  218:
1.1       etheisen  219:
1.10      nicm      220: #define        ch_zero()       (0)
1.9       shadchin  221:
1.10      nicm      222: #define        FAKE_EMPTYFILE  "@/\\less/\\empty/\\file/\\@"
1.7       shadchin  223:
                    224: /* Flags for cvt_text */
                    225: #define        CVT_TO_LC       01      /* Convert upper-case to lower-case */
                    226: #define        CVT_BS          02      /* Do backspace processing */
                    227: #define        CVT_CRLF        04      /* Remove CR after LF */
                    228: #define        CVT_ANSI        010     /* Remove ANSI escape sequences */
1.4       millert   229:
1.1       etheisen  230: #include "funcs.h"
1.4       millert   231:
                    232: /* Functions not included in funcs.h */
1.10      nicm      233: void postoa(off_t, char *, size_t);
                    234: void linenumtoa(LINENUM, char *, size_t);
                    235: void inttoa(int, char *, size_t);