2 * Copyright (c) 1988 Mark Nudleman
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
34 * @(#)less.h 8.1 (Berkeley) 6/6/93
39 #define MAXVARLENGTH (20)
41 #define NULL_POSITION ((off_t)(-1))
44 #define READ_INTR (-2)
46 #define NO_HORIZ_OFF (-1) /* Wrap lines like normal */
48 /* Special chars used to tell put_line() to do something special */
49 #define UL_CHAR '\201' /* Enter underline mode */
50 #define UE_CHAR '\202' /* Exit underline mode */
51 #define BO_CHAR '\203' /* Enter boldface mode */
52 #define BE_CHAR '\204' /* Exit boldface mode */
54 #define CONTROL_CHAR(c) (!isprint(c))
55 #define CARAT_CHAR(c) ((c == '\177') ? '?' : (c | 0100))
58 #define TOP_PLUS_ONE (1)
60 #define BOTTOM_PLUS_ONE (-2)
63 /* The return type of runmacro() */
64 enum runmacro { OK=0, TOOMACRO, BADMACRO, NOMACRO, BADCOMMAND };
67 #define GLOBAL(var, val) var = val
69 #define GLOBAL(var, val) extern var
74 * This style of error-reporting (see also command.c) is only used by some
75 * code. Eventually most of the code should use it, since it is becoming
76 * inconvenient to have John Q. random function() calling error().
78 * This style of error-reporting still leaves somewhat to be desired....
80 * Note that more(1) needs to potentially work under low-memory conditions
81 * (such as may occur when all available memory has been sucked-up by
82 * the file buffer in ch.c).
85 /* Be careful about ordering correctly!! (must match deferrinit_) */
86 enum error { E_OK=0, E_AMBIG, E_BADMATH, E_BADVAR, E_BOGCOM, E_CANTPARSE,
87 E_CANTXPND, E_COMPLIM, E_EXTERN, E_NOMAC, E_MALLOC, E_NONUM,
88 E_NOSTR, E_NOTOG, E_NULL };
90 /* Listed here for reference only. Be careful about ordering correctly!! */
91 #define deferrinit_ { \
93 "ambigious macro", /* E_AMBIG */ \
94 "invalid arithmetic expression", /* E_BADMATH */ \
95 "bad variable", /* E_BADVAR */ \
96 "bogus command", /* E_BOGCOM */ \
97 "could not parse command string", /* E_CANTPARSE */ \
98 "could not expand macro", /* E_CANTXPND */ \
99 "compile time limit", /* E_COMPLIM */ \
100 "external dependency error", /* E_EXTERN */ \
101 "could not find match for macro", /* E_NOMAC */ \
102 "malloc() failed", /* E_MALLOC */ \
103 "missing numeric argument to command", /* E_NONUM */ \
104 "missing string argument to command", /* E_NOSTR */ \
105 "bad n-toggle argument to command", /* E_NOTOG */ \
106 "to the unknown error", /* E_NULL */ \
108 GLOBAL(const char *deferr[], deferrinit_ );
111 * It is possible for erreur to become dis-synchronized from errstr if
112 * its users aren't careful. Access through the macros is considered
115 GLOBAL(enum error erreur, NULL);
116 GLOBAL(char *errstr, NULL); /* must point be null or free()'ble */
118 #define SETERR(e) do { \
120 if (errstr) free(errstr); \
123 /* SETERRSTR() also exists. It is in command.c */
126 * An emalloc() traditionally never fails, but fmalloc() may fail, hence
127 * the non-standard name. The fmalloc() is just syntactic sugar that sets
128 * erreur for the user.
130 * fmalloc(size, pointer-to-new-memory);
132 * Don't compile this puppy with -Wall...
135 #define FMALLOC(s,v) ((((v) = malloc(s)) ? 0 : \
136 ((errstr ? free(errstr), errstr=NULL : 0), erreur = E_MALLOC)), (v))