home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 036 / less232.zip / LESS.H < prev    next >
C/C++ Source or Header  |  1994-09-24  |  5KB  |  219 lines

  1. /*
  2.  * Copyright (c) 1984,1985,1989,1994  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.  * Include the file of compile-time options.
  34.  * The <> make cc search for it in -I., not srcdir.
  35.  */
  36. #include <defines.h>
  37.  
  38. /*
  39.  * Language details.
  40.  */
  41. #if HAVE_VOID
  42. #define    VOID_POINTER    void *
  43. #else
  44. #define    VOID_POINTER    char *
  45. #define    void  int
  46. #endif
  47.  
  48. #define    public        /* PUBLIC FUNCTION */
  49.  
  50. /* Library function declarations */
  51.  
  52. #if HAVE_SYS_TYPES_H
  53. #include <sys/types.h>
  54. #endif
  55. #if HAVE_STDIO_H
  56. #include <stdio.h>
  57. #endif
  58. #if HAVE_UNISTD_H
  59. #include <unistd.h>
  60. #endif
  61. #if STDC_HEADERS
  62. #include <stdlib.h>
  63. #include <string.h>
  64. #endif
  65. #if HAVE_FCNTL_H
  66. #include <fcntl.h>
  67. #endif
  68.  
  69. #if !STDC_HEADERS
  70. char *getenv();
  71. off_t lseek();
  72. VOID_POINTER calloc();
  73. void free();
  74. #endif
  75.  
  76. #ifndef NULL
  77. #define    NULL    0
  78. #endif
  79.  
  80. #ifndef HAVE_MEMCPY
  81. #ifndef memcpy
  82. #define    memcpy(to,from,len)    bcopy((from),(to),(len))
  83. #endif
  84. #endif
  85.  
  86. #define    BAD_LSEEK    ((off_t)-1)
  87.  
  88. /*
  89.  * Special types and constants.
  90.  */
  91. typedef long        POSITION;
  92. /*
  93.  * {{ Warning: if POSITION is changed to other than "long",
  94.  *    you may have to change some of the printfs which use "%ld"
  95.  *    to print a variable of type POSITION. }}
  96.  */
  97.  
  98. #define    NULL_POSITION    ((POSITION)(-1))
  99.  
  100. /*
  101.  * An IFILE represents an input file.
  102.  */
  103. #define    IFILE        VOID_POINTER
  104. #define    NULL_IFILE    ((IFILE)NULL)
  105.  
  106. /*
  107.  * The structure used to represent a "screen position".
  108.  * This consists of a file position, and a screen line number.
  109.  * The meaning is that the line starting at the given file
  110.  * position is displayed on the ln-th line of the screen.
  111.  * (Screen lines before ln are empty.)
  112.  */
  113. struct scrpos
  114. {
  115.     POSITION pos;
  116.     int ln;
  117. };
  118.  
  119. typedef union parg
  120. {
  121.     char *p_string;
  122.     int p_int;
  123. } PARG;
  124.  
  125. #define    NULL_PARG    ((PARG *)NULL)
  126.  
  127. struct textlist
  128. {
  129.     char *string;
  130.     char *endstring;
  131. };
  132.  
  133. #define    EOI        (-1)
  134.  
  135. #define    READ_INTR    (-2)
  136.  
  137. /* How quiet should we be? */
  138. #define    NOT_QUIET    0    /* Ring bell at eof and for errors */
  139. #define    LITTLE_QUIET    1    /* Ring bell only for errors */
  140. #define    VERY_QUIET    2    /* Never ring bell */
  141.  
  142. /* How should we prompt? */
  143. #define    PR_SHORT    0    /* Prompt with colon */
  144. #define    PR_MEDIUM    1    /* Prompt with message */
  145. #define    PR_LONG        2    /* Prompt with longer message */
  146.  
  147. /* How should we handle backspaces? */
  148. #define    BS_SPECIAL    0    /* Do special things for underlining and bold */
  149. #define    BS_NORMAL    1    /* \b treated as normal char; actually output */
  150. #define    BS_CONTROL    2    /* \b treated as control char; prints as ^H */
  151.  
  152. /* How should we search? */
  153. #define    SRCH_FORW    0    /* Search forward from current position */
  154. #define    SRCH_BACK    1    /* Search backward from current position */
  155. #define    SRCH_NOMATCH    0100    /* Search for non-matching lines */
  156. #define    SRCH_PAST_EOF    0200    /* Search past end-of-file, into next file */
  157. #define    SRCH_FIRST_FILE    0400    /* Search starting at the first file */
  158.  
  159. #define    SRCH_DIR(t)    ((t) & 01)
  160. #define    SRCH_REVERSE(t)    ((t) ^ 01)
  161.  
  162. /* */
  163. #define    NO_MCA        0
  164. #define    MCA_DONE    1
  165. #define    MCA_MORE    2
  166.  
  167. #define    CC_OK        0    /* Char was accepted & processed */
  168. #define    CC_QUIT        1    /* Char was a request to abort current cmd */
  169. #define    CC_ERROR    2    /* Char could not be accepted due to error */
  170. #define    CC_PASS        3    /* Char was rejected (internal) */
  171.  
  172. /* Special chars used to tell put_line() to do something special */
  173. #define    AT_NORMAL    (0)
  174. #define    AT_UNDERLINE    (1)
  175. #define    AT_BOLD        (2)
  176. #define    AT_BLINK    (3)
  177. #define    AT_INVIS    (4)
  178. #define    AT_STANDOUT    (5)
  179.  
  180. #define    CONTROL(c)    ((c)&037)
  181. #define    ESC        CONTROL('[')
  182.  
  183. /* Line editting characters */
  184. #define    EC_BACKSPACE    1
  185. #define    EC_LINEKILL    2
  186. #define    EC_RIGHT    3
  187. #define    EC_LEFT        4
  188. #define    EC_W_LEFT    5
  189. #define    EC_W_RIGHT    6
  190. #define    EC_INSERT     7
  191. #define    EC_DELETE    8
  192. #define    EC_HOME        9
  193. #define    EC_END        10
  194. #define    EC_W_BACKSPACE    11
  195. #define    EC_W_DELETE    12
  196. #define    EC_UP        13
  197. #define    EC_DOWN        14
  198. #define    EC_EXPAND    15
  199. #define    EC_F_COMPLETE    17
  200. #define    EC_B_COMPLETE    18
  201.  
  202. /* Flags for editchar() */
  203. #define    EC_PEEK        01
  204. #define    EC_NOHISTORY    02
  205.  
  206. #ifndef O_BINARY
  207. #define O_BINARY 0
  208. #endif
  209.  
  210. #define    SIGNAL(sig,func)    signal(sig,func)
  211.  
  212. #define    S_INTERRUPT    01
  213. #define    S_STOP        02
  214. #define S_WINCH        04
  215. #define    ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
  216.  
  217. #define    ch_zero()    ((POSITION)0)
  218. #include "funcs.h"
  219.