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