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