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