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