~ubuntu-branches/ubuntu/quantal/less/quantal

« back to all changes in this revision

Viewing changes to less.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Schoepf
  • Date: 2002-04-04 16:43:52 UTC
  • Revision ID: james.westby@ubuntu.com-20020404164352-qldq048yoc7x5sd5
Tags: upstream-374
ImportĀ upstreamĀ versionĀ 374

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 1984-2000  Mark Nudelman
 
3
 *
 
4
 * You may distribute under the terms of either the GNU General Public
 
5
 * License or the Less License, as specified in the README file.
 
6
 *
 
7
 * For more information about less, or for information on how to 
 
8
 * contact the author, see the README file.
 
9
 */
 
10
 
 
11
 
 
12
/*
 
13
 * Standard include file for "less".
 
14
 */
 
15
 
 
16
/*
 
17
 * Defines for MSDOS_COMPILER.
 
18
 */
 
19
#define MSOFTC          1       /* Microsoft C */
 
20
#define BORLANDC        2       /* Borland C */
 
21
#define WIN32C          3       /* Windows (Borland C or Microsoft C) */
 
22
#define DJGPPC          4       /* DJGPP C */
 
23
 
 
24
/*
 
25
 * Include the file of compile-time options.
 
26
 * The <> make cc search for it in -I., not srcdir.
 
27
 */
 
28
#include <defines.h>
 
29
 
 
30
#ifdef _SEQUENT_
 
31
/*
 
32
 * Kludge for Sequent Dynix systems that have sigsetmask, but
 
33
 * it's not compatible with the way less calls it.
 
34
 * {{ Do other systems need this? }}
 
35
 */
 
36
#undef HAVE_SIGSETMASK
 
37
#endif
 
38
 
 
39
/*
 
40
 * Language details.
 
41
 */
 
42
#if HAVE_VOID
 
43
#define VOID_POINTER    void *
 
44
#else
 
45
#define VOID_POINTER    char *
 
46
#define void  int
 
47
#endif
 
48
#if HAVE_CONST
 
49
#define constant        const
 
50
#else
 
51
#define constant
 
52
#endif
 
53
 
 
54
#define public          /* PUBLIC FUNCTION */
 
55
 
 
56
/* Library function declarations */
 
57
 
 
58
#if HAVE_SYS_TYPES_H
 
59
#include <sys/types.h>
 
60
#endif
 
61
#if HAVE_STDIO_H
 
62
#include <stdio.h>
 
63
#endif
 
64
#if HAVE_FCNTL_H
 
65
#include <fcntl.h>
 
66
#endif
 
67
#if HAVE_UNISTD_H
 
68
#include <unistd.h>
 
69
#endif
 
70
#if HAVE_CTYPE_H
 
71
#include <ctype.h>
 
72
#endif
 
73
#if HAVE_LIMITS_H
 
74
#include <limits.h>
 
75
#endif
 
76
#if HAVE_STDLIB_H
 
77
#include <stdlib.h>
 
78
#endif
 
79
#if HAVE_STRING_H
 
80
#include <string.h>
 
81
#endif
 
82
#ifdef _OSK
 
83
#include <modes.h>
 
84
#include <strings.h>
 
85
#endif
 
86
#if MSDOS_COMPILER==WIN32C || OS2
 
87
#include <io.h>
 
88
#endif
 
89
#if MSDOS_COMPILER==DJGPPC
 
90
#include <io.h>
 
91
#include <sys/exceptn.h>
 
92
#include <conio.h>
 
93
#include <pc.h>
 
94
#endif
 
95
 
 
96
#if !HAVE_STDLIB_H
 
97
char *getenv();
 
98
off_t lseek();
 
99
VOID_POINTER calloc();
 
100
void free();
 
101
#endif
 
102
 
 
103
/*
 
104
 * Simple lowercase test which can be used during option processing
 
105
 * (before options are parsed which might tell us what charset to use).
 
106
 */
 
107
#define SIMPLE_IS_UPPER(c)      ((c) >= 'A' && (c) <= 'Z')
 
108
#define SIMPLE_IS_LOWER(c)      ((c) >= 'a' && (c) <= 'z')
 
109
#define SIMPLE_TO_UPPER(c)      ((c) - 'a' + 'A')
 
110
#define SIMPLE_TO_LOWER(c)      ((c) - 'A' + 'a')
 
111
 
 
112
#if !HAVE_UPPER_LOWER
 
113
#define isupper(c)      SIMPLE_IS_UPPER(c)
 
114
#define islower(c)      SIMPLE_IS_LOWER(c)
 
115
#define toupper(c)      SIMPLE_TO_UPPER(c)
 
116
#define tolower(c)      SIMPLE_TO_LOWER(c)
 
117
#endif
 
118
 
 
119
#ifndef NULL
 
120
#define NULL    0
 
121
#endif
 
122
 
 
123
#ifndef TRUE
 
124
#define TRUE            1
 
125
#endif
 
126
#ifndef FALSE
 
127
#define FALSE           0
 
128
#endif
 
129
 
 
130
#define OPT_OFF         0
 
131
#define OPT_ON          1
 
132
#define OPT_ONPLUS      2
 
133
 
 
134
#if !HAVE_MEMCPY
 
135
#ifndef memcpy
 
136
#define memcpy(to,from,len)     bcopy((from),(to),(len))
 
137
#endif
 
138
#endif
 
139
 
 
140
#define BAD_LSEEK       ((off_t)-1)
 
141
 
 
142
#ifndef CHAR_BIT
 
143
#define CHAR_BIT 8
 
144
#endif
 
145
 
 
146
/*
 
147
 * Upper bound on the string length of an integer converted to string.
 
148
 * 302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
 
149
 * add 1 for integer division truncation; add 1 more for a minus sign.
 
150
 */
 
151
#define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
 
152
 
 
153
/*
 
154
 * Special types and constants.
 
155
 */
 
156
typedef off_t           POSITION;
 
157
 
 
158
#define NULL_POSITION   ((POSITION)(-1))
 
159
 
 
160
/*
 
161
 * Flags for open()
 
162
 */
 
163
#if MSDOS_COMPILER || OS2
 
164
#define OPEN_READ       (O_RDONLY|O_BINARY)
 
165
#else
 
166
#ifdef _OSK
 
167
#define OPEN_READ       (S_IREAD)
 
168
#else
 
169
#ifdef O_RDONLY
 
170
#define OPEN_READ       (O_RDONLY)
 
171
#else
 
172
#define OPEN_READ       (0)
 
173
#endif
 
174
#endif
 
175
#endif
 
176
 
 
177
#if defined(O_WRONLY) && defined(O_APPEND)
 
178
#define OPEN_APPEND     (O_APPEND|O_WRONLY)
 
179
#else
 
180
#ifdef _OSK
 
181
#define OPEN_APPEND     (S_IWRITE)
 
182
#else
 
183
#define OPEN_APPEND     (1)
 
184
#endif
 
185
#endif
 
186
 
 
187
/*
 
188
 * Set a file descriptor to binary mode.
 
189
 */
 
190
#if MSDOS_COMPILER==MSOFTC
 
191
#define SET_BINARY(f)   _setmode(f, _O_BINARY);
 
192
#else
 
193
#if MSDOS_COMPILER || OS2
 
194
#define SET_BINARY(f)   setmode(f, O_BINARY)
 
195
#else
 
196
#define SET_BINARY(f)
 
197
#endif
 
198
#endif
 
199
 
 
200
/*
 
201
 * Does the shell treat "?" as a metacharacter?
 
202
 */
 
203
#if MSDOS_COMPILER || OS2 || _OSK
 
204
#define SHELL_META_QUEST 0
 
205
#else
 
206
#define SHELL_META_QUEST 1
 
207
#endif
 
208
 
 
209
#define SPACES_IN_FILENAMES 1
 
210
 
 
211
/*
 
212
 * An IFILE represents an input file.
 
213
 */
 
214
#define IFILE           VOID_POINTER
 
215
#define NULL_IFILE      ((IFILE)NULL)
 
216
 
 
217
/*
 
218
 * The structure used to represent a "screen position".
 
219
 * This consists of a file position, and a screen line number.
 
220
 * The meaning is that the line starting at the given file
 
221
 * position is displayed on the ln-th line of the screen.
 
222
 * (Screen lines before ln are empty.)
 
223
 */
 
224
struct scrpos
 
225
{
 
226
        POSITION pos;
 
227
        int ln;
 
228
};
 
229
 
 
230
typedef union parg
 
231
{
 
232
        char *p_string;
 
233
        int p_int;
 
234
} PARG;
 
235
 
 
236
#define NULL_PARG       ((PARG *)NULL)
 
237
 
 
238
struct textlist
 
239
{
 
240
        char *string;
 
241
        char *endstring;
 
242
};
 
243
 
 
244
#define EOI             (-1)
 
245
 
 
246
#define READ_INTR       (-2)
 
247
 
 
248
/* How quiet should we be? */
 
249
#define NOT_QUIET       0       /* Ring bell at eof and for errors */
 
250
#define LITTLE_QUIET    1       /* Ring bell only for errors */
 
251
#define VERY_QUIET      2       /* Never ring bell */
 
252
 
 
253
/* How should we prompt? */
 
254
#define PR_SHORT        0       /* Prompt with colon */
 
255
#define PR_MEDIUM       1       /* Prompt with message */
 
256
#define PR_LONG         2       /* Prompt with longer message */
 
257
 
 
258
/* How should we handle backspaces? */
 
259
#define BS_SPECIAL      0       /* Do special things for underlining and bold */
 
260
#define BS_NORMAL       1       /* \b treated as normal char; actually output */
 
261
#define BS_CONTROL      2       /* \b treated as control char; prints as ^H */
 
262
 
 
263
/* How should we search? */
 
264
#define SRCH_FORW       000001  /* Search forward from current position */
 
265
#define SRCH_BACK       000002  /* Search backward from current position */
 
266
#define SRCH_NO_MOVE    000004  /* Highlight, but don't move */
 
267
#define SRCH_FIND_ALL   000010  /* Find and highlight all matches */
 
268
#define SRCH_NO_MATCH   000100  /* Search for non-matching lines */
 
269
#define SRCH_PAST_EOF   000200  /* Search past end-of-file, into next file */
 
270
#define SRCH_FIRST_FILE 000400  /* Search starting at the first file */
 
271
#define SRCH_NO_REGEX   001000  /* Don't use regular expressions */
 
272
 
 
273
#define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
 
274
                                (((t) & ~SRCH_FORW) | SRCH_BACK) : \
 
275
                                (((t) & ~SRCH_BACK) | SRCH_FORW))
 
276
 
 
277
/* */
 
278
#define NO_MCA          0
 
279
#define MCA_DONE        1
 
280
#define MCA_MORE        2
 
281
 
 
282
#define CC_OK           0       /* Char was accepted & processed */
 
283
#define CC_QUIT         1       /* Char was a request to abort current cmd */
 
284
#define CC_ERROR        2       /* Char could not be accepted due to error */
 
285
#define CC_PASS         3       /* Char was rejected (internal) */
 
286
 
 
287
#define CF_QUIT_ON_ERASE 0001   /* Abort cmd if its entirely erased */
 
288
 
 
289
/* Special chars used to tell put_line() to do something special */
 
290
#define AT_NORMAL       (0)
 
291
#define AT_UNDERLINE    (1)
 
292
#define AT_BOLD         (2)
 
293
#define AT_BLINK        (3)
 
294
#define AT_INVIS        (4)
 
295
#define AT_STANDOUT     (5)
 
296
 
 
297
#if '0' == 240
 
298
#define IS_EBCDIC_HOST 1
 
299
#endif
 
300
 
 
301
#if IS_EBCDIC_HOST
 
302
/*
 
303
 * Long definition for EBCDIC.
 
304
 * Since the argument is usually a constant, this macro normally compiles
 
305
 * into a constant.
 
306
 */
 
307
#define CONTROL(c) ( \
 
308
        (c)=='[' ? '\047' : \
 
309
        (c)=='a' ? '\001' : \
 
310
        (c)=='b' ? '\002' : \
 
311
        (c)=='c' ? '\003' : \
 
312
        (c)=='d' ? '\067' : \
 
313
        (c)=='e' ? '\055' : \
 
314
        (c)=='f' ? '\056' : \
 
315
        (c)=='g' ? '\057' : \
 
316
        (c)=='h' ? '\026' : \
 
317
        (c)=='i' ? '\005' : \
 
318
        (c)=='j' ? '\025' : \
 
319
        (c)=='k' ? '\013' : \
 
320
        (c)=='l' ? '\014' : \
 
321
        (c)=='m' ? '\015' : \
 
322
        (c)=='n' ? '\016' : \
 
323
        (c)=='o' ? '\017' : \
 
324
        (c)=='p' ? '\020' : \
 
325
        (c)=='q' ? '\021' : \
 
326
        (c)=='r' ? '\022' : \
 
327
        (c)=='s' ? '\023' : \
 
328
        (c)=='t' ? '\074' : \
 
329
        (c)=='u' ? '\075' : \
 
330
        (c)=='v' ? '\062' : \
 
331
        (c)=='w' ? '\046' : \
 
332
        (c)=='x' ? '\030' : \
 
333
        (c)=='y' ? '\031' : \
 
334
        (c)=='z' ? '\077' : \
 
335
        (c)=='A' ? '\001' : \
 
336
        (c)=='B' ? '\002' : \
 
337
        (c)=='C' ? '\003' : \
 
338
        (c)=='D' ? '\067' : \
 
339
        (c)=='E' ? '\055' : \
 
340
        (c)=='F' ? '\056' : \
 
341
        (c)=='G' ? '\057' : \
 
342
        (c)=='H' ? '\026' : \
 
343
        (c)=='I' ? '\005' : \
 
344
        (c)=='J' ? '\025' : \
 
345
        (c)=='K' ? '\013' : \
 
346
        (c)=='L' ? '\014' : \
 
347
        (c)=='M' ? '\015' : \
 
348
        (c)=='N' ? '\016' : \
 
349
        (c)=='O' ? '\017' : \
 
350
        (c)=='P' ? '\020' : \
 
351
        (c)=='Q' ? '\021' : \
 
352
        (c)=='R' ? '\022' : \
 
353
        (c)=='S' ? '\023' : \
 
354
        (c)=='T' ? '\074' : \
 
355
        (c)=='U' ? '\075' : \
 
356
        (c)=='V' ? '\062' : \
 
357
        (c)=='W' ? '\046' : \
 
358
        (c)=='X' ? '\030' : \
 
359
        (c)=='Y' ? '\031' : \
 
360
        (c)=='Z' ? '\077' : \
 
361
        (c)=='|' ? '\031' : \
 
362
        (c)=='\\' ? '\034' : \
 
363
        (c)=='^' ? '\036' : \
 
364
        (c)&077)
 
365
#else
 
366
#define CONTROL(c)      ((c)&037)
 
367
#endif /* IS_EBCDIC_HOST */
 
368
 
 
369
#define ESC             CONTROL('[')
 
370
 
 
371
#if _OSK_MWC32
 
372
#define LSIGNAL(sig,func)       os9_signal(sig,func)
 
373
#else
 
374
#define LSIGNAL(sig,func)       signal(sig,func)
 
375
#endif
 
376
 
 
377
#if HAVE_SIGPROCMASK
 
378
#if HAVE_SIGSET_T
 
379
#else
 
380
#undef HAVE_SIGPROCMASK
 
381
#endif
 
382
#endif
 
383
#if HAVE_SIGPROCMASK
 
384
#if HAVE_SIGEMPTYSET
 
385
#else
 
386
#undef  sigemptyset
 
387
#define sigemptyset(mp) *(mp) = 0
 
388
#endif
 
389
#endif
 
390
 
 
391
#define S_INTERRUPT     01
 
392
#define S_STOP          02
 
393
#define S_WINCH         04
 
394
#define ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
 
395
 
 
396
#define QUIT_OK         0
 
397
#define QUIT_ERROR      1
 
398
#define QUIT_SAVED_STATUS (-1)
 
399
 
 
400
/* filestate flags */
 
401
#define CH_CANSEEK      001
 
402
#define CH_KEEPOPEN     002
 
403
#define CH_POPENED      004
 
404
#define CH_HELPFILE     010
 
405
 
 
406
#define ch_zero()       ((POSITION)0)
 
407
 
 
408
#define FAKE_HELPFILE   "@/\\less/\\help/\\file/\\@"
 
409
 
 
410
#include "funcs.h"
 
411