3 * Copyright (C) 1984-2005 Mark Nudelman
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Less License, as specified in the README file.
8 * For more information about less, or for information on how to
9 * contact the author, see the README file.
14 * Standard include file for "less".
18 * Defines for MSDOS_COMPILER.
20 #define MSOFTC 1 /* Microsoft C */
21 #define BORLANDC 2 /* Borland C */
22 #define WIN32C 3 /* Windows (Borland C or Microsoft C) */
23 #define DJGPPC 4 /* DJGPP C */
26 * Include the file of compile-time options.
27 * The <> make cc search for it in -I., not srcdir.
33 * Kludge for Sequent Dynix systems that have sigsetmask, but
34 * it's not compatible with the way less calls it.
35 * {{ Do other systems need this? }}
37 #undef HAVE_SIGSETMASK
44 #define VOID_POINTER void *
46 #define VOID_POINTER char *
50 #define constant const
55 #define public /* PUBLIC FUNCTION */
57 /* Library function declarations */
60 #include <sys/types.h>
84 /* OS-specific includes */
94 #if MSDOS_COMPILER==WIN32C || OS2
98 #if MSDOS_COMPILER==DJGPPC
100 #include <sys/exceptn.h>
108 VOID_POINTER calloc();
113 * Simple lowercase test which can be used during option processing
114 * (before options are parsed which might tell us what charset to use).
116 #define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
117 #define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
118 #define ASCII_TO_UPPER(c) ((c) - 'a' + 'A')
119 #define ASCII_TO_LOWER(c) ((c) - 'A' + 'a')
128 #if !HAVE_UPPER_LOWER
129 #define IS_UPPER(c) ASCII_IS_UPPER(c)
130 #define IS_LOWER(c) ASCII_IS_LOWER(c)
131 #define TO_UPPER(c) ASCII_TO_UPPER(c)
132 #define TO_LOWER(c) ASCII_TO_LOWER(c)
134 #define IS_UPPER(c) isupper((unsigned char) (c))
135 #define IS_LOWER(c) islower((unsigned char) (c))
136 #define TO_UPPER(c) toupper((unsigned char) (c))
137 #define TO_LOWER(c) tolower((unsigned char) (c))
141 #define IS_SPACE(c) isspace((unsigned char)(c))
143 #define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
147 #define IS_DIGIT(c) isdigit((unsigned char)(c))
149 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
169 #define memcpy(to,from,len) bcopy((from),(to),(len))
174 #define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1))
175 #define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2))
176 #define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3))
177 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
179 /* Use unsafe sprintf if we don't have snprintf. */
180 #define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1))
181 #define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2))
182 #define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3))
183 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
186 #define BAD_LSEEK ((off_t)-1)
193 * Upper bound on the string length of an integer converted to string.
194 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
195 * add 1 for integer division truncation; add 1 more for a minus sign.
197 #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
200 * Special types and constants.
202 typedef unsigned long LWCHAR;
203 typedef off_t POSITION;
204 typedef off_t LINENUM;
205 #define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */
206 #define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */
208 #define NULL_POSITION ((POSITION)(-1))
213 #if MSDOS_COMPILER || OS2
214 #define OPEN_READ (O_RDONLY|O_BINARY)
217 #define OPEN_READ (S_IREAD)
220 #define OPEN_READ (O_RDONLY)
222 #define OPEN_READ (0)
227 #if defined(O_WRONLY) && defined(O_APPEND)
228 #define OPEN_APPEND (O_APPEND|O_WRONLY)
231 #define OPEN_APPEND (S_IWRITE)
233 #define OPEN_APPEND (1)
238 * Set a file descriptor to binary mode.
240 #if MSDOS_COMPILER==MSOFTC
241 #define SET_BINARY(f) _setmode(f, _O_BINARY);
243 #if MSDOS_COMPILER || OS2
244 #define SET_BINARY(f) setmode(f, O_BINARY)
246 #define SET_BINARY(f)
251 * Does the shell treat "?" as a metacharacter?
253 #if MSDOS_COMPILER || OS2 || _OSK
254 #define SHELL_META_QUEST 0
256 #define SHELL_META_QUEST 1
259 #define SPACES_IN_FILENAMES 1
262 * An IFILE represents an input file.
264 #define IFILE VOID_POINTER
265 #define NULL_IFILE ((IFILE)NULL)
268 * The structure used to represent a "screen position".
269 * This consists of a file position, and a screen line number.
270 * The meaning is that the line starting at the given file
271 * position is displayed on the ln-th line of the screen.
272 * (Screen lines before ln are empty.)
287 #define NULL_PARG ((PARG *)NULL)
297 #define READ_INTR (-2)
299 /* How quiet should we be? */
300 #define NOT_QUIET 0 /* Ring bell at eof and for errors */
301 #define LITTLE_QUIET 1 /* Ring bell only for errors */
302 #define VERY_QUIET 2 /* Never ring bell */
304 /* How should we prompt? */
305 #define PR_SHORT 0 /* Prompt with colon */
306 #define PR_MEDIUM 1 /* Prompt with message */
307 #define PR_LONG 2 /* Prompt with longer message */
309 /* How should we handle backspaces? */
310 #define BS_SPECIAL 0 /* Do special things for underlining and bold */
311 #define BS_NORMAL 1 /* \b treated as normal char; actually output */
312 #define BS_CONTROL 2 /* \b treated as control char; prints as ^H */
314 /* How should we search? */
315 #define SRCH_FORW (1 << 0) /* Search forward from current position */
316 #define SRCH_BACK (1 << 1) /* Search backward from current position */
317 #define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */
318 #define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */
319 #define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */
320 #define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */
321 #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
322 #define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */
324 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
325 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
326 (((t) & ~SRCH_BACK) | SRCH_FORW))
333 #define CC_OK 0 /* Char was accepted & processed */
334 #define CC_QUIT 1 /* Char was a request to abort current cmd */
335 #define CC_ERROR 2 /* Char could not be accepted due to error */
336 #define CC_PASS 3 /* Char was rejected (internal) */
338 #define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */
340 /* Special char bit-flags used to tell put_line() to do something special */
341 #define AT_NORMAL (0)
342 #define AT_UNDERLINE (1 << 0)
343 #define AT_BOLD (1 << 1)
344 #define AT_BLINK (1 << 2)
345 #define AT_STANDOUT (1 << 3)
346 #define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */
347 #define AT_BINARY (1 << 5) /* LESS*BINFMT representation */
348 #define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */
351 #define IS_EBCDIC_HOST 1
356 * Long definition for EBCDIC.
357 * Since the argument is usually a constant, this macro normally compiles
360 #define CONTROL(c) ( \
361 (c)=='[' ? '\047' : \
362 (c)=='a' ? '\001' : \
363 (c)=='b' ? '\002' : \
364 (c)=='c' ? '\003' : \
365 (c)=='d' ? '\067' : \
366 (c)=='e' ? '\055' : \
367 (c)=='f' ? '\056' : \
368 (c)=='g' ? '\057' : \
369 (c)=='h' ? '\026' : \
370 (c)=='i' ? '\005' : \
371 (c)=='j' ? '\025' : \
372 (c)=='k' ? '\013' : \
373 (c)=='l' ? '\014' : \
374 (c)=='m' ? '\015' : \
375 (c)=='n' ? '\016' : \
376 (c)=='o' ? '\017' : \
377 (c)=='p' ? '\020' : \
378 (c)=='q' ? '\021' : \
379 (c)=='r' ? '\022' : \
380 (c)=='s' ? '\023' : \
381 (c)=='t' ? '\074' : \
382 (c)=='u' ? '\075' : \
383 (c)=='v' ? '\062' : \
384 (c)=='w' ? '\046' : \
385 (c)=='x' ? '\030' : \
386 (c)=='y' ? '\031' : \
387 (c)=='z' ? '\077' : \
388 (c)=='A' ? '\001' : \
389 (c)=='B' ? '\002' : \
390 (c)=='C' ? '\003' : \
391 (c)=='D' ? '\067' : \
392 (c)=='E' ? '\055' : \
393 (c)=='F' ? '\056' : \
394 (c)=='G' ? '\057' : \
395 (c)=='H' ? '\026' : \
396 (c)=='I' ? '\005' : \
397 (c)=='J' ? '\025' : \
398 (c)=='K' ? '\013' : \
399 (c)=='L' ? '\014' : \
400 (c)=='M' ? '\015' : \
401 (c)=='N' ? '\016' : \
402 (c)=='O' ? '\017' : \
403 (c)=='P' ? '\020' : \
404 (c)=='Q' ? '\021' : \
405 (c)=='R' ? '\022' : \
406 (c)=='S' ? '\023' : \
407 (c)=='T' ? '\074' : \
408 (c)=='U' ? '\075' : \
409 (c)=='V' ? '\062' : \
410 (c)=='W' ? '\046' : \
411 (c)=='X' ? '\030' : \
412 (c)=='Y' ? '\031' : \
413 (c)=='Z' ? '\077' : \
414 (c)=='|' ? '\031' : \
415 (c)=='\\' ? '\034' : \
416 (c)=='^' ? '\036' : \
419 #define CONTROL(c) ((c)&037)
420 #endif /* IS_EBCDIC_HOST */
422 #define ESC CONTROL('[')
425 #define LSIGNAL(sig,func) os9_signal(sig,func)
427 #define LSIGNAL(sig,func) signal(sig,func)
433 #undef HAVE_SIGPROCMASK
440 #define sigemptyset(mp) *(mp) = 0
444 #define S_INTERRUPT 01
447 #define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP))
451 #define QUIT_SAVED_STATUS (-1)
453 /* filestate flags */
454 #define CH_CANSEEK 001
455 #define CH_KEEPOPEN 002
456 #define CH_POPENED 004
457 #define CH_HELPFILE 010
459 #define ch_zero() ((POSITION)0)
461 #define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@"
465 /* Functions not included in funcs.h */