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