home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / OS2 / BEAV132X.ZIP / WORD.C < prev   
C/C++ Source or Header  |  1992-01-06  |  3KB  |  122 lines

  1. /*
  2. *       Word mode commands.
  3. * The routines in this file
  4. * implement commands that work unit at
  5. * a time. There are all sorts of unit mode
  6. * commands. If I do any sentence and/or paragraph
  7. * mode commands, they are likely to be put in
  8. * this file.
  9. */
  10. #include    "def.h"
  11.  
  12. extern  BUFFER    sav_buf;
  13. char    forwunit ();
  14.  
  15. /*
  16. * Move the cursor backward by
  17. * "n" units. All of the details of motion
  18. * are performed by the "backchar" and "forwchar"
  19. * routines. Error if you try to move beyond
  20. * the buffers.
  21. */
  22. char    backunit (f, n, k)
  23. int f, n, k;
  24. {
  25.     char    ret;
  26.  
  27.     if (n < 0)
  28.         return (forwunit (f, -n, KRANDOM));
  29.  
  30.     curwp -> w_unit_offset = 0;
  31.     while (n--)
  32.     {
  33.         ret = move_ptr (curwp, -(long)R_B_PER_U(curwp), TRUE, TRUE, TRUE);
  34.     }
  35.     wind_on_dot (curwp);
  36.     curwp -> w_flag |= WFMODE;  /* update mode line */
  37.     return (ret);
  38. }
  39.  
  40.  
  41. /*
  42. * Move the cursor forward by
  43. * the specified number of units. All of the
  44. * motion is done by "forwchar". Error if you
  45. * try and move beyond the buffer's end.
  46. */
  47. char    forwunit (f, n, k)
  48. int f, n, k;
  49. {
  50.  
  51.     if      (n < 0)
  52.         return (backunit (f, -n, KRANDOM));
  53.  
  54.     curwp -> w_unit_offset = 0;
  55.     while (n--)
  56.     {
  57.         move_ptr (curwp, (long)R_B_PER_U(curwp), TRUE, TRUE, TRUE);
  58.     }
  59.     wind_on_dot (curwp);
  60.     curwp -> w_flag |= WFMODE;  /* update mode line */
  61.     return (TRUE);
  62. }
  63.  
  64.  
  65. /*
  66. * Kill forward by "n" units. The rules for final
  67. * status are now different. It is not considered an error
  68. * to delete fewer units than you asked. This lets you say
  69. * "kill lots of units" and have the command stop in a reasonable
  70. * way when it hits the end of the buffer.
  71. */
  72. bool delfunit (f, n, k)
  73. int f, n, k;
  74. {
  75.     if (n < 0)
  76.         return (FALSE);
  77.     if ((lastflag & CFKILL) == 0)/* Purge kill buffer.   */
  78.         bclear (&sav_buf);
  79.     thisflag |= CFKILL;
  80.     while (n--)
  81.     {
  82.         ldelete ((A32)(R_B_PER_U(curwp)), TRUE);
  83.     }
  84.     curwp -> w_flag |= WFHARD;
  85.     curwp -> w_unit_offset = 0;
  86.     return (TRUE);
  87. }
  88.  
  89.  
  90. /*
  91. * Kill backwards by "n" units. The rules
  92. * for success and failure are now different, to prevent
  93. * strange behavior at the start of the buffer. The command
  94. * only fails if something goes wrong with the actual delete
  95. * of the characters. It is successful even if no characters
  96. * are deleted, or if you say delete 5 units, and there are
  97. * only 4 units left. I considered making the first call
  98. * to "backchar" special, but decided that that would just
  99. * be wierd. Normally this is bound to "M-Rubout" and
  100. * to "M-Backspace".
  101. */
  102. bool delbunit (f, n, k)
  103. int f, n, k;
  104. {
  105.     int size;
  106.  
  107.     if (n < 0)
  108.         return (FALSE);
  109.     if ((lastflag & CFKILL) == 0)/* Purge kill buffer.   */
  110.         bclear (&sav_buf);
  111.     thisflag |= CFKILL;
  112.     size = R_B_PER_U(curwp);
  113.     while (n--)
  114.     {
  115.         if (move_ptr (curwp, -((long)size), TRUE, TRUE, TRUE))
  116.             ldelete ((A32)size, TRUE);
  117.     }
  118.     curwp -> w_flag |= WFHARD;
  119.     return (TRUE);
  120. }
  121.  
  122.