less.h revision 60786
160786Sps/* 260786Sps * Copyright (C) 1984-2000 Mark Nudelman 360786Sps * 460786Sps * You may distribute under the terms of either the GNU General Public 560786Sps * License or the Less License, as specified in the README file. 660786Sps * 760786Sps * For more information about less, or for information on how to 860786Sps * contact the author, see the README file. 960786Sps */ 1060786Sps 1160786Sps 1260786Sps/* 1360786Sps * Standard include file for "less". 1460786Sps */ 1560786Sps 1660786Sps/* 1760786Sps * Defines for MSDOS_COMPILER. 1860786Sps */ 1960786Sps#define MSOFTC 1 /* Microsoft C */ 2060786Sps#define BORLANDC 2 /* Borland C */ 2160786Sps#define WIN32C 3 /* Windows (Borland C or Microsoft C) */ 2260786Sps#define DJGPPC 4 /* DJGPP C */ 2360786Sps 2460786Sps/* 2560786Sps * Include the file of compile-time options. 2660786Sps * The <> make cc search for it in -I., not srcdir. 2760786Sps */ 2860786Sps#include <defines.h> 2960786Sps 3060786Sps#ifdef _SEQUENT_ 3160786Sps/* 3260786Sps * Kludge for Sequent Dynix systems that have sigsetmask, but 3360786Sps * it's not compatible with the way less calls it. 3460786Sps * {{ Do other systems need this? }} 3560786Sps */ 3660786Sps#undef HAVE_SIGSETMASK 3760786Sps#endif 3860786Sps 3960786Sps/* 4060786Sps * Language details. 4160786Sps */ 4260786Sps#if HAVE_VOID 4360786Sps#define VOID_POINTER void * 4460786Sps#else 4560786Sps#define VOID_POINTER char * 4660786Sps#define void int 4760786Sps#endif 4860786Sps#if HAVE_CONST 4960786Sps#define constant const 5060786Sps#else 5160786Sps#define constant 5260786Sps#endif 5360786Sps 5460786Sps#define public /* PUBLIC FUNCTION */ 5560786Sps 5660786Sps/* Library function declarations */ 5760786Sps 5860786Sps#if HAVE_SYS_TYPES_H 5960786Sps#include <sys/types.h> 6060786Sps#endif 6160786Sps#if HAVE_STDIO_H 6260786Sps#include <stdio.h> 6360786Sps#endif 6460786Sps#if HAVE_FCNTL_H 6560786Sps#include <fcntl.h> 6660786Sps#endif 6760786Sps#if HAVE_UNISTD_H 6860786Sps#include <unistd.h> 6960786Sps#endif 7060786Sps#if HAVE_CTYPE_H 7160786Sps#include <ctype.h> 7260786Sps#endif 7360786Sps#if HAVE_STDLIB_H 7460786Sps#include <stdlib.h> 7560786Sps#endif 7660786Sps#if HAVE_STRING_H 7760786Sps#include <string.h> 7860786Sps#endif 7960786Sps#ifdef _OSK 8060786Sps#include <modes.h> 8160786Sps#include <strings.h> 8260786Sps#endif 8360786Sps#if MSDOS_COMPILER==WIN32C 8460786Sps#include <io.h> 8560786Sps#endif 8660786Sps#if MSDOS_COMPILER==DJGPPC 8760786Sps#include <io.h> 8860786Sps#include <sys/exceptn.h> 8960786Sps#include <conio.h> 9060786Sps#include <pc.h> 9160786Sps#endif 9260786Sps 9360786Sps#if !HAVE_STDLIB_H 9460786Spschar *getenv(); 9560786Spsoff_t lseek(); 9660786SpsVOID_POINTER calloc(); 9760786Spsvoid free(); 9860786Sps#endif 9960786Sps 10060786Sps/* 10160786Sps * Simple lowercase test which can be used during option processing 10260786Sps * (before options are parsed which might tell us what charset to use). 10360786Sps */ 10460786Sps#define SIMPLE_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') 10560786Sps#define SIMPLE_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') 10660786Sps#define SIMPLE_TO_UPPER(c) ((c) - 'a' + 'A') 10760786Sps#define SIMPLE_TO_LOWER(c) ((c) - 'A' + 'a') 10860786Sps 10960786Sps#if !HAVE_UPPER_LOWER 11060786Sps#define isupper(c) SIMPLE_IS_UPPER(c) 11160786Sps#define islower(c) SIMPLE_IS_LOWER(c) 11260786Sps#define toupper(c) SIMPLE_TO_UPPER(c) 11360786Sps#define tolower(c) SIMPLE_TO_LOWER(c) 11460786Sps#endif 11560786Sps 11660786Sps#ifndef NULL 11760786Sps#define NULL 0 11860786Sps#endif 11960786Sps 12060786Sps#ifndef TRUE 12160786Sps#define TRUE 1 12260786Sps#endif 12360786Sps#ifndef FALSE 12460786Sps#define FALSE 0 12560786Sps#endif 12660786Sps 12760786Sps#define OPT_OFF 0 12860786Sps#define OPT_ON 1 12960786Sps#define OPT_ONPLUS 2 13060786Sps 13160786Sps#if !HAVE_MEMCPY 13260786Sps#ifndef memcpy 13360786Sps#define memcpy(to,from,len) bcopy((from),(to),(len)) 13460786Sps#endif 13560786Sps#endif 13660786Sps 13760786Sps#define BAD_LSEEK ((off_t)-1) 13860786Sps 13960786Sps/* 14060786Sps * Special types and constants. 14160786Sps */ 14260786Spstypedef long POSITION; 14360786Sps#define PR_POSITION "%ld" 14460786Sps#define MAX_PRINT_POSITION 20 14560786Sps#define MAX_PRINT_INT 10 14660786Sps 14760786Sps#define NULL_POSITION ((POSITION)(-1)) 14860786Sps 14960786Sps/* 15060786Sps * Flags for open() 15160786Sps */ 15260786Sps#if MSDOS_COMPILER || OS2 15360786Sps#define OPEN_READ (O_RDONLY|O_BINARY) 15460786Sps#else 15560786Sps#ifdef _OSK 15660786Sps#define OPEN_READ (S_IREAD) 15760786Sps#else 15860786Sps#ifdef O_RDONLY 15960786Sps#define OPEN_READ (O_RDONLY) 16060786Sps#else 16160786Sps#define OPEN_READ (0) 16260786Sps#endif 16360786Sps#endif 16460786Sps#endif 16560786Sps 16660786Sps#if defined(O_WRONLY) && defined(O_APPEND) 16760786Sps#define OPEN_APPEND (O_APPEND|O_WRONLY) 16860786Sps#else 16960786Sps#ifdef _OSK 17060786Sps#define OPEN_APPEND (S_IWRITE) 17160786Sps#else 17260786Sps#define OPEN_APPEND (1) 17360786Sps#endif 17460786Sps#endif 17560786Sps 17660786Sps/* 17760786Sps * Set a file descriptor to binary mode. 17860786Sps */ 17960786Sps#if MSDOS_COMPILER==MSOFTC 18060786Sps#define SET_BINARY(f) _setmode(f, _O_BINARY); 18160786Sps#else 18260786Sps#if MSDOS_COMPILER 18360786Sps#define SET_BINARY(f) setmode(f, O_BINARY) 18460786Sps#else 18560786Sps#define SET_BINARY(f) 18660786Sps#endif 18760786Sps#endif 18860786Sps 18960786Sps/* 19060786Sps * Does the shell treat "?" as a metacharacter? 19160786Sps */ 19260786Sps#if MSDOS_COMPILER || OS2 || _OSK 19360786Sps#define SHELL_META_QUEST 0 19460786Sps#else 19560786Sps#define SHELL_META_QUEST 1 19660786Sps#endif 19760786Sps 19860786Sps#define SPACES_IN_FILENAMES 1 19960786Sps 20060786Sps/* 20160786Sps * An IFILE represents an input file. 20260786Sps */ 20360786Sps#define IFILE VOID_POINTER 20460786Sps#define NULL_IFILE ((IFILE)NULL) 20560786Sps 20660786Sps/* 20760786Sps * The structure used to represent a "screen position". 20860786Sps * This consists of a file position, and a screen line number. 20960786Sps * The meaning is that the line starting at the given file 21060786Sps * position is displayed on the ln-th line of the screen. 21160786Sps * (Screen lines before ln are empty.) 21260786Sps */ 21360786Spsstruct scrpos 21460786Sps{ 21560786Sps POSITION pos; 21660786Sps int ln; 21760786Sps}; 21860786Sps 21960786Spstypedef union parg 22060786Sps{ 22160786Sps char *p_string; 22260786Sps int p_int; 22360786Sps} PARG; 22460786Sps 22560786Sps#define NULL_PARG ((PARG *)NULL) 22660786Sps 22760786Spsstruct textlist 22860786Sps{ 22960786Sps char *string; 23060786Sps char *endstring; 23160786Sps}; 23260786Sps 23360786Sps#define EOI (-1) 23460786Sps 23560786Sps#define READ_INTR (-2) 23660786Sps 23760786Sps/* How quiet should we be? */ 23860786Sps#define NOT_QUIET 0 /* Ring bell at eof and for errors */ 23960786Sps#define LITTLE_QUIET 1 /* Ring bell only for errors */ 24060786Sps#define VERY_QUIET 2 /* Never ring bell */ 24160786Sps 24260786Sps/* How should we prompt? */ 24360786Sps#define PR_SHORT 0 /* Prompt with colon */ 24460786Sps#define PR_MEDIUM 1 /* Prompt with message */ 24560786Sps#define PR_LONG 2 /* Prompt with longer message */ 24660786Sps 24760786Sps/* How should we handle backspaces? */ 24860786Sps#define BS_SPECIAL 0 /* Do special things for underlining and bold */ 24960786Sps#define BS_NORMAL 1 /* \b treated as normal char; actually output */ 25060786Sps#define BS_CONTROL 2 /* \b treated as control char; prints as ^H */ 25160786Sps 25260786Sps/* How should we search? */ 25360786Sps#define SRCH_FORW 000001 /* Search forward from current position */ 25460786Sps#define SRCH_BACK 000002 /* Search backward from current position */ 25560786Sps#define SRCH_NO_MOVE 000004 /* Highlight, but don't move */ 25660786Sps#define SRCH_FIND_ALL 000010 /* Find and highlight all matches */ 25760786Sps#define SRCH_NO_MATCH 000100 /* Search for non-matching lines */ 25860786Sps#define SRCH_PAST_EOF 000200 /* Search past end-of-file, into next file */ 25960786Sps#define SRCH_FIRST_FILE 000400 /* Search starting at the first file */ 26060786Sps#define SRCH_NO_REGEX 001000 /* Don't use regular expressions */ 26160786Sps 26260786Sps#define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \ 26360786Sps (((t) & ~SRCH_FORW) | SRCH_BACK) : \ 26460786Sps (((t) & ~SRCH_BACK) | SRCH_FORW)) 26560786Sps 26660786Sps/* */ 26760786Sps#define NO_MCA 0 26860786Sps#define MCA_DONE 1 26960786Sps#define MCA_MORE 2 27060786Sps 27160786Sps#define CC_OK 0 /* Char was accepted & processed */ 27260786Sps#define CC_QUIT 1 /* Char was a request to abort current cmd */ 27360786Sps#define CC_ERROR 2 /* Char could not be accepted due to error */ 27460786Sps#define CC_PASS 3 /* Char was rejected (internal) */ 27560786Sps 27660786Sps#define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */ 27760786Sps 27860786Sps/* Special chars used to tell put_line() to do something special */ 27960786Sps#define AT_NORMAL (0) 28060786Sps#define AT_UNDERLINE (1) 28160786Sps#define AT_BOLD (2) 28260786Sps#define AT_BLINK (3) 28360786Sps#define AT_INVIS (4) 28460786Sps#define AT_STANDOUT (5) 28560786Sps 28660786Sps#if IS_EBCDIC_HOST 28760786Sps/* 28860786Sps * Long definition for EBCDIC. 28960786Sps * Since the argument is usually a constant, this macro normally compiles 29060786Sps * into a constant. 29160786Sps */ 29260786Sps#define CONTROL(c) ( \ 29360786Sps (c)=='[' ? '\047' : \ 29460786Sps (c)=='a' ? '\001' : \ 29560786Sps (c)=='b' ? '\002' : \ 29660786Sps (c)=='c' ? '\003' : \ 29760786Sps (c)=='d' ? '\067' : \ 29860786Sps (c)=='e' ? '\055' : \ 29960786Sps (c)=='f' ? '\056' : \ 30060786Sps (c)=='g' ? '\057' : \ 30160786Sps (c)=='h' ? '\026' : \ 30260786Sps (c)=='i' ? '\005' : \ 30360786Sps (c)=='j' ? '\025' : \ 30460786Sps (c)=='k' ? '\013' : \ 30560786Sps (c)=='l' ? '\014' : \ 30660786Sps (c)=='m' ? '\015' : \ 30760786Sps (c)=='n' ? '\016' : \ 30860786Sps (c)=='o' ? '\017' : \ 30960786Sps (c)=='p' ? '\020' : \ 31060786Sps (c)=='q' ? '\021' : \ 31160786Sps (c)=='r' ? '\022' : \ 31260786Sps (c)=='s' ? '\023' : \ 31360786Sps (c)=='t' ? '\074' : \ 31460786Sps (c)=='u' ? '\075' : \ 31560786Sps (c)=='v' ? '\062' : \ 31660786Sps (c)=='w' ? '\046' : \ 31760786Sps (c)=='x' ? '\030' : \ 31860786Sps (c)=='y' ? '\031' : \ 31960786Sps (c)=='z' ? '\077' : \ 32060786Sps (c)=='A' ? '\001' : \ 32160786Sps (c)=='B' ? '\002' : \ 32260786Sps (c)=='C' ? '\003' : \ 32360786Sps (c)=='D' ? '\067' : \ 32460786Sps (c)=='E' ? '\055' : \ 32560786Sps (c)=='F' ? '\056' : \ 32660786Sps (c)=='G' ? '\057' : \ 32760786Sps (c)=='H' ? '\026' : \ 32860786Sps (c)=='I' ? '\005' : \ 32960786Sps (c)=='J' ? '\025' : \ 33060786Sps (c)=='K' ? '\013' : \ 33160786Sps (c)=='L' ? '\014' : \ 33260786Sps (c)=='M' ? '\015' : \ 33360786Sps (c)=='N' ? '\016' : \ 33460786Sps (c)=='O' ? '\017' : \ 33560786Sps (c)=='P' ? '\020' : \ 33660786Sps (c)=='Q' ? '\021' : \ 33760786Sps (c)=='R' ? '\022' : \ 33860786Sps (c)=='S' ? '\023' : \ 33960786Sps (c)=='T' ? '\074' : \ 34060786Sps (c)=='U' ? '\075' : \ 34160786Sps (c)=='V' ? '\062' : \ 34260786Sps (c)=='W' ? '\046' : \ 34360786Sps (c)=='X' ? '\030' : \ 34460786Sps (c)=='Y' ? '\031' : \ 34560786Sps (c)=='Z' ? '\077' : \ 34660786Sps (c)=='|' ? '\031' : \ 34760786Sps (c)=='\\' ? '\034' : \ 34860786Sps (c)=='^' ? '\036' : \ 34960786Sps (c)&077) 35060786Sps#else 35160786Sps#define CONTROL(c) ((c)&037) 35260786Sps#endif /* IS_EBCDIC_HOST */ 35360786Sps 35460786Sps#define ESC CONTROL('[') 35560786Sps 35660786Sps#if _OSK_MWC32 35760786Sps#define LSIGNAL(sig,func) os9_signal(sig,func) 35860786Sps#else 35960786Sps#define LSIGNAL(sig,func) signal(sig,func) 36060786Sps#endif 36160786Sps 36260786Sps#define S_INTERRUPT 01 36360786Sps#define S_STOP 02 36460786Sps#define S_WINCH 04 36560786Sps#define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP)) 36660786Sps 36760786Sps#define QUIT_OK 0 36860786Sps#define QUIT_ERROR 1 36960786Sps#define QUIT_SAVED_STATUS (-1) 37060786Sps 37160786Sps/* filestate flags */ 37260786Sps#define CH_CANSEEK 001 37360786Sps#define CH_KEEPOPEN 002 37460786Sps#define CH_POPENED 004 37560786Sps#define CH_HELPFILE 010 37660786Sps 37760786Sps#define ch_zero() ((POSITION)0) 37860786Sps 37960786Sps#define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@" 38060786Sps 38160786Sps#include "funcs.h" 38260786Sps 383