home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / rvi / part3 / rv_openline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-09  |  2.9 KB  |  147 lines

  1. #include "rv.h"
  2. #include <ctype.h>
  3.  
  4. boolean opened_line;     /* Set TRUE if openline() called */
  5. INT  autoindent;     /* Physical autoindent, used by insert() */
  6.  
  7. void
  8. openline(direction)
  9. /*
  10.  *  Openline - Open new line.
  11.  *
  12.  *  If direction < 0, open above current line, else
  13.  *                    open below current line.
  14.  */
  15. INT direction;
  16. {
  17.     register struct li_line      *line;
  18.     register struct sc_screen *sc;
  19.     register struct wi_window *wi;
  20.     char *s;
  21.  
  22.     sc = &screen;
  23.     wi = &window;
  24.  
  25.     file.fi_modified = TRUE;
  26.     xmit_curline();
  27.     opened_line = TRUE;
  28.  
  29.     /*
  30.      * Calculate autoindent
  31.      */
  32.     autoindent = 0;
  33.     if (set_autoindent) {
  34.         s = sc->sc_curline->li_text;
  35.         while (isspace(*s) && *s != '\0')
  36.             if (*s++ == '\t')
  37.                 autoindent += set_tabstops;
  38.             else
  39.                 autoindent++;
  40.     }
  41.  
  42.     /*
  43.      * Send blank line to ed
  44.      */
  45.     if (direction >= 0) {
  46.         xmit_ed("%da\n\n.\n", sc->sc_lineno);
  47.         sc->sc_lineno++;
  48.         sc->sc_curline++;
  49.     } else
  50.         xmit_ed("%di\n\n.\n", sc->sc_lineno);
  51.  
  52.     if (sc->sc_curline <= wi->wi_botline ||
  53.             wi->wi_botline < &line_array[NUM_WINDOW_LINES-1]) {
  54.         /*
  55.          * Case 1,2,3:  Opening line at top of window, within window,
  56.          *              or bottom of expandable window
  57.          */
  58.  
  59.         /*
  60.          * Scroll off bottom line of window if necessary
  61.          */
  62.         if (wi->wi_botline >= &line_array[NUM_WINDOW_LINES-1]) {
  63.             if (wi->wi_botline->li_text)
  64.                 free(wi->wi_botline->li_text);
  65.             wi->wi_botline->li_text = NULL;
  66.             wi->wi_botline--;
  67.         }
  68.  
  69.         /*
  70.          * Slide down window beyond line
  71.          */
  72.         for (line = wi->wi_botline; line >= sc->sc_curline; --line) {
  73.             (line+1)->li_width = line->li_width;
  74.             (line+1)->li_segments = line->li_segments;
  75.             (line+1)->li_text = line->li_text;
  76.         }
  77.         wi->wi_botline++;
  78.     } else {
  79.         /*
  80.          * Case 4: Opening line beyond edge of unexpandable window
  81.          */
  82.  
  83.         sc->sc_curline--;
  84.         /*
  85.          * Scroll off topline of window if necessary
  86.          */
  87.         if (wi->wi_topline <= &line_array[0]) {
  88.             if (wi->wi_topline->li_text)
  89.                 free(wi->wi_topline->li_text);
  90.             wi->wi_topline->li_text = NULL;
  91.             wi->wi_topline++;
  92.         }
  93.  
  94.         /*
  95.          * Slide up window
  96.          */
  97.         for (line = wi->wi_topline; line < sc->sc_curline; ++line) {
  98.             (line-1)->li_width = line->li_width;
  99.             (line-1)->li_segments = line->li_segments;
  100.             (line-1)->li_text = line->li_text;
  101.         }
  102.         wi->wi_topline--;
  103.         sc->sc_topline--;
  104.         sc->sc_botline--;
  105.     }
  106.  
  107.     /*
  108.      * Create the empty line
  109.      */
  110.     line = sc->sc_curline;
  111.     line->li_width = 0;
  112.     line->li_segments = 1;
  113.     line->li_text = xalloc(1);
  114.     line->li_text[0] = '\0';
  115.  
  116.     if (line > wi->wi_botline)
  117.         wi->wi_botline = line;
  118.  
  119.     file.fi_numlines++;
  120.  
  121.     /*
  122.      * Set up for insert()
  123.      */
  124.     sc->sc_firstcol = 0;
  125.     sc->sc_lastcol = -1;
  126.  
  127.     /*
  128.      * Remember opened line for later undo
  129.      */
  130.     undo.un_validcol = FALSE;
  131.     undo.un_firstline = sc->sc_lineno;
  132.     undo.un_lastline = sc->sc_lineno;
  133.     undo.un_inserted = TRUE;
  134.  
  135.     /*
  136.      * Update line to curses
  137.      */
  138.     if (line > sc->sc_botline) {
  139.         redraw_screen(sc->sc_botline+1);
  140.         move_cursor(sc->sc_lineno, 0);
  141.     } else {
  142.         move_cursor(sc->sc_lineno, 0);
  143.         rv_finsertln(1);
  144.         redraw_screen(sc->sc_botline);
  145.     }
  146. }
  147.