1 /* $NetBSD: less.h,v 1.4 2013/09/04 19:44:21 tron Exp $ */
4 * Copyright (C) 1984-2012 Mark Nudelman
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
15 * Standard include file for "less".
19 * Defines for MSDOS_COMPILER.
21 #define MSOFTC 1 /* Microsoft C */
22 #define BORLANDC 2 /* Borland C */
23 #define WIN32C 3 /* Windows (Borland C or Microsoft C) */
24 #define DJGPPC 4 /* DJGPP C */
27 * Include the file of compile-time options.
28 * The <> make cc search for it in -I., not srcdir.
34 * Kludge for Sequent Dynix systems that have sigsetmask, but
35 * it's not compatible with the way less calls it.
36 * {{ Do other systems need this? }}
38 #undef HAVE_SIGSETMASK
45 #define VOID_POINTER void *
47 #define VOID_POINTER char *
51 #define constant const
56 #define public /* PUBLIC FUNCTION */
58 /* Library function declarations */
61 #include <sys/types.h>
88 /* OS-specific includes */
98 #if MSDOS_COMPILER==WIN32C || OS2
102 #if MSDOS_COMPILER==DJGPPC
104 #include <sys/exceptn.h>
112 VOID_POINTER
calloc();
117 * Simple lowercase test which can be used during option processing
118 * (before options are parsed which might tell us what charset to use).
120 #define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
121 #define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
122 #define ASCII_TO_UPPER(c) ((c) - 'a' + 'A')
123 #define ASCII_TO_LOWER(c) ((c) - 'A' + 'a')
133 #define IS_UPPER(c) iswupper(c)
134 #define IS_LOWER(c) iswlower(c)
135 #define TO_UPPER(c) towupper(c)
136 #define TO_LOWER(c) towlower(c)
139 #define IS_UPPER(c) isupper((unsigned char) (c))
140 #define IS_LOWER(c) islower((unsigned char) (c))
141 #define TO_UPPER(c) toupper((unsigned char) (c))
142 #define TO_LOWER(c) tolower((unsigned char) (c))
144 #define IS_UPPER(c) ASCII_IS_UPPER(c)
145 #define IS_LOWER(c) ASCII_IS_LOWER(c)
146 #define TO_UPPER(c) ASCII_TO_UPPER(c)
147 #define TO_LOWER(c) ASCII_TO_LOWER(c)
152 #define IS_SPACE(c) isspace((unsigned char)(c))
154 #define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
158 #define IS_DIGIT(c) isdigit((unsigned char)(c))
160 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
163 #define IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI))
182 #define memcpy(to,from,len) bcopy((from),(to),(len))
187 #define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1))
188 #define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2))
189 #define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3))
190 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
192 /* Use unsafe sprintf if we don't have snprintf. */
193 #define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1))
194 #define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2))
195 #define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3))
196 #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
199 #define BAD_LSEEK ((off_t)-1)
213 * Upper bound on the string length of an integer converted to string.
214 * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
215 * add 1 for integer division truncation; add 1 more for a minus sign.
217 #define INT_STRLEN_BOUND(t) ((sizeof(t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
220 * Special types and constants.
222 typedef unsigned long LWCHAR
;
223 typedef off_t POSITION
;
224 typedef off_t LINENUM
;
225 #define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */
226 #define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */
228 #define NULL_POSITION ((POSITION)(-1))
233 #if MSDOS_COMPILER || OS2
234 #define OPEN_READ (O_RDONLY|O_BINARY)
237 #define OPEN_READ (S_IREAD)
240 #define OPEN_READ (O_RDONLY)
242 #define OPEN_READ (0)
247 #if defined(O_WRONLY) && defined(O_APPEND)
248 #define OPEN_APPEND (O_APPEND|O_WRONLY)
251 #define OPEN_APPEND (S_IWRITE)
253 #define OPEN_APPEND (1)
258 * Set a file descriptor to binary mode.
260 #if MSDOS_COMPILER==MSOFTC
261 #define SET_BINARY(f) _setmode(f, _O_BINARY);
263 #if MSDOS_COMPILER || OS2
264 #define SET_BINARY(f) setmode(f, O_BINARY)
266 #define SET_BINARY(f)
271 * Does the shell treat "?" as a metacharacter?
273 #if MSDOS_COMPILER || OS2 || _OSK
274 #define SHELL_META_QUEST 0
276 #define SHELL_META_QUEST 1
279 #define SPACES_IN_FILENAMES 1
282 * An IFILE represents an input file.
284 #define IFILE VOID_POINTER
285 #define NULL_IFILE ((IFILE)NULL)
288 * The structure used to represent a "screen position".
289 * This consists of a file position, and a screen line number.
290 * The meaning is that the line starting at the given file
291 * position is displayed on the ln-th line of the screen.
292 * (Screen lines before ln are empty.)
302 constant
char *p_string
;
307 #define NULL_PARG ((PARG *)NULL)
317 #define READ_INTR (-2)
319 /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */
320 #define NUM_FRAC_DENOM 1000000
321 #define NUM_LOG_FRAC_DENOM 6
323 /* How quiet should we be? */
324 #define NOT_QUIET 0 /* Ring bell at eof and for errors */
325 #define LITTLE_QUIET 1 /* Ring bell only for errors */
326 #define VERY_QUIET 2 /* Never ring bell */
328 /* How should we prompt? */
329 #define PR_SHORT 0 /* Prompt with colon */
330 #define PR_MEDIUM 1 /* Prompt with message */
331 #define PR_LONG 2 /* Prompt with longer message */
333 /* How should we handle backspaces? */
334 #define BS_SPECIAL 0 /* Do special things for underlining and bold */
335 #define BS_NORMAL 1 /* \b treated as normal char; actually output */
336 #define BS_CONTROL 2 /* \b treated as control char; prints as ^H */
338 /* How should we search? */
339 #define SRCH_FORW (1 << 0) /* Search forward from current position */
340 #define SRCH_BACK (1 << 1) /* Search backward from current position */
341 #define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */
342 #define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */
343 #define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */
344 #define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */
345 #define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
346 #define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */
347 #define SRCH_FILTER (1 << 13) /* Search is for '&' (filter) command */
348 #define SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */
350 #define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
351 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
352 (((t) & ~SRCH_BACK) | SRCH_FORW))
359 #define CC_OK 0 /* Char was accepted & processed */
360 #define CC_QUIT 1 /* Char was a request to abort current cmd */
361 #define CC_ERROR 2 /* Char could not be accepted due to error */
362 #define CC_PASS 3 /* Char was rejected (internal) */
364 #define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */
366 /* Special char bit-flags used to tell put_line() to do something special */
367 #define AT_NORMAL (0)
368 #define AT_UNDERLINE (1 << 0)
369 #define AT_BOLD (1 << 1)
370 #define AT_BLINK (1 << 2)
371 #define AT_STANDOUT (1 << 3)
372 #define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */
373 #define AT_BINARY (1 << 5) /* LESS*BINFMT representation */
374 #define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */
377 #define IS_EBCDIC_HOST 1
382 * Long definition for EBCDIC.
383 * Since the argument is usually a constant, this macro normally compiles
386 #define CONTROL(c) ( \
387 (c)=='[' ? '\047' : \
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)=='A' ? '\001' : \
415 (c)=='B' ? '\002' : \
416 (c)=='C' ? '\003' : \
417 (c)=='D' ? '\067' : \
418 (c)=='E' ? '\055' : \
419 (c)=='F' ? '\056' : \
420 (c)=='G' ? '\057' : \
421 (c)=='H' ? '\026' : \
422 (c)=='I' ? '\005' : \
423 (c)=='J' ? '\025' : \
424 (c)=='K' ? '\013' : \
425 (c)=='L' ? '\014' : \
426 (c)=='M' ? '\015' : \
427 (c)=='N' ? '\016' : \
428 (c)=='O' ? '\017' : \
429 (c)=='P' ? '\020' : \
430 (c)=='Q' ? '\021' : \
431 (c)=='R' ? '\022' : \
432 (c)=='S' ? '\023' : \
433 (c)=='T' ? '\074' : \
434 (c)=='U' ? '\075' : \
435 (c)=='V' ? '\062' : \
436 (c)=='W' ? '\046' : \
437 (c)=='X' ? '\030' : \
438 (c)=='Y' ? '\031' : \
439 (c)=='Z' ? '\077' : \
440 (c)=='|' ? '\031' : \
441 (c)=='\\' ? '\034' : \
442 (c)=='^' ? '\036' : \
445 #define CONTROL(c) ((c)&037)
446 #endif /* IS_EBCDIC_HOST */
448 #define ESC CONTROL('[')
449 #define CSI ((unsigned char)'\233')
452 #define LSIGNAL(sig,func) os9_signal(sig,func)
454 #define LSIGNAL(sig,func) signal(sig,func)
460 #undef HAVE_SIGPROCMASK
467 #define sigemptyset(mp) *(mp) = 0
471 #define S_INTERRUPT 01
474 #define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP))
478 #define QUIT_INTERRUPT 2
479 #define QUIT_SAVED_STATUS (-1)
481 #define FOLLOW_DESC 0
482 #define FOLLOW_NAME 1
484 /* filestate flags */
485 #define CH_CANSEEK 001
486 #define CH_KEEPOPEN 002
487 #define CH_POPENED 004
488 #define CH_HELPFILE 010
489 #define CH_NODATA 020 /* Special case for zero length files */
492 #define ch_zero() ((POSITION)0)
494 #define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@"
495 #define FAKE_EMPTYFILE "@/\\less/\\empty/\\file/\\@"
497 /* Flags for cvt_text */
498 #define CVT_TO_LC 01 /* Convert upper-case to lower-case */
499 #define CVT_BS 02 /* Do backspace processing */
500 #define CVT_CRLF 04 /* Remove CR after LF */
501 #define CVT_ANSI 010 /* Remove ANSI escape sequences */
505 /* Functions not included in funcs.h */