4 * 5 * You may distribute under the terms of either the GNU General Public 6 * License or the Less License, as specified in the README file. 7 * 8 * For more information about less, or for information on how to 9 * contact the author, see the README file. 10 */ 11 12#define NEWBOT 1 13 14/* 15 * Standard include file for "less". 16 */ 17 18/* 19 * Defines for MSDOS_COMPILER. 20 */ 21#define MSOFTC 1 /* Microsoft C */ 22#define BORLANDC 2 /* Borland C */ 23#define WIN32C 3 /* Windows (Borland C or Microsoft C) */ 24#define DJGPPC 4 /* DJGPP C */ 25 26/* 27 * Include the file of compile-time options. 28 * The <> make cc search for it in -I., not srcdir. 29 */ 30#include <defines.h> 31 32#ifdef _SEQUENT_ 33/* 34 * Kludge for Sequent Dynix systems that have sigsetmask, but 35 * it's not compatible with the way less calls it. 36 * {{ Do other systems need this? }} 37 */ 38#undef HAVE_SIGSETMASK 39#endif 40 41/* 42 * Language details. 43 */ 44#if HAVE_VOID 45#define VOID_POINTER void * 46#else 47#define VOID_POINTER char * 48#define void int 49#endif 50#if HAVE_CONST 51#define constant const 52#else 53#define constant 54#endif 55 56#define public /* PUBLIC FUNCTION */ 57 58/* Library function declarations */ 59 60#if HAVE_SYS_TYPES_H 61#include <sys/types.h> 62#endif 63#if HAVE_STDIO_H 64#include <stdio.h> 65#endif 66#if HAVE_FCNTL_H 67#include <fcntl.h> 68#endif 69#if HAVE_UNISTD_H 70#include <unistd.h> 71#endif 72#if HAVE_CTYPE_H 73#include <ctype.h> 74#endif 75#if HAVE_WCTYPE_H 76#include <wctype.h> 77#endif 78#if HAVE_LIMITS_H 79#include <limits.h> 80#endif 81#if HAVE_STDLIB_H 82#include <stdlib.h> 83#endif 84#if HAVE_STRING_H 85#include <string.h> 86#endif 87 88/* OS-specific includes */ 89#ifdef _OSK 90#include <modes.h> 91#include <strings.h> 92#endif 93 94#ifdef __TANDEM 95#include <floss.h> 96#endif 97 98#if MSDOS_COMPILER==WIN32C || OS2 99#include <io.h> 100#endif 101 102#if MSDOS_COMPILER==DJGPPC 103#include <io.h> 104#include <sys/exceptn.h> 105#include <conio.h> 106#include <pc.h> 107#endif 108 109#if !HAVE_STDLIB_H 110char *getenv(); 111off_t lseek(); 112VOID_POINTER calloc(); 113void free(); 114#endif 115 116/* 117 * Simple lowercase test which can be used during option processing 118 * (before options are parsed which might tell us what charset to use). 119 */ 120#define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') 121#define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') 122#define ASCII_TO_UPPER(c) ((c) - 'a' + 'A') 123#define ASCII_TO_LOWER(c) ((c) - 'A' + 'a') 124 125#undef IS_UPPER 126#undef IS_LOWER 127#undef TO_UPPER 128#undef TO_LOWER 129#undef IS_SPACE 130#undef IS_DIGIT 131 132#if HAVE_WCTYPE 133#define IS_UPPER(c) iswupper(c) 134#define IS_LOWER(c) iswlower(c) 135#define TO_UPPER(c) towupper(c) 136#define TO_LOWER(c) towlower(c) 137#else 138#if HAVE_UPPER_LOWER 139#define IS_UPPER(c) isupper((unsigned char) (c)) 140#define IS_LOWER(c) islower((unsigned char) (c)) 141#define TO_UPPER(c) toupper((unsigned char) (c)) 142#define TO_LOWER(c) tolower((unsigned char) (c)) 143#else 144#define IS_UPPER(c) ASCII_IS_UPPER(c) 145#define IS_LOWER(c) ASCII_IS_LOWER(c) 146#define TO_UPPER(c) ASCII_TO_UPPER(c) 147#define TO_LOWER(c) ASCII_TO_LOWER(c) 148#endif 149#endif 150 151#ifdef isspace 152#define IS_SPACE(c) isspace((unsigned char)(c)) 153#else 154#define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f') 155#endif 156 157#ifdef isdigit 158#define IS_DIGIT(c) isdigit((unsigned char)(c)) 159#else 160#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') 161#endif 162 163#define IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI)) 164 165#ifndef NULL 166#define NULL 0 167#endif 168 169#ifndef TRUE 170#define TRUE 1 171#endif 172#ifndef FALSE 173#define FALSE 0 174#endif 175 176#define OPT_OFF 0 177#define OPT_ON 1 178#define OPT_ONPLUS 2 179 180#if !HAVE_MEMCPY 181#ifndef memcpy 182#define memcpy(to,from,len) bcopy((from),(to),(len)) 183#endif 184#endif 185 186#if HAVE_SNPRINTF 187#define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1)) 188#define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2)) 189#define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3)) 190#define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4)) 191#else 192/* Use unsafe sprintf if we don't have snprintf. */ 193#define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1)) 194#define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2)) 195#define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3)) 196#define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4)) 197#endif 198 199#define BAD_LSEEK ((off_t)-1) 200 201#ifndef SEEK_SET 202#define SEEK_SET 0 203#endif 204#ifndef SEEK_END 205#define SEEK_END 2 206#endif 207 208#ifndef CHAR_BIT 209#define CHAR_BIT 8 210#endif 211 212/* 213 * Upper bound on the string length of an integer converted to string. 214 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit; 215 * add 1 for integer division truncation; add 1 more for a minus sign. 216 */ 217#define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1) 218 219/* 220 * Special types and constants. 221 */ 222typedef unsigned long LWCHAR; 223typedef off_t POSITION; 224typedef off_t LINENUM; 225#define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */ 226#define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */ 227 228#define NULL_POSITION ((POSITION)(-1)) 229 230/* 231 * Flags for open() 232 */ 233#if MSDOS_COMPILER || OS2 234#define OPEN_READ (O_RDONLY|O_BINARY) 235#else 236#ifdef _OSK 237#define OPEN_READ (S_IREAD) 238#else 239#ifdef O_RDONLY 240#define OPEN_READ (O_RDONLY) 241#else 242#define OPEN_READ (0) 243#endif 244#endif 245#endif 246 247#if defined(O_WRONLY) && defined(O_APPEND) 248#define OPEN_APPEND (O_APPEND|O_WRONLY) 249#else 250#ifdef _OSK 251#define OPEN_APPEND (S_IWRITE) 252#else 253#define OPEN_APPEND (1) 254#endif 255#endif 256 257/* 258 * Set a file descriptor to binary mode. 259 */ 260#if MSDOS_COMPILER==MSOFTC 261#define SET_BINARY(f) _setmode(f, _O_BINARY); 262#else 263#if MSDOS_COMPILER || OS2 264#define SET_BINARY(f) setmode(f, O_BINARY) 265#else 266#define SET_BINARY(f) 267#endif 268#endif 269 270/* 271 * Does the shell treat "?" as a metacharacter? 272 */ 273#if MSDOS_COMPILER || OS2 || _OSK 274#define SHELL_META_QUEST 0 275#else 276#define SHELL_META_QUEST 1 277#endif 278 279#define SPACES_IN_FILENAMES 1 280 281/* 282 * An IFILE represents an input file. 283 */ 284#define IFILE VOID_POINTER 285#define NULL_IFILE ((IFILE)NULL) 286 287/* 288 * The structure used to represent a "screen position". 289 * This consists of a file position, and a screen line number. 290 * The meaning is that the line starting at the given file 291 * position is displayed on the ln-th line of the screen. 292 * (Screen lines before ln are empty.) 293 */ 294struct scrpos 295{ 296 POSITION pos; 297 int ln; 298}; 299 300typedef union parg 301{ 302 char *p_string; 303 int p_int; 304 LINENUM p_linenum; 305} PARG; 306 307#define NULL_PARG ((PARG *)NULL) 308 309struct textlist 310{ 311 char *string; 312 char *endstring; 313}; 314 315#define EOI (-1) 316 317#define READ_INTR (-2) 318 319/* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */ 320#define NUM_FRAC_DENOM 1000000 321#define NUM_LOG_FRAC_DENOM 6 322 323/* How quiet should we be? */ 324#define NOT_QUIET 0 /* Ring bell at eof and for errors */ 325#define LITTLE_QUIET 1 /* Ring bell only for errors */ 326#define VERY_QUIET 2 /* Never ring bell */ 327 328/* How should we prompt? */ 329#define PR_SHORT 0 /* Prompt with colon */ 330#define PR_MEDIUM 1 /* Prompt with message */ 331#define PR_LONG 2 /* Prompt with longer message */ 332 333/* How should we handle backspaces? */ 334#define BS_SPECIAL 0 /* Do special things for underlining and bold */ 335#define BS_NORMAL 1 /* \b treated as normal char; actually output */ 336#define BS_CONTROL 2 /* \b treated as control char; prints as ^H */ 337 338/* How should we search? */ 339#define SRCH_FORW (1 << 0) /* Search forward from current position */ 340#define SRCH_BACK (1 << 1) /* Search backward from current position */ 341#define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */ 342#define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */ 343#define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */ 344#define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */ 345#define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */ 346#define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */ 347#define SRCH_FILTER (1 << 13) /* Search is for '&' (filter) command */
| 4 * 5 * You may distribute under the terms of either the GNU General Public 6 * License or the Less License, as specified in the README file. 7 * 8 * For more information about less, or for information on how to 9 * contact the author, see the README file. 10 */ 11 12#define NEWBOT 1 13 14/* 15 * Standard include file for "less". 16 */ 17 18/* 19 * Defines for MSDOS_COMPILER. 20 */ 21#define MSOFTC 1 /* Microsoft C */ 22#define BORLANDC 2 /* Borland C */ 23#define WIN32C 3 /* Windows (Borland C or Microsoft C) */ 24#define DJGPPC 4 /* DJGPP C */ 25 26/* 27 * Include the file of compile-time options. 28 * The <> make cc search for it in -I., not srcdir. 29 */ 30#include <defines.h> 31 32#ifdef _SEQUENT_ 33/* 34 * Kludge for Sequent Dynix systems that have sigsetmask, but 35 * it's not compatible with the way less calls it. 36 * {{ Do other systems need this? }} 37 */ 38#undef HAVE_SIGSETMASK 39#endif 40 41/* 42 * Language details. 43 */ 44#if HAVE_VOID 45#define VOID_POINTER void * 46#else 47#define VOID_POINTER char * 48#define void int 49#endif 50#if HAVE_CONST 51#define constant const 52#else 53#define constant 54#endif 55 56#define public /* PUBLIC FUNCTION */ 57 58/* Library function declarations */ 59 60#if HAVE_SYS_TYPES_H 61#include <sys/types.h> 62#endif 63#if HAVE_STDIO_H 64#include <stdio.h> 65#endif 66#if HAVE_FCNTL_H 67#include <fcntl.h> 68#endif 69#if HAVE_UNISTD_H 70#include <unistd.h> 71#endif 72#if HAVE_CTYPE_H 73#include <ctype.h> 74#endif 75#if HAVE_WCTYPE_H 76#include <wctype.h> 77#endif 78#if HAVE_LIMITS_H 79#include <limits.h> 80#endif 81#if HAVE_STDLIB_H 82#include <stdlib.h> 83#endif 84#if HAVE_STRING_H 85#include <string.h> 86#endif 87 88/* OS-specific includes */ 89#ifdef _OSK 90#include <modes.h> 91#include <strings.h> 92#endif 93 94#ifdef __TANDEM 95#include <floss.h> 96#endif 97 98#if MSDOS_COMPILER==WIN32C || OS2 99#include <io.h> 100#endif 101 102#if MSDOS_COMPILER==DJGPPC 103#include <io.h> 104#include <sys/exceptn.h> 105#include <conio.h> 106#include <pc.h> 107#endif 108 109#if !HAVE_STDLIB_H 110char *getenv(); 111off_t lseek(); 112VOID_POINTER calloc(); 113void free(); 114#endif 115 116/* 117 * Simple lowercase test which can be used during option processing 118 * (before options are parsed which might tell us what charset to use). 119 */ 120#define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') 121#define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') 122#define ASCII_TO_UPPER(c) ((c) - 'a' + 'A') 123#define ASCII_TO_LOWER(c) ((c) - 'A' + 'a') 124 125#undef IS_UPPER 126#undef IS_LOWER 127#undef TO_UPPER 128#undef TO_LOWER 129#undef IS_SPACE 130#undef IS_DIGIT 131 132#if HAVE_WCTYPE 133#define IS_UPPER(c) iswupper(c) 134#define IS_LOWER(c) iswlower(c) 135#define TO_UPPER(c) towupper(c) 136#define TO_LOWER(c) towlower(c) 137#else 138#if HAVE_UPPER_LOWER 139#define IS_UPPER(c) isupper((unsigned char) (c)) 140#define IS_LOWER(c) islower((unsigned char) (c)) 141#define TO_UPPER(c) toupper((unsigned char) (c)) 142#define TO_LOWER(c) tolower((unsigned char) (c)) 143#else 144#define IS_UPPER(c) ASCII_IS_UPPER(c) 145#define IS_LOWER(c) ASCII_IS_LOWER(c) 146#define TO_UPPER(c) ASCII_TO_UPPER(c) 147#define TO_LOWER(c) ASCII_TO_LOWER(c) 148#endif 149#endif 150 151#ifdef isspace 152#define IS_SPACE(c) isspace((unsigned char)(c)) 153#else 154#define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f') 155#endif 156 157#ifdef isdigit 158#define IS_DIGIT(c) isdigit((unsigned char)(c)) 159#else 160#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') 161#endif 162 163#define IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI)) 164 165#ifndef NULL 166#define NULL 0 167#endif 168 169#ifndef TRUE 170#define TRUE 1 171#endif 172#ifndef FALSE 173#define FALSE 0 174#endif 175 176#define OPT_OFF 0 177#define OPT_ON 1 178#define OPT_ONPLUS 2 179 180#if !HAVE_MEMCPY 181#ifndef memcpy 182#define memcpy(to,from,len) bcopy((from),(to),(len)) 183#endif 184#endif 185 186#if HAVE_SNPRINTF 187#define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1)) 188#define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2)) 189#define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3)) 190#define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4)) 191#else 192/* Use unsafe sprintf if we don't have snprintf. */ 193#define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1)) 194#define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2)) 195#define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3)) 196#define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4)) 197#endif 198 199#define BAD_LSEEK ((off_t)-1) 200 201#ifndef SEEK_SET 202#define SEEK_SET 0 203#endif 204#ifndef SEEK_END 205#define SEEK_END 2 206#endif 207 208#ifndef CHAR_BIT 209#define CHAR_BIT 8 210#endif 211 212/* 213 * Upper bound on the string length of an integer converted to string. 214 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit; 215 * add 1 for integer division truncation; add 1 more for a minus sign. 216 */ 217#define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1) 218 219/* 220 * Special types and constants. 221 */ 222typedef unsigned long LWCHAR; 223typedef off_t POSITION; 224typedef off_t LINENUM; 225#define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */ 226#define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */ 227 228#define NULL_POSITION ((POSITION)(-1)) 229 230/* 231 * Flags for open() 232 */ 233#if MSDOS_COMPILER || OS2 234#define OPEN_READ (O_RDONLY|O_BINARY) 235#else 236#ifdef _OSK 237#define OPEN_READ (S_IREAD) 238#else 239#ifdef O_RDONLY 240#define OPEN_READ (O_RDONLY) 241#else 242#define OPEN_READ (0) 243#endif 244#endif 245#endif 246 247#if defined(O_WRONLY) && defined(O_APPEND) 248#define OPEN_APPEND (O_APPEND|O_WRONLY) 249#else 250#ifdef _OSK 251#define OPEN_APPEND (S_IWRITE) 252#else 253#define OPEN_APPEND (1) 254#endif 255#endif 256 257/* 258 * Set a file descriptor to binary mode. 259 */ 260#if MSDOS_COMPILER==MSOFTC 261#define SET_BINARY(f) _setmode(f, _O_BINARY); 262#else 263#if MSDOS_COMPILER || OS2 264#define SET_BINARY(f) setmode(f, O_BINARY) 265#else 266#define SET_BINARY(f) 267#endif 268#endif 269 270/* 271 * Does the shell treat "?" as a metacharacter? 272 */ 273#if MSDOS_COMPILER || OS2 || _OSK 274#define SHELL_META_QUEST 0 275#else 276#define SHELL_META_QUEST 1 277#endif 278 279#define SPACES_IN_FILENAMES 1 280 281/* 282 * An IFILE represents an input file. 283 */ 284#define IFILE VOID_POINTER 285#define NULL_IFILE ((IFILE)NULL) 286 287/* 288 * The structure used to represent a "screen position". 289 * This consists of a file position, and a screen line number. 290 * The meaning is that the line starting at the given file 291 * position is displayed on the ln-th line of the screen. 292 * (Screen lines before ln are empty.) 293 */ 294struct scrpos 295{ 296 POSITION pos; 297 int ln; 298}; 299 300typedef union parg 301{ 302 char *p_string; 303 int p_int; 304 LINENUM p_linenum; 305} PARG; 306 307#define NULL_PARG ((PARG *)NULL) 308 309struct textlist 310{ 311 char *string; 312 char *endstring; 313}; 314 315#define EOI (-1) 316 317#define READ_INTR (-2) 318 319/* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */ 320#define NUM_FRAC_DENOM 1000000 321#define NUM_LOG_FRAC_DENOM 6 322 323/* How quiet should we be? */ 324#define NOT_QUIET 0 /* Ring bell at eof and for errors */ 325#define LITTLE_QUIET 1 /* Ring bell only for errors */ 326#define VERY_QUIET 2 /* Never ring bell */ 327 328/* How should we prompt? */ 329#define PR_SHORT 0 /* Prompt with colon */ 330#define PR_MEDIUM 1 /* Prompt with message */ 331#define PR_LONG 2 /* Prompt with longer message */ 332 333/* How should we handle backspaces? */ 334#define BS_SPECIAL 0 /* Do special things for underlining and bold */ 335#define BS_NORMAL 1 /* \b treated as normal char; actually output */ 336#define BS_CONTROL 2 /* \b treated as control char; prints as ^H */ 337 338/* How should we search? */ 339#define SRCH_FORW (1 << 0) /* Search forward from current position */ 340#define SRCH_BACK (1 << 1) /* Search backward from current position */ 341#define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */ 342#define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */ 343#define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */ 344#define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */ 345#define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */ 346#define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */ 347#define SRCH_FILTER (1 << 13) /* Search is for '&' (filter) command */
|