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