2 * Copyright (C) 1984-2022 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, see the README file.
13 * Standard include file for "less".
17 * Defines for MSDOS_COMPILER.
19 #define MSOFTC 1 /* Microsoft C */
20 #define BORLANDC 2 /* Borland C */
21 #define WIN32C 3 /* Windows (Borland C or Microsoft C) */
22 #define DJGPPC 4 /* DJGPP C */
25 * Include the file of compile-time options.
26 * The <> make cc search for it in -I., not srcdir.
32 * Kludge for Sequent Dynix systems that have sigsetmask, but
33 * it's not compatible with the way less calls it.
34 * {{ Do other systems need this? }}
36 #undef HAVE_SIGSETMASK
43 #define LESSPARAMS(a) a
45 #define LESSPARAMS(a) ()
48 #define VOID_POINTER void *
49 #define VOID_PARAM void
51 #define VOID_POINTER char *
56 #define constant const
61 #define public /* PUBLIC FUNCTION */
63 /* Library function declarations */
66 #include <sys/types.h>
93 /* OS-specific includes */
103 #if MSDOS_COMPILER==WIN32C || OS2
107 #if MSDOS_COMPILER==DJGPPC
109 #include <sys/exceptn.h>
117 VOID_POINTER
calloc();
122 * Simple lowercase test which can be used during option processing
123 * (before options are parsed which might tell us what charset to use).
125 #define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
126 #define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
127 #define ASCII_TO_UPPER(c) ((c) - 'a' + 'A')
128 #define ASCII_TO_LOWER(c) ((c) - 'A' + 'a')
138 #define IS_UPPER(c) iswupper(c)
139 #define IS_LOWER(c) iswlower(c)
140 #define TO_UPPER(c) towupper(c)
141 #define TO_LOWER(c) towlower(c)
144 #define IS_UPPER(c) isupper((unsigned char) (c))
145 #define IS_LOWER(c) islower((unsigned char) (c))
146 #define TO_UPPER(c) toupper((unsigned char) (c))
147 #define TO_LOWER(c) tolower((unsigned char) (c))
149 #define IS_UPPER(c) ASCII_IS_UPPER(c)
150 #define IS_LOWER(c) ASCII_IS_LOWER(c)
151 #define TO_UPPER(c) ASCII_TO_UPPER(c)
152 #define TO_LOWER(c) ASCII_TO_LOWER(c)
157 #define IS_SPACE(c) isspace((unsigned char)(c))
159 #define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
163 #define IS_DIGIT(c) isdigit((unsigned char)(c))
165 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
168 #define IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI))
187 #define memcpy(to,from,len) bcopy((from),(to),(len))
192 #define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1))
193 #define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2))
194 #define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3))
195 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
197 /* Use unsafe sprintf if we don't have snprintf. */
198 #define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1))
199 #define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2))
200 #define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3))
201 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
204 #define BAD_LSEEK ((off_t)-1)
218 * Upper bound on the string length of an integer converted to string.
219 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
220 * add 1 for integer division truncation; add 1 more for a minus sign.
222 #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
225 * Special types and constants.
227 typedef unsigned long LWCHAR
;
228 typedef off_t POSITION
;
229 typedef off_t LINENUM
;
230 #define MIN_LINENUM_WIDTH 7 /* Default min printing width of a line number */
231 #define MAX_LINENUM_WIDTH 16 /* Max width of a line number */
232 #define MAX_STATUSCOL_WIDTH 4 /* Max width of the status column */
233 #define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */
234 #define MAX_PRCHAR_LEN 31 /* Max chars in prchar() result */
236 #define NULL_POSITION ((POSITION)(-1))
241 #if MSDOS_COMPILER || OS2
242 #define OPEN_READ (O_RDONLY|O_BINARY)
245 #define OPEN_READ (S_IREAD)
248 #define OPEN_READ (O_RDONLY)
250 #define OPEN_READ (0)
255 #if defined(O_WRONLY) && defined(O_APPEND)
256 #define OPEN_APPEND (O_APPEND|O_WRONLY)
259 #define OPEN_APPEND (S_IWRITE)
261 #define OPEN_APPEND (1)
266 * Set a file descriptor to binary mode.
268 #if MSDOS_COMPILER==MSOFTC
269 #define SET_BINARY(f) _setmode(f, _O_BINARY);
271 #if MSDOS_COMPILER || OS2
272 #define SET_BINARY(f) setmode(f, O_BINARY)
274 #define SET_BINARY(f)
279 * Does the shell treat "?" as a metacharacter?
281 #if MSDOS_COMPILER || OS2 || _OSK
282 #define SHELL_META_QUEST 0
284 #define SHELL_META_QUEST 1
287 #define SPACES_IN_FILENAMES 1
290 * An IFILE represents an input file.
292 #define IFILE VOID_POINTER
293 #define NULL_IFILE ((IFILE)NULL)
296 * The structure used to represent a "screen position".
297 * This consists of a file position, and a screen line number.
298 * The meaning is that the line starting at the given file
299 * position is displayed on the ln-th line of the screen.
300 * (Screen lines before ln are empty.)
316 #define NULL_PARG ((PARG *)NULL)
329 struct wchar_range_table
331 struct wchar_range
*table
;
337 #define READ_INTR (-2)
339 /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
340 #define NUM_FRAC_DENOM 1000000
341 #define NUM_LOG_FRAC_DENOM 6
343 /* How quiet should we be? */
344 #define NOT_QUIET 0 /* Ring bell at eof and for errors */
345 #define LITTLE_QUIET 1 /* Ring bell only for errors */
346 #define VERY_QUIET 2 /* Never ring bell */
348 /* How should we prompt? */
349 #define PR_SHORT 0 /* Prompt with colon */
350 #define PR_MEDIUM 1 /* Prompt with message */
351 #define PR_LONG 2 /* Prompt with longer message */
353 /* How should we handle backspaces? */
354 #define BS_SPECIAL 0 /* Do special things for underlining and bold */
355 #define BS_NORMAL 1 /* \b treated as normal char; actually output */
356 #define BS_CONTROL 2 /* \b treated as control char; prints as ^H */
358 /* How should we search? */
359 #define SRCH_FORW (1 << 0) /* Search forward from current position */
360 #define SRCH_BACK (1 << 1) /* Search backward from current position */
361 #define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */
362 #define SRCH_INCR (1 << 3) /* Incremental search */
363 #define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */
364 #define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */
365 #define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */
366 #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
367 #define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */
368 #define SRCH_FILTER (1 << 13) /* Search is for '&' (filter) command */
369 #define SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
370 #define SRCH_WRAP (1 << 15) /* Wrap-around search (continue at BOF/EOF) */
372 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
373 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
374 (((t) & ~SRCH_BACK) | SRCH_FORW))
381 #define CC_OK 0 /* Char was accepted & processed */
382 #define CC_QUIT 1 /* Char was a request to abort current cmd */
383 #define CC_ERROR 2 /* Char could not be accepted due to error */
384 #define CC_PASS 3 /* Char was rejected (internal) */
386 #define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */
388 /* Special char bit-flags used to tell put_line() to do something special */
389 #define AT_NORMAL (0)
390 #define AT_UNDERLINE (1 << 0)
391 #define AT_BOLD (1 << 1)
392 #define AT_BLINK (1 << 2)
393 #define AT_STANDOUT (1 << 3)
394 #define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */
395 #define AT_BINARY (1 << 5) /* LESS*BINFMT representation */
396 #define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */
398 #define AT_COLOR_SHIFT 8
399 #define AT_NUM_COLORS 16
400 #define AT_COLOR ((AT_NUM_COLORS-1) << AT_COLOR_SHIFT)
401 #define AT_COLOR_ATTN (1 << AT_COLOR_SHIFT)
402 #define AT_COLOR_BIN (2 << AT_COLOR_SHIFT)
403 #define AT_COLOR_CTRL (3 << AT_COLOR_SHIFT)
404 #define AT_COLOR_ERROR (4 << AT_COLOR_SHIFT)
405 #define AT_COLOR_LINENUM (5 << AT_COLOR_SHIFT)
406 #define AT_COLOR_MARK (6 << AT_COLOR_SHIFT)
407 #define AT_COLOR_PROMPT (7 << AT_COLOR_SHIFT)
408 #define AT_COLOR_RSCROLL (8 << AT_COLOR_SHIFT)
409 #define AT_COLOR_SEARCH (9 << AT_COLOR_SHIFT)
410 #define AT_COLOR_HEADER (11 << AT_COLOR_SHIFT)
412 typedef enum { CT_NULL
, CT_4BIT
, CT_6BIT
} COLOR_TYPE
;
429 #define IS_EBCDIC_HOST 1
434 * Long definition for EBCDIC.
435 * Since the argument is usually a constant, this macro normally compiles
438 #define CONTROL(c) ( \
439 (c)=='[' ? '\047' : \
440 (c)=='a' ? '\001' : \
441 (c)=='b' ? '\002' : \
442 (c)=='c' ? '\003' : \
443 (c)=='d' ? '\067' : \
444 (c)=='e' ? '\055' : \
445 (c)=='f' ? '\056' : \
446 (c)=='g' ? '\057' : \
447 (c)=='h' ? '\026' : \
448 (c)=='i' ? '\005' : \
449 (c)=='j' ? '\025' : \
450 (c)=='k' ? '\013' : \
451 (c)=='l' ? '\014' : \
452 (c)=='m' ? '\015' : \
453 (c)=='n' ? '\016' : \
454 (c)=='o' ? '\017' : \
455 (c)=='p' ? '\020' : \
456 (c)=='q' ? '\021' : \
457 (c)=='r' ? '\022' : \
458 (c)=='s' ? '\023' : \
459 (c)=='t' ? '\074' : \
460 (c)=='u' ? '\075' : \
461 (c)=='v' ? '\062' : \
462 (c)=='w' ? '\046' : \
463 (c)=='x' ? '\030' : \
464 (c)=='y' ? '\031' : \
465 (c)=='z' ? '\077' : \
466 (c)=='A' ? '\001' : \
467 (c)=='B' ? '\002' : \
468 (c)=='C' ? '\003' : \
469 (c)=='D' ? '\067' : \
470 (c)=='E' ? '\055' : \
471 (c)=='F' ? '\056' : \
472 (c)=='G' ? '\057' : \
473 (c)=='H' ? '\026' : \
474 (c)=='I' ? '\005' : \
475 (c)=='J' ? '\025' : \
476 (c)=='K' ? '\013' : \
477 (c)=='L' ? '\014' : \
478 (c)=='M' ? '\015' : \
479 (c)=='N' ? '\016' : \
480 (c)=='O' ? '\017' : \
481 (c)=='P' ? '\020' : \
482 (c)=='Q' ? '\021' : \
483 (c)=='R' ? '\022' : \
484 (c)=='S' ? '\023' : \
485 (c)=='T' ? '\074' : \
486 (c)=='U' ? '\075' : \
487 (c)=='V' ? '\062' : \
488 (c)=='W' ? '\046' : \
489 (c)=='X' ? '\030' : \
490 (c)=='Y' ? '\031' : \
491 (c)=='Z' ? '\077' : \
492 (c)=='|' ? '\031' : \
493 (c)=='\\' ? '\034' : \
494 (c)=='^' ? '\036' : \
497 #define CONTROL(c) ((c)&037)
498 #endif /* IS_EBCDIC_HOST */
500 #define ESC CONTROL('[')
502 #define CSI ((unsigned char)'\233')
503 #define CHAR_END_COMMAND 0x40000000
506 #define LSIGNAL(sig,func) os9_signal(sig,func)
508 #define LSIGNAL(sig,func) signal(sig,func)
514 #undef HAVE_SIGPROCMASK
521 #define sigemptyset(mp) *(mp) = 0
525 #define S_INTERRUPT 01
528 #define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP))
532 #define QUIT_INTERRUPT 2
533 #define QUIT_SAVED_STATUS (-1)
535 #define FOLLOW_DESC 0
536 #define FOLLOW_NAME 1
538 /* filestate flags */
539 #define CH_CANSEEK 001
540 #define CH_KEEPOPEN 002
541 #define CH_POPENED 004
542 #define CH_HELPFILE 010
543 #define CH_NODATA 020 /* Special case for zero length files */
545 #define ch_zero() ((POSITION)0)
547 #define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@"
548 #define FAKE_EMPTYFILE "@/\\less/\\empty/\\file/\\@"
550 /* Flags for cvt_text */
551 #define CVT_TO_LC 01 /* Convert upper-case to lower-case */
552 #define CVT_BS 02 /* Do backspace processing */
553 #define CVT_CRLF 04 /* Remove CR after LF */
554 #define CVT_ANSI 010 /* Remove ANSI escape sequences */
557 #define time_type time_t
559 #define time_type long
562 /* X11 mouse reporting definitions */
563 #define X11MOUSE_BUTTON1 0 /* Left button press */
564 #define X11MOUSE_BUTTON2 1 /* Middle button press */
565 #define X11MOUSE_BUTTON3 2 /* Right button press */
566 #define X11MOUSE_BUTTON_REL 3 /* Button release */
567 #define X11MOUSE_WHEEL_UP 0x40 /* Wheel scroll up */
568 #define X11MOUSE_WHEEL_DOWN 0x41 /* Wheel scroll down */
569 #define X11MOUSE_OFFSET 0x20 /* Added to button & pos bytes to create a char */
579 /* Functions not included in funcs.h */
580 void postoa
LESSPARAMS ((POSITION
, char*));
581 void linenumtoa
LESSPARAMS ((LINENUM
, char*));
582 void inttoa
LESSPARAMS ((int, char*));
583 int lstrtoi
LESSPARAMS ((char*, char**));
584 POSITION lstrtopos
LESSPARAMS ((char*, char**));
585 #if MSDOS_COMPILER==WIN32C
586 int pclose
LESSPARAMS ((FILE*));