home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / rvi / part2 / rv_join.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.9 KB  |  101 lines

  1. #include "rv.h"
  2. #include <ctype.h>
  3.  
  4. void
  5. join()
  6. /*
  7.  *  Join current line with line following
  8.  */
  9. {
  10.     register struct li_line      *line, *line2;
  11.     register struct sc_screen *sc;
  12.     register char *s, *s2;
  13.     struct wi_window *wi;
  14.     struct ya_yank     *yk;
  15.     INT joincol, bottom;
  16.     char *txt;
  17.  
  18.     sc = &screen;
  19.     wi = &window;
  20.  
  21.     file.fi_modified = TRUE;
  22.     line = sc->sc_curline;
  23.     line2 = line+1;
  24.     if (sc->sc_lineno >= file.fi_numlines) {
  25.         flash();
  26.         errflag = 1;
  27.         return;
  28.     }
  29.  
  30.     if (line2 > wi->wi_botline) {
  31.         fetch_window(sc->sc_lineno - NUM_WINDOW_LINES/4 - LINES/2 + 1,
  32.             TRUE);
  33.         join();
  34.         return;
  35.     }
  36.  
  37.     txt = xalloc(strlen(line->li_text) + strlen(line2->li_text) + 3);
  38.     strcpy(txt, line->li_text);
  39.     joincol = line->li_width;
  40.     /*
  41.      * Add a space between lines, if not already there
  42.      * Add 2 spaces after a period
  43.      */
  44.     s = txt + line->li_width;
  45.     if (line->li_width > 0 && !isspace(*(s-1))) {
  46.         if (*(s-1) == '.')
  47.             *s++ = ' ';
  48.         *s++ = ' ';
  49.     }
  50.  
  51.     /*
  52.      * Strip leading spaces from second line
  53.      */
  54.     s2 = line2->li_text;
  55.     while (isspace(*s2) && *s2 != '\0')
  56.         ++s2;
  57.     
  58.     /*
  59.      * Append second line to first
  60.      */
  61.     while (*s2 != '\0')
  62.         *s++ = *s2++;
  63.     *s = '\0';
  64.     openline(-1);
  65.     redraw_curline(txt);
  66.     free(txt);
  67.  
  68.     /*
  69.      * Delete old lines
  70.      * Yank manually to prevent a fetch_window
  71.      */
  72.     move_abs_cursor(sc->sc_lineno+1, 0);
  73.     sc->sc_validcol = FALSE;
  74.     sc->sc_firstline = sc->sc_lineno;
  75.     sc->sc_lastline = sc->sc_firstline+1;
  76.     yank_cmd = ' ';
  77.     yank();
  78.     yk = &yank_array[0];
  79.     sc->sc_lastline = sc->sc_firstline;
  80.     bottom = (sc->sc_lineno >= file.fi_numlines-1);
  81.     delete();
  82.     delete();
  83.     yk->ya_type = YANK_LINES;
  84.     yk->ya_width = 0;
  85.     yk->ya_numlines = 2;
  86.     if (yk->ya_text) {
  87.         free(yk->ya_text);
  88.         yk->ya_text = NULL;
  89.     }
  90.  
  91.     /*
  92.      * Put cursor on spot between joined lines
  93.      */
  94.     if (!bottom)
  95.         move_cursor(sc->sc_lineno-1, joincol);
  96.     else
  97.         move_cursor(sc->sc_lineno, joincol);
  98.     undo.un_firstline = sc->sc_lineno; /* Bashed by delete() */
  99.     save_Undo();
  100. }
  101.