home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / x / xvisrc.zoo / xvi.h < prev    next >
C/C++ Source or Header  |  1992-07-28  |  31KB  |  1,079 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. /***
  3.  
  4. * @(#)xvi.h    2.5 (Chris & John Downey) 9/1/92
  5.  
  6. * program name:
  7.     xvi
  8. * function:
  9.     PD version of UNIX "vi" editor, with extensions.
  10. * module name:
  11.     xvi.h
  12. * module function:
  13.     General definitions for xvi.
  14.  
  15.     This file should really be split up into several files
  16.     rather than being concentrated into one huge monolith.
  17.  
  18. * history:
  19.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  20.     Originally by Tim Thompson (twitch!tjt)
  21.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  22.     Heavily modified by Chris & John Downey
  23.  
  24. ***/
  25.  
  26. /***************************************************************
  27.  *                                                             *
  28.  * SECTION 1: ENVIRONMENT                                      *
  29.  *                                                             *
  30.  * Most of this section is concerned with including the right  *
  31.  * header files; we also define some things by hand if the     *
  32.  * appropriate definitions are not provided by the system.     *
  33.  *                                                             *
  34.  ***************************************************************/
  35.  
  36. /*
  37.  * System include files ...
  38.  */
  39. #include <stdio.h>
  40. #include <signal.h>
  41. #include <string.h>
  42.  
  43. #ifdef    __STDC__
  44.  
  45. #   define  USE_STDHDRS
  46. #   define  STRERROR_AVAIL
  47. #   include <errno.h>
  48. #   include <stdarg.h>
  49. #   define  VA_START(a, b)    va_start(a, b)
  50. #   define  P(args)        args
  51.  
  52. #else    /* not __STDC__ */
  53.  
  54. #   ifdef   ultrix
  55. #       ifdef    mips
  56. #           define  USE_STDHDRS
  57. #       endif   /* mips */
  58. #   endif   /* ultrix */
  59. #   ifdef   sparc
  60. #       define    USE_STDHDRS
  61. #   endif   /* sparc */
  62. #   include <varargs.h>
  63. #   define  VA_START(a, b)    va_start(a)
  64.  
  65. #   define  P(args)         ()
  66.  
  67. #   define  const
  68. #   define  volatile
  69.  
  70. #endif    /* not __STDC__ */
  71.  
  72. #ifdef    USE_STDHDRS
  73. #   include <stdlib.h>
  74. #   include <stddef.h>
  75. #   include <limits.h>
  76. #else    /* USE_STDHDRS not defined */
  77.     extern  FILE    *fopen();
  78.     extern  char    *malloc();
  79.     extern  char    *realloc();
  80.     extern  char    *getenv();
  81.     extern  long    atol();
  82.     extern  char    *memcpy();
  83.     extern  char    *memset();
  84.     extern  void    exit();
  85. #endif    /* USE_STDHDRS not defined */
  86.  
  87. #undef USE_STDHDRS
  88.  
  89. /*
  90.  * Functions which ANSI does not specify should
  91.  * be included in any standard header file.
  92.  */
  93. extern    int    chdir P((const char *path));
  94. extern    char    *getcwd P((char *, unsigned));
  95. extern    void    sleep P((unsigned seconds));
  96.  
  97. /*
  98.  * If we have ANSI C, these should be defined in limits.h:
  99.  */
  100. #ifndef INT_MAX
  101. #   define INT_MAX    ((int) ((unsigned int) ~0 >> 1))
  102. #endif
  103. #ifndef INT_MIN
  104. #   define INT_MIN    (~INT_MAX)
  105. #endif
  106. #ifndef ULONG_MAX
  107. #   define ULONG_MAX    0xffffffff
  108. #endif
  109.  
  110. /*
  111.  * Macro to convert a long to an int.
  112.  * If a long is the same as an int, this is trivial.
  113.  */
  114. #define    LONG2INT(n)    (sizeof(int) == sizeof(long) ? (int) (n) : \
  115.              (int) ((n) > INT_MAX ? INT_MAX : \
  116.               ((n) < INT_MIN ? INT_MIN : (n))))
  117.  
  118.  
  119. /***************************************************************
  120.  *                                                             *
  121.  * SECTION 2: FUNDAMENTAL TYPES                                *
  122.  *                                                             *
  123.  * These types are used by other included header files.        *
  124.  *                                                             *
  125.  ***************************************************************/
  126.  
  127. /*
  128.  * Boolean type.
  129.  * It would be possible to make this an enumerated type,
  130.  * but it isn't worth the hassle - enums don't confer any
  131.  * real advantages, and it means we can't do things like
  132.  *
  133.  *    bool_t    value = (i == 47);
  134.  *
  135.  * but instead are forced to write the abominable
  136.  *
  137.  *    bool_t    value = (i == 47) ? TRUE : FALSE;
  138.  *
  139.  * which is silly.
  140.  */
  141. #undef    FALSE            /* just in case */
  142. #undef    TRUE
  143. #define    FALSE        0
  144. #define    TRUE        1
  145. typedef    int        bool_t;
  146.  
  147.  
  148. /***************************************************************
  149.  *                                                             *
  150.  * SECTION 3: FUNDAMENTAL HEADER FILES                         *
  151.  *                                                             *
  152.  * These header files define types which are used by Xvi.      *
  153.  *                                                             *
  154.  ***************************************************************/
  155.  
  156. #include "virtscr.h"
  157.  
  158.  
  159. /***************************************************************
  160.  *                                                             *
  161.  * SECTION 4: MISCELLANEOUS DEFINITIONS                        *
  162.  *                                                             *
  163.  * Definitions of limits and suchlike used within the editor.  *
  164.  *                                                             *
  165.  ***************************************************************/
  166.  
  167. /*
  168.  * Minimum number of rows a window can have, including status line.
  169.  */
  170. #define    MINROWS        2
  171.  
  172. /*
  173.  * SLOP is the amount of extra space we get for text on a line during
  174.  * editing operations that need more space. This keeps us from calling
  175.  * malloc every time we get a character during insert mode. No extra
  176.  * space is allocated when the file is initially read.
  177.  */
  178. #define    SLOP        10
  179.  
  180. /*
  181.  * The number of characters taken up by the line number
  182.  * when "number" is set; up to 6 digits plus two spaces.
  183.  */
  184. #define    NUM_SIZE    8
  185. #define    NUM_FMT        "%6ld  "
  186.  
  187. /*
  188.  * (MAX_LINE_LENGTH - 1) gives the maximum line length this editor can read in.
  189.  * Used by fileio.c (getfile()) and pipe.c (p_read()).
  190.  */
  191. #define    MAX_LINE_LENGTH    1024
  192.  
  193. /*
  194.  * Maximum value for the tabstop parameter.
  195.  */
  196. #define    MAX_TABSTOP    32
  197.  
  198. /*
  199.  * Default timeout for keystrokes (in milliseconds).
  200.  * The timeout parameter is set to this value.
  201.  */
  202. #define    DEF_TIMEOUT    200
  203.  
  204.  
  205. /***************************************************************
  206.  *                                                             *
  207.  * SECTION 5: PARAMETER TYPE DEFINITIONS                       *
  208.  *                                                             *
  209.  * These are definitions of types for particular parameters.   *
  210.  *                                                             *
  211.  ***************************************************************/
  212.  
  213. /*
  214.  * Regular expression search modes - used in search.c.
  215.  * These are the integer values to which the P_regextype
  216.  * enumerated parameter may be set. Note that these values
  217.  * are ordered; e.g. rt_GREP is considered to be earlier
  218.  * than, and/or less than, rt_EGREP. If the types are added
  219.  * to, this ordering must be maintained. Also note that the
  220.  * names in the rt_strings table must follow the same order.
  221.  */
  222. #define rt_TAGS        0    /* only ^ and $ are significant */
  223. #define rt_GREP        1    /* like grep, but with \< and \> */
  224. #define rt_EGREP    2    /* like egrep, but with \< and \> */
  225.  
  226. /*
  227.  * Array of names for the P_regextype enumeration, defined in
  228.  * search.c.
  229.  */
  230. extern    char        *rt_strings[];
  231.  
  232. /*
  233.  * Integer values for the P_preserve enumerated parameter. Note that
  234.  * the names in psv_strings must follow the same order.
  235.  */
  236. #define psv_UNSAFE    0    /* never preserve buffer before writing */
  237. #define psv_STANDARD    1    /*
  238.                  * only preserve buffer before writing
  239.                  * if it hasn't been preserved recently
  240.                  */
  241. #define psv_SAFE    2    /* always preserve buffer before writing */
  242. #define psv_PARANOID    3    /*
  243.                  * like psv_SAFE, but never remove the
  244.                  * preserve file
  245.                  */
  246.  
  247. /*
  248.  * Array of names for the P_preserve enumeration, defined in
  249.  * search.c.
  250.  */
  251. extern    char        *psv_strings[];
  252.  
  253. /*
  254.  * Integer values for the P_format enumerated parameter. These are for
  255.  * the formats we know about so far. Note that the entries in
  256.  * fmt_strings & tftable (defined in fileio.c) must follow the same order.
  257.  */
  258. #define    fmt_CSTRING    0
  259. #define    fmt_MACINTOSH    1
  260. #define    fmt_MSDOS    2
  261. #define    fmt_OS2        3
  262. #define    fmt_QNX        4
  263. #define    fmt_TOS        5
  264. #define    fmt_UNIX    6
  265.  
  266. /*
  267.  * Array of names for the P_format enumeration.
  268.  */
  269. extern    char        *fmt_strings[];
  270.  
  271. /*
  272.  * Integer values for the P_jumpscroll enumerated parameter. Note that
  273.  * the entries in js_strings (defined in param.c) must follow the same
  274.  * order.
  275.  */
  276. #define    js_OFF        0
  277. #define    js_AUTO        1
  278. #define    js_ON        2
  279.  
  280. /***************************************************************
  281.  *                                                             *
  282.  * SECTION 6: EDITOR TYPE DEFINITIONS                          *
  283.  *                                                             *
  284.  ***************************************************************/
  285.  
  286. /*
  287.  * Possible editor states.
  288.  */
  289. typedef enum {
  290.     NORMAL,            /* command mode */
  291.     INSERT,            /* insert mode */
  292.     REPLACE,            /* overwrite mode */
  293.     CMDLINE,            /* on the : command line */
  294.     DISPLAY            /* in display mode (e.g. g//p or :set all) */
  295. } state_t;
  296.  
  297. extern    state_t        State;    /* defined in main.c */
  298.  
  299. /*
  300.  * Possible return values for cmd_input(), which deals with command
  301.  * line input. This is for commands starting with :, /, ? and !.
  302.  */
  303. typedef enum {
  304.     cmd_COMPLETE,        /* user hit return (cmd line available) */
  305.     cmd_INCOMPLETE,        /* not finished typing command line yet */
  306.     cmd_CANCEL            /* user aborted command line */
  307. } Cmd_State;
  308.  
  309. /*
  310.  * Possible directions for searching, and opening lines.
  311.  */
  312. #define    FORWARD        0
  313. #define    BACKWARD    1
  314.  
  315. /*
  316.  * Line structure and its friends.
  317.  *
  318.  * The structure used to hold a line; this is used to form
  319.  * a doubly-linked list of the lines comprising a file.
  320.  *
  321.  * The definition for MAX_LINENO depends on the type of
  322.  * l_number, and on the size of the machine; we are fairly
  323.  * safe setting all bits here so long as l_number is always
  324.  * an unsigned type. Should really use a lineno_t here, and
  325.  * get rid of the need for a maximum lineno.
  326.  */
  327. typedef    struct    line {
  328.     struct line        *l_prev;    /* previous line */
  329.     struct line        *l_next;    /* next line */
  330.     char        *l_text;    /* text for this line */
  331.     int            l_size;        /* actual size of space at 's' */
  332.     unsigned long    l_number;    /* line "number" */
  333. } Line;
  334.  
  335. #define    MAX_LINENO    ULONG_MAX
  336.  
  337. /*
  338.  * These pseudo-functions operate on lines in a buffer, returning TRUE
  339.  * or FALSE according to whether l1 is later or earlier than l2.
  340.  * Note that there is no macro for "same", which is excluded by both
  341.  * "earlier" and "later".
  342.  */
  343. #define    later(l1, l2)    ((l1)->l_number > (l2)->l_number)
  344. #define    earlier(l1, l2)    ((l1)->l_number < (l2)->l_number)
  345.  
  346. /*
  347.  * This macro gives the line number of line 'l' in buffer 'b'.
  348.  */
  349. #define    lineno(b, l)    ((l)->l_number)
  350.  
  351. /*
  352.  * Easy ways of finding out whether a given line is the first
  353.  * or last line of a buffer, without needing a buffer pointer.
  354.  */
  355. #define    is_lastline(lp)    ((lp)->l_number == MAX_LINENO)
  356. #define    is_line0(lp)    ((lp)->l_number == 0)
  357.  
  358.  
  359. /*
  360.  * Structure used to hold a position in a file;
  361.  * this is just a pointer to the line, and an index.
  362.  */
  363. typedef    struct    position {
  364.     Line        *p_line;    /* line we're referencing */
  365.     int            p_index;    /* position within that line */
  366. } Posn;
  367.  
  368. /*
  369.  * This is stuff to do with marks - it should be privately defined
  370.  * in mark.c, but it needs to be related to each individual buffer.
  371.  */
  372. #define    NMARKS    10        /* max. # of marks that can be saved */
  373.  
  374. typedef    struct    mark {
  375.     char        m_name;
  376.     Posn        m_pos;
  377. } Mark;
  378.  
  379. /*
  380.  * Structure used to record a single change to a buffer.
  381.  * A change may either be a number of lines replaced with a
  382.  * new set, a number of characters removed or a number of
  383.  * characters replaced with a new set. Character changes
  384.  * never straddle line boundaries. A list of these
  385.  * structures forms a complex change. There is also a fourth
  386.  * type of "change", which does not actually change the
  387.  * buffer, but is simply a record of the cursor position at
  388.  * the time of the start of the change. This is needed so
  389.  * that the cursor returns to the correct position after an
  390.  * "undo".
  391.  *
  392.  * This entire structure is only used in undo.c and alloc.c, and
  393.  * no other code should touch it.
  394.  */
  395. typedef    struct change {
  396.     struct change    *c_next;
  397.     enum {
  398.     C_LINE,
  399.     C_CHAR,
  400.     C_DEL_CHAR,
  401.     C_POSITION
  402.     }            c_type;
  403.     unsigned long    c_lineno;
  404.     union {
  405.     struct {
  406.         long    cul_nlines;
  407.         Line    *cul_lines;
  408.     }    cu_l;
  409.     struct {
  410.         int        cuc_index;
  411.         int        cuc_nchars;
  412.         char    *cuc_chars;
  413.     }    cu_c;
  414.     struct {
  415.         long    cup_line;
  416.         int        cup_index;
  417.     }    cu_p;
  418.     }            c_u;
  419. } Change;
  420.  
  421. #define    c_nlines    c_u.cu_l.cul_nlines
  422. #define    c_lines        c_u.cu_l.cul_lines
  423. #define    c_index        c_u.cu_c.cuc_index
  424. #define    c_nchars    c_u.cu_c.cuc_nchars
  425. #define    c_chars        c_u.cu_c.cuc_chars
  426. #define    c_pline        c_u.cu_p.cup_line
  427. #define    c_pindex    c_u.cu_p.cup_index
  428.  
  429. /*
  430.  * Variable-length FIFO queue of characters.
  431.  */
  432. typedef struct
  433. {
  434.     char        *fxb_chars;    /* pointer to allocated space */
  435.     unsigned    fxb_max;    /* size of allocated space */
  436.     unsigned    fxb_rcnt;    /* number of characters read */
  437.     unsigned    fxb_wcnt;    /* number of characters written */
  438. /* public: */
  439. /*
  440.  * Initialize a Flexbuf.
  441.  */
  442. #define            flexnew(f)    ((f)->fxb_wcnt = (f)->fxb_max = 0)
  443. /*
  444.  * Reset a Flexbuf by clearing its contents, but without freeing the
  445.  * dynamically allocated space.
  446.  */
  447. #define            flexclear(f)    ((f)->fxb_wcnt = 0)
  448. /*
  449.  * Test whether a Flexbuf is empty.
  450.  */
  451. #define            flexempty(f)    ((f)->fxb_rcnt >= (f)->fxb_wcnt)
  452. /*
  453.  * Remove last character from a Flexbuf.
  454.  */
  455. #define            flexrmchar(f)    (!flexempty(f) && --(f)->fxb_wcnt)
  456. /*
  457.  * Return number of characters in a Flexbuf.
  458.  */
  459. #define            flexlen(f)    (flexempty(f) ? 0 : \
  460.                      (f)->fxb_wcnt - (f)->fxb_rcnt)
  461. }
  462. Flexbuf;
  463.  
  464. /*
  465.  * Structure used to hold all information about a "buffer" -
  466.  * i.e. the representation of a file in memory.
  467.  */
  468. typedef struct buffer {
  469.     Line        *b_line0;    /* ptr to zeroth line of file */
  470.     Line        *b_file;    /* ptr to first line of file */
  471.     Line        *b_lastline;    /* ptr to (n+1)th line of file */
  472.  
  473.     /*
  474.      * All of these are allocated, and should be freed
  475.      * before assigning any new value to them.
  476.      */
  477.     char        *b_filename;    /* file name, if any */
  478.     char        *b_tempfname;    /* name for temporary copy of file */
  479.  
  480.     unsigned int     b_flags;    /* flags */
  481.  
  482.     int            b_nwindows;    /* no of windows open on this buffer */
  483.  
  484.     /*
  485.      * The following only used in mark.c.
  486.      */
  487.     Mark        b_mlist[NMARKS];    /* current marks */
  488.     Mark        b_pcmark;        /* previous context mark */
  489.     bool_t        b_pcvalid;        /* true if pcmark is valid */
  490.  
  491.     /*
  492.      * The following only used in undo.c.
  493.      */
  494.     unsigned int    b_nlevels;    /* number of brackets surrounding */
  495.                     /* current change to buffer */
  496.     Change        *b_change;    /* ptr to list of changes made */
  497.  
  498. } Buffer;
  499.  
  500. /*
  501.  * Definitions for the "flags" field of a buffer.
  502.  */
  503. #define    FL_MODIFIED    0x1
  504. #define    FL_READONLY    0x2
  505. #define    FL_NOEDIT    0x4
  506. #define    is_modified(b)    ((b)->b_flags & FL_MODIFIED)
  507. #define    is_readonly(b)    (Pb(P_readonly) || ((b)->b_flags & FL_READONLY))
  508. #define    not_editable(b)    ((b)->b_flags & FL_NOEDIT)
  509.  
  510. /*
  511.  * Structure used to hold information about a "window" -
  512.  * this is intimately associated with the Buffer structure.
  513.  */
  514. typedef struct window {
  515.     Posn        *w_cursor;    /* cursor's position in buffer */
  516.  
  517.     Buffer        *w_buffer;    /* buffer we are a window into */
  518.  
  519.     Line        *w_topline;    /* line at top of screen */
  520.     Line        *w_botline;    /* line below bottom of screen */
  521.  
  522.     VirtScr        *w_vs;        /* virtual screen for window */
  523.  
  524.     unsigned        w_nrows;    /* number of rows in window */
  525.     unsigned        w_ncols;    /* number of columns in window */
  526.     unsigned        w_winpos;    /* row of top line of window */
  527.     unsigned        w_cmdline;    /* row of window command line */
  528.  
  529.     /*
  530.      * These are used by the ^O command to store the previous
  531.      * size of the window so that we can return to it.
  532.      */
  533.     int            w_2winpos;    /* last row of top line of window */
  534.     int            w_2nrows;    /* last no of rows in buffer window */
  535.     int            w_2cmdline;    /* last row of window command line */
  536.  
  537.  
  538.     /*
  539.      * Allocated within screen.c.
  540.      */
  541.     Flexbuf        w_statusline;    /* status information on status line */
  542.  
  543.  
  544.     /*
  545.      * These elements are related to the cursor's position in the window.
  546.      */
  547.     int            w_row, w_col;    /* cursor's position in window */
  548.  
  549.     int            w_virtcol;    /* column number of the file's actual */
  550.                     /* line, as opposed to the column */
  551.                     /* number we're at on the screen. */
  552.                     /* This makes a difference on lines */
  553.                     /* which span more than one screen */
  554.                     /* line. */
  555.  
  556.     int            w_curswant;    /* The column we'd like to be at. */
  557.                     /* This is used to try to stay in */
  558.                     /* the same column through up/down */
  559.                     /* cursor motions. */
  560.  
  561.     bool_t        w_set_want_col;    /* If set, then update w_curswant */
  562.                     /* the next time through cursupdate() */
  563.                     /* to the current virtual column */
  564.  
  565.     int            w_c_line_size;    /* current size of cursor line */
  566.  
  567.     bool_t        w_curs_new;    /* true if cursor should be updated */
  568.  
  569.     /*
  570.      * The following only used in windows.c.
  571.      */
  572.     struct window    *w_last;    /* first and last pointers */
  573.     struct window    *w_next;
  574. } Xviwin;
  575.  
  576. /*
  577.  * Values returned by inc() & dec().
  578.  */
  579. enum mvtype {
  580.     mv_NOMOVE = -1,    /* at beginning or end of buffer */
  581.     mv_SAMELINE = 0,    /* still within same line */
  582.     mv_CHLINE = 1,    /* changed to different line */
  583.     mv_EOL = 2        /* in same line, at terminating '\0' */
  584. };
  585.  
  586. /*
  587.  * Number of input characters since the last buffer preservation.
  588.  */
  589. extern volatile int    keystrokes;
  590.  
  591. /*
  592.  * Minimum number of keystrokes after which we do an automatic
  593.  * preservation of all modified buffers.
  594.  */
  595. #define PSVKEYS        60
  596.  
  597. /*
  598.  * Exceptional return values for get_file().
  599.  */
  600. #define gf_NEWFILE    ((long)-1)    /* no such file */
  601. #define gf_CANTOPEN    ((long)-2)    /* error opening file */
  602. #define gf_IOERR    ((long)-3)    /* error reading from file */
  603. #define gf_NOMEM    ((long)-4)    /* not enough memory */
  604.  
  605. /*
  606.  * Editor input events. Handled by xvi_handle_event().
  607.  */
  608. typedef struct event {
  609.     enum {
  610.     Ev_char,
  611.     Ev_timeout
  612.     }            ev_type;
  613.     union {
  614.     /* Ev_char: */
  615.     int    evu_inchar;
  616.  
  617.     /* Ev_timeout: */
  618.     }            ev_u;
  619. } xvEvent;
  620.  
  621. #define    ev_inchar    ev_u.evu_inchar
  622.  
  623.  
  624. /***************************************************************
  625.  *                                                             *
  626.  * SECTION 7: MISCELLANEOUS MACROS                             *
  627.  *                                                             *
  628.  ***************************************************************/
  629.  
  630.  
  631. /***************************************************************
  632.  *                                                             *
  633.  * SECTION 8: XVI-LOCAL HEADER FILES                           *
  634.  *                                                             *
  635.  * Various subsidiary header files with definitions relating   *
  636.  * to particular areas of the editor (or its environment).     *
  637.  * Note that these header files may use definitions in this    *
  638.  * file, so are included after all types are defined.          *
  639.  *                                                             *
  640.  ***************************************************************/
  641.  
  642. #include "ascii.h"
  643. #include "param.h"
  644. #include "ptrfunc.h"
  645.  
  646.  
  647. /***************************************************************
  648.  *                                                             *
  649.  * SECTION 9: SYSTEM-SPECIFIC HEADER FILES                     *
  650.  *                                                             *
  651.  ***************************************************************/
  652.  
  653. /*
  654.  * Include file for system interface module.
  655.  * We must have one of these.
  656.  */
  657.  
  658. #ifdef    ATARI
  659. #   include "tos.h"
  660. #   define    GOT_OS
  661. #endif
  662.  
  663. #ifdef    UNIX
  664. #   include "unix.h"
  665. #   define    GOT_OS
  666. #endif
  667.  
  668. #ifdef    OS2
  669.     /*
  670.      * Microsoft's wonderful compiler defines MSDOS, even when
  671.      * we're compiling for OS/2, but it doesn't define OS2.
  672.      * Ingenious, eh?
  673.      */
  674. #   undef MSDOS
  675. #   include "os2vio.h"
  676. #   define    GOT_OS
  677. #endif
  678.  
  679. #ifdef    MSDOS
  680. #   include "msdos.h"
  681. #   define    GOT_OS
  682. #endif
  683.  
  684. #ifdef    QNX
  685. #   include "qnx.h"
  686. #   define    GOT_OS
  687. #endif
  688.  
  689. #ifndef    GOT_OS
  690.     no system-specific include file found
  691. #endif
  692.  
  693.  
  694. /***************************************************************
  695.  *                                                             *
  696.  * SECTION 10: GLOBAL VARIABLE DECLARATIONS                    *
  697.  *                                                             *
  698.  ***************************************************************/
  699.  
  700. /*
  701.  * Miscellaneous global vars.
  702.  */
  703. extern    Buffer        *curbuf;    /* current buffer */
  704. extern    Xviwin        *curwin;    /* current window */
  705.  
  706. extern    int        indentchars;    /* auto-indentation on current line */
  707. extern    char        *altfilename;    /* name of current alternate file */
  708. extern    char        Version[];    /* version string for :ve command */
  709.  
  710. /*
  711.  * This flag is set when a keyboard interrupt is received.
  712.  */
  713. extern volatile unsigned char kbdintr;
  714.  
  715. /*
  716.  * This one indicates whether we should display the "Interrupted"
  717.  * message.
  718.  */
  719. extern    bool_t        imessage;
  720.  
  721. /*
  722.  * This variable (defined in main.c) is a bitmap which controls the
  723.  * verbosity of screen output. The meanings of the individual bits
  724.  * are:
  725.  *
  726.  *    e_CHARUPDATE means it's OK to update individual characters in
  727.  *    any window.
  728.  *
  729.  *    e_SCROLL means it's OK to scroll any area of the screen up or
  730.  *    down.
  731.  *
  732.  *    e_REPORT means it's OK for report() to report the number of
  733.  *    lines inserted or deleted.
  734.  *
  735.  *    e_SHOWINFO means it's OK for show_file_info() to display file
  736.  *    information for any buffer.
  737.  *
  738.  *    e_BEEP: not implemented yet.
  739.  *
  740.  *    e_REGERR means it's OK for functions in search.c to display
  741.  *    messages which may have resulted from an invalid regular
  742.  *    expression string.
  743.  *
  744.  *    e_NOMATCH means it's OK for functions in search.c to complain
  745.  *    if they fail to match a regular expression at least once.
  746.  *
  747.  * If we're reading an input sequence & e_CHARUPDATE & e_SCROLL are
  748.  * turned off, no screen updating will be done until an ESC is
  749.  * received.
  750.  */
  751. extern    unsigned    echo;
  752.  
  753. #define    e_CHARUPDATE    1
  754. #define    e_SCROLL    2
  755. #define    e_REPORT    4
  756. #define    e_SHOWINFO    010
  757. #define    e_BEEP        020
  758. #define    e_REGERR    040
  759. #define    e_NOMATCH    0100
  760.  
  761. #define e_ANY        0xffff
  762.  
  763.  
  764. /***************************************************************
  765.  *                                                             *
  766.  * SECTION 11: FUNCTION DECLARATIONS                           *
  767.  *                                                             *
  768.  ***************************************************************/
  769.  
  770. /*
  771.  * Declarations of all the routines exported from the various .c files.
  772.  */
  773.  
  774. /*
  775.  * main.c
  776.  */
  777. extern    Xviwin    *xvi_startup P((VirtScr *, int, char **, char *));
  778.  
  779. /*
  780.  * alloc.c
  781.  */
  782. extern    Change    *challoc P((void));
  783. extern    void    chfree P((Change *));
  784. extern    char    *alloc P((unsigned int));
  785. extern    char    *strsave P((const char *));
  786. extern    Line    *newline P((int));
  787. extern    bool_t    bufempty P((Buffer *));
  788. extern    bool_t    buf1line P((Buffer *));
  789. extern    bool_t    endofline P((Posn *));
  790. extern    bool_t    grow_line P((Line *, int));
  791. extern    void    throw P((Line *));
  792.  
  793. /*
  794.  * ascii.c
  795.  */
  796. extern unsigned vischar P((int, char **, int));
  797.  
  798. /*
  799.  * buffers.c
  800.  */
  801. extern    Buffer    *new_buffer P((void));
  802. extern    void    free_buffer P((Buffer *));
  803. extern    bool_t    clear_buffer P((Buffer *));
  804. extern    int    nbuffers;
  805.  
  806. /*
  807.  * edit.c
  808.  */
  809. extern    bool_t    i_proc P((int));
  810. extern    bool_t    r_proc P((int));
  811. extern    void    startinsert P((int));
  812. extern    void    startreplace P((int));
  813. extern    char    *mkstr P((int));
  814.  
  815. /*
  816.  * events.c
  817.  */
  818. extern    long    xvi_handle_event P((xvEvent *));
  819.  
  820. /*
  821.  * cmdline.c
  822.  */
  823. extern    void    do_colon P((char *, bool_t));
  824. extern    void    wait_return P((void));
  825.  
  826. /*
  827.  * cursor.c
  828.  */
  829. extern    void    cursupdate P((Xviwin *));
  830. extern    void    curs_horiz P((Xviwin *, int));
  831.  
  832. /*
  833.  * ex_cmds1.c
  834.  */
  835. extern    void    do_quit P((Xviwin *, bool_t));
  836. extern    void    do_split_window P((Xviwin *));
  837. extern    bool_t    do_buffer P((Xviwin *, char *));
  838. extern    void    do_close_window P((Xviwin *, bool_t));
  839. extern    void    do_xit P((Xviwin *));
  840. extern    bool_t    do_edit P((Xviwin *, bool_t, char *));
  841. extern    void    do_args P((Xviwin *));
  842. extern    void    do_next P((Xviwin *, int, char **, bool_t));
  843. extern    void    do_rewind P((Xviwin *, bool_t));
  844. extern    bool_t    do_write P((Xviwin *, char *, Line *, Line *, bool_t));
  845. extern    void    do_wq P((Xviwin *, char *, bool_t));
  846. extern    void    do_read P((Xviwin *, char *, Line *));
  847. extern    void    do_alt_edit P((Xviwin *));
  848. extern    void    do_compare P((void));
  849.  
  850. /*
  851.  * ex_cmds2.c
  852.  */
  853. extern    void    do_shell P((Xviwin *));
  854. extern    void    do_shcmd P((Xviwin *, char *));
  855. extern    void    do_suspend P((Xviwin *));
  856. extern    void    do_equals P((Xviwin *, Line *));
  857. extern    void    do_help P((Xviwin *));
  858. extern    bool_t    do_source P((bool_t, char *));
  859. extern    char    *do_chdir P((char *));
  860. extern    void    do_cdmy P((int, Line *, Line *, Line *));
  861.  
  862. /*
  863.  * fileio.c
  864.  */
  865. extern    bool_t    set_format P((Xviwin *, Paramval, bool_t));
  866. extern    long    get_file P((Xviwin *, char *, Line **, Line **, char *,
  867.                             char *));
  868. extern    bool_t    writeit P((Xviwin *, char *, Line *, Line *, bool_t));
  869. extern    bool_t    put_file P((Xviwin *, FILE *, Line *, Line *,
  870.                 unsigned long *, unsigned long *));
  871.  
  872. /*
  873.  * find.c
  874.  */
  875. extern    Posn    *searchc P((int, int, int, int));
  876. extern    Posn    *crepsearch P((Buffer *, int, int));
  877. extern    Posn    *showmatch P((void));
  878. extern    Posn    *find_pattern P((char *, int, int));
  879. extern    Posn    *fwd_word P((Posn *, int, bool_t));
  880. extern    Posn    *bck_word P((Posn *, int, bool_t));
  881. extern    Posn    *end_word P((Posn *, int, bool_t));
  882. extern    bool_t    dosearch P((Xviwin *, char *, int));
  883.  
  884. /*
  885.  * flexbuf.c
  886.  */
  887. extern    bool_t    flexaddch P((Flexbuf *, int));
  888. extern    char    *flexgetstr P((Flexbuf *));
  889. extern    int    flexpopch P((Flexbuf *));
  890. extern    void    flexdelete P((Flexbuf *));
  891. extern    bool_t    vformat P((Flexbuf *, char *, va_list));
  892. extern    bool_t    lformat P((Flexbuf *, char *, ...));
  893.  
  894. /*
  895.  * map.c
  896.  */
  897. extern    void    stuff P((char *, ...));
  898. extern    int    map_getc P((void));
  899. extern    void    map_char P((int));
  900. extern    void    map_timeout P((void));
  901. extern    bool_t    map_waiting P((void));
  902. extern    int    mapped_char P((int));
  903. extern    void    xvi_map P((int, char **, bool_t, bool_t));
  904. extern    void    xvi_keymap P((char *, char *));
  905. extern    void    xvi_unmap P((int, char **, bool_t, bool_t));
  906. extern    void    do_unmap P((int, char **, bool_t, bool_t));
  907.  
  908. /*
  909.  * mark.c
  910.  */
  911. extern    void    init_marks P((Buffer *));
  912. extern    bool_t    setmark P((int, Buffer *, Posn *));
  913. extern    void    setpcmark P((Xviwin *));
  914. extern    Posn    *getmark P((int, Buffer *));
  915. extern    void    clrmark P((Line *, Buffer *));
  916.  
  917. /*
  918.  * misccmds.c
  919.  */
  920. extern    bool_t    openfwd P((bool_t));
  921. extern    bool_t    openbwd P((void));
  922. extern    long    cntllines P((Line *, Line *));
  923. extern    long    cntplines P((Xviwin *, Line *, Line *));
  924. extern    long    plines P((Xviwin *, Line *));
  925. extern    Line    *gotoline P((Buffer *, unsigned long));
  926. extern    int    get_indent P((Line *));
  927. extern    int    set_indent P((Line *, int));
  928. extern    void    tabinout P((int, Line *, Line *));
  929. extern    void    makeargv P((char *, int *, char ***, char *));
  930.  
  931. /*
  932.  * mouse.c
  933.  */
  934. extern    void    mouseclick P((int, int));
  935. extern    void    mousedrag P((int, int, int, int));
  936.  
  937. /*
  938.  * movement.c
  939.  */
  940. extern    int    shiftdown P((Xviwin *, unsigned));
  941. extern    int    shiftup P((Xviwin *, unsigned));
  942. extern    void    scrolldown P((Xviwin *, unsigned));
  943. extern    void    scrollup P((Xviwin *, unsigned));
  944. extern    bool_t    oneup P((Xviwin *, long));
  945. extern    bool_t    onedown P((Xviwin *, long));
  946. extern    bool_t    one_left P((Xviwin *, bool_t));
  947. extern    bool_t    one_right P((Xviwin *, bool_t));
  948. extern    void    begin_line P((Xviwin *, bool_t));
  949. extern    void    coladvance P((Xviwin *, int));
  950. extern    void    do_goto P((long));
  951. extern    void    move_cursor P((Xviwin *, Line *, int));
  952. extern    void    move_window_to_cursor P((Xviwin *));
  953. extern    void    move_cursor_to_window P((Xviwin *));
  954.  
  955. /*
  956.  * normal.c
  957.  */
  958. extern    bool_t    normal P((int));
  959.  
  960. /*
  961.  * param.c
  962.  */
  963. extern    void    init_params P((void));
  964. extern    void    do_set P((Xviwin *, int, char **, bool_t));
  965. extern    void    set_param P((int, ...));
  966.  
  967. /*
  968.  * pipe.c
  969.  */
  970. extern    void    specify_pipe_range P((Xviwin *, Line *, Line *));
  971. extern    void    do_pipe P((Xviwin *, char *));
  972.  
  973. /*
  974.  * preserve.c
  975.  */
  976. extern    bool_t    preservebuf P((Xviwin *));
  977. extern    bool_t    do_preserve P((void));
  978.  
  979. /*
  980.  * ptrfunc.c
  981.  */
  982. extern    enum mvtype    inc P((Posn *));
  983. extern    enum mvtype    dec P((Posn *));
  984. extern    void    pswap P((Posn *, Posn *));
  985. extern    bool_t    lt P((Posn *, Posn *));
  986.  
  987. /*
  988.  * screen.c
  989.  */
  990. extern    void    init_screen P((Xviwin *));
  991. extern    void    updateline P((Xviwin *));
  992. extern    void    update_sline P((Xviwin *));
  993. extern    void    update_window P((Xviwin *));
  994. extern    void    update_all P((void));
  995. extern    void    redraw_screen P((void));
  996. extern    void    clear P((Xviwin *));
  997. extern    void    s_ins P((Xviwin *, int, int));
  998. extern    void    s_del P((Xviwin *, int, int));
  999. extern    void    s_inschar P((Xviwin *, int));
  1000. extern    void    wind_goto P((Xviwin *));
  1001. extern    void    cmd_init P((Xviwin *, int));
  1002. extern    Cmd_State
  1003.         cmd_input P((Xviwin *, int));
  1004. extern    char    *get_cmd P((Xviwin *));
  1005. extern    void    gotocmd P((Xviwin *, bool_t));
  1006. extern    void    prompt P((char *));
  1007. extern    void    beep P((Xviwin *));
  1008. extern    void    disp_init P((Xviwin *, char *(*) P((void)), int, bool_t));
  1009. extern    bool_t    disp_screen P((Xviwin *));
  1010.  
  1011. /*
  1012.  * search.c
  1013.  */
  1014. extern    Posn    *search P((Xviwin *, Line *, int, int, char **));
  1015. extern    Posn    *nsearch P((Xviwin *, Line *, int, int, char *));
  1016. extern    Line    *linesearch P((Xviwin *, int, char **));
  1017. extern    void    do_global P((Xviwin *, Line *, Line *, char *, bool_t));
  1018. extern    long    do_substitute P((Xviwin *, Line *, Line *, char *));
  1019. extern    long    do_ampersand P((Xviwin *, Line *, Line *, char *));
  1020. extern    long    do_tilde P((Xviwin *, Line *, Line *, char *));
  1021.  
  1022. /*
  1023.  * signal.c
  1024.  */
  1025. extern    void    ignore_signals P((void));
  1026. extern    void    catch_signals P((void));
  1027.  
  1028. /*
  1029.  * status.c
  1030.  */
  1031. extern    void    init_sline P((Xviwin *));
  1032. extern    void    show_message P((Xviwin *, char *, ...));
  1033. extern    void    show_error P((Xviwin *, char *, ...));
  1034. extern    void    show_file_info P((Xviwin *));
  1035.  
  1036. /*
  1037.  * tags.c
  1038.  */
  1039. extern    bool_t    set_tags P((Xviwin *, Paramval, bool_t));
  1040. extern    void    tagword P((void));
  1041. extern    bool_t    do_tag P((Xviwin *, char *, bool_t, bool_t, bool_t));
  1042.  
  1043. /*
  1044.  * undo.c
  1045.  */
  1046. extern    void    init_undo P((Buffer *));
  1047. extern    bool_t    start_command P((Xviwin *));
  1048. extern    void    end_command P((Xviwin *));
  1049. extern    void    replchars P((Xviwin *, Line *, int, int, char *));
  1050. extern    void    repllines P((Xviwin *, Line *, long, Line *));
  1051. extern    void    replbuffer P((Xviwin *, Line *));
  1052. extern    void    undo P((Xviwin *));
  1053. extern    bool_t    set_edit P((Xviwin *, Paramval, bool_t));
  1054.  
  1055. /*
  1056.  * windows.c
  1057.  */
  1058. extern    Xviwin    *init_window P((VirtScr *));
  1059. extern    void    free_window P((Xviwin *));
  1060. extern    Xviwin    *split_window P((Xviwin *));
  1061. extern    void    map_window_onto_buffer P((Xviwin *, Buffer *));
  1062. extern    void    unmap_window P((Xviwin *));
  1063. extern    Xviwin    *next_window P((Xviwin *));
  1064. extern    Xviwin    *find_window P((Xviwin *, char *));
  1065. extern    void    resize_window P((Xviwin *, int));
  1066. extern    int    move_sline P((Xviwin *, int));
  1067. extern    void    update_buffer P((Buffer *));
  1068. extern    bool_t    can_split P((void));
  1069.  
  1070. /*
  1071.  * yankput.c
  1072.  */
  1073. extern    void    init_yankput P((void));
  1074. extern    bool_t    do_yank P((Buffer *, Posn *, Posn *, bool_t, int));
  1075. extern    bool_t    yank_str P((int, char *, bool_t));
  1076. extern    void    do_put P((Xviwin *, Posn *, int, int));
  1077. extern    void    yp_stuff_input P((Xviwin *, int, bool_t));
  1078. extern    void    yp_push_deleted P((void));
  1079.