less.h revision 60814
10SN/A/* $FreeBSD: head/contrib/less/less.h 60814 2000-05-23 07:34:27Z ps $ */
29330SN/A/*
30SN/A * Copyright (C) 1984-2000  Mark Nudelman
40SN/A *
50SN/A * You may distribute under the terms of either the GNU General Public
60SN/A * License or the Less License, as specified in the README file.
72362SN/A *
80SN/A * For more information about less, or for information on how to
92362SN/A * contact the author, see the README file.
100SN/A */
110SN/A
120SN/A
130SN/A/*
140SN/A * Standard include file for "less".
150SN/A */
160SN/A
170SN/A/*
180SN/A * Defines for MSDOS_COMPILER.
190SN/A */
200SN/A#define	MSOFTC		1	/* Microsoft C */
212362SN/A#define	BORLANDC	2	/* Borland C */
222362SN/A#define	WIN32C		3	/* Windows (Borland C or Microsoft C) */
232362SN/A#define	DJGPPC		4	/* DJGPP C */
240SN/A
250SN/A/*
260SN/A * Include the file of compile-time options.
270SN/A * The <> make cc search for it in -I., not srcdir.
280SN/A */
290SN/A#include <defines.h>
300SN/A
310SN/A#ifdef _SEQUENT_
320SN/A/*
330SN/A * Kludge for Sequent Dynix systems that have sigsetmask, but
3413629Savstepan * it's not compatible with the way less calls it.
3513629Savstepan * {{ Do other systems need this? }}
360SN/A */
3713629Savstepan#undef HAVE_SIGSETMASK
380SN/A#endif
3913629Savstepan
400SN/A/*
418565SN/A * Language details.
420SN/A */
430SN/A#if HAVE_VOID
440SN/A#define	VOID_POINTER	void *
4513629Savstepan#else
4613629Savstepan#define	VOID_POINTER	char *
4713629Savstepan#define	void  int
480SN/A#endif
4913629Savstepan#if HAVE_CONST
5013629Savstepan#define	constant	const
510SN/A#else
520SN/A#define	constant
530SN/A#endif
540SN/A
550SN/A#define	public		/* PUBLIC FUNCTION */
560SN/A
570SN/A/* Library function declarations */
580SN/A
590SN/A#if HAVE_SYS_TYPES_H
600SN/A#include <sys/types.h>
610SN/A#endif
620SN/A#if HAVE_STDIO_H
630SN/A#include <stdio.h>
640SN/A#endif
6513629Savstepan#if HAVE_FCNTL_H
660SN/A#include <fcntl.h>
670SN/A#endif
680SN/A#if HAVE_UNISTD_H
690SN/A#include <unistd.h>
700SN/A#endif
710SN/A#if HAVE_CTYPE_H
720SN/A#include <ctype.h>
730SN/A#endif
748565SN/A#if HAVE_STDLIB_H
750SN/A#include <stdlib.h>
760SN/A#endif
770SN/A#if HAVE_STRING_H
780SN/A#include <string.h>
790SN/A#endif
800SN/A#ifdef _OSK
810SN/A#include <modes.h>
820SN/A#include <strings.h>
838565SN/A#endif
840SN/A#if MSDOS_COMPILER==WIN32C
850SN/A#include <io.h>
860SN/A#endif
870SN/A#if MSDOS_COMPILER==DJGPPC
880SN/A#include <io.h>
890SN/A#include <sys/exceptn.h>
900SN/A#include <conio.h>
9113629Savstepan#include <pc.h>
9213629Savstepan#endif
9313629Savstepan
9413629Savstepan#if !HAVE_STDLIB_H
9513629Savstepanchar *getenv();
960SN/Aoff_t lseek();
9713629SavstepanVOID_POINTER calloc();
980SN/Avoid free();
9913629Savstepan#endif
1000SN/A
1010SN/A/*
1020SN/A * Simple lowercase test which can be used during option processing
1030SN/A * (before options are parsed which might tell us what charset to use).
1040SN/A */
1050SN/A#define SIMPLE_IS_UPPER(c)	((c) >= 'A' && (c) <= 'Z')
1060SN/A#define SIMPLE_IS_LOWER(c)	((c) >= 'a' && (c) <= 'z')
1070SN/A#define	SIMPLE_TO_UPPER(c)	((c) - 'a' + 'A')
1080SN/A#define	SIMPLE_TO_LOWER(c)	((c) - 'A' + 'a')
1090SN/A
1100SN/A#if !HAVE_UPPER_LOWER
1110SN/A#define	isupper(c)	SIMPLE_IS_UPPER(c)
11213629Savstepan#define	islower(c)	SIMPLE_IS_LOWER(c)
11313629Savstepan#define	toupper(c)	SIMPLE_TO_UPPER(c)
1140SN/A#define	tolower(c)	SIMPLE_TO_LOWER(c)
1150SN/A#endif
11613629Savstepan
1170SN/A#ifndef NULL
1180SN/A#define	NULL	0
1190SN/A#endif
12013629Savstepan
1210SN/A#ifndef TRUE
1220SN/A#define	TRUE		1
1230SN/A#endif
1240SN/A#ifndef FALSE
1250SN/A#define	FALSE		0
1260SN/A#endif
1270SN/A
1280SN/A#define	OPT_OFF		0
1290SN/A#define	OPT_ON		1
1300SN/A#define	OPT_ONPLUS	2
1310SN/A
13213629Savstepan#if !HAVE_MEMCPY
1330SN/A#ifndef memcpy
1349551SN/A#define	memcpy(to,from,len)	bcopy((from),(to),(len))
13513629Savstepan#endif
1360SN/A#endif
1370SN/A
1380SN/A#define	BAD_LSEEK	((off_t)-1)
1390SN/A
1400SN/A/*
1410SN/A * Special types and constants.
1420SN/A */
14313629Savstepantypedef off_t		POSITION;
1448565SN/A#define PR_POSITION	"%lld"
14513629Savstepan#define MAX_PRINT_POSITION 20
1460SN/A#define MAX_PRINT_INT      10
1470SN/A
14813629Savstepan#define	NULL_POSITION	((POSITION)(-1))
14913629Savstepan
1500SN/A/*
1510SN/A * Flags for open()
1520SN/A */
1530SN/A#if MSDOS_COMPILER || OS2
1540SN/A#define	OPEN_READ	(O_RDONLY|O_BINARY)
1550SN/A#else
1560SN/A#ifdef _OSK
1570SN/A#define	OPEN_READ	(S_IREAD)
1580SN/A#else
1590SN/A#ifdef O_RDONLY
1600SN/A#define	OPEN_READ	(O_RDONLY)
1610SN/A#else
1628565SN/A#define	OPEN_READ	(0)
1630SN/A#endif
1640SN/A#endif
1650SN/A#endif
1660SN/A
1670SN/A#if defined(O_WRONLY) && defined(O_APPEND)
1680SN/A#define	OPEN_APPEND	(O_APPEND|O_WRONLY)
1690SN/A#else
1700SN/A#ifdef _OSK
1710SN/A#define OPEN_APPEND	(S_IWRITE)
1720SN/A#else
1730SN/A#define	OPEN_APPEND	(1)
1740SN/A#endif
1758565SN/A#endif
1760SN/A
1770SN/A/*
1780SN/A * Set a file descriptor to binary mode.
1790SN/A */
1800SN/A#if MSDOS_COMPILER==MSOFTC
1810SN/A#define	SET_BINARY(f)	_setmode(f, _O_BINARY);
1820SN/A#else
1830SN/A#if MSDOS_COMPILER
1840SN/A#define	SET_BINARY(f)	setmode(f, O_BINARY)
1850SN/A#else
186#define	SET_BINARY(f)
187#endif
188#endif
189
190/*
191 * Does the shell treat "?" as a metacharacter?
192 */
193#if MSDOS_COMPILER || OS2 || _OSK
194#define	SHELL_META_QUEST 0
195#else
196#define	SHELL_META_QUEST 1
197#endif
198
199#define	SPACES_IN_FILENAMES 1
200
201/*
202 * An IFILE represents an input file.
203 */
204#define	IFILE		VOID_POINTER
205#define	NULL_IFILE	((IFILE)NULL)
206
207/*
208 * The structure used to represent a "screen position".
209 * This consists of a file position, and a screen line number.
210 * The meaning is that the line starting at the given file
211 * position is displayed on the ln-th line of the screen.
212 * (Screen lines before ln are empty.)
213 */
214struct scrpos
215{
216	POSITION pos;
217	int ln;
218};
219
220typedef union parg
221{
222	char *p_string;
223	int p_int;
224} PARG;
225
226#define	NULL_PARG	((PARG *)NULL)
227
228struct textlist
229{
230	char *string;
231	char *endstring;
232};
233
234#define	EOI		(-1)
235
236#define	READ_INTR	(-2)
237
238/* How quiet should we be? */
239#define	NOT_QUIET	0	/* Ring bell at eof and for errors */
240#define	LITTLE_QUIET	1	/* Ring bell only for errors */
241#define	VERY_QUIET	2	/* Never ring bell */
242
243/* How should we prompt? */
244#define	PR_SHORT	0	/* Prompt with colon */
245#define	PR_MEDIUM	1	/* Prompt with message */
246#define	PR_LONG		2	/* Prompt with longer message */
247
248/* How should we handle backspaces? */
249#define	BS_SPECIAL	0	/* Do special things for underlining and bold */
250#define	BS_NORMAL	1	/* \b treated as normal char; actually output */
251#define	BS_CONTROL	2	/* \b treated as control char; prints as ^H */
252
253/* How should we search? */
254#define	SRCH_FORW	000001	/* Search forward from current position */
255#define	SRCH_BACK	000002	/* Search backward from current position */
256#define	SRCH_NO_MOVE	000004	/* Highlight, but don't move */
257#define	SRCH_FIND_ALL	000010	/* Find and highlight all matches */
258#define	SRCH_NO_MATCH	000100	/* Search for non-matching lines */
259#define	SRCH_PAST_EOF	000200	/* Search past end-of-file, into next file */
260#define	SRCH_FIRST_FILE	000400	/* Search starting at the first file */
261#define	SRCH_NO_REGEX	001000	/* Don't use regular expressions */
262
263#define	SRCH_REVERSE(t)	(((t) & SRCH_FORW) ? \
264				(((t) & ~SRCH_FORW) | SRCH_BACK) : \
265				(((t) & ~SRCH_BACK) | SRCH_FORW))
266
267/* */
268#define	NO_MCA		0
269#define	MCA_DONE	1
270#define	MCA_MORE	2
271
272#define	CC_OK		0	/* Char was accepted & processed */
273#define	CC_QUIT		1	/* Char was a request to abort current cmd */
274#define	CC_ERROR	2	/* Char could not be accepted due to error */
275#define	CC_PASS		3	/* Char was rejected (internal) */
276
277#define CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
278
279/* Special chars used to tell put_line() to do something special */
280#define	AT_NORMAL	(0)
281#define	AT_UNDERLINE	(1)
282#define	AT_BOLD		(2)
283#define	AT_BLINK	(3)
284#define	AT_INVIS	(4)
285#define	AT_STANDOUT	(5)
286
287#if IS_EBCDIC_HOST
288/*
289 * Long definition for EBCDIC.
290 * Since the argument is usually a constant, this macro normally compiles
291 * into a constant.
292 */
293#define CONTROL(c) ( \
294	(c)=='[' ? '\047' : \
295	(c)=='a' ? '\001' : \
296	(c)=='b' ? '\002' : \
297	(c)=='c' ? '\003' : \
298	(c)=='d' ? '\067' : \
299	(c)=='e' ? '\055' : \
300	(c)=='f' ? '\056' : \
301	(c)=='g' ? '\057' : \
302	(c)=='h' ? '\026' : \
303	(c)=='i' ? '\005' : \
304	(c)=='j' ? '\025' : \
305	(c)=='k' ? '\013' : \
306	(c)=='l' ? '\014' : \
307	(c)=='m' ? '\015' : \
308	(c)=='n' ? '\016' : \
309	(c)=='o' ? '\017' : \
310	(c)=='p' ? '\020' : \
311	(c)=='q' ? '\021' : \
312	(c)=='r' ? '\022' : \
313	(c)=='s' ? '\023' : \
314	(c)=='t' ? '\074' : \
315	(c)=='u' ? '\075' : \
316	(c)=='v' ? '\062' : \
317	(c)=='w' ? '\046' : \
318	(c)=='x' ? '\030' : \
319	(c)=='y' ? '\031' : \
320	(c)=='z' ? '\077' : \
321	(c)=='A' ? '\001' : \
322	(c)=='B' ? '\002' : \
323	(c)=='C' ? '\003' : \
324	(c)=='D' ? '\067' : \
325	(c)=='E' ? '\055' : \
326	(c)=='F' ? '\056' : \
327	(c)=='G' ? '\057' : \
328	(c)=='H' ? '\026' : \
329	(c)=='I' ? '\005' : \
330	(c)=='J' ? '\025' : \
331	(c)=='K' ? '\013' : \
332	(c)=='L' ? '\014' : \
333	(c)=='M' ? '\015' : \
334	(c)=='N' ? '\016' : \
335	(c)=='O' ? '\017' : \
336	(c)=='P' ? '\020' : \
337	(c)=='Q' ? '\021' : \
338	(c)=='R' ? '\022' : \
339	(c)=='S' ? '\023' : \
340	(c)=='T' ? '\074' : \
341	(c)=='U' ? '\075' : \
342	(c)=='V' ? '\062' : \
343	(c)=='W' ? '\046' : \
344	(c)=='X' ? '\030' : \
345	(c)=='Y' ? '\031' : \
346	(c)=='Z' ? '\077' : \
347	(c)=='|' ? '\031' : \
348	(c)=='\\' ? '\034' : \
349	(c)=='^' ? '\036' : \
350	(c)&077)
351#else
352#define	CONTROL(c)	((c)&037)
353#endif /* IS_EBCDIC_HOST */
354
355#define	ESC		CONTROL('[')
356
357#if _OSK_MWC32
358#define	LSIGNAL(sig,func)	os9_signal(sig,func)
359#else
360#define	LSIGNAL(sig,func)	signal(sig,func)
361#endif
362
363#define	S_INTERRUPT	01
364#define	S_STOP		02
365#define S_WINCH		04
366#define	ABORT_SIGS()	(sigs & (S_INTERRUPT|S_STOP))
367
368#define	QUIT_OK		0
369#define	QUIT_ERROR	1
370#define	QUIT_SAVED_STATUS (-1)
371
372/* filestate flags */
373#define	CH_CANSEEK	001
374#define	CH_KEEPOPEN	002
375#define	CH_POPENED	004
376#define	CH_HELPFILE	010
377
378#define	ch_zero()	((POSITION)0)
379
380#define	FAKE_HELPFILE	"@/\\less/\\help/\\file/\\@"
381
382#include "funcs.h"
383
384