home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume33 / xvi / part16 < prev    next >
Encoding:
Text File  |  1992-11-01  |  55.0 KB  |  2,378 lines

  1. Newsgroups: comp.sources.misc
  2. From: jmd@cyclone.bt.co.uk (John Downey)
  3. Subject:  v33i025:  xvi - portable multi-window vi-like editor, Part16/18
  4. Message-ID: <1992Oct24.172536.2452@sparky.imd.sterling.com>
  5. X-Md4-Signature: ce97faa7180d44bf36cc76e6ff28bef2
  6. Date: Sat, 24 Oct 1992 17:25:36 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jmd@cyclone.bt.co.uk (John Downey)
  10. Posting-number: Volume 33, Issue 25
  11. Archive-name: xvi/part16
  12. Environment: Unix, MS-DOS, OS/2, QNX
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  xvi/src/cursor.c xvi/src/events.c xvi/src/ibmpc_c.c
  19. #   xvi/src/makefile.386 xvi/src/mouse.c xvi/src/os2vio.h
  20. #   xvi/src/param.h xvi/src/pc386.c xvi/src/pipe.c xvi/src/preserve.c
  21. #   xvi/src/unix.h
  22. # Wrapped by kent@sparky on Thu Oct 22 09:03:44 1992
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 16 (of 18)."'
  26. if test -f 'xvi/src/cursor.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'xvi/src/cursor.c'\"
  28. else
  29.   echo shar: Extracting \"'xvi/src/cursor.c'\" \(3663 characters\)
  30.   sed "s/^X//" >'xvi/src/cursor.c' <<'END_OF_FILE'
  31. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  32. X#ifndef lint
  33. Xstatic char *sccsid = "@(#)cursor.c    2.2 (Chris & John Downey) 9/1/92";
  34. X#endif
  35. X
  36. X/***
  37. X
  38. X* program name:
  39. X    xvi
  40. X* function:
  41. X    PD version of UNIX "vi" editor, with extensions.
  42. X* module name:
  43. X    cursor.c
  44. X* module function:
  45. X    Deal with movement of the screen cursor - i.e. when the
  46. X    logical cursor moves within a buffer, work out the new
  47. X    position of the screen cursor within its window.
  48. X* history:
  49. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  50. X    Originally by Tim Thompson (twitch!tjt)
  51. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  52. X    Heavily modified by Chris & John Downey
  53. X
  54. X***/
  55. X
  56. X#include "xvi.h"
  57. X
  58. Xstatic    void    calc_position_in_line P((Xviwin *));
  59. X
  60. X/*
  61. X * Update the window's variables which say where the cursor is.
  62. X * These are row, col and virtcol, curswant if w_set_want_col.
  63. X *
  64. X * We also update w_c_line_size, which is used in screen.c to
  65. X * figure out whether the cursor line has changed size or not.
  66. X */
  67. Xvoid
  68. Xcursupdate(win)
  69. XXviwin    *win;
  70. X{
  71. X#if 0
  72. X    if (win->w_curs_new == FALSE) {
  73. X        return;
  74. X    }
  75. X#endif
  76. X    win->w_curs_new = FALSE;
  77. X
  78. X    /*
  79. X     * Calculate physical lines from logical lines.
  80. X     */
  81. X    win->w_row = cntplines(win, win->w_topline, win->w_cursor->p_line);
  82. X    win->w_c_line_size = plines(win, win->w_cursor->p_line);
  83. X
  84. X    /*
  85. X     * Calculate new position within the line.
  86. X     */
  87. X    calc_position_in_line(win);
  88. X}
  89. X
  90. X/*
  91. X * The cursor has moved along by nchars within the current line.
  92. X * Updating it here saves the overhead of cursupdate().
  93. X */
  94. Xvoid
  95. Xcurs_horiz(win, nchars)
  96. XXviwin    *win;
  97. Xint    nchars;
  98. X{
  99. X    /*
  100. X     * For the moment, just completely recalculate the position
  101. X     * in the line. More optimisation can come later.
  102. X     */
  103. X    /*
  104. X     * This doesn't work for longlines, because it recalculates
  105. X     * the row from a starting position of the current row, and
  106. X     * so adds (c_line_size - 1) to the row:
  107. X    calc_position_in_line(win);
  108. X     * so we just call cursupdate() instead.
  109. X     */
  110. X    win->w_curs_new = TRUE;
  111. X}
  112. X
  113. Xstatic void
  114. Xcalc_position_in_line(win)
  115. XXviwin    *win;
  116. X{
  117. X    register Posn    *curp;
  118. X    register int    c;
  119. X    register int    i;
  120. X    register unsigned    width;
  121. X    register int    ccol;
  122. X
  123. X    curp = win->w_cursor;
  124. X
  125. X    /*
  126. X     * Work out the virtual column within the current line.
  127. X     */
  128. X    ccol = Pb(P_number) ? NUM_SIZE : 0;
  129. X    for (i = width = 0; i <= curp->p_index; i++) {
  130. X
  131. X    c = curp->p_line->l_text[i];
  132. X    ccol += width;
  133. X    width = vischar(c, (char **) NULL, ccol);
  134. X    }
  135. X
  136. X    if (State != INSERT && c == '\t' && ! Pb(P_list) && Pb(P_tabs)) {
  137. X    /*
  138. X     * If we are inserting, or we're on a control
  139. X     * character other than a tab, or we aren't showing
  140. X     * tabs normally, the cursor goes to the first column
  141. X     * of the control character representation: otherwise,
  142. X     * if it's a tab & we aren't in insert mode, we place
  143. X     * the cursor on the last column of the tab
  144. X     * representation. (This is like the "real" vi.)
  145. X     */
  146. X    ccol += width - 1;
  147. X    }
  148. X
  149. X    /*
  150. X     * If showing line numbers, adjust the virtual column within the line.
  151. X     */
  152. X    win->w_virtcol = ccol - (Pb(P_number) ? NUM_SIZE : 0);
  153. X
  154. X    /*
  155. X     * Convert virtual column to screen column by line folding.
  156. X     */
  157. X    while (ccol >= win->w_ncols) {
  158. X    win->w_row++;
  159. X    ccol -= win->w_ncols;
  160. X    }
  161. X    win->w_col = ccol;
  162. X
  163. X    /*
  164. X     * Don't go past bottom line of window. (This should only
  165. X     * happen on a longline which is too big to fit in the
  166. X     * window.)
  167. X     */
  168. X    if (win->w_row >= win->w_nrows - 1) {
  169. X    win->w_row = win->w_nrows - 2;
  170. X    }
  171. X
  172. X    if (win->w_set_want_col) {
  173. X    win->w_curswant = win->w_virtcol;
  174. X    win->w_set_want_col = FALSE;
  175. X    }
  176. X}
  177. END_OF_FILE
  178.   if test 3663 -ne `wc -c <'xvi/src/cursor.c'`; then
  179.     echo shar: \"'xvi/src/cursor.c'\" unpacked with wrong size!
  180.   fi
  181.   # end of 'xvi/src/cursor.c'
  182. fi
  183. if test -f 'xvi/src/events.c' -a "${1}" != "-c" ; then 
  184.   echo shar: Will not clobber existing file \"'xvi/src/events.c'\"
  185. else
  186.   echo shar: Extracting \"'xvi/src/events.c'\" \(3643 characters\)
  187.   sed "s/^X//" >'xvi/src/events.c' <<'END_OF_FILE'
  188. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  189. X#ifndef lint
  190. Xstatic char *sccsid = "@(#)events.c    1.1 (Chris & John Downey) 7/31/92";
  191. X#endif
  192. X
  193. X/***
  194. X
  195. X* program name:
  196. X    xvi
  197. X* function:
  198. X    PD version of UNIX "vi" editor, with extensions.
  199. X* module name:
  200. X    events.c
  201. X* module function:
  202. X    Deals with incoming events.
  203. X    The main entry point for input to the editor.
  204. X* history:
  205. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  206. X    Originally by Tim Thompson (twitch!tjt)
  207. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  208. X    Heavily modified by Chris & John Downey
  209. X
  210. X***/
  211. X
  212. X#include "xvi.h"
  213. X
  214. Xstatic    bool_t    n_proc P((int));
  215. Xstatic    bool_t    c_proc P((int));
  216. Xstatic    bool_t    d_proc P((int));
  217. X
  218. Xvolatile int    keystrokes;
  219. X
  220. Xlong
  221. Xxvi_handle_event(ev)
  222. XxvEvent    *ev;
  223. X{
  224. X    bool_t        do_update;
  225. X    int        c;
  226. X
  227. X    switch (ev->ev_type) {
  228. X    case Ev_char:
  229. X    keystrokes++;
  230. X    map_char(ev->ev_inchar);
  231. X    break;
  232. X
  233. X    case Ev_timeout:
  234. X    if (map_waiting()) {
  235. X        map_timeout();
  236. X    } else if (keystrokes >= PSVKEYS) {
  237. X        do_preserve();
  238. X        keystrokes = 0;
  239. X    }
  240. X    break;
  241. X    }
  242. X
  243. X    /*
  244. X     * Look to see if the event produced any input characters
  245. X     * which we can feed into the editor. Call the appropriate
  246. X     * function for each one, according to the current State.
  247. X     */
  248. X    do_update = FALSE;
  249. X    while ((c = map_getc()) != EOF) {
  250. X    bool_t    (*func)P((int));
  251. X
  252. X    switch (State) {
  253. X    case NORMAL:
  254. X        func = n_proc;
  255. X        break;
  256. X
  257. X    case CMDLINE:
  258. X        func = c_proc;
  259. X        break;
  260. X
  261. X    case DISPLAY:
  262. X        func = d_proc;
  263. X        break;
  264. X
  265. X    case INSERT:
  266. X        func = i_proc;
  267. X        break;
  268. X
  269. X    case REPLACE:
  270. X        func = r_proc;
  271. X        break;
  272. X    }
  273. X    if ((*func)(c)) {
  274. X        do_update = TRUE;
  275. X    }
  276. X
  277. X    /*
  278. X     * Look at the resultant state, and the
  279. X     * result of the proc() routine, to see
  280. X     * whether to update the display.
  281. X     */
  282. X    switch (State) {
  283. X    case CMDLINE:
  284. X    case DISPLAY:
  285. X        break;
  286. X
  287. X    case NORMAL:
  288. X    case INSERT:
  289. X    case REPLACE:
  290. X        if (do_update) {
  291. X        move_window_to_cursor(curwin);
  292. X        cursupdate(curwin);
  293. X        wind_goto(curwin);
  294. X        }
  295. X    }
  296. X    }
  297. X
  298. X    if (kbdintr) {
  299. X    if (imessage) {
  300. X        show_message(curwin, "Interrupted");
  301. X        wind_goto(curwin);    /* put cursor back */
  302. X    }
  303. X    imessage = (kbdintr = 0);
  304. X    }
  305. X
  306. X    if (map_waiting()) {
  307. X    return((long) Pn(P_timeout));
  308. X    } else if (keystrokes >= PSVKEYS) {
  309. X    return((long) Pn(P_preservetime) * 1000);
  310. X    } else {
  311. X    return(0);
  312. X    }
  313. X}
  314. X
  315. X/*
  316. X * Process the given character in command mode.
  317. X */
  318. Xstatic bool_t
  319. Xn_proc(c)
  320. Xint    c;
  321. X{
  322. X    unsigned    savecho;
  323. X    bool_t    result;
  324. X
  325. X    savecho = echo;
  326. X    result = normal(c);
  327. X    echo = savecho;
  328. X    return(result);
  329. X}
  330. X
  331. X/*
  332. X * Returns TRUE if screen wants updating, FALSE otherwise.
  333. X */
  334. Xstatic bool_t
  335. Xc_proc(c)
  336. Xint    c;
  337. X{
  338. X    char    *cmdline;
  339. X
  340. X    switch (cmd_input(curwin, c)) {
  341. X    case cmd_CANCEL:
  342. X    /*
  343. X     * Put the status line back as it should be.
  344. X     */
  345. X    show_file_info(curwin);
  346. X    update_window(curwin);
  347. X    return(FALSE);
  348. X
  349. X    case cmd_INCOMPLETE:
  350. X    return(FALSE);
  351. X
  352. X    case cmd_COMPLETE:
  353. X    cmdline = get_cmd(curwin);
  354. X    (void) yank_str(cmdline[0], cmdline, TRUE);
  355. X    switch (cmdline[0]) {
  356. X    case '/':
  357. X    case '?':
  358. X        (void) dosearch(curwin, cmdline + 1, cmdline[0]);
  359. X        move_window_to_cursor(curwin);
  360. X        break;
  361. X
  362. X    case '!':
  363. X        do_pipe(curwin, cmdline + 1);
  364. X        break;
  365. X
  366. X    case ':':
  367. X        do_colon(cmdline + 1, TRUE);
  368. X    }
  369. X    return(TRUE);
  370. X    }
  371. X    /*NOTREACHED*/
  372. X}
  373. X
  374. X/*ARGSUSED*/
  375. Xstatic bool_t
  376. Xd_proc(c)
  377. Xint    c;
  378. X{
  379. X    if (c == CTRL('C')) {
  380. X    /*
  381. X     * In some environments it's possible to type
  382. X     * control-C without actually generating an interrupt,
  383. X     * but if they do, in this context, they probably want
  384. X     * the semantics of an interrupt anyway.
  385. X     */
  386. X    imessage = (kbdintr = 1);
  387. X    }
  388. X    return(disp_screen(curwin));
  389. X}
  390. END_OF_FILE
  391.   if test 3643 -ne `wc -c <'xvi/src/events.c'`; then
  392.     echo shar: \"'xvi/src/events.c'\" unpacked with wrong size!
  393.   fi
  394.   # end of 'xvi/src/events.c'
  395. fi
  396. if test -f 'xvi/src/ibmpc_c.c' -a "${1}" != "-c" ; then 
  397.   echo shar: Will not clobber existing file \"'xvi/src/ibmpc_c.c'\"
  398. else
  399.   echo shar: Extracting \"'xvi/src/ibmpc_c.c'\" \(5791 characters\)
  400.   sed "s/^X//" >'xvi/src/ibmpc_c.c' <<'END_OF_FILE'
  401. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  402. X#ifndef lint
  403. Xstatic char *sccsid = "@(#)ibmpc_c.c    2.1 (Chris & John Downey) 7/29/92";
  404. X#endif
  405. X
  406. X/***
  407. X
  408. X* program name:
  409. X    xvi
  410. X* function:
  411. X    PD version of UNIX "vi" editor, with extensions.
  412. X* module name:
  413. X    ibmpc_c.c
  414. X* module function:
  415. X    C part of terminal interface module for IBM PC compatibles
  416. X    running MS-DOS.
  417. X
  418. X* history:
  419. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  420. X    Originally by Tim Thompson (twitch!tjt)
  421. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  422. X    Heavily modified by Chris & John Downey
  423. X
  424. X***/
  425. X
  426. X#include "xvi.h"
  427. X
  428. X/*
  429. X * Screen dimensions, defined here so they'll go in the C default data
  430. X * segment.
  431. X */
  432. Xunsigned int    Rows;
  433. Xunsigned int    Columns;
  434. X
  435. X/*
  436. X * IBM-compatible PC's have a default typeahead buffer which is only
  437. X * big enough for 16 characters, & some 8088-based PC's are so
  438. X * unbelievably slow that xvi can't handle more than about 2
  439. X * characters a second. So we do some input buffering here to
  440. X * alleviate the problem.
  441. X */
  442. X
  443. Xstatic    char        kbuf[16];
  444. Xstatic    char        *kbrp = kbuf,
  445. Xstatic    char        *kbwp = kbuf;
  446. Xstatic    unsigned    kbcount;
  447. X
  448. Xstatic void near
  449. Xkbfill()
  450. X{
  451. X    register int    c;
  452. X
  453. X    while (kbcount < sizeof kbuf && (c = getchnw()) >= 0) {
  454. X    kbcount++;
  455. X    *kbwp = c;
  456. X    if (kbwp++ >= &kbuf[sizeof kbuf - 1])
  457. X        kbwp = kbuf;
  458. X    }
  459. X}
  460. X
  461. Xstatic unsigned char near
  462. Xkbget()
  463. X{
  464. X    for (;;) {
  465. X    if (kbcount > 0) {
  466. X        unsigned char c;
  467. X
  468. X        --kbcount;
  469. X        c = *kbrp;
  470. X        if (kbrp++ >= &kbuf[sizeof kbuf - 1])
  471. X        kbrp = kbuf;
  472. X        return c;
  473. X    } else {
  474. X        kbfill();
  475. X    }
  476. X    }
  477. X}
  478. X
  479. X/*
  480. X * Convert milliseconds to clock ticks.
  481. X */
  482. X#if CLK_TCK > 1000
  483. X#        define    MS2CLK(m)    ((long)(m) * (CLK_TCK / 1000))
  484. X#else
  485. X#    if CLK_TCK < 1000
  486. X#        define    MS2CLK(m)    ((long)(m) / (1000 / CLK_TCK))
  487. X#    else
  488. X#        define    MS2CLK(m)    (m)
  489. X#    endif
  490. X#endif
  491. X
  492. X/*
  493. X * inchar() - get a character from the keyboard
  494. X */
  495. Xint
  496. Xinchar(long mstimeout)
  497. X{
  498. X    clock_t        stoptime;
  499. X
  500. X    if (kbcount == 0) {
  501. X    flush_output();
  502. X    if (mstimeout != 0) {
  503. X        stoptime = clock() + MS2CLK(mstimeout);
  504. X    }
  505. X    kbfill();
  506. X    }
  507. X    for (;;) {
  508. X    static clock_t    lastevent;
  509. X    register int    c;
  510. X
  511. X    if (kbcount == 0) {
  512. X        unsigned    prevbstate;
  513. X        unsigned    prevx, prevy;
  514. X        bool_t    isdrag;
  515. X
  516. X        if (State == NORMAL) {
  517. X        showmouse();
  518. X        prevbstate = 0;
  519. X        }
  520. X        for (; kbcount == 0; kbfill()) {
  521. X        /*
  522. X         * Time out if we have to.
  523. X         */
  524. X        if (mstimeout != 0 && clock() > stoptime) {
  525. X            break;
  526. X        }
  527. X        if (State == NORMAL) {
  528. X            unsigned    buttonstate;
  529. X            unsigned    mousex,
  530. X                mousey;
  531. X
  532. X            /*
  533. X             * If there's no keyboard input waiting to be
  534. X             * read, watch out for mouse events. We don't do
  535. X             * this if we're in insert or command line mode.
  536. X             */
  537. X
  538. X            buttonstate = mousestatus(&mousex, &mousey) & 7;
  539. X            mousex /= 8;
  540. X            mousey /= 8;
  541. X            if (prevbstate == 0) {
  542. X            isdrag = FALSE;
  543. X            } else {
  544. X            if (buttonstate) {
  545. X                /*
  546. X                 * If a button is being held down, & the
  547. X                 * position has changed, this is a mouse
  548. X                 * drag event.
  549. X                 */
  550. X                if (mousex != prevx || mousey != prevy) {
  551. X                hidemouse();
  552. X                mousedrag(prevy, mousey, prevx, mousex);
  553. X                showmouse();
  554. X                isdrag = TRUE;
  555. X                }
  556. X            } else {
  557. X                if (!isdrag) {
  558. X                /*
  559. X                 * They've pressed & released a button
  560. X                 * without moving the mouse.
  561. X                 */
  562. X                hidemouse();
  563. X                mouseclick(mousey, mousex);
  564. X                showmouse();
  565. X                }
  566. X            }
  567. X            }
  568. X            if ((prevbstate = buttonstate) != 0) {
  569. X            prevx = mousex;
  570. X            prevy = mousey;
  571. X            }
  572. X        }
  573. X        }
  574. X        if (State == NORMAL) {
  575. X        hidemouse();
  576. X        }
  577. X        if (kbcount == 0) {
  578. X        /*
  579. X         * We must have timed out.
  580. X         */
  581. X        return EOF;
  582. X        }
  583. X    }
  584. X    c = kbget();
  585. X    /*
  586. X     * On IBM compatible PC's, function keys return '\0' followed
  587. X     * by another character. Check for this, and turn function key
  588. X     * presses into appropriate "normal" characters to do the
  589. X     * right thing in xvi.
  590. X     */
  591. X    if (c != '\0') {
  592. X        return(c);
  593. X    }
  594. X    /* else must be a function key press */
  595. X    {
  596. X        if (State != NORMAL) {
  597. X        /*
  598. X         * Function key pressed during insert or command line
  599. X         * mode. Get the next character ...
  600. X         */
  601. X        if (kbget() == 0x53) {
  602. X            /*
  603. X             * ... and if it's the delete key, return it as a
  604. X             * backspace ...
  605. X             */
  606. X            return '\b';
  607. X        }
  608. X        /*
  609. X         * ... otherwise it isn't valid ...
  610. X         */
  611. X        alert();
  612. X
  613. X        /*
  614. X         * Typical MS-DOS users are fairly naive & may not
  615. X         * understand how to get out of insert mode. To make
  616. X         * things easier, we do it for them here.
  617. X         */
  618. X        switch (State) {
  619. X        case INSERT:
  620. X        case REPLACE:
  621. X            return ESC;
  622. X        default:
  623. X            continue;
  624. X        }
  625. X        }
  626. X        /* else (State == NORMAL) ... */
  627. X        switch (kbget()) {
  628. X        case 0x3b: return(K_HELP);        /* F1 key */
  629. X        case 0x47: return('H');        /* home key */
  630. X        case 0x48: return('k');        /* up arrow key */
  631. X        case 0x49: return (CTRL('B'));    /* page up key */
  632. X        case 0x4b: return('\b');        /* left arrow key */
  633. X        case 0x4d: return(' ');        /* right arrow key */
  634. X        case 0x4f: return('L');        /* end key */
  635. X        case 0x50: return('j');        /* down arrow key */
  636. X        case 0x51: return (CTRL('F'));    /* page down key */
  637. X        case 0x52: return('i');        /* insert key */
  638. X        case 0x53: return('x');        /* delete key */
  639. X        /*
  640. X         * default:
  641. X         *    fall through and ignore both characters ...
  642. X         */
  643. X        }
  644. X        continue;
  645. X    }
  646. X    }
  647. X}
  648. X
  649. X#ifdef __ZTC__
  650. X#   ifdef DOS386
  651. X#    define Z386
  652. X#   endif
  653. X#endif
  654. X
  655. X#ifndef Z386
  656. X
  657. X/*
  658. X * The routines in ibmpc_a.asm need to call this because they can't
  659. X * invoke C macros directly.
  660. X *
  661. X * Return Pn(P_colour) in the al register, Pn(P_statuscolour) in ah, &
  662. X * Pb(P_vbell) in dx.
  663. X *
  664. X * This will only work with a Microsoft-compatible compiler.
  665. X */
  666. Xlong
  667. Xcparams()
  668. X{
  669. X    return ((long) Pb(P_vbell) << 16) |
  670. X       (unsigned short) ((Pn(P_statuscolour) << 8) |
  671. X         (unsigned char) Pn(P_colour));
  672. X}
  673. X
  674. X#endif    /* not Z386 */
  675. END_OF_FILE
  676.   if test 5791 -ne `wc -c <'xvi/src/ibmpc_c.c'`; then
  677.     echo shar: \"'xvi/src/ibmpc_c.c'\" unpacked with wrong size!
  678.   fi
  679.   # end of 'xvi/src/ibmpc_c.c'
  680. fi
  681. if test -f 'xvi/src/makefile.386' -a "${1}" != "-c" ; then 
  682.   echo shar: Will not clobber existing file \"'xvi/src/makefile.386'\"
  683. else
  684.   echo shar: Extracting \"'xvi/src/makefile.386'\" \(3534 characters\)
  685.   sed "s/^X//" >'xvi/src/makefile.386' <<'END_OF_FILE'
  686. X# Copyright (c) 1990,1991,1992 Chris and John Downey
  687. X#***
  688. X#
  689. X# @(#)makefile.386    2.2 (Chris & John Downey) 7/31/92
  690. X#
  691. X# program name:
  692. X#    xvi
  693. X# function:
  694. X#    PD version of UNIX "vi" editor, with extensions.
  695. X# module name:
  696. X#    makefile.386
  697. X# module function:
  698. X#    Makefile for MS-DOS 386 protected mode version using Zortech
  699. X#    C 3.00 & PharLap DOS extender.
  700. X# history:
  701. X#    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  702. X#    Originally by Tim Thompson (twitch!tjt)
  703. X#    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  704. X#    Heavily modified by Chris & John Downey
  705. X#***
  706. X
  707. X#
  708. X# Name of this file.
  709. X#
  710. XTHISFILE=    makefile.386
  711. X
  712. XMEMMODEL=    p
  713. XCC=        ztc
  714. XLIBDIR=        $(LIB)
  715. XPHARLAP=    d:\osu\pharlap
  716. XOPTFLAGS=    -o+dc -o+li -o+loop
  717. XDEBUGFLAGS=    -g
  718. XCDEFS=        -DMSDOS -D__STDC__=1
  719. XCFLAGS=        -m$(MEMMODEL) -bx $(CDEFS) $(OPTFLAGS)
  720. XLD=        $(PHARLAP)\386linkp
  721. XTARGET=        xvi
  722. X
  723. XINC=        ascii.h param.h ptrfunc.h regexp.h regmagic.h xvi.h \
  724. X        virtscr.h msdos.h pc386.h
  725. X
  726. XSRC=        defscr.c \
  727. X        alloc.c ascii.c buffers.c cmdline.c cursor.c \
  728. X        edit.c ex_cmds1.c ex_cmds2.c events.c flexbuf.c \
  729. X        fileio.c find.c map.c mark.c misccmds.c \
  730. X        mouse.c movement.c normal.c param.c pipe.c \
  731. X        preserve.c ptrfunc.c screen.c regexp.c \
  732. X        search.c startup.c status.c \
  733. X        tags.c undo.c version.c windows.c yankput.c \
  734. X        msdos_c.c ibmpc_c.c pc386.c
  735. X
  736. XOBJ=        defscr.obj \
  737. X        alloc.obj ascii.obj buffers.obj cmdline.obj cursor.obj \
  738. X        edit.obj ex_cmds1.obj ex_cmds2.obj events.obj flexbuf.obj \
  739. X        fileio.obj find.obj map.obj mark.obj misccmds.obj \
  740. X        mouse.obj movement.obj normal.obj param.obj pipe.obj \
  741. X        preserve.obj ptrfunc.obj screen.obj regexp.obj \
  742. X        search.obj startup.obj status.obj \
  743. X        tags.obj undo.obj version.obj windows.obj yankput.obj \
  744. X        msdos_c.obj ibmpc_c.obj pc386.obj
  745. X
  746. XLINKFILE=    $(TARGET).lnk
  747. X
  748. X$(TARGET).exe:    $(TARGET).exp
  749. X        $(PHARLAP)\bind386 $(PHARLAP)\run386b $(TARGET)
  750. X
  751. X$(TARGET).exp:    $(OBJ) $(LINKFILE) version.c
  752. X        $(CC) $(CFLAGS) -c version.c
  753. X        $(LD) @$(LINKFILE)
  754. X
  755. X$(LINKFILE):    $(THISFILE) echonl.com
  756. X        +echo $(LIBDIR)\realmode > $@
  757. X        # +echo $(LIBDIR)\int >> $@
  758. X        +echo defscr >> $@
  759. X        +echo alloc >> $@
  760. X        +echo ascii >> $@
  761. X        +echo buffers >> $@
  762. X        +echo cmdline >> $@
  763. X        +echo cursor >> $@
  764. X        +echo edit >> $@
  765. X        +echo ex_cmds1 >> $@
  766. X        +echo ex_cmds2 >> $@
  767. X        +echo events >> $@
  768. X        +echo flexbuf >> $@
  769. X        +echo fileio >> $@
  770. X        +echo find >> $@
  771. X        +echo map >> $@
  772. X        +echo mark >> $@
  773. X        +echo misccmds >> $@
  774. X        +echo mouse >> $@
  775. X        +echo movement >> $@
  776. X        +echo normal >> $@
  777. X        +echo param >> $@
  778. X        +echo pipe >> $@
  779. X        +echo preserve >> $@
  780. X        +echo ptrfunc >> $@
  781. X        +echo regexp >> $@
  782. X        +echo screen >> $@
  783. X        +echo search >> $@
  784. X        +echo startup >> $@
  785. X        +echo status >> $@
  786. X        +echo tags >> $@
  787. X        +echo undo >> $@
  788. X        +echo version >> $@
  789. X        +echo windows >> $@
  790. X        +echo yankput >> $@
  791. X        +echo msdos_c >> $@
  792. X        +echo ibmpc_c >> $@
  793. X        +echo pc386 >> $@
  794. X        +echonl >> $@
  795. X        +echo -lib $(LIBDIR)\zps.lib -tc -MAXREAL 4096 >> $@
  796. X        +echo -exe $(TARGET).exp >> $@
  797. X
  798. X.c.obj:
  799. X        $(CC) $(CFLAGS) -o$@ -c $<
  800. X
  801. X.asm.com:
  802. X        @masm $* ;
  803. X        @link $* ;
  804. X        @del $*.obj
  805. X        @exe2bin $*.exe $*.com
  806. X        @del $*.exe
  807. X
  808. Xechonl.com:    echonl.asm
  809. X
  810. X#
  811. X# Generate program to output a single newline. This is needed to
  812. X# generate the link file.
  813. X#
  814. Xechonl.asm:    $(THISFILE)
  815. X        +echo cseg segment > $@
  816. X        +echo assume cs:cseg >> $@
  817. X        +echo org 100h >> $@
  818. X        +echo start: >> $@
  819. X        +echo mov dx, offset crnl >> $@
  820. X        +echo mov ah, 9 >> $@
  821. X        +echo int 21h >> $@
  822. X        +echo mov ax, 4c00h >> $@
  823. X        +echo int 21h >> $@
  824. X        +echo crnl db 0dh, 0ah, 024h >> $@
  825. X        +echo cseg ends >> $@
  826. X        +echo end start >> $@
  827. X
  828. Xclean:
  829. X        del *.obj
  830. X        del $(LINKFILE)
  831. X        del *.map
  832. X        del echonl.com
  833. END_OF_FILE
  834.   if test 3534 -ne `wc -c <'xvi/src/makefile.386'`; then
  835.     echo shar: \"'xvi/src/makefile.386'\" unpacked with wrong size!
  836.   fi
  837.   # end of 'xvi/src/makefile.386'
  838. fi
  839. if test -f 'xvi/src/mouse.c' -a "${1}" != "-c" ; then 
  840.   echo shar: Will not clobber existing file \"'xvi/src/mouse.c'\"
  841. else
  842.   echo shar: Extracting \"'xvi/src/mouse.c'\" \(4855 characters\)
  843.   sed "s/^X//" >'xvi/src/mouse.c' <<'END_OF_FILE'
  844. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  845. X#ifndef lint
  846. Xstatic char *sccsid = "@(#)mouse.c    2.1 (Chris & John Downey) 7/29/92";
  847. X#endif
  848. X
  849. X/***
  850. X
  851. X* program name:
  852. X    xvi
  853. X* function:
  854. X    PD version of UNIX "vi" editor, with extensions.
  855. X* module name:
  856. X    mouse.c
  857. X* module function:
  858. X    Machine-independent mouse interface routines.
  859. X* history:
  860. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  861. X    Originally by Tim Thompson (twitch!tjt)
  862. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  863. X    Heavily modified by Chris & John Downey
  864. X***/
  865. X
  866. X#include "xvi.h"
  867. X
  868. X/*
  869. X * Find the Line corresponding to a given physical screen row.
  870. X *
  871. X * Also return (in *pstartrow) the physical screen row on which that
  872. X * Line starts.
  873. X */
  874. Xstatic Line *
  875. Xfindline(wp, row, pstartrow)
  876. XXviwin        *wp;
  877. Xregister int    row;
  878. Xint        *pstartrow;
  879. X{
  880. X    register int    lposn;
  881. X    int            maxrow;
  882. X    register Line    *lp;
  883. X    Line        *lastline;
  884. X
  885. X    lp = wp->w_topline;
  886. X    lastline = wp->w_buffer->b_lastline;
  887. X    lposn = wp->w_winpos;
  888. X    maxrow = wp->w_cmdline;
  889. X
  890. X    for (;;) {
  891. X    register int    newposn;
  892. X
  893. X    newposn = lposn + LONG2INT(plines(wp, lp));
  894. X    if (
  895. X        (
  896. X        /*
  897. X         * If we've found the right line ...
  898. X         */
  899. X        row >= lposn
  900. X        &&
  901. X        row < newposn
  902. X        )
  903. X        ||
  904. X        (
  905. X        /*
  906. X         * ... or we've got to the end of the buffer ...
  907. X         */
  908. X        lp->l_next == wp->w_buffer->b_lastline
  909. X        )
  910. X        ||
  911. X        (
  912. X        /*
  913. X         * ... or we're at the bottom of the window ...
  914. X         */
  915. X        newposn >= maxrow
  916. X        )
  917. X    ) {
  918. X        /*
  919. X         * ... we return this line.
  920. X         */
  921. X        *pstartrow = lposn;
  922. X        return lp;
  923. X    }
  924. X    lposn = newposn;
  925. X    lp = lp->l_next;
  926. X    }
  927. X}
  928. X
  929. X/*
  930. X * Move the text cursor as near as possible to the given physical
  931. X * screen co-ordinates.
  932. X */
  933. Xstatic void
  934. Xsetcursor(wp, row, col)
  935. XXviwin    *wp;
  936. Xint    row;        /* row where mouse was clicked */
  937. Xint    col;        /* column where mouse was clicked */
  938. X{
  939. X    int        startrow;    /* row at which line starts */
  940. X    int        vcol;        /* virtual column */
  941. X    Line    *lp;        /* logical line corresponding to row */
  942. X
  943. X    lp = findline(wp, row, &startrow);
  944. X    vcol = col + ((row - startrow) * wp->w_ncols);
  945. X    move_cursor(wp, lp, 0);
  946. X    coladvance(wp, (wp->w_curswant = vcol));
  947. X}
  948. X
  949. X/*
  950. X * Find the window a given physical screen row is in.
  951. X */
  952. Xstatic Xviwin *
  953. Xfindwin(row)
  954. Xregister int    row;
  955. X{
  956. X    register Xviwin    *wp;
  957. X
  958. X    wp = curwin;
  959. X    for (;;) {
  960. X    if (wp->w_winpos <= row && row <= wp->w_cmdline) {
  961. X        /*
  962. X         * We've found the right window.
  963. X         */
  964. X        return wp;
  965. X    }
  966. X    if ((wp = next_window(wp)) == curwin) {
  967. X        /*
  968. X         * This can't happen: the mouse isn't in any
  969. X         * window.
  970. X         */
  971. X        return NULL;
  972. X    }
  973. X    }
  974. X}
  975. X
  976. X/*
  977. X * Handle mouse drag event.
  978. X */
  979. Xvoid
  980. Xmousedrag(row1, row2, col1, col2)
  981. Xint row1, row2, col1, col2;
  982. X{
  983. X    if (State == NORMAL && row1 != row2 && row1 < Rows - 1) {
  984. X    Xviwin *wp;
  985. X
  986. X    if ((wp = findwin(row1)) == NULL) {
  987. X        /*
  988. X         * This can't happen.
  989. X         */
  990. X        return;
  991. X    }
  992. X
  993. X    if (wp->w_cmdline == row1) {
  994. X        unsigned savecho;
  995. X
  996. X        savecho = echo;
  997. X        echo &= ~e_CHARUPDATE;
  998. X
  999. X        (void) move_sline(wp, row2 - row1);
  1000. X
  1001. X        echo = savecho;
  1002. X
  1003. X        move_cursor_to_window(curwin);
  1004. X        update_all();
  1005. X        cursupdate(curwin);
  1006. X        wind_goto(curwin);
  1007. X    }
  1008. X    }
  1009. X}
  1010. X
  1011. X/*
  1012. X * This function is called by the (obviously machine-dependent) mouse
  1013. X * event handling code when a mouse button is pressed & released.
  1014. X *
  1015. X * The algorithm we use here is semantically complicated, but seems to
  1016. X * be fairly intuitive in actual use.
  1017. X */
  1018. Xvoid
  1019. Xmouseclick(row, col)
  1020. Xregister int    row;    /* row the mouse cursor is in */
  1021. Xint        col;    /* column the mouse cursor is in */
  1022. X{
  1023. X    register Xviwin    *wp;
  1024. X
  1025. X    if (State != NORMAL) {
  1026. X    return;
  1027. X    }
  1028. X
  1029. X    /*
  1030. X     * First find which window the mouse is in.
  1031. X     */
  1032. X    if ((wp = findwin(row)) == NULL) {
  1033. X    /*
  1034. X     * This can't happen.
  1035. X     */
  1036. X    return;
  1037. X    }
  1038. X
  1039. X    if (wp != curwin) {
  1040. X    /*
  1041. X     * The window the mouse is in isn't the current window.
  1042. X     * Make it the current window.
  1043. X     */
  1044. X    curwin = wp;
  1045. X    curbuf = wp->w_buffer;
  1046. X    }
  1047. X
  1048. X    if (row == wp->w_cmdline) {
  1049. X    /*
  1050. X     * If the mouse is on the status line of any window,
  1051. X     * we update the information on the status line. This
  1052. X     * applies whether or not it was already the current
  1053. X     * window.
  1054. X     */
  1055. X    show_file_info(wp);
  1056. X    } else {
  1057. X    /*
  1058. X     * Move the cursor as near as possible to where the
  1059. X     * mouse was clicked.
  1060. X     */
  1061. X    setcursor(wp, row, col);
  1062. X
  1063. X    /*
  1064. X     * If the window has at least 2 text rows, and ...
  1065. X     */
  1066. X    if (wp->w_nrows > 2) {
  1067. X        if (row == wp->w_winpos) {
  1068. X        /*
  1069. X         * ... we're on the top line of the
  1070. X         * window - scroll down ...
  1071. X         */
  1072. X        scrolldown(wp, (unsigned) 1);
  1073. X        update_window(wp);
  1074. X        } else if (row == wp->w_cmdline - 1) {
  1075. X        /*
  1076. X         * ... or we're on the bottom line of
  1077. X         * the window - scroll up ...
  1078. X         */
  1079. X        scrollup(wp, (unsigned) 1);
  1080. X        update_window(wp);
  1081. X        }
  1082. X    }
  1083. X    }
  1084. X
  1085. X    /*
  1086. X     * Make sure physical screen and cursor position are updated.
  1087. X     */
  1088. X    cursupdate(wp);
  1089. X    wind_goto(wp);
  1090. X}
  1091. END_OF_FILE
  1092.   if test 4855 -ne `wc -c <'xvi/src/mouse.c'`; then
  1093.     echo shar: \"'xvi/src/mouse.c'\" unpacked with wrong size!
  1094.   fi
  1095.   # end of 'xvi/src/mouse.c'
  1096. fi
  1097. if test -f 'xvi/src/os2vio.h' -a "${1}" != "-c" ; then 
  1098.   echo shar: Will not clobber existing file \"'xvi/src/os2vio.h'\"
  1099. else
  1100.   echo shar: Extracting \"'xvi/src/os2vio.h'\" \(4160 characters\)
  1101.   sed "s/^X//" >'xvi/src/os2vio.h' <<'END_OF_FILE'
  1102. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  1103. X/***
  1104. X* @(#)os2vio.h    2.1 (Chris & John Downey) 7/29/92
  1105. X
  1106. X* program name:
  1107. X    xvi
  1108. X* function:
  1109. X    PD version of UNIX "vi" editor, with extensions.
  1110. X* module name:
  1111. X    os2vio.h
  1112. X* module function:
  1113. X    Definitions for OS/2 system interface.
  1114. X* history:
  1115. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  1116. X    Originally by Tim Thompson (twitch!tjt)
  1117. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  1118. X    Heavily modified by Chris & John Downey
  1119. X
  1120. X***/
  1121. X
  1122. X/*
  1123. X * System include files.
  1124. X */
  1125. X#define INCL_BASE
  1126. X#define INCL_DOS
  1127. X#define INCL_SUB
  1128. X#define INCL_DOSERRORS
  1129. X
  1130. X#include <os2.h>
  1131. X
  1132. X/*
  1133. X * Include files for Microsoft C library.
  1134. X */
  1135. X#include <fcntl.h>
  1136. X#include <malloc.h>
  1137. X#include <process.h>
  1138. X#include <stdlib.h>
  1139. X#include <time.h>
  1140. X#ifndef SIGINT
  1141. X#   include <signal.h>
  1142. X#endif
  1143. X
  1144. X/*
  1145. X * This is a multi-thread program, so we allocate multiple stacks
  1146. X * within the same stack segment, so there isn't much point in letting
  1147. X * the compiler put in stack probes.
  1148. X */
  1149. X#pragma check_stack(off)
  1150. X
  1151. X#ifndef HELPFILE
  1152. X#   define HELPFILE    "d:\\jmd\\xvi\\help"
  1153. X#endif
  1154. X
  1155. X/*
  1156. X * System-dependent constants.
  1157. X *
  1158. X * These are right for MS-DOS & (I think) OS/2. (jmd)
  1159. X */
  1160. X#define    MAXPATHLEN    143    /* maximum length of full path name */
  1161. X#define    MAXNAMLEN    12    /* maximum length of file name */
  1162. X#define    DIRSEPS        "\\/"    /*
  1163. X                 * directory separators within
  1164. X                 * pathnames
  1165. X                 */
  1166. X
  1167. X/*
  1168. X * Under OS/2, characters with the top bit set are perfectly valid
  1169. X * (although not necessarily always what you want to see).
  1170. X */
  1171. X#define    DEF_CCHARS    TRUE
  1172. X#define    DEF_MCHARS    TRUE
  1173. X
  1174. X#define    SETVBUF_AVAIL
  1175. X#define    WRTBUFSIZ    0x7000
  1176. X#define    READBUFSIZ    0x7000
  1177. X
  1178. Xextern unsigned        Rows, Columns;
  1179. Xextern unsigned char    virt_row, virt_col;
  1180. Xextern unsigned char    curcell[2];
  1181. X
  1182. X/*
  1183. X * Default value for P_format parameter.
  1184. X */
  1185. X#define DEF_TFF        fmt_OS2
  1186. X
  1187. X/*
  1188. X * Terminal driving functions - just use macros here.
  1189. X */
  1190. X#define insert_line()        /* insert one line */
  1191. X#define delete_line()        /* delete one line */
  1192. X#define save_cursor()        /* save cursor position */
  1193. X#define restore_cursor()    /* restore cursor position */
  1194. X#define invis_cursor()        /* invisible cursor */
  1195. X#define vis_cursor()        /* visible cursor */
  1196. X#define tty_goto(r,c)    (virt_row = (r), virt_col = (c))
  1197. X#define cost_goto    0    /* cost of using tty_goto() */
  1198. X
  1199. X/*
  1200. X * Update actual screen cursor position. This is the only output flushing we
  1201. X * need to do, because outstr() & outchar() use system calls which update
  1202. X * video memory directly.
  1203. X */
  1204. X#define flush_output()    VioSetCurPos(virt_row, virt_col, 0)
  1205. X
  1206. X#define can_ins_line    FALSE
  1207. X#define can_del_line    FALSE
  1208. X#define can_scroll_area TRUE
  1209. X/*
  1210. X * tty_linefeed() isn't needed if can_scroll_area is TRUE.
  1211. X */
  1212. X#define tty_linefeed()
  1213. X
  1214. X#define can_inschar    FALSE
  1215. X#define inschar(c)
  1216. X
  1217. X#define set_colour(a)    (curcell[1] = (a))
  1218. X/*
  1219. X * User-definable screen colours. Default values are for mono
  1220. X * displays.
  1221. X */
  1222. X#define DEF_COLOUR    7
  1223. X#define DEF_STCOLOUR    112
  1224. X#define DEF_SYSCOLOUR    7
  1225. X
  1226. X#define alert()        DosBeep(2000, 150)
  1227. X
  1228. X/*
  1229. X * Macros to open files in binary mode,
  1230. X * and to expand filenames.
  1231. X */
  1232. X#define fopenrb(f)    fopen((f),"rb")
  1233. X#define fopenwb(f)    fopen((f),"wb")
  1234. X#define fexpand(f)    (f)
  1235. X
  1236. X/*
  1237. X * exists(): TRUE if file exists.
  1238. X */
  1239. X#define exists(f)    (access((f),0) == 0)
  1240. X/*
  1241. X * can_write(): TRUE if file does not exist or exists and is writeable.
  1242. X */
  1243. X#define can_write(f)    (access((f),0) != 0 || access((f), 2) == 0)
  1244. X#define delay()        DosSleep((long) 200)
  1245. X#define call_shell(s)    spawnlp(P_WAIT, (s), (s), (char *) NULL)
  1246. X#define call_system(s)    system(s)
  1247. X
  1248. X/*
  1249. X * Declarations for system interface routines in os2vio.c.
  1250. X */
  1251. Xextern    void        erase_display(void);
  1252. Xextern    void        erase_line(void);
  1253. Xextern    int        inchar(long);
  1254. Xextern    void        outchar(int);
  1255. Xextern    void        outstr(char*);
  1256. Xextern    void        scroll_down(unsigned, unsigned, unsigned);
  1257. Xextern    void        scroll_up(unsigned, unsigned, unsigned);
  1258. Xextern    char        *tempfname(char *);
  1259. Xextern    void        sys_init(void);
  1260. Xextern    void        sys_exit(int);
  1261. Xextern    bool_t        sys_pipe P((char *, int (*)(FILE *), long (*)(FILE *)));
  1262. Xextern    void        sys_startv(void);
  1263. Xextern    void        sys_endv(void);
  1264. X
  1265. X/*
  1266. X * in i286.asm:
  1267. X */
  1268. Xextern void far            es0(void);
  1269. Xextern unsigned char * far    newstack(int);
  1270. END_OF_FILE
  1271.   if test 4160 -ne `wc -c <'xvi/src/os2vio.h'`; then
  1272.     echo shar: \"'xvi/src/os2vio.h'\" unpacked with wrong size!
  1273.   fi
  1274.   # end of 'xvi/src/os2vio.h'
  1275. fi
  1276. if test -f 'xvi/src/param.h' -a "${1}" != "-c" ; then 
  1277.   echo shar: Will not clobber existing file \"'xvi/src/param.h'\"
  1278. else
  1279.   echo shar: Extracting \"'xvi/src/param.h'\" \(4258 characters\)
  1280.   sed "s/^X//" >'xvi/src/param.h' <<'END_OF_FILE'
  1281. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  1282. X/***
  1283. X
  1284. X* @(#)param.h    2.1 (Chris & John Downey) 7/29/92
  1285. X
  1286. X* program name:
  1287. X    xvi
  1288. X* function:
  1289. X    PD version of UNIX "vi" editor, with extensions.
  1290. X* module name:
  1291. X    param.h
  1292. X* module function:
  1293. X    Definitions for parameter access.
  1294. X
  1295. X    This is all going to change when we have local parameters.
  1296. X* history:
  1297. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  1298. X    Originally by Tim Thompson (twitch!tjt)
  1299. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  1300. X    Heavily modified by Chris & John Downey
  1301. X
  1302. X***/
  1303. X
  1304. X/*
  1305. X * Settable parameters.
  1306. X */
  1307. X
  1308. Xtypedef union {
  1309. X    int        pv_i;
  1310. X    bool_t    pv_b;
  1311. X    char    *pv_s;
  1312. X    char    **pv_l;
  1313. X} Paramval;
  1314. X
  1315. Xtypedef    struct    param {
  1316. X    char    *p_fullname;    /* full parameter name */
  1317. X    char    *p_shortname;    /* permissible abbreviation */
  1318. X    int        p_flags;    /* type of parameter, and whether implemented */
  1319. X
  1320. X    /*
  1321. X     * This field is used for numeric and boolean values,
  1322. X     * and for storing the numeric representation for enums.
  1323. X     */
  1324. X    int        p_value;
  1325. X
  1326. X    /*
  1327. X     * Special function to set parameter.
  1328. X     * This is called whenever the parameter is set by the user.
  1329. X     */
  1330. X    bool_t    (*p_func) P((Xviwin *, Paramval, bool_t));
  1331. X
  1332. X    /*
  1333. X     * This field is used for strings, lists and enums.
  1334. X     * Note that making this the last field allows us to initialise the
  1335. X     * parameter table, since we can just leave this field uninitialised.
  1336. X     */
  1337. X    union {
  1338. X    char    *pu_str;
  1339. X    char    **pu_list;
  1340. X    } pu;
  1341. X} Param;
  1342. X
  1343. X#define    p_num    p_value
  1344. X#define    p_bool    p_value
  1345. X#define    p_eval    p_value
  1346. X
  1347. X#define    p_str    pu.pu_str
  1348. X#define    p_list    pu.pu_list
  1349. X#define    p_elist    pu.pu_list
  1350. X
  1351. X#ifdef __ZTC__
  1352. X#   define    PFUNCADDR(f)    ((bool_t (*)(Xviwin *, Paramval, bool_t))(f))
  1353. X#else
  1354. X#   define    PFUNCADDR(f)    (f)
  1355. X#endif
  1356. X
  1357. Xextern    Param    params[];
  1358. X
  1359. X/*
  1360. X * Flags
  1361. X */
  1362. X#define    P_BOOL        0x01    /* the parameter is boolean */
  1363. X#define    P_NUM        0x02    /* the parameter is numeric */
  1364. X#define    P_STRING    0x04    /* the parameter is a string */
  1365. X#define    P_ENUM        0x08    /* the parameter is an enumerated type */
  1366. X#define    P_LIST        0x20    /* the parameter is a list of strings */
  1367. X
  1368. X#define    P_TYPE        0x2f    /* used to mask out type from other bits */
  1369. X
  1370. X#define    P_CHANGED    0x10    /* the parameter has been changed */
  1371. X
  1372. X/*
  1373. X * Macros to set/get the value of a parameter.
  1374. X * One each for the four parameter types.
  1375. X * May change implementation later to do more checking.
  1376. X */
  1377. X#define    Pn(n)        (params[n].p_num)
  1378. X#define    Pb(n)        (params[n].p_bool)
  1379. X#define    Ps(n)        (params[n].p_str)
  1380. X#define    Pl(n)        (params[n].p_list)
  1381. X#define    Pen(n)        (params[n].p_value)
  1382. X#define    Pes(n)        (params[n].p_elist[params[n].p_eval])
  1383. X
  1384. X#define P_ischanged(n)    (params[n].p_flags & P_CHANGED)
  1385. X#define P_setchanged(n)    (params[n].p_flags |= P_CHANGED)
  1386. X
  1387. X/*
  1388. X * The following are the indices in the params array for each parameter.
  1389. X * They must not be changed without also changing the table in "param.c".
  1390. X */
  1391. X#define P_ada        0
  1392. X#define P_adapath     1
  1393. X#define P_autoindent     2
  1394. X#define P_autoprint     3
  1395. X#define P_autosplit     4
  1396. X#define P_autowrite     5
  1397. X#define P_beautify     6
  1398. X#define P_cchars     7
  1399. X#define P_colour     8
  1400. X#define P_directory     9
  1401. X#define P_edcompatible     10
  1402. X#define P_edit         11
  1403. X#define P_errorbells     12
  1404. X#define P_format     13
  1405. X#define P_hardtabs     14
  1406. X#define P_helpfile     15
  1407. X#define P_ignorecase     16
  1408. X#define P_jumpscroll     17
  1409. X#define P_lisp         18
  1410. X#define P_list         19
  1411. X#define P_magic     20
  1412. X#define P_mchars     21
  1413. X#define P_mesg         22
  1414. X#define P_minrows     23
  1415. X#define P_modeline     24
  1416. X#define P_number     25
  1417. X#define P_open         26
  1418. X#define P_optimize     27
  1419. X#define P_paragraphs     28
  1420. X#define P_preserve     29
  1421. X#define P_preservetime     30
  1422. X#define P_prompt     31
  1423. X#define P_readonly     32
  1424. X#define P_redraw     33
  1425. X#define P_regextype     34
  1426. X#define P_remap     35
  1427. X#define P_report     36
  1428. X#define P_roscolour     37
  1429. X#define P_scroll     38
  1430. X#define P_sections     39
  1431. X#define P_sentences     40
  1432. X#define P_shell     41
  1433. X#define P_shiftwidth     42
  1434. X#define P_showmatch     43
  1435. X#define P_slowopen     44
  1436. X#define P_sourceany     45
  1437. X#define P_statuscolour     46
  1438. X#define P_systemcolour     47
  1439. X#define P_tabs         48
  1440. X#define P_tabstop     49
  1441. X#define P_taglength     50
  1442. X#define P_tags         51
  1443. X#define P_term         52
  1444. X#define P_terse     53
  1445. X#define P_timeout     54
  1446. X#define P_ttytype     55
  1447. X#define P_vbell     56
  1448. X#define P_warn         57
  1449. X#define P_window     58
  1450. X#define P_wrapmargin     59
  1451. X#define P_wrapscan     60
  1452. X#define P_writeany     61
  1453. END_OF_FILE
  1454.   if test 4258 -ne `wc -c <'xvi/src/param.h'`; then
  1455.     echo shar: \"'xvi/src/param.h'\" unpacked with wrong size!
  1456.   fi
  1457.   # end of 'xvi/src/param.h'
  1458. fi
  1459. if test -f 'xvi/src/pc386.c' -a "${1}" != "-c" ; then 
  1460.   echo shar: Will not clobber existing file \"'xvi/src/pc386.c'\"
  1461. else
  1462.   echo shar: Extracting \"'xvi/src/pc386.c'\" \(5712 characters\)
  1463.   sed "s/^X//" >'xvi/src/pc386.c' <<'END_OF_FILE'
  1464. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  1465. X#ifndef lint
  1466. Xstatic char *sccsid = "@(#)pc386.c    2.1 (Chris & John Downey) 7/29/92";
  1467. X#endif
  1468. X
  1469. X/***
  1470. X
  1471. X* program name:
  1472. X    xvi
  1473. X* function:
  1474. X    PD version of UNIX "vi" editor, with extensions.
  1475. X* module name:
  1476. X    pc386.c
  1477. X* module function:
  1478. X    Routines for MS-DOS 386 protected mode version.
  1479. X
  1480. X    This file implements the same routines as ibmpc_a.asm &
  1481. X    msdos_a.asm, which are for the real mode version.
  1482. X
  1483. X    Zortech C++ version 3.0 or later & an appropriate DOS extender
  1484. X    package (such as PharLap's) are required.
  1485. X* history:
  1486. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  1487. X    Originally by Tim Thompson (twitch!tjt)
  1488. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  1489. X    Heavily modified by Chris & John Downey
  1490. X***/
  1491. X
  1492. X#include "xvi.h"
  1493. X
  1494. X#include <cerror.h>
  1495. X#include <controlc.h>
  1496. X
  1497. X/*
  1498. X * Virtual mode handling.
  1499. X *
  1500. X * On EGA's & VGA's, the number of rows in text modes can vary because
  1501. X * fonts with different sizes can be loaded, so we use virtual modes
  1502. X * to contain the additional information needed. (Actually, we handle
  1503. X * it a bit simplistically because the Zortech display library only
  1504. X * knows about certain cases: 25 rows (default), 43 rows (EGA with
  1505. X * 8 x 8 font) & 50 rows (VGA with 8 x 8 font). The last two are
  1506. X * treated as equivalent.)
  1507. X */
  1508. X#define MONO25X80    2
  1509. X#define COLOUR25X80    3
  1510. X#define MDA25X80    7
  1511. X#define MASK43        043000
  1512. X#define COLOUR43X80    (COLOUR25X80 | MASK43)
  1513. X#define MONO43X80    (MONO25X80 | MASK43)
  1514. X#define MDA43X80    (MDA25X80 | MASK43)
  1515. X
  1516. Xstatic unsigned
  1517. Xgetvmode()
  1518. X{
  1519. X    unsigned    mode;
  1520. X
  1521. X    if ((mode = disp_getmode()) == COLOUR25X80 || mode == MONO25X80 ||
  1522. X                                mode == MDA25X80) {
  1523. X    if (disp_numrows > 25) {
  1524. X        return mode | MASK43;
  1525. X    }
  1526. X    }
  1527. X    return mode;
  1528. X}
  1529. X
  1530. Xstatic void
  1531. Xsetvmode(unsigned vmode)
  1532. X{
  1533. X    {
  1534. X    int    mode;
  1535. X
  1536. X    if (disp_getmode() != (mode = vmode & ~MASK43)) {
  1537. X        disp_close();
  1538. X        disp_setmode(mode);
  1539. X        disp_open();
  1540. X    }
  1541. X    }
  1542. X    {
  1543. X    unsigned    m43;
  1544. X
  1545. X    m43 = vmode & MASK43;
  1546. X    if (disp_ega && ((m43 && disp_numrows <= 25) ||
  1547. X             (!m43 && disp_numrows > 25))) {
  1548. X        disp_close();
  1549. X        if (m43) {
  1550. X        disp_set43();
  1551. X        } else {
  1552. X        disp_reset43();
  1553. X        }
  1554. X        disp_open();
  1555. X    }
  1556. X    }
  1557. X}
  1558. X
  1559. Xstatic unsigned startmode;        /* system virtual mode */
  1560. X
  1561. X#if 0
  1562. X
  1563. X/*
  1564. X * Critical error handler.
  1565. X *
  1566. X * See notes in msdos_a.asm.
  1567. X */
  1568. Xstatic int _far _cdecl
  1569. Xcriterr(int *pax, int *pdi)
  1570. X{
  1571. X    *pax = ((_osmajor >= 3) ? 3 : 0);
  1572. X}
  1573. X
  1574. X#endif
  1575. X
  1576. X/*
  1577. X * Keyboard interrupt handler.
  1578. X */
  1579. Xstatic void _cdecl
  1580. Xinthandler(void)
  1581. X{
  1582. X    kbdintr = 1;
  1583. X#if 0
  1584. X    return(-1);    /* don't chain to previously installed vector */
  1585. X#endif
  1586. X}
  1587. X
  1588. X/*
  1589. X * Install interrupt handlers.
  1590. X */
  1591. Xvoid
  1592. Xmsdsignal(unsigned char *flagp)
  1593. X{
  1594. X    _controlc_handler = inthandler;
  1595. X    controlc_open();
  1596. X#if 0
  1597. X    _cerror_handler = criterr;
  1598. X    cerror_open();
  1599. X    int_intercept(0x23, inthandler, 0);
  1600. X    int_intercept(0x24, criterr, 0);
  1601. X#endif
  1602. X}
  1603. X
  1604. Xvoid
  1605. Xcatch_signals(void)
  1606. X{
  1607. X    /*
  1608. X     * Set console break flag so that we can be interrupted even
  1609. X     * when we're not waiting for console input.
  1610. X     */
  1611. X    dos_set_ctrl_break(1);
  1612. X}
  1613. X
  1614. X/*
  1615. X * Pointer to copy of previous screen.
  1616. X */
  1617. Xstatic unsigned short *oldscreen = NULL;
  1618. X
  1619. Xvoid
  1620. Xtty_open(unsigned *prows, unsigned *pcolumns)
  1621. X{
  1622. X    if (!disp_inited) {
  1623. X    disp_open();
  1624. X    }
  1625. X    startmode = getvmode();
  1626. X
  1627. X    if (disp_base) {
  1628. X    /*
  1629. X     * Allocate storage for copy of previous screen
  1630. X     * (except bottom line).
  1631. X     *
  1632. X     * We don't do this if we're using BIOS calls
  1633. X     * (indicated by disp_base == 0) because the BIOS
  1634. X     * doesn't do it very well (it causes a lot of cursor
  1635. X     * flicker).
  1636. X     */
  1637. X    oldscreen = (unsigned short *)
  1638. X            malloc((disp_numrows - 1) * disp_numcols *
  1639. X                        sizeof(unsigned short));
  1640. X    }
  1641. X    *prows = disp_numrows;
  1642. X    *pcolumns = disp_numcols;
  1643. X}
  1644. X
  1645. Xstatic enum {
  1646. X    m_INITIAL = 0,
  1647. X    m_SYS = 1,
  1648. X    m_VI = 2
  1649. X}    curmode;
  1650. X
  1651. X/*
  1652. X * Save screen contents & set up video state for editor.
  1653. X */
  1654. Xvoid
  1655. Xtty_startv(void)
  1656. X{
  1657. X    switch (curmode) {
  1658. X    case m_VI:
  1659. X    /*
  1660. X     * We're already in vi mode.
  1661. X     */
  1662. X    return;
  1663. X    case m_SYS:
  1664. X    /*
  1665. X     * This isn't the first call. Force display
  1666. X     * package's variables to be re-initialized.
  1667. X     */
  1668. X    disp_close();
  1669. X    disp_open();
  1670. X    }
  1671. X    curmode = m_VI;
  1672. X    if (getvmode() != startmode) {
  1673. X    /*
  1674. X     * The display mode has changed; set it back to what we
  1675. X     * started with.
  1676. X     */
  1677. X    setvmode(startmode);
  1678. X    }
  1679. X    if (oldscreen) {
  1680. X    /*
  1681. X     * Save screen contents (except bottom line) so they
  1682. X     * can be restored afterwards.
  1683. X     */
  1684. X    disp_peekbox(oldscreen, 0, 0, disp_numrows - 2, disp_numcols - 1);
  1685. X    }
  1686. X    msm_init();
  1687. X    /*
  1688. X     * Apparently, the Microsoft mouse driver sometimes
  1689. X     * gets the number of screen rows wrong.
  1690. X     */
  1691. X    msm_setareay(0, (disp_numrows - 1) * 8);
  1692. X}
  1693. X
  1694. X/*
  1695. X * Restore video state to what it was when we started.
  1696. X *
  1697. X * tty_endv() can be called after it's been called already with no
  1698. X * intervening tty_startv(), so we have to check.
  1699. X */
  1700. Xvoid
  1701. Xtty_endv(void)
  1702. X{
  1703. X    if (curmode != m_VI) {
  1704. X    return;
  1705. X    }
  1706. X    /*
  1707. X     * Restore contents of screen.
  1708. X     */
  1709. X    if (oldscreen != NULL) {
  1710. X    disp_pokebox(oldscreen, 0, 0, disp_numrows - 2, disp_numcols - 1);
  1711. X    }
  1712. X    disp_flush();
  1713. X    curmode = m_SYS;
  1714. X    msm_term();
  1715. X}
  1716. X
  1717. X#ifndef ABS
  1718. X#    define ABS(n) ((n) < 0 ? -(n) : (n))
  1719. X#endif
  1720. X
  1721. Xvoid
  1722. Xpc_scroll(unsigned start, unsigned end, int nlines)
  1723. X{
  1724. X    if (ABS(nlines) > end + 1 - start) {
  1725. X    nlines = 0;
  1726. X    }
  1727. X    disp_scroll(nlines, start, 0, end, disp_numcols - 1, Pn(P_colour));
  1728. X}
  1729. X
  1730. X/*
  1731. X * Return a character from standard input if one is immediately
  1732. X * available, otherwise -1.
  1733. X *
  1734. X * Don't do anything special if control-C is typed. Just return it.
  1735. X */
  1736. Xint
  1737. Xgetchnw()
  1738. X{
  1739. X    union REGS r;
  1740. X
  1741. X    r.h.ah = 6;
  1742. X    r.h.dl = 0xff;
  1743. X    intdos(&r, &r);
  1744. X    return (r.e.flags & 0x40) ?        /* zero flag */
  1745. X    -1 : (unsigned char) r.h.al;
  1746. X}
  1747. END_OF_FILE
  1748.   if test 5712 -ne `wc -c <'xvi/src/pc386.c'`; then
  1749.     echo shar: \"'xvi/src/pc386.c'\" unpacked with wrong size!
  1750.   fi
  1751.   # end of 'xvi/src/pc386.c'
  1752. fi
  1753. if test -f 'xvi/src/pipe.c' -a "${1}" != "-c" ; then 
  1754.   echo shar: Will not clobber existing file \"'xvi/src/pipe.c'\"
  1755. else
  1756.   echo shar: Extracting \"'xvi/src/pipe.c'\" \(4811 characters\)
  1757.   sed "s/^X//" >'xvi/src/pipe.c' <<'END_OF_FILE'
  1758. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  1759. X#ifndef lint
  1760. Xstatic char *sccsid = "@(#)pipe.c    2.1 (Chris & John Downey) 7/29/92";
  1761. X#endif
  1762. X
  1763. X/***
  1764. X
  1765. X* program name:
  1766. X    xvi
  1767. X* function:
  1768. X    PD version of UNIX "vi" editor, with extensions.
  1769. X* module name:
  1770. X    pipe.c
  1771. X* module function:
  1772. X    Handle pipe operators.
  1773. X* history:
  1774. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  1775. X    Originally by Tim Thompson (twitch!tjt)
  1776. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  1777. X    Heavily modified by Chris & John Downey
  1778. X
  1779. X***/
  1780. X
  1781. X#include "xvi.h"
  1782. X
  1783. Xstatic    int    p_write P((FILE *));
  1784. Xstatic    long    p_read P((FILE *));
  1785. X
  1786. Xstatic    Xviwin    *specwin;
  1787. Xstatic    Line    *line1, *line2;
  1788. Xstatic    Line    *newlines;
  1789. X
  1790. X/*
  1791. X * This function is called when the ! is typed in initially,
  1792. X * to specify the range; do_pipe() is then called later on
  1793. X * when the line has been typed in completely.
  1794. X *
  1795. X * Note that we record the first and last+1th lines to make the loop easier.
  1796. X */
  1797. Xvoid
  1798. Xspecify_pipe_range(window, l1, l2)
  1799. XXviwin    *window;
  1800. XLine    *l1;
  1801. XLine    *l2;
  1802. X{
  1803. X    /*
  1804. X     * Ensure that the lines specified are in the right order.
  1805. X     */
  1806. X    if (l1 != NULL && l2 != NULL && earlier(l2, l1)) {
  1807. X    register Line    *tmp;
  1808. X
  1809. X    tmp = l1;
  1810. X    l1 = l2;
  1811. X    l2 = tmp;
  1812. X    }
  1813. X    line1 = (l1 != NULL) ? l1 : window->w_buffer->b_file;
  1814. X    line2 = (l2 != NULL) ? l2->l_next : window->w_buffer->b_lastline;
  1815. X    specwin = window;
  1816. X}
  1817. X
  1818. X/*
  1819. X * Pipe the given sequence of lines through the command,
  1820. X * replacing the old set with its output.
  1821. X */
  1822. Xvoid
  1823. Xdo_pipe(window, command)
  1824. XXviwin    *window;
  1825. Xchar    *command;
  1826. X{
  1827. X    if (line1 == NULL || line2 == NULL || specwin != window) {
  1828. X    show_error(window,
  1829. X        "Internal error: pipe through badly-specified range.");
  1830. X    return;
  1831. X    }
  1832. X
  1833. X    newlines = NULL;
  1834. X    if (sys_pipe(command, p_write, p_read) && newlines != NULL) {
  1835. X    repllines(window, line1, cntllines(line1, line2) - 1, newlines);
  1836. X    update_buffer(window->w_buffer);
  1837. X    begin_line(window, TRUE);
  1838. X    } else {
  1839. X    show_error(window, "Failed to execute \"%s\"", command);
  1840. X    redraw_screen();
  1841. X    }
  1842. X    cursupdate(window);
  1843. X}
  1844. X
  1845. Xstatic int
  1846. Xp_write(fp)
  1847. XFILE    *fp;
  1848. X{
  1849. X    Line    *l;
  1850. X    long    n;
  1851. X
  1852. X    for (l = line1, n = 0; l != line2; l = l->l_next, n++) {
  1853. X    (void) fputs(l->l_text, fp);
  1854. X    (void) putc('\n', fp);
  1855. X    }
  1856. X    return(n);
  1857. X}
  1858. X
  1859. X/*
  1860. X * Returns the number of lines read, or -1 for failure.
  1861. X */
  1862. Xstatic long
  1863. Xp_read(fp)
  1864. XFILE    *fp;
  1865. X{
  1866. X    Line    *lptr = NULL;    /* pointer to list of lines */
  1867. X    Line    *last = NULL;    /* last complete line read in */
  1868. X    Line    *lp;        /* line currently being read in */
  1869. X    register enum {
  1870. X    at_soln,
  1871. X    in_line,
  1872. X    at_eoln,
  1873. X    at_eof
  1874. X    }    state;
  1875. X    char    *buff;        /* text of line being read in */
  1876. X    int        col;        /* current column in line */
  1877. X    unsigned long
  1878. X        nlines;        /* number of lines read */
  1879. X
  1880. X    col = 0;
  1881. X    nlines = 0;
  1882. X    state = at_soln;
  1883. X    while (state != at_eof) {
  1884. X
  1885. X    register int    c;
  1886. X
  1887. X    c = getc(fp);
  1888. X
  1889. X    /*
  1890. X     * Nulls are special; they can't show up in the file.
  1891. X     */
  1892. X    if (c == '\0') {
  1893. X        continue;
  1894. X    }
  1895. X
  1896. X    if (c == EOF) {
  1897. X        if (state != at_soln) {
  1898. X        /*
  1899. X         * Reached EOF in the middle of a line; what
  1900. X         * we do here is to pretend we got a properly
  1901. X         * terminated line, and assume that a
  1902. X         * subsequent getc will still return EOF.
  1903. X         */
  1904. X        state = at_eoln;
  1905. X        } else {
  1906. X        state = at_eof;
  1907. X        }
  1908. X    } else {
  1909. X        if (state == at_soln) {
  1910. X        /*
  1911. X         * We're at the start of a line, &
  1912. X         * we've got at least one character,
  1913. X         * so we have to allocate a new Line
  1914. X         * structure.
  1915. X         *
  1916. X         * If we can't do it, we throw away
  1917. X         * the lines we've read in so far, &
  1918. X         * return gf_NOMEM.
  1919. X         */
  1920. X        lp = newline(MAX_LINE_LENGTH);
  1921. X        if (lp == NULL) {
  1922. X            if (lptr != NULL)
  1923. X            throw(lptr);
  1924. X            return(-1);
  1925. X        } else {
  1926. X            buff = lp->l_text;
  1927. X        }
  1928. X        }
  1929. X
  1930. X        if (c == '\n') {
  1931. X        state = at_eoln;
  1932. X        }
  1933. X    }
  1934. X
  1935. X    /*
  1936. X     * Fake eoln for lines which are too long.
  1937. X     * Don't lose the input character.
  1938. X     */
  1939. X    if (col >= MAX_LINE_LENGTH - 1) {
  1940. X        (void) ungetc(c, fp);
  1941. X        state = at_eoln;
  1942. X    }
  1943. X
  1944. X    switch (state) {
  1945. X    /*
  1946. X     *    case at_eof:
  1947. X     *        break;
  1948. X     */
  1949. X
  1950. X    case at_soln:
  1951. X    case in_line:
  1952. X        state = in_line;
  1953. X        buff[col++] = c;
  1954. X        break;
  1955. X
  1956. X    case at_eoln:
  1957. X        /*
  1958. X         * First null-terminate the old line.
  1959. X         */
  1960. X        buff[col] = '\0';
  1961. X
  1962. X        /*
  1963. X         * If this fails, we squeak at the user and
  1964. X         * then throw away the lines read in so far.
  1965. X         */
  1966. X        buff = realloc(buff, (unsigned) col + 1);
  1967. X        if (buff == NULL) {
  1968. X        if (lptr != NULL)
  1969. X            throw(lptr);
  1970. X        return(-1);
  1971. X        }
  1972. X        lp->l_text = buff;
  1973. X        lp->l_size = col + 1;
  1974. X
  1975. X        /*
  1976. X         * Tack the line onto the end of the list,
  1977. X         * and then point "last" at it.
  1978. X         */
  1979. X        if (lptr == NULL) {
  1980. X        lptr = lp;
  1981. X        last = lptr;
  1982. X        } else {
  1983. X        last->l_next = lp;
  1984. X        lp->l_prev = last;
  1985. X        last = lp;
  1986. X        }
  1987. X
  1988. X        nlines++;
  1989. X        col = 0;
  1990. X        state = at_soln;
  1991. X        break;
  1992. X    }
  1993. X    }
  1994. X
  1995. X    newlines = lptr;
  1996. X
  1997. X    return(nlines);
  1998. X}
  1999. END_OF_FILE
  2000.   if test 4811 -ne `wc -c <'xvi/src/pipe.c'`; then
  2001.     echo shar: \"'xvi/src/pipe.c'\" unpacked with wrong size!
  2002.   fi
  2003.   # end of 'xvi/src/pipe.c'
  2004. fi
  2005. if test -f 'xvi/src/preserve.c' -a "${1}" != "-c" ; then 
  2006.   echo shar: Will not clobber existing file \"'xvi/src/preserve.c'\"
  2007. else
  2008.   echo shar: Extracting \"'xvi/src/preserve.c'\" \(3765 characters\)
  2009.   sed "s/^X//" >'xvi/src/preserve.c' <<'END_OF_FILE'
  2010. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2011. X#ifndef lint
  2012. Xstatic char *sccsid = "@(#)preserve.c    2.1 (Chris & John Downey) 7/29/92";
  2013. X#endif
  2014. X
  2015. X/***
  2016. X
  2017. X* program name:
  2018. X    xvi
  2019. X* function:
  2020. X    PD version of UNIX "vi" editor, with extensions.
  2021. X* module name:
  2022. X    preserve.c
  2023. X* module function:
  2024. X    Buffer preservation routines.
  2025. X
  2026. X    The do_preserve() routine saves the contents of all modified
  2027. X    buffers in temporary files. It can be invoked with the
  2028. X    :preserve command or it may be called by one of the system
  2029. X    interface modules when at least PSVKEYS keystrokes have been
  2030. X    read, & at least Pn(P_preservetime) seconds have elsapsed
  2031. X    since the last keystroke. (PSVKEYS is defined in xvi.h.) The
  2032. X    preservebuf() routine can be used to preserve a single buffer.
  2033. X
  2034. X* history:
  2035. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  2036. X    Originally by Tim Thompson (twitch!tjt)
  2037. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  2038. X    Heavily modified by Chris & John Downey
  2039. X***/
  2040. X
  2041. X#include "xvi.h"
  2042. X
  2043. X/*
  2044. X * Names of values for the P_preserve enumerated parameter.
  2045. X */
  2046. Xchar    *psv_strings[] =
  2047. X{
  2048. X    "unsafe",
  2049. X    "standard",
  2050. X    "safe",
  2051. X    "paranoid",
  2052. X    NULL
  2053. X};
  2054. X
  2055. X/*
  2056. X * Open temporary file for given buffer.
  2057. X */
  2058. Xstatic FILE *
  2059. Xpsvfile(window)
  2060. XXviwin    *window;
  2061. X{
  2062. X    register Buffer    *buffer;
  2063. X    FILE        *fp;
  2064. X
  2065. X    buffer = window->w_buffer;
  2066. X
  2067. X    if (buffer->b_tempfname == NULL) {
  2068. X    char    *fname;
  2069. X
  2070. X    fname = buffer->b_filename;
  2071. X    if (fname == NULL)
  2072. X        fname = "unnamed";
  2073. X    buffer->b_tempfname = tempfname(fname);
  2074. X    if (buffer->b_tempfname == NULL) {
  2075. X        show_error(window, "Can't create name for preserve file");
  2076. X        return(NULL);
  2077. X    }
  2078. X    }
  2079. X    fp = fopenwb(buffer->b_tempfname);
  2080. X    if (fp == NULL) {
  2081. X    show_error(window, "Can't open preserve file %s",
  2082. X                         buffer->b_tempfname);
  2083. X    }
  2084. X    return(fp);
  2085. X}
  2086. X
  2087. X/*
  2088. X * Write contents of buffer to file & close file. Return TRUE if no
  2089. X * errors detected.
  2090. X */
  2091. Xstatic bool_t
  2092. Xputbuf(wp, fp)
  2093. XXviwin        *wp;
  2094. Xregister FILE    *fp;
  2095. X{
  2096. X    unsigned long    l1, l2;
  2097. X
  2098. X    if (put_file(wp, fp, (Line *) NULL, (Line *) NULL, &l1, &l2) == FALSE) {
  2099. X    show_error(wp, "Error writing preserve file %s",
  2100. X                         wp->w_buffer->b_tempfname);
  2101. X    return(FALSE);
  2102. X    } else {
  2103. X    return(TRUE);
  2104. X    }
  2105. X}
  2106. X
  2107. X/*
  2108. X * Preserve contents of a single buffer, so that a backup copy is
  2109. X * available in case something goes wrong while the file itself is
  2110. X * being written.
  2111. X *
  2112. X * This is controlled by the P_preserve parameter: if it's set to
  2113. X * psv_UNSAFE, we just return. If it's psv_STANDARD, to save time, we
  2114. X * only preserve the buffer if it doesn't appear to have been
  2115. X * preserved recently: otherwise, if it's psv_SAFE or psv_PARANOID, we
  2116. X * always preserve it.
  2117. X *
  2118. X * Return FALSE if an error occurs during preservation, otherwise TRUE.
  2119. X */
  2120. Xbool_t
  2121. Xpreservebuf(window)
  2122. XXviwin    *window;
  2123. X{
  2124. X    FILE    *fp;
  2125. X    Buffer    *bp;
  2126. X
  2127. X    if (
  2128. X    Pn(P_preserve) == psv_UNSAFE
  2129. X    ||
  2130. X    (
  2131. X        Pn(P_preserve) == psv_STANDARD
  2132. X        &&
  2133. X        /*
  2134. X         * If there is a preserve file already ...
  2135. X         */
  2136. X        (bp = window->w_buffer)->b_tempfname != NULL
  2137. X        &&
  2138. X        exists(bp->b_tempfname)
  2139. X        &&
  2140. X        /*
  2141. X         * & a preserve appears to have been done recently ...
  2142. X         */
  2143. X        keystrokes < PSVKEYS
  2144. X    )
  2145. X    ) {
  2146. X    /*
  2147. X     * ... don't bother.
  2148. X     */
  2149. X    return(TRUE);
  2150. X    }
  2151. X
  2152. X    fp = psvfile(window);
  2153. X    if (fp == NULL) {
  2154. X    return(FALSE);
  2155. X    }
  2156. X
  2157. X    return(putbuf(window, fp));
  2158. X}
  2159. X
  2160. X/*
  2161. X * Preserve contents of all modified buffers.
  2162. X */
  2163. Xbool_t
  2164. Xdo_preserve()
  2165. X{
  2166. X    Xviwin        *wp;
  2167. X    bool_t        psvstatus = TRUE;
  2168. X
  2169. X    wp = curwin;
  2170. X    do {
  2171. X    if (is_modified(wp->w_buffer)) {
  2172. X        FILE    *fp;
  2173. X
  2174. X        fp = psvfile(wp);
  2175. X        if (fp != NULL) {
  2176. X        if (!putbuf(wp, fp))
  2177. X            psvstatus = FALSE;
  2178. X        } else {
  2179. X        psvstatus = FALSE;
  2180. X        }
  2181. X    }
  2182. X    } while ((wp = next_window(wp)) != curwin);
  2183. X
  2184. X    return(psvstatus);
  2185. X}
  2186. END_OF_FILE
  2187.   if test 3765 -ne `wc -c <'xvi/src/preserve.c'`; then
  2188.     echo shar: \"'xvi/src/preserve.c'\" unpacked with wrong size!
  2189.   fi
  2190.   # end of 'xvi/src/preserve.c'
  2191. fi
  2192. if test -f 'xvi/src/unix.h' -a "${1}" != "-c" ; then 
  2193.   echo shar: Will not clobber existing file \"'xvi/src/unix.h'\"
  2194. else
  2195.   echo shar: Extracting \"'xvi/src/unix.h'\" \(3773 characters\)
  2196.   sed "s/^X//" >'xvi/src/unix.h' <<'END_OF_FILE'
  2197. X/* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2198. X/***
  2199. X
  2200. X* @(#)unix.h    2.1 (Chris & John Downey) 7/29/92
  2201. X
  2202. X* program name:
  2203. X    xvi
  2204. X* function:
  2205. X    PD version of UNIX "vi" editor, with extensions.
  2206. X* module name:
  2207. X    unix.h
  2208. X* module function:
  2209. X    Definitions for UNIX system interface module.
  2210. X* history:
  2211. X    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  2212. X    Originally by Tim Thompson (twitch!tjt)
  2213. X    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  2214. X    Heavily modified by Chris & John Downey
  2215. X
  2216. X***/
  2217. X
  2218. X#include <errno.h>
  2219. X#include <fcntl.h>
  2220. X#if defined(BSD) && !defined(__STDC__)
  2221. X#   include <sys/time.h>
  2222. X#else
  2223. X#   include <time.h>
  2224. X#endif
  2225. X
  2226. X#if defined(SUNVIEW) || defined(XVIEW)
  2227. X#   include "sunview.h"
  2228. X#else
  2229. X#   include "termcap.h"
  2230. X#endif
  2231. X
  2232. X/*
  2233. X * Default value for helpfile parameter.
  2234. X */
  2235. X#ifndef HELPFILE
  2236. X#   define  HELPFILE    "/usr/lib/xvi.help"
  2237. X#endif
  2238. X
  2239. X#if defined(sun) || defined(ultrix) || defined(XENIX) || defined(__STDC__)
  2240. X#   define SETVBUF_AVAIL
  2241. X    /*
  2242. X     * These are the buffer sizes we use for reading & writing files.
  2243. X     */
  2244. X#   define  READBUFSIZ    16384
  2245. X#   define  WRTBUFSIZ    16384
  2246. X#endif
  2247. X
  2248. X/*
  2249. X * If we don't have an ANSI compiler, strerror() is implemented in unix.c.
  2250. X */
  2251. X#define STRERROR_AVAIL
  2252. X
  2253. X#ifndef    __STDC__
  2254. X    /*
  2255. X     * Conditionally compile this to be safe.
  2256. X     */
  2257. X    extern const char    *strerror P((int));
  2258. X#endif
  2259. X
  2260. X#ifdef sun
  2261. X    /*
  2262. X     * getwd() is a system call, which doesn't need to run the pwd
  2263. X     * program (as getcwd() does).
  2264. X     */
  2265. X    extern char        *getwd P((char *));
  2266. X#   define getcwd(p,s)    getwd(p)
  2267. X#endif
  2268. X
  2269. X/*
  2270. X * Macros to open files in binary mode.
  2271. X */
  2272. X#define fopenrb(f)    fopen((f),"r")
  2273. X#define fopenwb(f)    fopen((f),"w")
  2274. X
  2275. X/*
  2276. X * ANSI C libraries should have remove(), but unlink() does exactly
  2277. X * the same thing.
  2278. X */
  2279. X#define remove(f)    unlink(f)
  2280. X
  2281. X/*
  2282. X * BSD doesn't provide memcpy, but bcopy does the same thing.
  2283. X * Similarly, strchr=index and strrchr=rindex.
  2284. X * However, any __STDC__ environment must provide these,
  2285. X * and SunOS provides them too, as does ULTRIX.
  2286. X */
  2287. X#if defined(BSD) && !defined(__STDC__) && !defined(sun) && !defined(ultrix)
  2288. X#   define  memcpy(to, from, n)    bcopy((from), (to), (n))
  2289. X#   define  strchr        index
  2290. X#   define  strrchr        rindex
  2291. X#endif
  2292. X
  2293. X/*
  2294. X * System-dependent constants - these are needed by file i/o routines.
  2295. X */
  2296. X#ifdef    BSD
  2297. X#   include <sys/param.h>
  2298. X#   include <sys/dir.h>
  2299. X#   include <sys/file.h>    /* get W_OK define for access() */
  2300. X#else    /* not BSD */
  2301. X    /*
  2302. X     * I think these are right for System V. (jmd)
  2303. X     */
  2304. X#   define  MAXPATHLEN    1024    /* max length of full path name */
  2305. X#   define  MAXNAMLEN    14    /* max length of file name */
  2306. X#endif    /* BSD */
  2307. X
  2308. X#ifndef W_OK
  2309. X#   define    F_OK    0
  2310. X#   define    W_OK    2
  2311. X#endif
  2312. X
  2313. X/*
  2314. X * exists(): TRUE if file exists.
  2315. X */
  2316. X#define exists(f)    (access((f),F_OK) == 0)
  2317. X
  2318. X/*
  2319. X * can_write(): TRUE if file does not exist or exists and is writeable.
  2320. X */
  2321. X#define can_write(f)    (access((f),F_OK) != 0 || access((f), W_OK) == 0)
  2322. X
  2323. X#define    DIRSEPS        "/"    /* directory separators within pathnames */
  2324. X
  2325. X/*
  2326. X * Default file format.
  2327. X */
  2328. X#define DEF_TFF        fmt_UNIX
  2329. X
  2330. X/*
  2331. X * These are needed for the termcap terminal interface module.
  2332. X */
  2333. X#define oflush()    (void) fflush(stdout)
  2334. X#define moutch(c)    putchar(c)
  2335. X
  2336. X/*
  2337. X * Declarations for standard UNIX functions.
  2338. X */
  2339. Xextern    int        rename P((const char *, const char *));
  2340. X
  2341. X/*
  2342. X * Declarations for system interface routines in unix.c.
  2343. X */
  2344. Xextern    char        *fexpand P((char *));
  2345. Xextern    void        foutch P((int));
  2346. Xextern    void        delay P((void));
  2347. Xextern    void        sys_init P((void));
  2348. Xextern    void        sys_startv P((void));
  2349. Xextern    void        sys_endv P((void));
  2350. Xextern    void        sys_exit P((int));
  2351. Xextern    int        call_shell P((char *));
  2352. Xextern    int        call_system P((char *));
  2353. Xextern    bool_t        sys_pipe P((char *, int (*)(FILE *), long (*)(FILE *)));
  2354. Xextern    char        *tempfname P((char *));
  2355. END_OF_FILE
  2356.   if test 3773 -ne `wc -c <'xvi/src/unix.h'`; then
  2357.     echo shar: \"'xvi/src/unix.h'\" unpacked with wrong size!
  2358.   fi
  2359.   # end of 'xvi/src/unix.h'
  2360. fi
  2361. echo shar: End of archive 16 \(of 18\).
  2362. cp /dev/null ark16isdone
  2363. MISSING=""
  2364. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  2365.     if test ! -f ark${I}isdone ; then
  2366.     MISSING="${MISSING} ${I}"
  2367.     fi
  2368. done
  2369. if test "${MISSING}" = "" ; then
  2370.     echo You have unpacked all 18 archives.
  2371.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2372. else
  2373.     echo You still must unpack the following archives:
  2374.     echo "        " ${MISSING}
  2375. fi
  2376. exit 0
  2377. exit 0 # Just in case...
  2378.