home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / less-321-src.tgz / tar.out / fsf / less / less.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  7KB  |  305 lines

  1. /*
  2.  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice in the documentation and/or other materials provided with 
  12.  *    the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
  15.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  17.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
  18.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  19.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
  20.  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
  21.  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  22.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
  23.  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
  24.  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  */
  26.  
  27.  
  28. /*
  29.  * Standard include file for "less".
  30.  */
  31.  
  32. /*
  33.  * Defines for MSDOS_COMPILER.
  34.  */
  35. #define    MSOFTC        1    /* Microsoft C */
  36. #define    BORLANDC    2    /* Borland C */
  37. #define    WIN32C        3    /* Windows (Borland C) */
  38.  
  39. /*
  40.  * Include the file of compile-time options.
  41.  * The <> make cc search for it in -I., not srcdir.
  42.  */
  43. #include <defines.h>
  44.  
  45. #ifdef _SEQUENT_
  46. /*
  47.  * Kludge for Sequent Dynix systems that have sigsetmask, but
  48.  * it's not compatible with the way less calls it.
  49.  * {{ Do other systems need this? }}
  50.  */
  51. #undef HAVE_SIGSETMASK
  52. #endif
  53.  
  54. /*
  55.  * Language details.
  56.  */
  57. #if HAVE_VOID
  58. #define    VOID_POINTER    void *
  59. #else
  60. #define    VOID_POINTER    char *
  61. #define    void  int
  62. #endif
  63. #if HAVE_CONST
  64. #define    constant    const
  65. #else
  66. #define    constant
  67. #endif
  68.  
  69. #define    public        /* PUBLIC FUNCTION */
  70.  
  71. /* Library function declarations */
  72.  
  73. #if HAVE_SYS_TYPES_H
  74. #include <sys/types.h>
  75. #endif
  76. #if HAVE_STDIO_H
  77. #include <stdio.h>
  78. #endif
  79. #if HAVE_FCNTL_H
  80. #include <fcntl.h>
  81. #endif
  82. #if HAVE_UNISTD_H
  83. #include <unistd.h>
  84. #endif
  85. #if HAVE_CTYPE_H
  86. #include <ctype.h>
  87. #endif
  88. #if STDC_HEADERS
  89. #include <stdlib.h>
  90. #include <string.h>
  91. #endif
  92. #ifdef _OSK
  93. #include <modes.h>
  94. #include <strings.h>
  95. #endif
  96. #if MSDOS_COMPILER==WIN32C
  97. #include <io.h>
  98. #endif
  99.  
  100. #if !STDC_HEADERS
  101. char *getenv();
  102. off_t lseek();
  103. VOID_POINTER calloc();
  104. void free();
  105. #endif
  106.  
  107. #if !HAVE_UPPER_LOWER
  108. #define    isupper(c)    ((c) >= 'A' && (c) <= 'Z')
  109. #define    islower(c)    ((c) >= 'a' && (c) <= 'z')
  110. #define    toupper(c)    ((c) - 'a' + 'A')
  111. #define    tolower(c)    ((c) - 'A' + 'a')
  112. #endif
  113.  
  114. #ifndef NULL
  115. #define    NULL    0
  116. #endif
  117.  
  118. #ifndef TRUE
  119. #define    TRUE        1
  120. #endif
  121. #ifndef FALSE
  122. #define    FALSE        0
  123. #endif
  124.  
  125. #define    OPT_OFF        0
  126. #define    OPT_ON        1
  127. #define    OPT_ONPLUS    2
  128.  
  129. #ifndef HAVE_MEMCPY
  130. #ifndef memcpy
  131. #define    memcpy(to,from,len)    bcopy((from),(to),(len))
  132. #endif
  133. #endif
  134.  
  135. #define    BAD_LSEEK    ((off_t)-1)
  136.  
  137. /*
  138.  * Special types and constants.
  139.  */
  140. typedef long        POSITION;
  141. /*
  142.  * {{ Warning: if POSITION is changed to other than "long",
  143.  *    you may have to change some of the printfs which use "%ld"
  144.  *    to print a variable of type POSITION. }}
  145.  */
  146.  
  147. #define    NULL_POSITION    ((POSITION)(-1))
  148.  
  149. /*
  150.  * Flags for open()
  151.  */
  152. #if MSDOS_COMPILER || OS2
  153. #define    OPEN_READ    (O_RDONLY|O_BINARY)
  154. #else
  155. #ifdef _OSK
  156. #define    OPEN_READ    (S_IREAD)
  157. #else
  158. #ifdef O_RDONLY
  159. #define    OPEN_READ    (O_RDONLY)
  160. #else
  161. #define    OPEN_READ    (0)
  162. #endif
  163. #endif
  164. #endif
  165.  
  166. #if defined(O_WRONLY) && defined(O_APPEND)
  167. #define    OPEN_APPEND    (O_APPEND|O_WRONLY)
  168. #else
  169. #ifdef _OSK
  170. #define OPEN_APPEND    (S_IWRITE)
  171. #else
  172. #define    OPEN_APPEND    (1)
  173. #endif
  174. #endif
  175.  
  176. #if MSDOS_COMPILER || OS2
  177. #define    OPEN_TTYIN()    open("CON", OPEN_READ)
  178. #else
  179. #ifdef __amigaos__
  180. #define OPEN_TTYIN()    2   /* FIXME: should be something like open("con:", OPEN_READ) */
  181. #else
  182. #define    OPEN_TTYIN()    open("/dev/tty", OPEN_READ)
  183. #endif
  184. #endif
  185.  
  186. #if MSDOS_COMPILER || OS2 || _OSK
  187. #define    SHELL_META_QUEST 0
  188. #else
  189. #define    SHELL_META_QUEST 1
  190. #endif
  191.  
  192. /*
  193.  * An IFILE represents an input file.
  194.  */
  195. #define    IFILE        VOID_POINTER
  196. #define    NULL_IFILE    ((IFILE)NULL)
  197.  
  198. /*
  199.  * The structure used to represent a "screen position".
  200.  * This consists of a file position, and a screen line number.
  201.  * The meaning is that the line starting at the given file
  202.  * position is displayed on the ln-th line of the screen.
  203.  * (Screen lines before ln are empty.)
  204.  */
  205. struct scrpos
  206. {
  207.     POSITION pos;
  208.     int ln;
  209. };
  210.  
  211. typedef union parg
  212. {
  213.     char *p_string;
  214.     int p_int;
  215. } PARG;
  216.  
  217. #define    NULL_PARG    ((PARG *)NULL)
  218.  
  219. struct textlist
  220. {
  221.     char *string;
  222.     char *endstring;
  223. };
  224.  
  225. #define    EOI        (-1)
  226.  
  227. #define    READ_INTR    (-2)
  228.  
  229. /* How quiet should we be? */
  230. #define    NOT_QUIET    0    /* Ring bell at eof and for errors */
  231. #define    LITTLE_QUIET    1    /* Ring bell only for errors */
  232. #define    VERY_QUIET    2    /* Never ring bell */
  233.  
  234. /* How should we prompt? */
  235. #define    PR_SHORT    0    /* Prompt with colon */
  236. #define    PR_MEDIUM    1    /* Prompt with message */
  237. #define    PR_LONG        2    /* Prompt with longer message */
  238.  
  239. /* How should we handle backspaces? */
  240. #define    BS_SPECIAL    0    /* Do special things for underlining and bold */
  241. #define    BS_NORMAL    1    /* \b treated as normal char; actually output */
  242. #define    BS_CONTROL    2    /* \b treated as control char; prints as ^H */
  243.  
  244. /* How should we search? */
  245. #define    SRCH_FORW    000001    /* Search forward from current position */
  246. #define    SRCH_BACK    000002    /* Search backward from current position */
  247. #define    SRCH_NO_MOVE    000004    /* Highlight, but don't move */
  248. #define    SRCH_FIND_ALL    000010    /* Find and highlight all matches */
  249. #define    SRCH_NO_MATCH    000100    /* Search for non-matching lines */
  250. #define    SRCH_PAST_EOF    000200    /* Search past end-of-file, into next file */
  251. #define    SRCH_FIRST_FILE    000400    /* Search starting at the first file */
  252. #define    SRCH_NO_REGEX    001000    /* Don't use regular expressions */
  253.  
  254. #define    SRCH_REVERSE(t)    (((t) & SRCH_FORW) ? \
  255.                 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
  256.                 (((t) & ~SRCH_BACK) | SRCH_FORW))
  257.  
  258. /* */
  259. #define    NO_MCA        0
  260. #define    MCA_DONE    1
  261. #define    MCA_MORE    2
  262.  
  263. #define    CC_OK        0    /* Char was accepted & processed */
  264. #define    CC_QUIT        1    /* Char was a request to abort current cmd */
  265. #define    CC_ERROR    2    /* Char could not be accepted due to error */
  266. #define    CC_PASS        3    /* Char was rejected (internal) */
  267.  
  268. /* Special chars used to tell put_line() to do something special */
  269. #define    AT_NORMAL    (0)
  270. #define    AT_UNDERLINE    (1)
  271. #define    AT_BOLD        (2)
  272. #define    AT_BLINK    (3)
  273. #define    AT_INVIS    (4)
  274. #define    AT_STANDOUT    (5)
  275.  
  276. #define    CONTROL(c)    ((c)&037)
  277. #define    ESC        CONTROL('[')
  278.  
  279. #if _OSK_MWC32
  280. #define    LSIGNAL(sig,func)    os9_signal(sig,func)
  281. #else
  282. #define    LSIGNAL(sig,func)    signal(sig,func)
  283. #endif
  284.  
  285. #define    S_INTERRUPT    01
  286. #define    S_STOP        02
  287. #define S_WINCH        04
  288. #define    ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
  289.  
  290. #define    QUIT_OK        0
  291. #define    QUIT_ERROR    1
  292. #define    QUIT_SAVED_STATUS (-1)
  293.  
  294. /* filestate flags */
  295. #define    CH_CANSEEK    001
  296. #define    CH_KEEPOPEN    002
  297. #define    CH_POPENED    004
  298. #define    CH_HELPFILE    010
  299.  
  300. #define    ch_zero()    ((POSITION)0)
  301.  
  302. #define    FAKE_HELPFILE    "@/\\less/\\help/\\file/\\@"
  303.  
  304. #include "funcs.h"
  305.