less.h revision 128348
160814Sps/* $FreeBSD: head/contrib/less/less.h 128348 2004-04-17 07:24:09Z tjr $ */
260786Sps/*
3128348Stjr * Copyright (C) 1984-2002  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
7489022Sps#if HAVE_LIMITS_H
7589022Sps#include <limits.h>
7689022Sps#endif
7760786Sps#if HAVE_STDLIB_H
7860786Sps#include <stdlib.h>
7960786Sps#endif
8060786Sps#if HAVE_STRING_H
8160786Sps#include <string.h>
8260786Sps#endif
8360786Sps#ifdef _OSK
8460786Sps#include <modes.h>
8560786Sps#include <strings.h>
8660786Sps#endif
8789022Sps#if MSDOS_COMPILER==WIN32C || OS2
8860786Sps#include <io.h>
8960786Sps#endif
9060786Sps#if MSDOS_COMPILER==DJGPPC
9160786Sps#include <io.h>
9260786Sps#include <sys/exceptn.h>
9360786Sps#include <conio.h>
9460786Sps#include <pc.h>
9560786Sps#endif
9660786Sps
9760786Sps#if !HAVE_STDLIB_H
9860786Spschar *getenv();
9960786Spsoff_t lseek();
10060786SpsVOID_POINTER calloc();
10160786Spsvoid free();
10260786Sps#endif
10360786Sps
10460786Sps/*
10560786Sps * Simple lowercase test which can be used during option processing
10660786Sps * (before options are parsed which might tell us what charset to use).
10760786Sps */
10860786Sps#define SIMPLE_IS_UPPER(c)	((c) >= 'A' && (c) <= 'Z')
10960786Sps#define SIMPLE_IS_LOWER(c)	((c) >= 'a' && (c) <= 'z')
11060786Sps#define	SIMPLE_TO_UPPER(c)	((c) - 'a' + 'A')
11160786Sps#define	SIMPLE_TO_LOWER(c)	((c) - 'A' + 'a')
11260786Sps
11360786Sps#if !HAVE_UPPER_LOWER
11460786Sps#define	isupper(c)	SIMPLE_IS_UPPER(c)
11560786Sps#define	islower(c)	SIMPLE_IS_LOWER(c)
11660786Sps#define	toupper(c)	SIMPLE_TO_UPPER(c)
11760786Sps#define	tolower(c)	SIMPLE_TO_LOWER(c)
11860786Sps#endif
11960786Sps
12060786Sps#ifndef NULL
12160786Sps#define	NULL	0
12260786Sps#endif
12360786Sps
12460786Sps#ifndef TRUE
12560786Sps#define	TRUE		1
12660786Sps#endif
12760786Sps#ifndef FALSE
12860786Sps#define	FALSE		0
12960786Sps#endif
13060786Sps
13160786Sps#define	OPT_OFF		0
13260786Sps#define	OPT_ON		1
13360786Sps#define	OPT_ONPLUS	2
13460786Sps
13560786Sps#if !HAVE_MEMCPY
13660786Sps#ifndef memcpy
13760786Sps#define	memcpy(to,from,len)	bcopy((from),(to),(len))
13860786Sps#endif
13960786Sps#endif
14060786Sps
14160786Sps#define	BAD_LSEEK	((off_t)-1)
14260786Sps
14389022Sps#ifndef CHAR_BIT
14489022Sps#define CHAR_BIT 8
14589022Sps#endif
14689022Sps
14760786Sps/*
14889022Sps * Upper bound on the string length of an integer converted to string.
14989022Sps * 302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
15089022Sps * add 1 for integer division truncation; add 1 more for a minus sign.
15189022Sps */
15289022Sps#define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
15389022Sps
15489022Sps/*
15560786Sps * Special types and constants.
15660786Sps */
15760814Spstypedef off_t		POSITION;
158128348Stjrtypedef off_t		LINENUM;
159128348Stjr#define MIN_LINENUM_WIDTH  7	/* Min printing width of a line number */
16060786Sps
16160786Sps#define	NULL_POSITION	((POSITION)(-1))
16260786Sps
16360786Sps/*
16460786Sps * Flags for open()
16560786Sps */
16660786Sps#if MSDOS_COMPILER || OS2
16760786Sps#define	OPEN_READ	(O_RDONLY|O_BINARY)
16860786Sps#else
16960786Sps#ifdef _OSK
17060786Sps#define	OPEN_READ	(S_IREAD)
17160786Sps#else
17260786Sps#ifdef O_RDONLY
17360786Sps#define	OPEN_READ	(O_RDONLY)
17460786Sps#else
17560786Sps#define	OPEN_READ	(0)
17660786Sps#endif
17760786Sps#endif
17860786Sps#endif
17960786Sps
18060786Sps#if defined(O_WRONLY) && defined(O_APPEND)
18160786Sps#define	OPEN_APPEND	(O_APPEND|O_WRONLY)
18260786Sps#else
18360786Sps#ifdef _OSK
18460786Sps#define OPEN_APPEND	(S_IWRITE)
18560786Sps#else
18660786Sps#define	OPEN_APPEND	(1)
18760786Sps#endif
18860786Sps#endif
18960786Sps
19060786Sps/*
19160786Sps * Set a file descriptor to binary mode.
19260786Sps */
19360786Sps#if MSDOS_COMPILER==MSOFTC
19460786Sps#define	SET_BINARY(f)	_setmode(f, _O_BINARY);
19560786Sps#else
19689022Sps#if MSDOS_COMPILER || OS2
19760786Sps#define	SET_BINARY(f)	setmode(f, O_BINARY)
19860786Sps#else
19960786Sps#define	SET_BINARY(f)
20060786Sps#endif
20160786Sps#endif
20260786Sps
20360786Sps/*
20460786Sps * Does the shell treat "?" as a metacharacter?
20560786Sps */
20660786Sps#if MSDOS_COMPILER || OS2 || _OSK
20760786Sps#define	SHELL_META_QUEST 0
20860786Sps#else
20960786Sps#define	SHELL_META_QUEST 1
21060786Sps#endif
21160786Sps
21260786Sps#define	SPACES_IN_FILENAMES 1
21360786Sps
21460786Sps/*
21560786Sps * An IFILE represents an input file.
21660786Sps */
21760786Sps#define	IFILE		VOID_POINTER
21860786Sps#define	NULL_IFILE	((IFILE)NULL)
21960786Sps
22060786Sps/*
22160786Sps * The structure used to represent a "screen position".
22260786Sps * This consists of a file position, and a screen line number.
22360786Sps * The meaning is that the line starting at the given file
22460786Sps * position is displayed on the ln-th line of the screen.
22560786Sps * (Screen lines before ln are empty.)
22660786Sps */
22760786Spsstruct scrpos
22860786Sps{
22960786Sps	POSITION pos;
23060786Sps	int ln;
23160786Sps};
23260786Sps
23360786Spstypedef union parg
23460786Sps{
23560786Sps	char *p_string;
23660786Sps	int p_int;
237128348Stjr	LINENUM p_linenum;
23860786Sps} PARG;
23960786Sps
24060786Sps#define	NULL_PARG	((PARG *)NULL)
24160786Sps
24260786Spsstruct textlist
24360786Sps{
24460786Sps	char *string;
24560786Sps	char *endstring;
24660786Sps};
24760786Sps
24860786Sps#define	EOI		(-1)
24960786Sps
25060786Sps#define	READ_INTR	(-2)
25160786Sps
25260786Sps/* How quiet should we be? */
25360786Sps#define	NOT_QUIET	0	/* Ring bell at eof and for errors */
25460786Sps#define	LITTLE_QUIET	1	/* Ring bell only for errors */
25560786Sps#define	VERY_QUIET	2	/* Never ring bell */
25660786Sps
25760786Sps/* How should we prompt? */
25860786Sps#define	PR_SHORT	0	/* Prompt with colon */
25960786Sps#define	PR_MEDIUM	1	/* Prompt with message */
26060786Sps#define	PR_LONG		2	/* Prompt with longer message */
26160786Sps
26260786Sps/* How should we handle backspaces? */
26360786Sps#define	BS_SPECIAL	0	/* Do special things for underlining and bold */
26460786Sps#define	BS_NORMAL	1	/* \b treated as normal char; actually output */
26560786Sps#define	BS_CONTROL	2	/* \b treated as control char; prints as ^H */
26660786Sps
26760786Sps/* How should we search? */
26860786Sps#define	SRCH_FORW	000001	/* Search forward from current position */
26960786Sps#define	SRCH_BACK	000002	/* Search backward from current position */
27060786Sps#define	SRCH_NO_MOVE	000004	/* Highlight, but don't move */
27160786Sps#define	SRCH_FIND_ALL	000010	/* Find and highlight all matches */
27260786Sps#define	SRCH_NO_MATCH	000100	/* Search for non-matching lines */
27360786Sps#define	SRCH_PAST_EOF	000200	/* Search past end-of-file, into next file */
27460786Sps#define	SRCH_FIRST_FILE	000400	/* Search starting at the first file */
27560786Sps#define	SRCH_NO_REGEX	001000	/* Don't use regular expressions */
27660786Sps
27760786Sps#define	SRCH_REVERSE(t)	(((t) & SRCH_FORW) ? \
27860786Sps				(((t) & ~SRCH_FORW) | SRCH_BACK) : \
27960786Sps				(((t) & ~SRCH_BACK) | SRCH_FORW))
28060786Sps
28160786Sps/* */
28260786Sps#define	NO_MCA		0
28360786Sps#define	MCA_DONE	1
28460786Sps#define	MCA_MORE	2
28560786Sps
28660786Sps#define	CC_OK		0	/* Char was accepted & processed */
28760786Sps#define	CC_QUIT		1	/* Char was a request to abort current cmd */
28860786Sps#define	CC_ERROR	2	/* Char could not be accepted due to error */
28960786Sps#define	CC_PASS		3	/* Char was rejected (internal) */
29060786Sps
29160786Sps#define CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
29260786Sps
29360786Sps/* Special chars used to tell put_line() to do something special */
29460786Sps#define	AT_NORMAL	(0)
29560786Sps#define	AT_UNDERLINE	(1)
29660786Sps#define	AT_BOLD		(2)
29760786Sps#define	AT_BLINK	(3)
29860786Sps#define	AT_INVIS	(4)
29960786Sps#define	AT_STANDOUT	(5)
30060786Sps
30189022Sps#if '0' == 240
30289022Sps#define IS_EBCDIC_HOST 1
30389022Sps#endif
30489022Sps
30560786Sps#if IS_EBCDIC_HOST
30660786Sps/*
30760786Sps * Long definition for EBCDIC.
30860786Sps * Since the argument is usually a constant, this macro normally compiles
30960786Sps * into a constant.
31060786Sps */
31160786Sps#define CONTROL(c) ( \
31260786Sps	(c)=='[' ? '\047' : \
31360786Sps	(c)=='a' ? '\001' : \
31460786Sps	(c)=='b' ? '\002' : \
31560786Sps	(c)=='c' ? '\003' : \
31660786Sps	(c)=='d' ? '\067' : \
31760786Sps	(c)=='e' ? '\055' : \
31860786Sps	(c)=='f' ? '\056' : \
31960786Sps	(c)=='g' ? '\057' : \
32060786Sps	(c)=='h' ? '\026' : \
32160786Sps	(c)=='i' ? '\005' : \
32260786Sps	(c)=='j' ? '\025' : \
32360786Sps	(c)=='k' ? '\013' : \
32460786Sps	(c)=='l' ? '\014' : \
32560786Sps	(c)=='m' ? '\015' : \
32660786Sps	(c)=='n' ? '\016' : \
32760786Sps	(c)=='o' ? '\017' : \
32860786Sps	(c)=='p' ? '\020' : \
32960786Sps	(c)=='q' ? '\021' : \
33060786Sps	(c)=='r' ? '\022' : \
33160786Sps	(c)=='s' ? '\023' : \
33260786Sps	(c)=='t' ? '\074' : \
33360786Sps	(c)=='u' ? '\075' : \
33460786Sps	(c)=='v' ? '\062' : \
33560786Sps	(c)=='w' ? '\046' : \
33660786Sps	(c)=='x' ? '\030' : \
33760786Sps	(c)=='y' ? '\031' : \
33860786Sps	(c)=='z' ? '\077' : \
33960786Sps	(c)=='A' ? '\001' : \
34060786Sps	(c)=='B' ? '\002' : \
34160786Sps	(c)=='C' ? '\003' : \
34260786Sps	(c)=='D' ? '\067' : \
34360786Sps	(c)=='E' ? '\055' : \
34460786Sps	(c)=='F' ? '\056' : \
34560786Sps	(c)=='G' ? '\057' : \
34660786Sps	(c)=='H' ? '\026' : \
34760786Sps	(c)=='I' ? '\005' : \
34860786Sps	(c)=='J' ? '\025' : \
34960786Sps	(c)=='K' ? '\013' : \
35060786Sps	(c)=='L' ? '\014' : \
35160786Sps	(c)=='M' ? '\015' : \
35260786Sps	(c)=='N' ? '\016' : \
35360786Sps	(c)=='O' ? '\017' : \
35460786Sps	(c)=='P' ? '\020' : \
35560786Sps	(c)=='Q' ? '\021' : \
35660786Sps	(c)=='R' ? '\022' : \
35760786Sps	(c)=='S' ? '\023' : \
35860786Sps	(c)=='T' ? '\074' : \
35960786Sps	(c)=='U' ? '\075' : \
36060786Sps	(c)=='V' ? '\062' : \
36160786Sps	(c)=='W' ? '\046' : \
36260786Sps	(c)=='X' ? '\030' : \
36360786Sps	(c)=='Y' ? '\031' : \
36460786Sps	(c)=='Z' ? '\077' : \
36560786Sps	(c)=='|' ? '\031' : \
36660786Sps	(c)=='\\' ? '\034' : \
36760786Sps	(c)=='^' ? '\036' : \
36860786Sps	(c)&077)
36960786Sps#else
37060786Sps#define	CONTROL(c)	((c)&037)
37160786Sps#endif /* IS_EBCDIC_HOST */
37260786Sps
37360786Sps#define	ESC		CONTROL('[')
37460786Sps
37560786Sps#if _OSK_MWC32
37660786Sps#define	LSIGNAL(sig,func)	os9_signal(sig,func)
37760786Sps#else
37860786Sps#define	LSIGNAL(sig,func)	signal(sig,func)
37960786Sps#endif
38060786Sps
38163131Sps#if HAVE_SIGPROCMASK
38263131Sps#if HAVE_SIGSET_T
38363131Sps#else
38463131Sps#undef HAVE_SIGPROCMASK
38563131Sps#endif
38663131Sps#endif
38763131Sps#if HAVE_SIGPROCMASK
38863131Sps#if HAVE_SIGEMPTYSET
38963131Sps#else
39063131Sps#undef  sigemptyset
39163131Sps#define sigemptyset(mp) *(mp) = 0
39263131Sps#endif
39363131Sps#endif
39463131Sps
39560786Sps#define	S_INTERRUPT	01
39660786Sps#define	S_STOP		02
39760786Sps#define S_WINCH		04
39860786Sps#define	ABORT_SIGS()	(sigs & (S_INTERRUPT|S_STOP))
39960786Sps
40060786Sps#define	QUIT_OK		0
40160786Sps#define	QUIT_ERROR	1
40260786Sps#define	QUIT_SAVED_STATUS (-1)
40360786Sps
40460786Sps/* filestate flags */
40560786Sps#define	CH_CANSEEK	001
40660786Sps#define	CH_KEEPOPEN	002
40760786Sps#define	CH_POPENED	004
40860786Sps#define	CH_HELPFILE	010
40960786Sps
41060786Sps#define	ch_zero()	((POSITION)0)
41160786Sps
41260786Sps#define	FAKE_HELPFILE	"@/\\less/\\help/\\file/\\@"
41360786Sps
41460786Sps#include "funcs.h"
41560786Sps
416128348Stjr/* Functions not included in funcs.h */
417128348Stjrvoid postoa();
418128348Stjrvoid linenumtoa();
419128348Stjrvoid inttoa();
420