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