1 /*
2  * Copyright (c) 1988 Mark Nudleman
3  * Copyright (c) 1988, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed by the University of
17  *	California, Berkeley and its contributors.
18  * 4. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)less.h	8.1 (Berkeley) 6/6/93
35  *
36  * $FreeBSD: src/usr.bin/more/less.h,v 1.7 2000/05/14 03:30:58 hoek Exp $
37  */
38 
39 #define MAXVARLENGTH	(20)
40 
41 #define	NULL_POSITION	((off_t)(-1))
42 
43 #define	EOI		(0)
44 #define	READ_INTR	(-2)
45 
46 /* Special chars used to tell put_line() to do something special */
47 #define	UL_CHAR		'\201'		/* Enter underline mode */
48 #define	UE_CHAR		'\202'		/* Exit underline mode */
49 #define	BO_CHAR		'\203'		/* Enter boldface mode */
50 #define	BE_CHAR		'\204'		/* Exit boldface mode */
51 
52 #define CONTROL_CHAR(c)         (!isprint(c))
53 #define	CARAT_CHAR(c)		((c == '\177') ? '?' : (c | 0100))
54 
55 #define	TOP		(0)
56 #define	TOP_PLUS_ONE	(1)
57 #define	BOTTOM		(-1)
58 #define	BOTTOM_PLUS_ONE	(-2)
59 #define	MIDDLE		(-3)
60 
61 /* The return type of runmacro() */
62 enum runmacro { OK=0, TOOMACRO, BADMACRO, NOMACRO, BADCOMMAND };
63 
64 #define NOFLAGS 0
65 #define FORCE_OPEN 0         /* edit() flag */
66 #define NO_FORCE_OPEN 1      /* edit() flag */
67 
68 #ifdef DEFINEGLOBALS
69 #define GLOBAL(var, val) var = val
70 #else
71 #define GLOBAL(var, val) extern var
72 #endif
73 
74 /*
75  * This style of error-reporting (see also command.c) is only used by some
76  * code.  Eventually most of the code should use it, since it is becoming
77  * inconvenient to have John Q. random function() calling error().
78  *
79  * This style of error-reporting still leaves somewhat to be desired....
80  *
81  * Note that more(1) needs to potentially work under low-memory conditions
82  * (such as may occur when all available memory has been sucked-up by
83  * the file buffer in ch.c).
84  */
85 
86 /* Be careful about ordering correctly!!  (must match deferrinit_) */
87 enum error { E_OK=0, E_AMBIG, E_BADMATH, E_BADVAR, E_BOGCOM, E_CANTPARSE,
88              E_CANTXPND, E_COMPLIM, E_EXTERN, E_NOMAC, E_MALLOC, E_NONUM,
89              E_NOSTR, E_NOTOG, E_SYSTEM, E_NULL };
90 
91 /* Listed here for reference only.  Be careful about ordering correctly!! */
92 #define deferrinit_ { \
93 	"",						/* E_OK */ \
94 	"ambigious macro",				/* E_AMBIG */ \
95 	"invalid arithmetic expression",                /* E_BADMATH */ \
96 	"bad variable",                                 /* E_BADVAR */ \
97 	"bogus command",				/* E_BOGCOM */ \
98 	"could not parse command string",		/* E_CANTPARSE */ \
99 	"could not expand macro",			/* E_CANTXPND */ \
100 	"compile time limit",                           /* E_COMPLIM */ \
101 	"external dependency error",                    /* E_EXTERN */ \
102 	"could not find match for macro",               /* E_NOMAC */ \
103 	"malloc() failed",				/* E_MALLOC */ \
104 	"missing numeric argument to command",          /* E_NONUM */ \
105 	"missing string argument to command",           /* E_NOSTR */ \
106 	"bad n-toggle argument to command",             /* E_NOTOG */ \
107 	"system error",                                 /* E_SYSTEM */ \
108 	"to the unknown error",                         /* E_NULL */ \
109 }
110 GLOBAL(const char *deferr[], deferrinit_ );
111 
112 /*
113  * It is possible for erreur to become unsynchronized from errstr if
114  * its users aren't careful.  Access through the macros is considered
115  * careful.
116  */
117 GLOBAL(enum error erreur, E_OK);
118 GLOBAL(char *errstr, NULL);  /* must point be null or free()'ble */
119 
120 #define SETERR(e) do { \
121 		erreur = (e); \
122 		if (errstr) free(errstr); \
123 		errstr = NULL; \
124 	} while (0)
125 /* SETERRSTR() also exists.  It is in command.c */
126 
127 /*
128  * An emalloc() traditionally never fails, but fmalloc() may fail, hence
129  * the non-standard name.  The fmalloc() is just syntactic sugar that sets
130  * erreur for the user.
131  *
132  * fmalloc(size, pointer-to-new-memory);
133  *
134  * Don't compile this puppy with -Wall or she'll squeel loud!
135  */
136 
137 #define FMALLOC(s,v) ((((v) = malloc(s)) ? 0 : \
138 	((errstr ? free(errstr), errstr=NULL : 0), erreur = E_MALLOC)), (v))
139