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