1 /* $FreeBSD$ */ 2 /* 3 * Copyright (C) 1984-2000 Mark Nudelman 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 13 /* 14 * Standard include file for "less". 15 */ 16 17 /* 18 * Defines for MSDOS_COMPILER. 19 */ 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 */ 24 25 /* 26 * Include the file of compile-time options. 27 * The <> make cc search for it in -I., not srcdir. 28 */ 29 #include <defines.h> 30 31 #ifdef _SEQUENT_ 32 /* 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? }} 36 */ 37 #undef HAVE_SIGSETMASK 38 #endif 39 40 /* 41 * Language details. 42 */ 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 54 55 #define public /* PUBLIC FUNCTION */ 56 57 /* Library function declarations */ 58 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 83 #ifdef _OSK 84 #include <modes.h> 85 #include <strings.h> 86 #endif 87 #if MSDOS_COMPILER==WIN32C || OS2 88 #include <io.h> 89 #endif 90 #if MSDOS_COMPILER==DJGPPC 91 #include <io.h> 92 #include <sys/exceptn.h> 93 #include <conio.h> 94 #include <pc.h> 95 #endif 96 97 #if !HAVE_STDLIB_H 98 char *getenv(); 99 off_t lseek(); 100 VOID_POINTER calloc(); 101 void free(); 102 #endif 103 104 /* 105 * Simple lowercase test which can be used during option processing 106 * (before options are parsed which might tell us what charset to use). 107 */ 108 #define SIMPLE_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') 109 #define SIMPLE_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') 110 #define SIMPLE_TO_UPPER(c) ((c) - 'a' + 'A') 111 #define SIMPLE_TO_LOWER(c) ((c) - 'A' + 'a') 112 113 #if !HAVE_UPPER_LOWER 114 #define isupper(c) SIMPLE_IS_UPPER(c) 115 #define islower(c) SIMPLE_IS_LOWER(c) 116 #define toupper(c) SIMPLE_TO_UPPER(c) 117 #define tolower(c) SIMPLE_TO_LOWER(c) 118 #endif 119 120 #ifndef NULL 121 #define NULL 0 122 #endif 123 124 #ifndef TRUE 125 #define TRUE 1 126 #endif 127 #ifndef FALSE 128 #define FALSE 0 129 #endif 130 131 #define OPT_OFF 0 132 #define OPT_ON 1 133 #define OPT_ONPLUS 2 134 135 #if !HAVE_MEMCPY 136 #ifndef memcpy 137 #define memcpy(to,from,len) bcopy((from),(to),(len)) 138 #endif 139 #endif 140 141 #define BAD_LSEEK ((off_t)-1) 142 143 #ifndef CHAR_BIT 144 #define CHAR_BIT 8 145 #endif 146 147 /* 148 * Upper bound on the string length of an integer converted to string. 149 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit; 150 * add 1 for integer division truncation; add 1 more for a minus sign. 151 */ 152 #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1) 153 154 /* 155 * Special types and constants. 156 */ 157 typedef off_t POSITION; 158 159 #define NULL_POSITION ((POSITION)(-1)) 160 161 /* 162 * Flags for open() 163 */ 164 #if MSDOS_COMPILER || OS2 165 #define OPEN_READ (O_RDONLY|O_BINARY) 166 #else 167 #ifdef _OSK 168 #define OPEN_READ (S_IREAD) 169 #else 170 #ifdef O_RDONLY 171 #define OPEN_READ (O_RDONLY) 172 #else 173 #define OPEN_READ (0) 174 #endif 175 #endif 176 #endif 177 178 #if defined(O_WRONLY) && defined(O_APPEND) 179 #define OPEN_APPEND (O_APPEND|O_WRONLY) 180 #else 181 #ifdef _OSK 182 #define OPEN_APPEND (S_IWRITE) 183 #else 184 #define OPEN_APPEND (1) 185 #endif 186 #endif 187 188 /* 189 * Set a file descriptor to binary mode. 190 */ 191 #if MSDOS_COMPILER==MSOFTC 192 #define SET_BINARY(f) _setmode(f, _O_BINARY); 193 #else 194 #if MSDOS_COMPILER || OS2 195 #define SET_BINARY(f) setmode(f, O_BINARY) 196 #else 197 #define SET_BINARY(f) 198 #endif 199 #endif 200 201 /* 202 * Does the shell treat "?" as a metacharacter? 203 */ 204 #if MSDOS_COMPILER || OS2 || _OSK 205 #define SHELL_META_QUEST 0 206 #else 207 #define SHELL_META_QUEST 1 208 #endif 209 210 #define SPACES_IN_FILENAMES 1 211 212 /* 213 * An IFILE represents an input file. 214 */ 215 #define IFILE VOID_POINTER 216 #define NULL_IFILE ((IFILE)NULL) 217 218 /* 219 * The structure used to represent a "screen position". 220 * This consists of a file position, and a screen line number. 221 * The meaning is that the line starting at the given file 222 * position is displayed on the ln-th line of the screen. 223 * (Screen lines before ln are empty.) 224 */ 225 struct scrpos 226 { 227 POSITION pos; 228 int ln; 229 }; 230 231 typedef union parg 232 { 233 char *p_string; 234 int p_int; 235 } PARG; 236 237 #define NULL_PARG ((PARG *)NULL) 238 239 struct textlist 240 { 241 char *string; 242 char *endstring; 243 }; 244 245 #define EOI (-1) 246 247 #define READ_INTR (-2) 248 249 /* How quiet should we be? */ 250 #define NOT_QUIET 0 /* Ring bell at eof and for errors */ 251 #define LITTLE_QUIET 1 /* Ring bell only for errors */ 252 #define VERY_QUIET 2 /* Never ring bell */ 253 254 /* How should we prompt? */ 255 #define PR_SHORT 0 /* Prompt with colon */ 256 #define PR_MEDIUM 1 /* Prompt with message */ 257 #define PR_LONG 2 /* Prompt with longer message */ 258 259 /* How should we handle backspaces? */ 260 #define BS_SPECIAL 0 /* Do special things for underlining and bold */ 261 #define BS_NORMAL 1 /* \b treated as normal char; actually output */ 262 #define BS_CONTROL 2 /* \b treated as control char; prints as ^H */ 263 264 /* How should we search? */ 265 #define SRCH_FORW 000001 /* Search forward from current position */ 266 #define SRCH_BACK 000002 /* Search backward from current position */ 267 #define SRCH_NO_MOVE 000004 /* Highlight, but don't move */ 268 #define SRCH_FIND_ALL 000010 /* Find and highlight all matches */ 269 #define SRCH_NO_MATCH 000100 /* Search for non-matching lines */ 270 #define SRCH_PAST_EOF 000200 /* Search past end-of-file, into next file */ 271 #define SRCH_FIRST_FILE 000400 /* Search starting at the first file */ 272 #define SRCH_NO_REGEX 001000 /* Don't use regular expressions */ 273 274 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \ 275 (((t) & ~SRCH_FORW) | SRCH_BACK) : \ 276 (((t) & ~SRCH_BACK) | SRCH_FORW)) 277 278 /* */ 279 #define NO_MCA 0 280 #define MCA_DONE 1 281 #define MCA_MORE 2 282 283 #define CC_OK 0 /* Char was accepted & processed */ 284 #define CC_QUIT 1 /* Char was a request to abort current cmd */ 285 #define CC_ERROR 2 /* Char could not be accepted due to error */ 286 #define CC_PASS 3 /* Char was rejected (internal) */ 287 288 #define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */ 289 290 /* Special chars used to tell put_line() to do something special */ 291 #define AT_NORMAL (0) 292 #define AT_UNDERLINE (1) 293 #define AT_BOLD (2) 294 #define AT_BLINK (3) 295 #define AT_INVIS (4) 296 #define AT_STANDOUT (5) 297 298 #if '0' == 240 299 #define IS_EBCDIC_HOST 1 300 #endif 301 302 #if IS_EBCDIC_HOST 303 /* 304 * Long definition for EBCDIC. 305 * Since the argument is usually a constant, this macro normally compiles 306 * into a constant. 307 */ 308 #define CONTROL(c) ( \ 309 (c)=='[' ? '\047' : \ 310 (c)=='a' ? '\001' : \ 311 (c)=='b' ? '\002' : \ 312 (c)=='c' ? '\003' : \ 313 (c)=='d' ? '\067' : \ 314 (c)=='e' ? '\055' : \ 315 (c)=='f' ? '\056' : \ 316 (c)=='g' ? '\057' : \ 317 (c)=='h' ? '\026' : \ 318 (c)=='i' ? '\005' : \ 319 (c)=='j' ? '\025' : \ 320 (c)=='k' ? '\013' : \ 321 (c)=='l' ? '\014' : \ 322 (c)=='m' ? '\015' : \ 323 (c)=='n' ? '\016' : \ 324 (c)=='o' ? '\017' : \ 325 (c)=='p' ? '\020' : \ 326 (c)=='q' ? '\021' : \ 327 (c)=='r' ? '\022' : \ 328 (c)=='s' ? '\023' : \ 329 (c)=='t' ? '\074' : \ 330 (c)=='u' ? '\075' : \ 331 (c)=='v' ? '\062' : \ 332 (c)=='w' ? '\046' : \ 333 (c)=='x' ? '\030' : \ 334 (c)=='y' ? '\031' : \ 335 (c)=='z' ? '\077' : \ 336 (c)=='A' ? '\001' : \ 337 (c)=='B' ? '\002' : \ 338 (c)=='C' ? '\003' : \ 339 (c)=='D' ? '\067' : \ 340 (c)=='E' ? '\055' : \ 341 (c)=='F' ? '\056' : \ 342 (c)=='G' ? '\057' : \ 343 (c)=='H' ? '\026' : \ 344 (c)=='I' ? '\005' : \ 345 (c)=='J' ? '\025' : \ 346 (c)=='K' ? '\013' : \ 347 (c)=='L' ? '\014' : \ 348 (c)=='M' ? '\015' : \ 349 (c)=='N' ? '\016' : \ 350 (c)=='O' ? '\017' : \ 351 (c)=='P' ? '\020' : \ 352 (c)=='Q' ? '\021' : \ 353 (c)=='R' ? '\022' : \ 354 (c)=='S' ? '\023' : \ 355 (c)=='T' ? '\074' : \ 356 (c)=='U' ? '\075' : \ 357 (c)=='V' ? '\062' : \ 358 (c)=='W' ? '\046' : \ 359 (c)=='X' ? '\030' : \ 360 (c)=='Y' ? '\031' : \ 361 (c)=='Z' ? '\077' : \ 362 (c)=='|' ? '\031' : \ 363 (c)=='\\' ? '\034' : \ 364 (c)=='^' ? '\036' : \ 365 (c)&077) 366 #else 367 #define CONTROL(c) ((c)&037) 368 #endif /* IS_EBCDIC_HOST */ 369 370 #define ESC CONTROL('[') 371 372 #if _OSK_MWC32 373 #define LSIGNAL(sig,func) os9_signal(sig,func) 374 #else 375 #define LSIGNAL(sig,func) signal(sig,func) 376 #endif 377 378 #if HAVE_SIGPROCMASK 379 #if HAVE_SIGSET_T 380 #else 381 #undef HAVE_SIGPROCMASK 382 #endif 383 #endif 384 #if HAVE_SIGPROCMASK 385 #if HAVE_SIGEMPTYSET 386 #else 387 #undef sigemptyset 388 #define sigemptyset(mp) *(mp) = 0 389 #endif 390 #endif 391 392 #define S_INTERRUPT 01 393 #define S_STOP 02 394 #define S_WINCH 04 395 #define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP)) 396 397 #define QUIT_OK 0 398 #define QUIT_ERROR 1 399 #define QUIT_SAVED_STATUS (-1) 400 401 /* filestate flags */ 402 #define CH_CANSEEK 001 403 #define CH_KEEPOPEN 002 404 #define CH_POPENED 004 405 #define CH_HELPFILE 010 406 407 #define ch_zero() ((POSITION)0) 408 409 #define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@" 410 411 #include "funcs.h" 412 413