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

1.1       etheisen    1: /*
1.1.1.4 ! shadchin    2:  * Copyright (C) 1984-2012  Mark Nudelman
1.1       etheisen    3:  *
1.1.1.2   millert     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.
1.1       etheisen    6:  *
1.1.1.4 ! shadchin    7:  * For more information, see the README file.
1.1       etheisen    8:  */
                      9:
1.1.1.3   shadchin   10: #define NEWBOT 1
1.1       etheisen   11:
                     12: /*
                     13:  * Standard include file for "less".
                     14:  */
                     15:
                     16: /*
1.1.1.2   millert    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: /*
1.1       etheisen   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:  * Language details.
                     41:  */
                     42: #if HAVE_VOID
                     43: #define        VOID_POINTER    void *
                     44: #else
                     45: #define        VOID_POINTER    char *
                     46: #define        void  int
                     47: #endif
1.1.1.2   millert    48: #if HAVE_CONST
                     49: #define        constant        const
                     50: #else
                     51: #define        constant
                     52: #endif
1.1       etheisen   53:
                     54: #define        public          /* PUBLIC FUNCTION */
                     55:
                     56: /* Library function declarations */
                     57:
                     58: #if HAVE_SYS_TYPES_H
                     59: #include <sys/types.h>
                     60: #endif
                     61: #if HAVE_STDIO_H
                     62: #include <stdio.h>
                     63: #endif
                     64: #if HAVE_FCNTL_H
                     65: #include <fcntl.h>
                     66: #endif
                     67: #if HAVE_UNISTD_H
                     68: #include <unistd.h>
                     69: #endif
                     70: #if HAVE_CTYPE_H
                     71: #include <ctype.h>
                     72: #endif
1.1.1.3   shadchin   73: #if HAVE_WCTYPE_H
                     74: #include <wctype.h>
                     75: #endif
1.1.1.2   millert    76: #if HAVE_LIMITS_H
                     77: #include <limits.h>
                     78: #endif
                     79: #if HAVE_STDLIB_H
1.1       etheisen   80: #include <stdlib.h>
1.1.1.2   millert    81: #endif
                     82: #if HAVE_STRING_H
1.1       etheisen   83: #include <string.h>
                     84: #endif
1.1.1.4 ! shadchin   85: #include <signal.h>
1.1.1.3   shadchin   86:
                     87: /* OS-specific includes */
1.1.1.2   millert    88: #ifdef _OSK
                     89: #include <modes.h>
                     90: #include <strings.h>
                     91: #endif
1.1.1.3   shadchin   92:
                     93: #ifdef __TANDEM
                     94: #include <floss.h>
                     95: #endif
                     96:
1.1.1.2   millert    97: #if MSDOS_COMPILER==WIN32C || OS2
                     98: #include <io.h>
                     99: #endif
1.1.1.3   shadchin  100:
1.1.1.2   millert   101: #if MSDOS_COMPILER==DJGPPC
                    102: #include <io.h>
                    103: #include <sys/exceptn.h>
                    104: #include <conio.h>
                    105: #include <pc.h>
                    106: #endif
1.1       etheisen  107:
1.1.1.2   millert   108: #if !HAVE_STDLIB_H
1.1       etheisen  109: char *getenv();
                    110: off_t lseek();
                    111: VOID_POINTER calloc();
                    112: void free();
                    113: #endif
                    114:
1.1.1.2   millert   115: /*
                    116:  * Simple lowercase test which can be used during option processing
                    117:  * (before options are parsed which might tell us what charset to use).
                    118:  */
1.1.1.3   shadchin  119: #define ASCII_IS_UPPER(c)      ((c) >= 'A' && (c) <= 'Z')
                    120: #define ASCII_IS_LOWER(c)      ((c) >= 'a' && (c) <= 'z')
                    121: #define        ASCII_TO_UPPER(c)       ((c) - 'a' + 'A')
                    122: #define        ASCII_TO_LOWER(c)       ((c) - 'A' + 'a')
                    123:
                    124: #undef IS_UPPER
                    125: #undef IS_LOWER
                    126: #undef TO_UPPER
                    127: #undef TO_LOWER
                    128: #undef IS_SPACE
                    129: #undef IS_DIGIT
                    130:
                    131: #if HAVE_WCTYPE
                    132: #define        IS_UPPER(c)     iswupper(c)
                    133: #define        IS_LOWER(c)     iswlower(c)
                    134: #define        TO_UPPER(c)     towupper(c)
                    135: #define        TO_LOWER(c)     towlower(c)
                    136: #else
                    137: #if HAVE_UPPER_LOWER
                    138: #define        IS_UPPER(c)     isupper((unsigned char) (c))
                    139: #define        IS_LOWER(c)     islower((unsigned char) (c))
                    140: #define        TO_UPPER(c)     toupper((unsigned char) (c))
                    141: #define        TO_LOWER(c)     tolower((unsigned char) (c))
                    142: #else
                    143: #define        IS_UPPER(c)     ASCII_IS_UPPER(c)
                    144: #define        IS_LOWER(c)     ASCII_IS_LOWER(c)
                    145: #define        TO_UPPER(c)     ASCII_TO_UPPER(c)
                    146: #define        TO_LOWER(c)     ASCII_TO_LOWER(c)
                    147: #endif
                    148: #endif
                    149:
                    150: #ifdef isspace
                    151: #define IS_SPACE(c)    isspace((unsigned char)(c))
                    152: #else
                    153: #define IS_SPACE(c)    ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
                    154: #endif
                    155:
                    156: #ifdef isdigit
                    157: #define IS_DIGIT(c)    isdigit((unsigned char)(c))
                    158: #else
                    159: #define IS_DIGIT(c)    ((c) >= '0' && (c) <= '9')
1.1       etheisen  160: #endif
                    161:
1.1.1.3   shadchin  162: #define IS_CSI_START(c)        (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI))
                    163:
1.1       etheisen  164: #ifndef NULL
                    165: #define        NULL    0
                    166: #endif
                    167:
                    168: #ifndef TRUE
                    169: #define        TRUE            1
                    170: #endif
                    171: #ifndef FALSE
                    172: #define        FALSE           0
                    173: #endif
                    174:
                    175: #define        OPT_OFF         0
                    176: #define        OPT_ON          1
                    177: #define        OPT_ONPLUS      2
                    178:
1.1.1.2   millert   179: #if !HAVE_MEMCPY
1.1       etheisen  180: #ifndef memcpy
                    181: #define        memcpy(to,from,len)     bcopy((from),(to),(len))
                    182: #endif
                    183: #endif
                    184:
1.1.1.3   shadchin  185: #if HAVE_SNPRINTF
                    186: #define SNPRINTF1(str, size, fmt, v1)             snprintf((str), (size), (fmt), (v1))
                    187: #define SNPRINTF2(str, size, fmt, v1, v2)         snprintf((str), (size), (fmt), (v1), (v2))
                    188: #define SNPRINTF3(str, size, fmt, v1, v2, v3)     snprintf((str), (size), (fmt), (v1), (v2), (v3))
                    189: #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
                    190: #else
                    191: /* Use unsafe sprintf if we don't have snprintf. */
                    192: #define SNPRINTF1(str, size, fmt, v1)             sprintf((str), (fmt), (v1))
                    193: #define SNPRINTF2(str, size, fmt, v1, v2)         sprintf((str), (fmt), (v1), (v2))
                    194: #define SNPRINTF3(str, size, fmt, v1, v2, v3)     sprintf((str), (fmt), (v1), (v2), (v3))
                    195: #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
                    196: #endif
                    197:
1.1       etheisen  198: #define        BAD_LSEEK       ((off_t)-1)
                    199:
1.1.1.3   shadchin  200: #ifndef SEEK_SET
                    201: #define SEEK_SET 0
                    202: #endif
                    203: #ifndef SEEK_END
                    204: #define SEEK_END 2
                    205: #endif
                    206:
1.1.1.2   millert   207: #ifndef CHAR_BIT
                    208: #define CHAR_BIT 8
                    209: #endif
                    210:
1.1       etheisen  211: /*
1.1.1.2   millert   212:  * Upper bound on the string length of an integer converted to string.
                    213:  * 302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
                    214:  * add 1 for integer division truncation; add 1 more for a minus sign.
1.1       etheisen  215:  */
1.1.1.2   millert   216: #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
                    217:
1.1       etheisen  218: /*
1.1.1.2   millert   219:  * Special types and constants.
1.1       etheisen  220:  */
1.1.1.3   shadchin  221: typedef unsigned long LWCHAR;
1.1.1.2   millert   222: typedef off_t          POSITION;
                    223: typedef off_t          LINENUM;
                    224: #define MIN_LINENUM_WIDTH  7   /* Min printing width of a line number */
1.1.1.3   shadchin  225: #define MAX_UTF_CHAR_LEN   6   /* Max bytes in one UTF-8 char */
1.1       etheisen  226:
                    227: #define        NULL_POSITION   ((POSITION)(-1))
                    228:
                    229: /*
                    230:  * Flags for open()
                    231:  */
1.1.1.2   millert   232: #if MSDOS_COMPILER || OS2
1.1       etheisen  233: #define        OPEN_READ       (O_RDONLY|O_BINARY)
                    234: #else
1.1.1.2   millert   235: #ifdef _OSK
                    236: #define        OPEN_READ       (S_IREAD)
                    237: #else
                    238: #ifdef O_RDONLY
                    239: #define        OPEN_READ       (O_RDONLY)
                    240: #else
1.1       etheisen  241: #define        OPEN_READ       (0)
                    242: #endif
1.1.1.2   millert   243: #endif
                    244: #endif
                    245:
                    246: #if defined(O_WRONLY) && defined(O_APPEND)
1.1       etheisen  247: #define        OPEN_APPEND     (O_APPEND|O_WRONLY)
                    248: #else
1.1.1.2   millert   249: #ifdef _OSK
                    250: #define OPEN_APPEND    (S_IWRITE)
                    251: #else
1.1       etheisen  252: #define        OPEN_APPEND     (1)
                    253: #endif
1.1.1.2   millert   254: #endif
1.1       etheisen  255:
1.1.1.2   millert   256: /*
                    257:  * Set a file descriptor to binary mode.
                    258:  */
                    259: #if MSDOS_COMPILER==MSOFTC
                    260: #define        SET_BINARY(f)   _setmode(f, _O_BINARY);
1.1       etheisen  261: #else
1.1.1.2   millert   262: #if MSDOS_COMPILER || OS2
                    263: #define        SET_BINARY(f)   setmode(f, O_BINARY)
                    264: #else
                    265: #define        SET_BINARY(f)
                    266: #endif
1.1       etheisen  267: #endif
                    268:
                    269: /*
1.1.1.2   millert   270:  * Does the shell treat "?" as a metacharacter?
                    271:  */
                    272: #if MSDOS_COMPILER || OS2 || _OSK
                    273: #define        SHELL_META_QUEST 0
                    274: #else
                    275: #define        SHELL_META_QUEST 1
                    276: #endif
                    277:
                    278: #define        SPACES_IN_FILENAMES 1
                    279:
                    280: /*
1.1       etheisen  281:  * An IFILE represents an input file.
                    282:  */
                    283: #define        IFILE           VOID_POINTER
                    284: #define        NULL_IFILE      ((IFILE)NULL)
                    285:
                    286: /*
                    287:  * The structure used to represent a "screen position".
                    288:  * This consists of a file position, and a screen line number.
                    289:  * The meaning is that the line starting at the given file
                    290:  * position is displayed on the ln-th line of the screen.
                    291:  * (Screen lines before ln are empty.)
                    292:  */
                    293: struct scrpos
                    294: {
                    295:        POSITION pos;
                    296:        int ln;
                    297: };
                    298:
                    299: typedef union parg
                    300: {
                    301:        char *p_string;
                    302:        int p_int;
1.1.1.2   millert   303:        LINENUM p_linenum;
1.1       etheisen  304: } PARG;
                    305:
                    306: #define        NULL_PARG       ((PARG *)NULL)
                    307:
                    308: struct textlist
                    309: {
                    310:        char *string;
                    311:        char *endstring;
                    312: };
                    313:
                    314: #define        EOI             (-1)
                    315:
                    316: #define        READ_INTR       (-2)
                    317:
1.1.1.3   shadchin  318: /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
                    319: #define NUM_FRAC_DENOM                 1000000
                    320: #define NUM_LOG_FRAC_DENOM             6
                    321:
1.1       etheisen  322: /* How quiet should we be? */
                    323: #define        NOT_QUIET       0       /* Ring bell at eof and for errors */
                    324: #define        LITTLE_QUIET    1       /* Ring bell only for errors */
                    325: #define        VERY_QUIET      2       /* Never ring bell */
                    326:
                    327: /* How should we prompt? */
                    328: #define        PR_SHORT        0       /* Prompt with colon */
                    329: #define        PR_MEDIUM       1       /* Prompt with message */
                    330: #define        PR_LONG         2       /* Prompt with longer message */
                    331:
                    332: /* How should we handle backspaces? */
                    333: #define        BS_SPECIAL      0       /* Do special things for underlining and bold */
                    334: #define        BS_NORMAL       1       /* \b treated as normal char; actually output */
                    335: #define        BS_CONTROL      2       /* \b treated as control char; prints as ^H */
                    336:
                    337: /* How should we search? */
1.1.1.3   shadchin  338: #define        SRCH_FORW       (1 << 0)  /* Search forward from current position */
                    339: #define        SRCH_BACK       (1 << 1)  /* Search backward from current position */
                    340: #define SRCH_NO_MOVE    (1 << 2)  /* Highlight, but don't move */
                    341: #define SRCH_FIND_ALL   (1 << 4)  /* Find and highlight all matches */
                    342: #define SRCH_NO_MATCH   (1 << 8)  /* Search for non-matching lines */
                    343: #define SRCH_PAST_EOF   (1 << 9)  /* Search past end-of-file, into next file */
                    344: #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
                    345: #define SRCH_NO_REGEX   (1 << 12) /* Don't use regular expressions */
                    346: #define SRCH_FILTER     (1 << 13) /* Search is for '&' (filter) command */
                    347: #define SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
1.1       etheisen  348:
                    349: #define        SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
                    350:                                (((t) & ~SRCH_FORW) | SRCH_BACK) : \
                    351:                                (((t) & ~SRCH_BACK) | SRCH_FORW))
                    352:
                    353: /* */
                    354: #define        NO_MCA          0
                    355: #define        MCA_DONE        1
                    356: #define        MCA_MORE        2
                    357:
                    358: #define        CC_OK           0       /* Char was accepted & processed */
                    359: #define        CC_QUIT         1       /* Char was a request to abort current cmd */
                    360: #define        CC_ERROR        2       /* Char could not be accepted due to error */
                    361: #define        CC_PASS         3       /* Char was rejected (internal) */
                    362:
1.1.1.2   millert   363: #define CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
                    364:
1.1.1.3   shadchin  365: /* Special char bit-flags used to tell put_line() to do something special */
1.1       etheisen  366: #define        AT_NORMAL       (0)
1.1.1.3   shadchin  367: #define        AT_UNDERLINE    (1 << 0)
                    368: #define        AT_BOLD         (1 << 1)
                    369: #define        AT_BLINK        (1 << 2)
                    370: #define        AT_STANDOUT     (1 << 3)
                    371: #define        AT_ANSI         (1 << 4)  /* Content-supplied "ANSI" escape sequence */
                    372: #define        AT_BINARY       (1 << 5)  /* LESS*BINFMT representation */
                    373: #define        AT_HILITE       (1 << 6)  /* Internal highlights (e.g., for search) */
1.1       etheisen  374:
1.1.1.2   millert   375: #if '0' == 240
                    376: #define IS_EBCDIC_HOST 1
                    377: #endif
                    378:
                    379: #if IS_EBCDIC_HOST
                    380: /*
                    381:  * Long definition for EBCDIC.
                    382:  * Since the argument is usually a constant, this macro normally compiles
                    383:  * into a constant.
                    384:  */
                    385: #define CONTROL(c) ( \
                    386:        (c)=='[' ? '\047' : \
                    387:        (c)=='a' ? '\001' : \
                    388:        (c)=='b' ? '\002' : \
                    389:        (c)=='c' ? '\003' : \
                    390:        (c)=='d' ? '\067' : \
                    391:        (c)=='e' ? '\055' : \
                    392:        (c)=='f' ? '\056' : \
                    393:        (c)=='g' ? '\057' : \
                    394:        (c)=='h' ? '\026' : \
                    395:        (c)=='i' ? '\005' : \
                    396:        (c)=='j' ? '\025' : \
                    397:        (c)=='k' ? '\013' : \
                    398:        (c)=='l' ? '\014' : \
                    399:        (c)=='m' ? '\015' : \
                    400:        (c)=='n' ? '\016' : \
                    401:        (c)=='o' ? '\017' : \
                    402:        (c)=='p' ? '\020' : \
                    403:        (c)=='q' ? '\021' : \
                    404:        (c)=='r' ? '\022' : \
                    405:        (c)=='s' ? '\023' : \
                    406:        (c)=='t' ? '\074' : \
                    407:        (c)=='u' ? '\075' : \
                    408:        (c)=='v' ? '\062' : \
                    409:        (c)=='w' ? '\046' : \
                    410:        (c)=='x' ? '\030' : \
                    411:        (c)=='y' ? '\031' : \
                    412:        (c)=='z' ? '\077' : \
                    413:        (c)=='A' ? '\001' : \
                    414:        (c)=='B' ? '\002' : \
                    415:        (c)=='C' ? '\003' : \
                    416:        (c)=='D' ? '\067' : \
                    417:        (c)=='E' ? '\055' : \
                    418:        (c)=='F' ? '\056' : \
                    419:        (c)=='G' ? '\057' : \
                    420:        (c)=='H' ? '\026' : \
                    421:        (c)=='I' ? '\005' : \
                    422:        (c)=='J' ? '\025' : \
                    423:        (c)=='K' ? '\013' : \
                    424:        (c)=='L' ? '\014' : \
                    425:        (c)=='M' ? '\015' : \
                    426:        (c)=='N' ? '\016' : \
                    427:        (c)=='O' ? '\017' : \
                    428:        (c)=='P' ? '\020' : \
                    429:        (c)=='Q' ? '\021' : \
                    430:        (c)=='R' ? '\022' : \
                    431:        (c)=='S' ? '\023' : \
                    432:        (c)=='T' ? '\074' : \
                    433:        (c)=='U' ? '\075' : \
                    434:        (c)=='V' ? '\062' : \
                    435:        (c)=='W' ? '\046' : \
                    436:        (c)=='X' ? '\030' : \
                    437:        (c)=='Y' ? '\031' : \
                    438:        (c)=='Z' ? '\077' : \
                    439:        (c)=='|' ? '\031' : \
                    440:        (c)=='\\' ? '\034' : \
                    441:        (c)=='^' ? '\036' : \
                    442:        (c)&077)
                    443: #else
1.1       etheisen  444: #define        CONTROL(c)      ((c)&037)
1.1.1.2   millert   445: #endif /* IS_EBCDIC_HOST */
                    446:
1.1       etheisen  447: #define        ESC             CONTROL('[')
1.1.1.3   shadchin  448: #define        CSI             ((unsigned char)'\233')
1.1       etheisen  449:
1.1.1.2   millert   450: #if _OSK_MWC32
                    451: #define        LSIGNAL(sig,func)       os9_signal(sig,func)
                    452: #else
1.1.1.4 ! shadchin  453: #define        LSIGNAL(sig,func)       lsignal(sig,func)
1.1.1.2   millert   454: #endif
                    455:
                    456: #if HAVE_SIGPROCMASK
                    457: #if HAVE_SIGSET_T
                    458: #else
                    459: #undef HAVE_SIGPROCMASK
                    460: #endif
                    461: #endif
                    462: #if HAVE_SIGPROCMASK
                    463: #if HAVE_SIGEMPTYSET
                    464: #else
                    465: #undef  sigemptyset
                    466: #define sigemptyset(mp) *(mp) = 0
                    467: #endif
                    468: #endif
1.1       etheisen  469:
                    470: #define        S_INTERRUPT     01
                    471: #define        S_STOP          02
                    472: #define S_WINCH                04
                    473: #define        ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
                    474:
                    475: #define        QUIT_OK         0
                    476: #define        QUIT_ERROR      1
1.1.1.3   shadchin  477: #define        QUIT_INTERRUPT  2
1.1       etheisen  478: #define        QUIT_SAVED_STATUS (-1)
                    479:
1.1.1.3   shadchin  480: #define FOLLOW_DESC     0
                    481: #define FOLLOW_NAME     1
                    482:
1.1       etheisen  483: /* filestate flags */
                    484: #define        CH_CANSEEK      001
                    485: #define        CH_KEEPOPEN     002
                    486: #define        CH_POPENED      004
1.1.1.2   millert   487: #define        CH_HELPFILE     010
1.1.1.4 ! shadchin  488: #define        CH_NODATA       020     /* Special case for zero length files */
        !           489:
1.1       etheisen  490:
                    491: #define        ch_zero()       ((POSITION)0)
                    492:
1.1.1.2   millert   493: #define        FAKE_HELPFILE   "@/\\less/\\help/\\file/\\@"
1.1.1.4 ! shadchin  494: #define FAKE_EMPTYFILE "@/\\less/\\empty/\\file/\\@"
1.1.1.3   shadchin  495:
                    496: /* Flags for cvt_text */
                    497: #define        CVT_TO_LC       01      /* Convert upper-case to lower-case */
                    498: #define        CVT_BS          02      /* Do backspace processing */
                    499: #define        CVT_CRLF        04      /* Remove CR after LF */
                    500: #define        CVT_ANSI        010     /* Remove ANSI escape sequences */
1.1.1.2   millert   501:
1.1       etheisen  502: #include "funcs.h"
1.1.1.2   millert   503:
                    504: /* Functions not included in funcs.h */
                    505: void postoa();
                    506: void linenumtoa();
                    507: void inttoa();