[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.21

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_SPACE
                     42: #undef IS_DIGIT
                     43:
1.10      nicm       44: #define        IS_SPACE(c)     isspace((unsigned char)(c))
                     45: #define        IS_DIGIT(c)     isdigit((unsigned char)(c))
1.7       shadchin   46:
1.10      nicm       47: #define        IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI))
1.1       etheisen   48:
                     49: #ifndef TRUE
                     50: #define        TRUE            1
                     51: #endif
                     52: #ifndef FALSE
                     53: #define        FALSE           0
                     54: #endif
                     55:
                     56: #define        OPT_OFF         0
                     57: #define        OPT_ON          1
                     58: #define        OPT_ONPLUS      2
                     59:
1.4       millert    60: #ifndef CHAR_BIT
1.10      nicm       61: #define        CHAR_BIT 8
1.4       millert    62: #endif
                     63:
                     64: /*
                     65:  * Upper bound on the string length of an integer converted to string.
                     66:  * 302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
                     67:  * add 1 for integer division truncation; add 1 more for a minus sign.
                     68:  */
1.10      nicm       69: #define        INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
1.4       millert    70:
1.1       etheisen   71: /*
                     72:  * Special types and constants.
                     73:  */
1.7       shadchin   74: typedef unsigned long LWCHAR;
1.10      nicm       75: #define        MIN_LINENUM_WIDTH  7    /* Min printing width of a line number */
                     76: #define        MAX_UTF_CHAR_LEN   6    /* Max bytes in one UTF-8 char */
1.1       etheisen   77:
1.4       millert    78: #define        SHELL_META_QUEST 1
1.1       etheisen   79:
                     80: /*
                     81:  * An IFILE represents an input file.
                     82:  */
1.10      nicm       83: #define        IFILE           void *
1.1       etheisen   84:
                     85: /*
                     86:  * The structure used to represent a "screen position".
                     87:  * This consists of a file position, and a screen line number.
                     88:  * The meaning is that the line starting at the given file
                     89:  * position is displayed on the ln-th line of the screen.
                     90:  * (Screen lines before ln are empty.)
                     91:  */
1.10      nicm       92: struct scrpos {
                     93:        off_t pos;
1.1       etheisen   94:        int ln;
                     95: };
                     96:
1.15      deraadt    97: typedef union parg {
1.1       etheisen   98:        char *p_string;
                     99:        int p_int;
1.21    ! mmcc      100:        off_t p_linenum;
1.1       etheisen  101: } PARG;
                    102:
1.15      deraadt   103: struct textlist {
1.1       etheisen  104:        char *string;
                    105:        char *endstring;
                    106: };
                    107:
                    108: #define        EOI             (-1)
                    109:
                    110: #define        READ_INTR       (-2)
                    111:
1.7       shadchin  112: /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
1.10      nicm      113: #define        NUM_FRAC_DENOM                  1000000
                    114: #define        NUM_LOG_FRAC_DENOM              6
1.7       shadchin  115:
1.1       etheisen  116: /* How quiet should we be? */
                    117: #define        NOT_QUIET       0       /* Ring bell at eof and for errors */
                    118: #define        LITTLE_QUIET    1       /* Ring bell only for errors */
                    119: #define        VERY_QUIET      2       /* Never ring bell */
                    120:
                    121: /* How should we prompt? */
                    122: #define        PR_SHORT        0       /* Prompt with colon */
                    123: #define        PR_MEDIUM       1       /* Prompt with message */
                    124: #define        PR_LONG         2       /* Prompt with longer message */
                    125:
                    126: /* How should we handle backspaces? */
                    127: #define        BS_SPECIAL      0       /* Do special things for underlining and bold */
                    128: #define        BS_NORMAL       1       /* \b treated as normal char; actually output */
                    129: #define        BS_CONTROL      2       /* \b treated as control char; prints as ^H */
                    130:
                    131: /* How should we search? */
1.10      nicm      132: #define        SRCH_FORW       (1 << 0)  /* Search forward from current position */
                    133: #define        SRCH_BACK       (1 << 1)  /* Search backward from current position */
                    134: #define        SRCH_NO_MOVE    (1 << 2)  /* Highlight, but don't move */
                    135: #define        SRCH_FIND_ALL   (1 << 4)  /* Find and highlight all matches */
                    136: #define        SRCH_NO_MATCH   (1 << 8)  /* Search for non-matching lines */
                    137: #define        SRCH_PAST_EOF   (1 << 9)  /* Search past end-of-file, into next file */
                    138: #define        SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
                    139: #define        SRCH_NO_REGEX   (1 << 12) /* Don't use regular expressions */
                    140: #define        SRCH_FILTER     (1 << 13) /* Search is for '&' (filter) command */
                    141: #define        SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
1.1       etheisen  142:
                    143: #define        SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
                    144:                                (((t) & ~SRCH_FORW) | SRCH_BACK) : \
                    145:                                (((t) & ~SRCH_BACK) | SRCH_FORW))
                    146:
                    147: /* */
                    148: #define        NO_MCA          0
                    149: #define        MCA_DONE        1
                    150: #define        MCA_MORE        2
                    151:
                    152: #define        CC_OK           0       /* Char was accepted & processed */
                    153: #define        CC_QUIT         1       /* Char was a request to abort current cmd */
                    154: #define        CC_ERROR        2       /* Char could not be accepted due to error */
                    155: #define        CC_PASS         3       /* Char was rejected (internal) */
                    156:
1.10      nicm      157: #define        CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
1.4       millert   158:
1.7       shadchin  159: /* Special char bit-flags used to tell put_line() to do something special */
1.1       etheisen  160: #define        AT_NORMAL       (0)
1.7       shadchin  161: #define        AT_UNDERLINE    (1 << 0)
                    162: #define        AT_BOLD         (1 << 1)
                    163: #define        AT_BLINK        (1 << 2)
                    164: #define        AT_STANDOUT     (1 << 3)
                    165: #define        AT_ANSI         (1 << 4)  /* Content-supplied "ANSI" escape sequence */
                    166: #define        AT_BINARY       (1 << 5)  /* LESS*BINFMT representation */
                    167: #define        AT_HILITE       (1 << 6)  /* Internal highlights (e.g., for search) */
1.1       etheisen  168:
                    169: #define        CONTROL(c)      ((c)&037)
1.4       millert   170:
1.1       etheisen  171: #define        ESC             CONTROL('[')
1.7       shadchin  172: #define        CSI             ((unsigned char)'\233')
1.1       etheisen  173:
                    174: #define        S_INTERRUPT     01
                    175: #define        S_STOP          02
1.10      nicm      176: #define        S_WINCH         04
1.1       etheisen  177: #define        ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
                    178:
                    179: #define        QUIT_OK         0
                    180: #define        QUIT_ERROR      1
1.7       shadchin  181: #define        QUIT_INTERRUPT  2
1.1       etheisen  182: #define        QUIT_SAVED_STATUS (-1)
                    183:
1.10      nicm      184: #define        FOLLOW_DESC     0
                    185: #define        FOLLOW_NAME     1
1.7       shadchin  186:
1.1       etheisen  187: /* filestate flags */
                    188: #define        CH_CANSEEK      001
                    189: #define        CH_KEEPOPEN     002
                    190: #define        CH_POPENED      004
1.7       shadchin  191: #define        CH_HELPFILE     010
1.11      deraadt   192: #define        CH_NODATA       020     /* Special case for zero length files */
1.9       shadchin  193:
1.1       etheisen  194:
1.10      nicm      195: #define        ch_zero()       (0)
1.9       shadchin  196:
1.10      nicm      197: #define        FAKE_EMPTYFILE  "@/\\less/\\empty/\\file/\\@"
1.7       shadchin  198:
                    199: /* Flags for cvt_text */
                    200: #define        CVT_TO_LC       01      /* Convert upper-case to lower-case */
                    201: #define        CVT_BS          02      /* Do backspace processing */
                    202: #define        CVT_CRLF        04      /* Remove CR after LF */
                    203: #define        CVT_ANSI        010     /* Remove ANSI escape sequences */
1.4       millert   204:
1.1       etheisen  205: #include "funcs.h"
1.4       millert   206:
                    207: /* Functions not included in funcs.h */
1.10      nicm      208: void postoa(off_t, char *, size_t);
1.21    ! mmcc      209: void linenumtoa(off_t, char *, size_t);
1.10      nicm      210: void inttoa(int, char *, size_t);