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

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:
1.4       millert    90: #define        SHELL_META_QUEST 1
1.1       etheisen   91:
1.4       millert    92: #define        SPACES_IN_FILENAMES 1
                     93:
1.1       etheisen   94: /*
                     95:  * An IFILE represents an input file.
                     96:  */
1.10      nicm       97: #define        IFILE           void *
                     98: #define        NULL_IFILE      (NULL)
1.1       etheisen   99:
                    100: /*
                    101:  * The structure used to represent a "screen position".
                    102:  * This consists of a file position, and a screen line number.
                    103:  * The meaning is that the line starting at the given file
                    104:  * position is displayed on the ln-th line of the screen.
                    105:  * (Screen lines before ln are empty.)
                    106:  */
1.10      nicm      107: struct scrpos {
                    108:        off_t pos;
1.1       etheisen  109:        int ln;
                    110: };
                    111:
1.15    ! deraadt   112: typedef union parg {
1.1       etheisen  113:        char *p_string;
                    114:        int p_int;
1.4       millert   115:        LINENUM p_linenum;
1.1       etheisen  116: } PARG;
                    117:
                    118: #define        NULL_PARG       ((PARG *)NULL)
                    119:
1.15    ! deraadt   120: struct textlist {
1.1       etheisen  121:        char *string;
                    122:        char *endstring;
                    123: };
                    124:
                    125: #define        EOI             (-1)
                    126:
                    127: #define        READ_INTR       (-2)
                    128:
1.7       shadchin  129: /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
1.10      nicm      130: #define        NUM_FRAC_DENOM                  1000000
                    131: #define        NUM_LOG_FRAC_DENOM              6
1.7       shadchin  132:
1.1       etheisen  133: /* How quiet should we be? */
                    134: #define        NOT_QUIET       0       /* Ring bell at eof and for errors */
                    135: #define        LITTLE_QUIET    1       /* Ring bell only for errors */
                    136: #define        VERY_QUIET      2       /* Never ring bell */
                    137:
                    138: /* How should we prompt? */
                    139: #define        PR_SHORT        0       /* Prompt with colon */
                    140: #define        PR_MEDIUM       1       /* Prompt with message */
                    141: #define        PR_LONG         2       /* Prompt with longer message */
                    142:
                    143: /* How should we handle backspaces? */
                    144: #define        BS_SPECIAL      0       /* Do special things for underlining and bold */
                    145: #define        BS_NORMAL       1       /* \b treated as normal char; actually output */
                    146: #define        BS_CONTROL      2       /* \b treated as control char; prints as ^H */
                    147:
                    148: /* How should we search? */
1.10      nicm      149: #define        SRCH_FORW       (1 << 0)  /* Search forward from current position */
                    150: #define        SRCH_BACK       (1 << 1)  /* Search backward from current position */
                    151: #define        SRCH_NO_MOVE    (1 << 2)  /* Highlight, but don't move */
                    152: #define        SRCH_FIND_ALL   (1 << 4)  /* Find and highlight all matches */
                    153: #define        SRCH_NO_MATCH   (1 << 8)  /* Search for non-matching lines */
                    154: #define        SRCH_PAST_EOF   (1 << 9)  /* Search past end-of-file, into next file */
                    155: #define        SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
                    156: #define        SRCH_NO_REGEX   (1 << 12) /* Don't use regular expressions */
                    157: #define        SRCH_FILTER     (1 << 13) /* Search is for '&' (filter) command */
                    158: #define        SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
1.1       etheisen  159:
                    160: #define        SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
                    161:                                (((t) & ~SRCH_FORW) | SRCH_BACK) : \
                    162:                                (((t) & ~SRCH_BACK) | SRCH_FORW))
                    163:
                    164: /* */
                    165: #define        NO_MCA          0
                    166: #define        MCA_DONE        1
                    167: #define        MCA_MORE        2
                    168:
                    169: #define        CC_OK           0       /* Char was accepted & processed */
                    170: #define        CC_QUIT         1       /* Char was a request to abort current cmd */
                    171: #define        CC_ERROR        2       /* Char could not be accepted due to error */
                    172: #define        CC_PASS         3       /* Char was rejected (internal) */
                    173:
1.10      nicm      174: #define        CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
1.4       millert   175:
1.7       shadchin  176: /* Special char bit-flags used to tell put_line() to do something special */
1.1       etheisen  177: #define        AT_NORMAL       (0)
1.7       shadchin  178: #define        AT_UNDERLINE    (1 << 0)
                    179: #define        AT_BOLD         (1 << 1)
                    180: #define        AT_BLINK        (1 << 2)
                    181: #define        AT_STANDOUT     (1 << 3)
                    182: #define        AT_ANSI         (1 << 4)  /* Content-supplied "ANSI" escape sequence */
                    183: #define        AT_BINARY       (1 << 5)  /* LESS*BINFMT representation */
                    184: #define        AT_HILITE       (1 << 6)  /* Internal highlights (e.g., for search) */
1.1       etheisen  185:
                    186: #define        CONTROL(c)      ((c)&037)
1.4       millert   187:
1.1       etheisen  188: #define        ESC             CONTROL('[')
1.7       shadchin  189: #define        CSI             ((unsigned char)'\233')
1.1       etheisen  190:
                    191: #define        S_INTERRUPT     01
                    192: #define        S_STOP          02
1.10      nicm      193: #define        S_WINCH         04
1.1       etheisen  194: #define        ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
                    195:
                    196: #define        QUIT_OK         0
                    197: #define        QUIT_ERROR      1
1.7       shadchin  198: #define        QUIT_INTERRUPT  2
1.1       etheisen  199: #define        QUIT_SAVED_STATUS (-1)
                    200:
1.10      nicm      201: #define        FOLLOW_DESC     0
                    202: #define        FOLLOW_NAME     1
1.7       shadchin  203:
1.1       etheisen  204: /* filestate flags */
                    205: #define        CH_CANSEEK      001
                    206: #define        CH_KEEPOPEN     002
                    207: #define        CH_POPENED      004
1.7       shadchin  208: #define        CH_HELPFILE     010
1.11      deraadt   209: #define        CH_NODATA       020     /* Special case for zero length files */
1.9       shadchin  210:
1.1       etheisen  211:
1.10      nicm      212: #define        ch_zero()       (0)
1.9       shadchin  213:
1.10      nicm      214: #define        FAKE_EMPTYFILE  "@/\\less/\\empty/\\file/\\@"
1.7       shadchin  215:
                    216: /* Flags for cvt_text */
                    217: #define        CVT_TO_LC       01      /* Convert upper-case to lower-case */
                    218: #define        CVT_BS          02      /* Do backspace processing */
                    219: #define        CVT_CRLF        04      /* Remove CR after LF */
                    220: #define        CVT_ANSI        010     /* Remove ANSI escape sequences */
1.4       millert   221:
1.1       etheisen  222: #include "funcs.h"
1.4       millert   223:
                    224: /* Functions not included in funcs.h */
1.10      nicm      225: void postoa(off_t, char *, size_t);
                    226: void linenumtoa(LINENUM, char *, size_t);
                    227: void inttoa(int, char *, size_t);