1 /* 2 * Copyright (C) 1984-2026 Mark Nudelman 3 * 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. 6 * 7 * For more information, see the README file. 8 */ 9 10 /* 11 * Standard include file for "less". 12 */ 13 14 /* 15 * Defines for MSDOS_COMPILER. 16 */ 17 #define MSOFTC 1 /* Microsoft C */ 18 #define BORLANDC 2 /* Borland C */ 19 #define WIN32C 3 /* Windows (Borland C or Microsoft C) */ 20 #define DJGPPC 4 /* DJGPP C */ 21 22 /* 23 * Include the file of compile-time options. 24 * The <> make cc search for it in -I., not srcdir. 25 */ 26 #include <defines.h> 27 28 #ifdef _SEQUENT_ 29 /* 30 * Kludge for Sequent Dynix systems that have sigsetmask, but 31 * it's not compatible with the way less calls it. 32 * {{ Do other systems need this? }} 33 */ 34 #undef HAVE_SIGSETMASK 35 #endif 36 37 38 /* Library function declarations */ 39 40 #if HAVE_SYS_TYPES_H 41 #include <sys/types.h> 42 #endif 43 #if HAVE_STDIO_H 44 #include <stdio.h> 45 #endif 46 #if HAVE_FCNTL_H 47 #include <fcntl.h> 48 #endif 49 #if HAVE_UNISTD_H 50 #include <unistd.h> 51 #endif 52 #if HAVE_CTYPE_H 53 #include <ctype.h> 54 #endif 55 #if HAVE_LIMITS_H 56 #include <limits.h> 57 #endif 58 #if HAVE_STDINT_H 59 #include <stdint.h> 60 #endif 61 #if HAVE_STDLIB_H 62 #include <stdlib.h> 63 #endif 64 #if HAVE_STRING_H 65 #include <string.h> 66 #endif 67 68 #if HAVE_STDCKDINT_H 69 #include <stdckdint.h> 70 #else 71 /* 72 * These substitutes for C23 stdckdint macros do not set *R on overflow, 73 * and they assume A and B are nonnegative. That is good enough for us. 74 */ 75 #define ckd_add(r, a, b) help_ckd_add(r, (uintmax)(a), (uintmax)(b), sizeof *(r), signed_expr(*(r))) 76 #define ckd_mul(r, a, b) help_ckd_mul(r, (uintmax)(a), (uintmax)(b), sizeof *(r), signed_expr(*(r))) 77 /* True if the integer expression E, after promotion, is signed. */ 78 #define signed_expr(e) ((TRUE ? 0 : e) - 1 < 0) 79 #endif 80 #define muldiv(val,num,den) umuldiv((uintmax)(val), (uintmax)(num), (uintmax)(den)) 81 82 #include "lang.h" 83 #include "lmsg.h" 84 85 #if defined UINTMAX_MAX 86 typedef uintmax_t uintmax; 87 #elif defined ULLONG_MAX 88 typedef unsigned long long uintmax; 89 #else 90 typedef unsigned long uintmax; 91 #endif 92 93 /* OS-specific includes */ 94 #ifdef _OSK 95 #include <modes.h> 96 #include <strings.h> 97 #endif 98 99 #ifdef __TANDEM 100 #include <floss.h> 101 #endif 102 103 #if MSDOS_COMPILER==WIN32C || OS2 104 #include <io.h> 105 #endif 106 107 #if MSDOS_COMPILER==DJGPPC 108 #include <io.h> 109 #include <sys/exceptn.h> 110 #include <conio.h> 111 #include <pc.h> 112 #endif 113 114 #if !HAVE_STDLIB_H 115 char *getenv(); 116 off_t lseek(); 117 void *calloc(); 118 void free(); 119 #endif 120 121 /* 122 * Simple lowercase test which can be used during option processing 123 * (before options are parsed which might tell us what charset to use). 124 */ 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') 129 130 #undef IS_UPPER 131 #undef IS_LOWER 132 #undef TO_UPPER 133 #undef TO_LOWER 134 #undef IS_SPACE 135 #undef IS_DIGIT 136 137 #if HAVE_WCTYPE 138 #define IS_UPPER(c) iswupper((wint_t) (c)) 139 #define IS_LOWER(c) iswlower((wint_t) (c)) 140 #define TO_UPPER(c) towupper((wint_t) (c)) 141 #define TO_LOWER(c) towlower((wint_t) (c)) 142 #else 143 #if HAVE_UPPER_LOWER 144 #define IS_UPPER(c) (is_ascii_char(c) && isupper((unsigned char) (c))) 145 #define IS_LOWER(c) (is_ascii_char(c) && islower((unsigned char) (c))) 146 #define TO_UPPER(c) (is_ascii_char(c) ? (LWCHAR) toupper((unsigned char) (c)) : (LWCHAR) (c)) 147 #define TO_LOWER(c) (is_ascii_char(c) ? (LWCHAR) tolower((unsigned char) (c)) : (LWCHAR) (c)) 148 #else 149 #define IS_UPPER(c) (is_ascii_char(c) && ASCII_IS_UPPER(c)) 150 #define IS_LOWER(c) (is_ascii_char(c) && ASCII_IS_LOWER(c)) 151 #define TO_UPPER(c) (is_ascii_char(c) ? (LWCHAR) ASCII_TO_UPPER(c) : (LWCHAR) (c)) 152 #define TO_LOWER(c) (is_ascii_char(c) ? (LWCHAR) ASCII_TO_LOWER(c) : (LWCHAR) (c)) 153 #endif 154 #endif 155 156 #ifdef isspace 157 #define IS_SPACE(c) isspace((unsigned char)(c)) 158 #else 159 #define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f') 160 #endif 161 162 #ifdef isdigit 163 #define IS_DIGIT(c) isdigit((unsigned char)(c)) 164 #else 165 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') 166 #endif 167 168 #define IS_CSI_START(c) (control_char(c) && (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI))) 169 170 #define OPT_OFF 0 171 #define OPT_ON 1 172 #define OPT_ONPLUS 2 173 174 #if !HAVE_MEMCPY 175 #ifndef memcpy 176 #define memcpy(to,from,len) bcopy((from),(to),(len)) 177 #endif 178 #endif 179 180 #if HAVE_SNPRINTF 181 #define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1)) 182 #define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2)) 183 #define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3)) 184 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4)) 185 #else 186 /* Use unsafe sprintf if we don't have snprintf. */ 187 #define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1)) 188 #define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2)) 189 #define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3)) 190 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4)) 191 #endif 192 193 #define BAD_LSEEK ((off_t)-1) 194 195 #ifndef SEEK_SET 196 #define SEEK_SET 0 197 #endif 198 #ifndef SEEK_END 199 #define SEEK_END 2 200 #endif 201 202 #ifndef CHAR_BIT 203 #define CHAR_BIT 8 204 #endif 205 206 /* 207 * Upper bound on the string length of an integer converted to string. 208 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit; 209 * add 1 for integer division truncation; add 1 more for a minus sign. 210 */ 211 #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1) 212 213 /* 214 * Special types and constants. 215 */ 216 typedef unsigned long LWCHAR; 217 #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER >= 1500) 218 typedef long long less_off_t; /* __int64 */ 219 typedef struct _stat64 less_stat_t; 220 #define less_fstat _fstat64 221 #define less_stat _stat64 222 #define less_lseek _lseeki64 223 #else 224 typedef off_t less_off_t; 225 typedef struct stat less_stat_t; 226 #define less_fstat fstat 227 #define less_stat stat 228 #define less_lseek lseek 229 #endif 230 typedef less_off_t POSITION; 231 typedef off_t LINENUM; 232 #define MIN_LINENUM_WIDTH 7 /* Default min printing width of a line number */ 233 #define MAX_LINENUM_WIDTH 16 /* Max width of a line number */ 234 #define MAX_STATUSCOL_WIDTH 4 /* Max width of the status column */ 235 #define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */ 236 #define MAX_PRCHAR_LEN 31 /* Max chars in prchar() result */ 237 238 #define NULL_POSITION ((POSITION)(-1)) 239 240 /* 241 * Flags for open() 242 */ 243 #if MSDOS_COMPILER || OS2 244 #define OPEN_READ (O_RDONLY|O_BINARY) 245 #else 246 #ifdef _OSK 247 #define OPEN_READ (S_IREAD) 248 #else 249 #ifdef O_RDONLY 250 #define OPEN_READ (O_RDONLY) 251 #else 252 #define OPEN_READ (0) 253 #endif 254 #endif 255 #endif 256 257 #if defined(O_WRONLY) && defined(O_APPEND) 258 #define OPEN_APPEND (O_APPEND|O_WRONLY) 259 #else 260 #ifdef _OSK 261 #define OPEN_APPEND (S_IWRITE) 262 #else 263 #define OPEN_APPEND (1) 264 #endif 265 #endif 266 267 /* Use iread() to read tty? */ 268 #if !MSDOS_COMPILER || MSDOS_COMPILER == DJGPPC 269 #define LESS_IREAD_TTY 1 270 #endif 271 272 /* 273 * Flags for creat() 274 */ 275 #if MSDOS_COMPILER 276 #define CREAT_RW (S_IREAD|S_IWRITE) 277 #else 278 #define CREAT_RW 0644 279 #endif 280 281 /* 282 * Set a file descriptor to binary mode. 283 */ 284 #if MSDOS_COMPILER==MSOFTC 285 #define SET_BINARY(f) _setmode(f, _O_BINARY); 286 #else 287 #if MSDOS_COMPILER || OS2 288 #define SET_BINARY(f) setmode(f, O_BINARY) 289 #else 290 #define SET_BINARY(f) 291 #endif 292 #endif 293 294 #define SPACES_IN_FILENAMES 1 295 296 /* 297 * An IFILE represents an input file. 298 */ 299 #define IFILE void* 300 #define NULL_IFILE ((IFILE)NULL) 301 302 /* 303 * The structure used to represent a "screen position". 304 * This consists of a file position, and a screen line number. 305 * The meaning is that the line starting at the given file 306 * position is displayed on the ln-th line of the screen. 307 * (Screen lines before ln are empty.) 308 */ 309 struct scrpos 310 { 311 POSITION pos; 312 int ln; 313 }; 314 315 typedef union parg 316 { 317 constant char *p_string; 318 int p_int; 319 LINENUM p_linenum; 320 char p_char; 321 } PARG; 322 323 #define NULL_PARG ((PARG *)NULL) 324 325 struct textlist 326 { 327 char *string; 328 char *endstring; 329 }; 330 331 struct wchar_range 332 { 333 LWCHAR first, last; 334 }; 335 336 struct wchar_range_table 337 { 338 struct wchar_range *table; 339 unsigned int count; 340 }; 341 342 struct csl_bitmap_def 343 { 344 constant char *bit_name; 345 int bit_value; 346 }; 347 348 #if HAVE_POLL 349 typedef short POLL_EVENTS; 350 #endif 351 352 #define EOI (-1) 353 354 #define READ_ERR (-1) 355 #define READ_INTR (-2) 356 #define READ_AGAIN (-3) 357 358 /* 359 * A fraction is represented by a long n; the fraction is n/NUM_FRAC_DENOM. 360 * To avoid overflow problems, 0 <= n < NUM_FRAC_DENUM <= LONG_MAX/100. 361 */ 362 #define NUM_FRAC_DENOM 1000000 363 #define NUM_LOG_FRAC_DENOM 6 364 365 /* 366 * Max expected reasonable duration of a paste. 367 * Increasing this value avoids accidentally reenabling unwanted paste input 368 * in the middle of a very long paste but risks apparently frozen UI if the 369 * end bracket is missing. 370 */ 371 #define MAX_PASTE_IGNORE_SEC 5 372 373 /* How quiet should we be? */ 374 #define NOT_QUIET 0 /* Ring bell at eof and for errors */ 375 #define LITTLE_QUIET 1 /* Ring bell only for errors */ 376 #define VERY_QUIET 2 /* Never ring bell */ 377 378 /* How should we prompt? */ 379 #define PR_SHORT 0 /* Prompt with colon */ 380 #define PR_MEDIUM 1 /* Prompt with message */ 381 #define PR_LONG 2 /* Prompt with longer message */ 382 383 /* How should we handle backspaces? */ 384 #define BS_SPECIAL 0 /* Do special things for underlining and bold */ 385 #define BS_NORMAL 1 /* \b treated as normal char; actually output */ 386 #define BS_CONTROL 2 /* \b treated as control char; prints as ^H */ 387 388 /* How should we search? */ 389 #define SRCH_FORW (1 << 0) /* Search forward from current position */ 390 #define SRCH_BACK (1 << 1) /* Search backward from current position */ 391 #define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */ 392 #define SRCH_INCR (1 << 3) /* Incremental search */ 393 #define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */ 394 #define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */ 395 #define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */ 396 #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */ 397 #define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */ 398 #define SRCH_FILTER (1 << 13) /* Search is for '&' (filter) command */ 399 #define SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */ 400 #define SRCH_WRAP (1 << 15) /* Wrap-around search (continue at BOF/EOF) */ 401 #if OSC8_LINK 402 #define SRCH_OSC8 (1 << 16) /* */ 403 #endif 404 #define SRCH_SUBSEARCH(i) (1 << (17+(i))) /* Search for subpattern */ 405 /* {{ Depends on NUM_SEARCH_COLORS==5 }} */ 406 #define SRCH_SUBSEARCH_ALL (SRCH_SUBSEARCH(1)|SRCH_SUBSEARCH(2)|SRCH_SUBSEARCH(3)|SRCH_SUBSEARCH(4)|SRCH_SUBSEARCH(5)) 407 408 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \ 409 (((t) & ~SRCH_FORW) | SRCH_BACK) : \ 410 (((t) & ~SRCH_BACK) | SRCH_FORW)) 411 /* Parsing position in an OSC8 link: "\e]8;PARAMS;URI\e\\" (final "\e\\" may be "\7") */ 412 typedef enum osc8_state { 413 OSC_START, /* Waiting for initial \e */ 414 OSC_INTRO, /* Waiting for intro char, usually ']' */ 415 OSC_TYPENUM, /* Reading OS command type */ 416 OSC_STRING, /* Reading OS command string */ 417 OSC_STRING_CSI, /* Waiting for backslash after the final ESC. */ 418 OSC_END, /* At end */ 419 420 OSC8_PARAMS, /* In the OSC8 parameters */ 421 OSC8_URI, /* In the OSC8 URI */ 422 OSC8_URI_CSI, /* Waiting for backslash after the final ESC. */ 423 OSC8_NOT, /* This is not an OSC8 link */ 424 } osc8_state; 425 426 /* */ 427 #define NO_MCA 0 428 #define MCA_DONE 1 429 #define MCA_MORE 2 430 431 #define CC_OK 0 /* Char was accepted & processed */ 432 #define CC_QUIT 1 /* Char was a request to abort current cmd */ 433 #define CC_ERROR 2 /* Char could not be accepted due to error */ 434 #define CC_PASS 3 /* Char was rejected (internal) */ 435 436 #define CF_QUIT_ON_ERASE (1<<0) /* Abort cmd if its entirely erased */ 437 #define CF_OPTION (1<<1) /* A_OPT_TOGGLE */ 438 439 /* Special char bit-flags used to tell put_line() to do something special */ 440 #define AT_NORMAL (0) 441 #define AT_UNDERLINE (1 << 0) 442 #define AT_BOLD (1 << 1) 443 #define AT_BLINK (1 << 2) 444 #define AT_STANDOUT (1 << 3) 445 #define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */ 446 #define AT_BINARY (1 << 5) /* LESS*BINFMT representation */ 447 #define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */ 448 #define AT_PLACEHOLDER (1 << 7) /* Placeholder for half of double-wide char */ 449 450 #define AT_COLOR_SHIFT 8 451 #define AT_COLOR ((~(unsigned)0) << AT_COLOR_SHIFT) 452 #define AT_COLOR_ATTN (1 << AT_COLOR_SHIFT) 453 #define AT_COLOR_BIN (2 << AT_COLOR_SHIFT) 454 #define AT_COLOR_CTRL (3 << AT_COLOR_SHIFT) 455 #define AT_COLOR_ERROR (4 << AT_COLOR_SHIFT) 456 #define AT_COLOR_LINENUM (5 << AT_COLOR_SHIFT) 457 #define AT_COLOR_MARK (6 << AT_COLOR_SHIFT) 458 #define AT_COLOR_PROMPT (7 << AT_COLOR_SHIFT) 459 #define AT_COLOR_RSCROLL (8 << AT_COLOR_SHIFT) 460 #define AT_COLOR_HEADER (9 << AT_COLOR_SHIFT) 461 #define AT_COLOR_SEARCH (10 << AT_COLOR_SHIFT) 462 #define AT_COLOR_TILDE (11 << AT_COLOR_SHIFT) 463 #define AT_COLOR_TARGET (12 << AT_COLOR_SHIFT) 464 #define AT_COLOR_OSC8 (13 << AT_COLOR_SHIFT) 465 #define AT_COLOR_SS_OFFSET 14 /* largest AT_COLOR_* value + 1 */ 466 #define NUM_SEARCH_COLORS 5 467 #define AT_NUM_COLORS (AT_COLOR_SS_OFFSET + NUM_SEARCH_COLORS) 468 #define AT_COLOR_SUBSEARCH(i) ((AT_COLOR_SS_OFFSET+(i)-1) << AT_COLOR_SHIFT) 469 470 typedef enum { CT_NULL, CT_4BIT, CT_6BIT } COLOR_TYPE; 471 472 typedef enum { 473 CV_BLUE = 1, 474 CV_GREEN = 2, 475 CV_RED = 4, 476 CV_BRIGHT = 8, 477 CV_NOCHANGE = -2, 478 CV_ERROR = -1 479 } COLOR_VALUE; 480 481 typedef enum { 482 CATTR_NULL = 0, 483 CATTR_STANDOUT = (1 << 0), 484 CATTR_BOLD = (1 << 1), 485 CATTR_UNDERLINE = (1 << 2), 486 CATTR_BLINK = (1 << 3), 487 } CHAR_ATTR; 488 489 /* ANSI states */ 490 typedef enum { 491 ANSI_NULL, 492 ANSI_MID, 493 ANSI_ERR, 494 ANSI_END, 495 } ansi_state; 496 497 #if '0' == 240 498 #define IS_EBCDIC_HOST 1 499 #endif 500 501 #if IS_EBCDIC_HOST 502 /* 503 * Long definition for EBCDIC. 504 * Since the argument is usually a constant, this macro normally compiles 505 * into a constant. 506 */ 507 #define CONTROL(c) ( \ 508 (c)=='[' ? '\047' : \ 509 (c)=='a' ? '\001' : \ 510 (c)=='b' ? '\002' : \ 511 (c)=='c' ? '\003' : \ 512 (c)=='d' ? '\067' : \ 513 (c)=='e' ? '\055' : \ 514 (c)=='f' ? '\056' : \ 515 (c)=='g' ? '\057' : \ 516 (c)=='h' ? '\026' : \ 517 (c)=='i' ? '\005' : \ 518 (c)=='j' ? '\025' : \ 519 (c)=='k' ? '\013' : \ 520 (c)=='l' ? '\014' : \ 521 (c)=='m' ? '\015' : \ 522 (c)=='n' ? '\016' : \ 523 (c)=='o' ? '\017' : \ 524 (c)=='p' ? '\020' : \ 525 (c)=='q' ? '\021' : \ 526 (c)=='r' ? '\022' : \ 527 (c)=='s' ? '\023' : \ 528 (c)=='t' ? '\074' : \ 529 (c)=='u' ? '\075' : \ 530 (c)=='v' ? '\062' : \ 531 (c)=='w' ? '\046' : \ 532 (c)=='x' ? '\030' : \ 533 (c)=='y' ? '\031' : \ 534 (c)=='z' ? '\077' : \ 535 (c)=='A' ? '\001' : \ 536 (c)=='B' ? '\002' : \ 537 (c)=='C' ? '\003' : \ 538 (c)=='D' ? '\067' : \ 539 (c)=='E' ? '\055' : \ 540 (c)=='F' ? '\056' : \ 541 (c)=='G' ? '\057' : \ 542 (c)=='H' ? '\026' : \ 543 (c)=='I' ? '\005' : \ 544 (c)=='J' ? '\025' : \ 545 (c)=='K' ? '\013' : \ 546 (c)=='L' ? '\014' : \ 547 (c)=='M' ? '\015' : \ 548 (c)=='N' ? '\016' : \ 549 (c)=='O' ? '\017' : \ 550 (c)=='P' ? '\020' : \ 551 (c)=='Q' ? '\021' : \ 552 (c)=='R' ? '\022' : \ 553 (c)=='S' ? '\023' : \ 554 (c)=='T' ? '\074' : \ 555 (c)=='U' ? '\075' : \ 556 (c)=='V' ? '\062' : \ 557 (c)=='W' ? '\046' : \ 558 (c)=='X' ? '\030' : \ 559 (c)=='Y' ? '\031' : \ 560 (c)=='Z' ? '\077' : \ 561 (c)=='|' ? '\031' : \ 562 (c)=='\\' ? '\034' : \ 563 (c)=='^' ? '\036' : \ 564 (c)&077) 565 #else 566 #define CONTROL(c) ((c)&037) 567 #endif /* IS_EBCDIC_HOST */ 568 569 #define ESC CONTROL('[') 570 #define ESCS "\33" 571 #define CSI ((unsigned char)'\233') 572 #define VARSEL_15 ((LWCHAR)0xFE0E) /* VARIATION SELECTOR 15 */ 573 #define VARSEL_16 ((LWCHAR)0xFE0F) /* VARIATION SELECTOR 16 */ 574 575 #if _OSK_MWC32 576 #define LSIGNAL(sig,func) os9_signal(sig,func) 577 #else 578 #define LSIGNAL(sig,func) signal(sig,func) 579 #endif 580 581 #if HAVE_SIGPROCMASK 582 #if HAVE_SIGSET_T 583 #else 584 #undef HAVE_SIGPROCMASK 585 #endif 586 #endif 587 #if HAVE_SIGPROCMASK 588 #if HAVE_SIGEMPTYSET 589 #else 590 #undef sigemptyset 591 #define sigemptyset(mp) *(mp) = 0 592 #endif 593 #endif 594 595 #define S_INTERRUPT (1<<0) 596 #define S_SWINTERRUPT (1<<1) 597 #define S_STOP (1<<2) 598 #define S_WINCH (1<<3) 599 #define ABORT_SIGS() (sigs & (S_INTERRUPT|S_SWINTERRUPT|S_STOP)) 600 601 #ifdef EXIT_SUCCESS 602 #define QUIT_OK EXIT_SUCCESS 603 #else 604 #define QUIT_OK 0 605 #endif 606 #ifdef EXIT_FAILURE 607 #define QUIT_ERROR EXIT_FAILURE 608 #define QUIT_INTERRUPT (EXIT_FAILURE+1) 609 #else 610 #define QUIT_ERROR 1 611 #define QUIT_INTERRUPT 2 612 #endif 613 #define QUIT_SAVED_STATUS (-1) 614 615 #define FOLLOW_DESC 0 616 #define FOLLOW_NAME 1 617 618 /* filestate flags */ 619 #define CH_CANSEEK 001 620 #define CH_KEEPOPEN 002 621 #define CH_POPENED 004 622 #define CH_HELPFILE 010 623 #define CH_NODATA 020 /* Special case for zero length files */ 624 #define CH_NOTRUSTSIZE 040 /* For files that claim 0 length size falsely */ 625 626 #define ch_zero() ((POSITION)0) 627 628 #define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@" 629 #define FAKE_EMPTYFILE "@/\\less/\\empty/\\file/\\@" 630 631 /* Flags for cvt_text */ 632 #define CVT_TO_LC 01 /* Convert upper-case to lower-case */ 633 #define CVT_BS 02 /* Do backspace processing */ 634 #define CVT_CRLF 04 /* Remove CR after LF */ 635 #define CVT_ANSI 010 /* Remove ANSI escape sequences */ 636 637 #if HAVE_TIME_T 638 #define time_type time_t 639 #else 640 #define time_type long 641 #endif 642 643 /* X11 mouse reporting definitions */ 644 #define X11MOUSE_BUTTON1 0 /* Left button press */ 645 #define X11MOUSE_BUTTON2 1 /* Middle button press */ 646 #define X11MOUSE_BUTTON3 2 /* Right button press */ 647 #define X11MOUSE_BUTTON_REL 3 /* Button release */ 648 #define X11MOUSE_DRAG 0x20 /* Drag with button down */ 649 #define X11MOUSE_WHEEL_UP 0x40 /* Wheel scroll up */ 650 #define X11MOUSE_WHEEL_DOWN 0x41 /* Wheel scroll down */ 651 #define X11MOUSE_WHEEL_LEFT 0x42 /* Wheel scroll left */ 652 #define X11MOUSE_WHEEL_RIGHT 0x43 /* Wheel scroll right */ 653 #define X11MOUSE_OFFSET 0x20 /* Added to button & pos bytes to create a char */ 654 655 /* Mouse features */ 656 #define EMOUSE_HSCROLL (1<<0) /* Horizontal scroll */ 657 #define EMOUSE_VSCROLL (1<<1) /* Vertical scroll */ 658 #define EMOUSE_HDRAG (1<<2) /* Horizontal drag */ 659 #define EMOUSE_VDRAG (1<<3) /* Vertical drag */ 660 #define EMOUSE_LCLICK (1<<4) /* Left click */ 661 #define EMOUSE_RCLICK (1<<5) /* Right click */ 662 #define EMOUSE_COUNT 6 663 664 /* Security features. */ 665 #define SF_EDIT (1<<1) /* Edit file (v) */ 666 #define SF_EXAMINE (1<<2) /* Examine file (:e) */ 667 #define SF_GLOB (1<<3) /* Expand file pattern */ 668 #define SF_HISTORY (1<<4) /* History file */ 669 #define SF_LESSKEY (1<<5) /* Lesskey files */ 670 #define SF_LESSOPEN (1<<6) /* LESSOPEN */ 671 #define SF_LOGFILE (1<<7) /* Log file (s, -o) */ 672 #define SF_PIPE (1<<8) /* Pipe (|) */ 673 #define SF_SHELL (1<<9) /* Shell command (!) */ 674 #define SF_STOP (1<<10) /* Stop signal */ 675 #define SF_TAGS (1<<11) /* Tags */ 676 #define SF_OSC8_OPEN (1<<12) /* OSC8 open */ 677 678 #if LESSTEST 679 #define LESS_DUMP_CHAR CONTROL(']') 680 #endif 681 682 struct mlist; 683 struct loption; 684 struct hilite_tree; 685 struct ansi_state; 686 struct lesskey_tables; 687 #include "pattern.h" 688 #include "xbuf.h" 689 #include "funcs.h" 690 691 /* Functions not included in funcs.h */ 692 void postoa(POSITION, char*, int); 693 void linenumtoa(LINENUM, char*, int); 694 void inttoa(int, char*, int); 695 int lstrtoi(char*, char**, int); 696 POSITION lstrtopos(char*, char**, int); 697 unsigned long lstrtoul(char*, char**, int); 698 int lstrtoic(constant char*, constant char**, int); 699 POSITION lstrtoposc(constant char*, constant char**, int); 700 unsigned long lstrtoulc(constant char*, constant char**, int); 701 #if MSDOS_COMPILER==WIN32C 702 int pclose(FILE*); 703 #endif 704 #if !HAVE_STRCHR 705 char * strchr(char *s, char c); 706 #endif 707 #if !HAVE_MEMCPY 708 void * memcpy(void *dst, constant void *src, size_t len); 709 #endif 710 #if !HAVE_STRSTR 711 char * strstr(constant char *haystack, constant char *needle); 712 #endif 713