TEACL is a fork of TECOC created for the purpose of describing diffs in a document being collaboratively edited
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

  1. /*****************************************************************************
  2. ExeK()
  3. This function executes a K command.
  4. nK Kill n lines
  5. m,nK Delete between m and n
  6. *****************************************************************************/
  7. #include "zport.h" /* define portability identifiers */
  8. #include "tecoc.h" /* define general identifiers */
  9. #include "defext.h" /* define external global variables */
  10. DEFAULT ExeK() /* execute a K command */
  11. {
  12. ptrdiff_t HowFar;
  13. DBGFEN(1,"ExeK",NULL);
  14. if (EStTop == EStBot) { /* if no numeric argument */
  15. NArgmt = 1; /* default is 1K */
  16. } else {
  17. UMinus(); /* if it's -K, make it -1K */
  18. if (GetNmA() == FAILURE) { /* get numeric argument */
  19. DBGFEX(1,DbgFNm,"FALURE");
  20. return FAILURE;
  21. }
  22. }
  23. if (CmdMod & MARGIS) { /* if it's m,nK */
  24. if (NArgmt == MArgmt) { /* if n equals m */
  25. CmdMod = '\0'; /* clear modifiers flags */
  26. DBGFEX(1,DbgFNm,"SUCCESS");
  27. return SUCCESS;
  28. }
  29. MEMMOVE(ErrTxt,
  30. (*CBfPtr == 'D' || *CBfPtr=='d') ? "m,nD" : "m,nK",
  31. 5);
  32. if (GetAra() == FAILURE) {
  33. DBGFEX(1,DbgFNm,"FAILURE");
  34. return FAILURE;
  35. }
  36. if ((AraBeg < GapBeg) && (AraEnd > GapEnd)) {
  37. GapBeg = AraBeg;
  38. GapEnd = AraEnd;
  39. } else {
  40. if (AraEnd < GapEnd) {
  41. HowFar = (GapBeg-1) - AraEnd;
  42. GapBeg -= HowFar;
  43. GapEnd -= HowFar;
  44. MEMMOVE(GapEnd+1, GapBeg, (SIZE_T)HowFar);
  45. GapBeg = AraBeg;
  46. } else {
  47. HowFar = AraBeg - (GapEnd+1);
  48. MEMMOVE(GapBeg, GapEnd+1, (SIZE_T)HowFar);
  49. GapBeg += HowFar;
  50. GapEnd = AraEnd;
  51. }
  52. }
  53. } else { /* else it's nK */
  54. NArgmt = Ln2Chr(NArgmt); /* cvt line to char offset */
  55. if (NArgmt > 0) {
  56. GapEnd += NArgmt;
  57. } else {
  58. GapBeg += NArgmt;
  59. }
  60. }
  61. CmdMod = '\0'; /* clear modifiers flags */
  62. DBGFEX(1,DbgFNm,"SUCCESS");
  63. return SUCCESS;
  64. }