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

  1. #include "rv.h"
  2.  
  3. extern char *realloc();
  4.  
  5. void
  6. put(direction)
  7. /*
  8.  * Put buffer at cursor.
  9.  */
  10. INT direction; /* Negative if above cursor */
  11. {
  12.     register struct li_line      *line;
  13.     register struct ya_yank   *yank;
  14.     register struct sc_screen *sc;
  15.     INT    indx;
  16.  
  17.     sc = &screen;
  18.     line = sc->sc_curline;
  19.  
  20.     indx = char_to_yank(yank_cmd);
  21.     if (errflag) {
  22.         flash();
  23.         return;
  24.     }
  25.     yank = &yank_array[indx];
  26.  
  27.     file.fi_modified = TRUE;
  28.     if (yank->ya_type == YANK_EMPTY) {
  29.         errflag = 1;
  30.         if (yank_cmd == ' ')
  31.             flash();
  32.         else 
  33.             botprint(TRUE, "Register %c is empty", yank_cmd);
  34.         return;
  35.     }
  36.     undo.un_inserted = TRUE;
  37.     undo.un_firstline = undo.un_lastline = sc->sc_lineno;
  38.     undo.un_validcol = FALSE;
  39.     if (yank->ya_type == YANK_COLS) {
  40.         /*
  41.          * Put text within line
  42.          */
  43.         register char *s, *s2, *s3;
  44.  
  45.         save_Undo();
  46.         undo.un_validcol = sc->sc_validcol = TRUE;
  47.         undo.un_firstcol = sc->sc_firstcol = sc->sc_column+1;
  48.         undo.un_lastcol = sc->sc_lastcol = sc->sc_column+yank->ya_width;
  49.         line->li_text = realloc(line->li_text, line->li_width +
  50.             yank->ya_width + 1);
  51.         s = &line->li_text[sc->sc_firstcol];
  52.         s2 = &line->li_text[line->li_width];
  53.         s3 = &line->li_text[line->li_width + yank->ya_width];
  54.         while (s2 >= s)
  55.             *s3-- = *s2--;
  56.         s2 = yank->ya_text;
  57.         while (*s2)
  58.             *s++ = *s2++;
  59.         redraw_curline(line->li_text);
  60.         move_cursor(sc->sc_lineno, sc->sc_firstcol + yank->ya_width-1);
  61.         if (set_fortran && line->li_width > 72) {
  62.             botprint(FALSE, "Line is longer than 72 columns");
  63.             hitcr_continue();
  64.         }
  65.     }
  66.     else { /* Put text between lines */
  67.         sc->sc_validcol = FALSE;
  68.         if (yank->ya_type == YANK_SINGLE) {
  69.             /*
  70.              * Simple case - put 1 line
  71.              */
  72.             openline(direction);
  73.             save_Undo();
  74.             redraw_curline(yank->ya_text);
  75.             move_cursor(sc->sc_lineno, COL_FIRST_NONWHITE);
  76.         }
  77.         else {
  78.             /*
  79.              * put multiple lines
  80.              */
  81.             xmit_curline();
  82.             xmit_ed("%dr /tmp/yk%d.%d\n", sc->sc_lineno -
  83.                 (direction >= 0 ? 0 : 1), getpid(), indx);
  84.             undo.un_lastline = sc->sc_lineno + yank->ya_numlines-1;
  85.             fetch_window(sc->sc_lineno - NUM_WINDOW_LINES/4 -
  86.                 LINES/2 + 1, TRUE);
  87.             botprint(FALSE, "%d more lines", yank->ya_numlines);
  88.             hitcr_continue();
  89.         }
  90.     }
  91. }
  92.