Add our READMEs.
[dragonfly/vkernel-mp.git] / contrib / less-403 / less.h
blobbf8b803649afde02755e621e98f15c1823dcb4dd
1 /*
2 * Copyright (C) 1984-2007 Mark Nudelman
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.
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
9 */
11 #define NEWBOT 1
14 * Standard include file for "less".
18 * Defines for MSDOS_COMPILER.
20 #define MSOFTC 1 /* Microsoft C */
21 #define BORLANDC 2 /* Borland C */
22 #define WIN32C 3 /* Windows (Borland C or Microsoft C) */
23 #define DJGPPC 4 /* DJGPP C */
26 * Include the file of compile-time options.
27 * The <> make cc search for it in -I., not srcdir.
29 #include <defines.h>
31 #ifdef _SEQUENT_
33 * Kludge for Sequent Dynix systems that have sigsetmask, but
34 * it's not compatible with the way less calls it.
35 * {{ Do other systems need this? }}
37 #undef HAVE_SIGSETMASK
38 #endif
41 * Language details.
43 #if HAVE_VOID
44 #define VOID_POINTER void *
45 #else
46 #define VOID_POINTER char *
47 #define void int
48 #endif
49 #if HAVE_CONST
50 #define constant const
51 #else
52 #define constant
53 #endif
55 #define public /* PUBLIC FUNCTION */
57 /* Library function declarations */
59 #if HAVE_SYS_TYPES_H
60 #include <sys/types.h>
61 #endif
62 #if HAVE_STDIO_H
63 #include <stdio.h>
64 #endif
65 #if HAVE_FCNTL_H
66 #include <fcntl.h>
67 #endif
68 #if HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
71 #if HAVE_CTYPE_H
72 #include <ctype.h>
73 #endif
74 #if HAVE_LIMITS_H
75 #include <limits.h>
76 #endif
77 #if HAVE_STDLIB_H
78 #include <stdlib.h>
79 #endif
80 #if HAVE_STRING_H
81 #include <string.h>
82 #endif
84 /* OS-specific includes */
85 #ifdef _OSK
86 #include <modes.h>
87 #include <strings.h>
88 #endif
90 #ifdef __TANDEM
91 #include <floss.h>
92 #endif
94 #if MSDOS_COMPILER==WIN32C || OS2
95 #include <io.h>
96 #endif
98 #if MSDOS_COMPILER==DJGPPC
99 #include <io.h>
100 #include <sys/exceptn.h>
101 #include <conio.h>
102 #include <pc.h>
103 #endif
105 #if !HAVE_STDLIB_H
106 char *getenv();
107 off_t lseek();
108 VOID_POINTER calloc();
109 void free();
110 #endif
113 * Simple lowercase test which can be used during option processing
114 * (before options are parsed which might tell us what charset to use).
116 #define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
117 #define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
118 #define ASCII_TO_UPPER(c) ((c) - 'a' + 'A')
119 #define ASCII_TO_LOWER(c) ((c) - 'A' + 'a')
121 #undef IS_UPPER
122 #undef IS_LOWER
123 #undef TO_UPPER
124 #undef TO_LOWER
125 #undef IS_SPACE
126 #undef IS_DIGIT
128 #if !HAVE_UPPER_LOWER
129 #define IS_UPPER(c) ASCII_IS_UPPER(c)
130 #define IS_LOWER(c) ASCII_IS_LOWER(c)
131 #define TO_UPPER(c) ASCII_TO_UPPER(c)
132 #define TO_LOWER(c) ASCII_TO_LOWER(c)
133 #else
134 #define IS_UPPER(c) isupper((unsigned char) (c))
135 #define IS_LOWER(c) islower((unsigned char) (c))
136 #define TO_UPPER(c) toupper((unsigned char) (c))
137 #define TO_LOWER(c) tolower((unsigned char) (c))
138 #endif
140 #ifdef isspace
141 #define IS_SPACE(c) isspace((unsigned char)(c))
142 #else
143 #define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
144 #endif
146 #ifdef isdigit
147 #define IS_DIGIT(c) isdigit((unsigned char)(c))
148 #else
149 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
150 #endif
152 #ifndef NULL
153 #define NULL 0
154 #endif
156 #ifndef TRUE
157 #define TRUE 1
158 #endif
159 #ifndef FALSE
160 #define FALSE 0
161 #endif
163 #define OPT_OFF 0
164 #define OPT_ON 1
165 #define OPT_ONPLUS 2
167 #if !HAVE_MEMCPY
168 #ifndef memcpy
169 #define memcpy(to,from,len) bcopy((from),(to),(len))
170 #endif
171 #endif
173 #if HAVE_SNPRINTF
174 #define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1))
175 #define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2))
176 #define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3))
177 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
178 #else
179 /* Use unsafe sprintf if we don't have snprintf. */
180 #define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1))
181 #define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2))
182 #define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3))
183 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
184 #endif
186 #define BAD_LSEEK ((off_t)-1)
188 #ifndef CHAR_BIT
189 #define CHAR_BIT 8
190 #endif
193 * Upper bound on the string length of an integer converted to string.
194 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
195 * add 1 for integer division truncation; add 1 more for a minus sign.
197 #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
200 * Special types and constants.
202 typedef unsigned long LWCHAR;
203 typedef off_t POSITION;
204 typedef off_t LINENUM;
205 #define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */
206 #define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */
208 #define NULL_POSITION ((POSITION)(-1))
211 * Flags for open()
213 #if MSDOS_COMPILER || OS2
214 #define OPEN_READ (O_RDONLY|O_BINARY)
215 #else
216 #ifdef _OSK
217 #define OPEN_READ (S_IREAD)
218 #else
219 #ifdef O_RDONLY
220 #define OPEN_READ (O_RDONLY)
221 #else
222 #define OPEN_READ (0)
223 #endif
224 #endif
225 #endif
227 #if defined(O_WRONLY) && defined(O_APPEND)
228 #define OPEN_APPEND (O_APPEND|O_WRONLY)
229 #else
230 #ifdef _OSK
231 #define OPEN_APPEND (S_IWRITE)
232 #else
233 #define OPEN_APPEND (1)
234 #endif
235 #endif
238 * Set a file descriptor to binary mode.
240 #if MSDOS_COMPILER==MSOFTC
241 #define SET_BINARY(f) _setmode(f, _O_BINARY);
242 #else
243 #if MSDOS_COMPILER || OS2
244 #define SET_BINARY(f) setmode(f, O_BINARY)
245 #else
246 #define SET_BINARY(f)
247 #endif
248 #endif
251 * Does the shell treat "?" as a metacharacter?
253 #if MSDOS_COMPILER || OS2 || _OSK
254 #define SHELL_META_QUEST 0
255 #else
256 #define SHELL_META_QUEST 1
257 #endif
259 #define SPACES_IN_FILENAMES 1
262 * An IFILE represents an input file.
264 #define IFILE VOID_POINTER
265 #define NULL_IFILE ((IFILE)NULL)
268 * The structure used to represent a "screen position".
269 * This consists of a file position, and a screen line number.
270 * The meaning is that the line starting at the given file
271 * position is displayed on the ln-th line of the screen.
272 * (Screen lines before ln are empty.)
274 struct scrpos
276 POSITION pos;
277 int ln;
280 typedef union parg
282 char *p_string;
283 int p_int;
284 LINENUM p_linenum;
285 } PARG;
287 #define NULL_PARG ((PARG *)NULL)
289 struct textlist
291 char *string;
292 char *endstring;
295 #define EOI (-1)
297 #define READ_INTR (-2)
299 /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
300 #define NUM_FRAC_DENOM 1000000
301 #define NUM_LOG_FRAC_DENOM 6
303 /* How quiet should we be? */
304 #define NOT_QUIET 0 /* Ring bell at eof and for errors */
305 #define LITTLE_QUIET 1 /* Ring bell only for errors */
306 #define VERY_QUIET 2 /* Never ring bell */
308 /* How should we prompt? */
309 #define PR_SHORT 0 /* Prompt with colon */
310 #define PR_MEDIUM 1 /* Prompt with message */
311 #define PR_LONG 2 /* Prompt with longer message */
313 /* How should we handle backspaces? */
314 #define BS_SPECIAL 0 /* Do special things for underlining and bold */
315 #define BS_NORMAL 1 /* \b treated as normal char; actually output */
316 #define BS_CONTROL 2 /* \b treated as control char; prints as ^H */
318 /* How should we search? */
319 #define SRCH_FORW (1 << 0) /* Search forward from current position */
320 #define SRCH_BACK (1 << 1) /* Search backward from current position */
321 #define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */
322 #define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */
323 #define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */
324 #define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */
325 #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
326 #define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */
328 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
329 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
330 (((t) & ~SRCH_BACK) | SRCH_FORW))
332 /* */
333 #define NO_MCA 0
334 #define MCA_DONE 1
335 #define MCA_MORE 2
337 #define CC_OK 0 /* Char was accepted & processed */
338 #define CC_QUIT 1 /* Char was a request to abort current cmd */
339 #define CC_ERROR 2 /* Char could not be accepted due to error */
340 #define CC_PASS 3 /* Char was rejected (internal) */
342 #define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */
344 /* Special char bit-flags used to tell put_line() to do something special */
345 #define AT_NORMAL (0)
346 #define AT_UNDERLINE (1 << 0)
347 #define AT_BOLD (1 << 1)
348 #define AT_BLINK (1 << 2)
349 #define AT_STANDOUT (1 << 3)
350 #define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */
351 #define AT_BINARY (1 << 5) /* LESS*BINFMT representation */
352 #define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */
354 #if '0' == 240
355 #define IS_EBCDIC_HOST 1
356 #endif
358 #if IS_EBCDIC_HOST
360 * Long definition for EBCDIC.
361 * Since the argument is usually a constant, this macro normally compiles
362 * into a constant.
364 #define CONTROL(c) ( \
365 (c)=='[' ? '\047' : \
366 (c)=='a' ? '\001' : \
367 (c)=='b' ? '\002' : \
368 (c)=='c' ? '\003' : \
369 (c)=='d' ? '\067' : \
370 (c)=='e' ? '\055' : \
371 (c)=='f' ? '\056' : \
372 (c)=='g' ? '\057' : \
373 (c)=='h' ? '\026' : \
374 (c)=='i' ? '\005' : \
375 (c)=='j' ? '\025' : \
376 (c)=='k' ? '\013' : \
377 (c)=='l' ? '\014' : \
378 (c)=='m' ? '\015' : \
379 (c)=='n' ? '\016' : \
380 (c)=='o' ? '\017' : \
381 (c)=='p' ? '\020' : \
382 (c)=='q' ? '\021' : \
383 (c)=='r' ? '\022' : \
384 (c)=='s' ? '\023' : \
385 (c)=='t' ? '\074' : \
386 (c)=='u' ? '\075' : \
387 (c)=='v' ? '\062' : \
388 (c)=='w' ? '\046' : \
389 (c)=='x' ? '\030' : \
390 (c)=='y' ? '\031' : \
391 (c)=='z' ? '\077' : \
392 (c)=='A' ? '\001' : \
393 (c)=='B' ? '\002' : \
394 (c)=='C' ? '\003' : \
395 (c)=='D' ? '\067' : \
396 (c)=='E' ? '\055' : \
397 (c)=='F' ? '\056' : \
398 (c)=='G' ? '\057' : \
399 (c)=='H' ? '\026' : \
400 (c)=='I' ? '\005' : \
401 (c)=='J' ? '\025' : \
402 (c)=='K' ? '\013' : \
403 (c)=='L' ? '\014' : \
404 (c)=='M' ? '\015' : \
405 (c)=='N' ? '\016' : \
406 (c)=='O' ? '\017' : \
407 (c)=='P' ? '\020' : \
408 (c)=='Q' ? '\021' : \
409 (c)=='R' ? '\022' : \
410 (c)=='S' ? '\023' : \
411 (c)=='T' ? '\074' : \
412 (c)=='U' ? '\075' : \
413 (c)=='V' ? '\062' : \
414 (c)=='W' ? '\046' : \
415 (c)=='X' ? '\030' : \
416 (c)=='Y' ? '\031' : \
417 (c)=='Z' ? '\077' : \
418 (c)=='|' ? '\031' : \
419 (c)=='\\' ? '\034' : \
420 (c)=='^' ? '\036' : \
421 (c)&077)
422 #else
423 #define CONTROL(c) ((c)&037)
424 #endif /* IS_EBCDIC_HOST */
426 #define ESC CONTROL('[')
428 #if _OSK_MWC32
429 #define LSIGNAL(sig,func) os9_signal(sig,func)
430 #else
431 #define LSIGNAL(sig,func) signal(sig,func)
432 #endif
434 #if HAVE_SIGPROCMASK
435 #if HAVE_SIGSET_T
436 #else
437 #undef HAVE_SIGPROCMASK
438 #endif
439 #endif
440 #if HAVE_SIGPROCMASK
441 #if HAVE_SIGEMPTYSET
442 #else
443 #undef sigemptyset
444 #define sigemptyset(mp) *(mp) = 0
445 #endif
446 #endif
448 #define S_INTERRUPT 01
449 #define S_STOP 02
450 #define S_WINCH 04
451 #define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP))
453 #define QUIT_OK 0
454 #define QUIT_ERROR 1
455 #define QUIT_SAVED_STATUS (-1)
457 /* filestate flags */
458 #define CH_CANSEEK 001
459 #define CH_KEEPOPEN 002
460 #define CH_POPENED 004
461 #define CH_HELPFILE 010
463 #define ch_zero() ((POSITION)0)
465 #define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@"
467 #include "funcs.h"
469 /* Functions not included in funcs.h */
470 void postoa();
471 void linenumtoa();
472 void inttoa();