2 * Copyright (C) 1984-2007 Mark Nudelman
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.
7 * For more information about less, or for information on how to
8 * 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>
87 /* OS-specific includes */
97 #if MSDOS_COMPILER==WIN32C || OS2
101 #if MSDOS_COMPILER==DJGPPC
103 #include <sys/exceptn.h>
111 VOID_POINTER
calloc();
116 * Simple lowercase test which can be used during option processing
117 * (before options are parsed which might tell us what charset to use).
119 #define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
120 #define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
121 #define ASCII_TO_UPPER(c) ((c) - 'a' + 'A')
122 #define ASCII_TO_LOWER(c) ((c) - 'A' + 'a')
132 #define IS_UPPER(c) iswupper(c)
133 #define IS_LOWER(c) iswlower(c)
134 #define TO_UPPER(c) towupper(c)
135 #define TO_LOWER(c) towlower(c)
138 #define IS_UPPER(c) isupper((unsigned char) (c))
139 #define IS_LOWER(c) islower((unsigned char) (c))
140 #define TO_UPPER(c) toupper((unsigned char) (c))
141 #define TO_LOWER(c) tolower((unsigned char) (c))
143 #define IS_UPPER(c) ASCII_IS_UPPER(c)
144 #define IS_LOWER(c) ASCII_IS_LOWER(c)
145 #define TO_UPPER(c) ASCII_TO_UPPER(c)
146 #define TO_LOWER(c) ASCII_TO_LOWER(c)
151 #define IS_SPACE(c) isspace((unsigned char)(c))
153 #define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
157 #define IS_DIGIT(c) isdigit((unsigned char)(c))
159 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
162 #define IS_CSI_START(c) ((c) == ESC || (!utf_mode && ((unsigned char)(c)) == CSI))
181 #define memcpy(to,from,len) bcopy((from),(to),(len))
186 #define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1))
187 #define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2))
188 #define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3))
189 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
191 /* Use unsafe sprintf if we don't have snprintf. */
192 #define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1))
193 #define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2))
194 #define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3))
195 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
198 #define BAD_LSEEK ((off_t)-1)
212 * Upper bound on the string length of an integer converted to string.
213 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
214 * add 1 for integer division truncation; add 1 more for a minus sign.
216 #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
219 * Special types and constants.
221 typedef unsigned long LWCHAR
;
222 typedef off_t POSITION
;
223 typedef off_t LINENUM
;
224 #define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */
225 #define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */
227 #define NULL_POSITION ((POSITION)(-1))
232 #if MSDOS_COMPILER || OS2
233 #define OPEN_READ (O_RDONLY|O_BINARY)
236 #define OPEN_READ (S_IREAD)
239 #define OPEN_READ (O_RDONLY)
241 #define OPEN_READ (0)
246 #if defined(O_WRONLY) && defined(O_APPEND)
247 #define OPEN_APPEND (O_APPEND|O_WRONLY)
250 #define OPEN_APPEND (S_IWRITE)
252 #define OPEN_APPEND (1)
257 * Set a file descriptor to binary mode.
259 #if MSDOS_COMPILER==MSOFTC
260 #define SET_BINARY(f) _setmode(f, _O_BINARY);
262 #if MSDOS_COMPILER || OS2
263 #define SET_BINARY(f) setmode(f, O_BINARY)
265 #define SET_BINARY(f)
270 * Does the shell treat "?" as a metacharacter?
272 #if MSDOS_COMPILER || OS2 || _OSK
273 #define SHELL_META_QUEST 0
275 #define SHELL_META_QUEST 1
278 #define SPACES_IN_FILENAMES 1
281 * An IFILE represents an input file.
283 #define IFILE VOID_POINTER
284 #define NULL_IFILE ((IFILE)NULL)
287 * The structure used to represent a "screen position".
288 * This consists of a file position, and a screen line number.
289 * The meaning is that the line starting at the given file
290 * position is displayed on the ln-th line of the screen.
291 * (Screen lines before ln are empty.)
306 #define NULL_PARG ((PARG *)NULL)
316 #define READ_INTR (-2)
318 /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
319 #define NUM_FRAC_DENOM 1000000
320 #define NUM_LOG_FRAC_DENOM 6
322 /* How quiet should we be? */
323 #define NOT_QUIET 0 /* Ring bell at eof and for errors */
324 #define LITTLE_QUIET 1 /* Ring bell only for errors */
325 #define VERY_QUIET 2 /* Never ring bell */
327 /* How should we prompt? */
328 #define PR_SHORT 0 /* Prompt with colon */
329 #define PR_MEDIUM 1 /* Prompt with message */
330 #define PR_LONG 2 /* Prompt with longer message */
332 /* How should we handle backspaces? */
333 #define BS_SPECIAL 0 /* Do special things for underlining and bold */
334 #define BS_NORMAL 1 /* \b treated as normal char; actually output */
335 #define BS_CONTROL 2 /* \b treated as control char; prints as ^H */
337 /* How should we search? */
338 #define SRCH_FORW (1 << 0) /* Search forward from current position */
339 #define SRCH_BACK (1 << 1) /* Search backward from current position */
340 #define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */
341 #define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */
342 #define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */
343 #define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */
344 #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
345 #define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */
347 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
348 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
349 (((t) & ~SRCH_BACK) | SRCH_FORW))
356 #define CC_OK 0 /* Char was accepted & processed */
357 #define CC_QUIT 1 /* Char was a request to abort current cmd */
358 #define CC_ERROR 2 /* Char could not be accepted due to error */
359 #define CC_PASS 3 /* Char was rejected (internal) */
361 #define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */
363 /* Special char bit-flags used to tell put_line() to do something special */
364 #define AT_NORMAL (0)
365 #define AT_UNDERLINE (1 << 0)
366 #define AT_BOLD (1 << 1)
367 #define AT_BLINK (1 << 2)
368 #define AT_STANDOUT (1 << 3)
369 #define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */
370 #define AT_BINARY (1 << 5) /* LESS*BINFMT representation */
371 #define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */
374 #define IS_EBCDIC_HOST 1
379 * Long definition for EBCDIC.
380 * Since the argument is usually a constant, this macro normally compiles
383 #define CONTROL(c) ( \
384 (c)=='[' ? '\047' : \
385 (c)=='a' ? '\001' : \
386 (c)=='b' ? '\002' : \
387 (c)=='c' ? '\003' : \
388 (c)=='d' ? '\067' : \
389 (c)=='e' ? '\055' : \
390 (c)=='f' ? '\056' : \
391 (c)=='g' ? '\057' : \
392 (c)=='h' ? '\026' : \
393 (c)=='i' ? '\005' : \
394 (c)=='j' ? '\025' : \
395 (c)=='k' ? '\013' : \
396 (c)=='l' ? '\014' : \
397 (c)=='m' ? '\015' : \
398 (c)=='n' ? '\016' : \
399 (c)=='o' ? '\017' : \
400 (c)=='p' ? '\020' : \
401 (c)=='q' ? '\021' : \
402 (c)=='r' ? '\022' : \
403 (c)=='s' ? '\023' : \
404 (c)=='t' ? '\074' : \
405 (c)=='u' ? '\075' : \
406 (c)=='v' ? '\062' : \
407 (c)=='w' ? '\046' : \
408 (c)=='x' ? '\030' : \
409 (c)=='y' ? '\031' : \
410 (c)=='z' ? '\077' : \
411 (c)=='A' ? '\001' : \
412 (c)=='B' ? '\002' : \
413 (c)=='C' ? '\003' : \
414 (c)=='D' ? '\067' : \
415 (c)=='E' ? '\055' : \
416 (c)=='F' ? '\056' : \
417 (c)=='G' ? '\057' : \
418 (c)=='H' ? '\026' : \
419 (c)=='I' ? '\005' : \
420 (c)=='J' ? '\025' : \
421 (c)=='K' ? '\013' : \
422 (c)=='L' ? '\014' : \
423 (c)=='M' ? '\015' : \
424 (c)=='N' ? '\016' : \
425 (c)=='O' ? '\017' : \
426 (c)=='P' ? '\020' : \
427 (c)=='Q' ? '\021' : \
428 (c)=='R' ? '\022' : \
429 (c)=='S' ? '\023' : \
430 (c)=='T' ? '\074' : \
431 (c)=='U' ? '\075' : \
432 (c)=='V' ? '\062' : \
433 (c)=='W' ? '\046' : \
434 (c)=='X' ? '\030' : \
435 (c)=='Y' ? '\031' : \
436 (c)=='Z' ? '\077' : \
437 (c)=='|' ? '\031' : \
438 (c)=='\\' ? '\034' : \
439 (c)=='^' ? '\036' : \
442 #define CONTROL(c) ((c)&037)
443 #endif /* IS_EBCDIC_HOST */
445 #define ESC CONTROL('[')
446 #define CSI ((unsigned char)'\233')
449 #define LSIGNAL(sig,func) os9_signal(sig,func)
451 #define LSIGNAL(sig,func) signal(sig,func)
457 #undef HAVE_SIGPROCMASK
464 #define sigemptyset(mp) *(mp) = 0
468 #define S_INTERRUPT 01
471 #define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP))
475 #define QUIT_SAVED_STATUS (-1)
477 #define FOLLOW_DESC 0
478 #define FOLLOW_NAME 1
480 /* filestate flags */
481 #define CH_CANSEEK 001
482 #define CH_KEEPOPEN 002
483 #define CH_POPENED 004
484 #define CH_HELPFILE 010
486 #define ch_zero() ((POSITION)0)
488 #define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@"
492 /* Functions not included in funcs.h */