deleteln.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. deleteln
  5. --------
  6. ### Synopsis
  7. int deleteln(void);
  8. int wdeleteln(WINDOW *win);
  9. int insdelln(int n);
  10. int winsdelln(WINDOW *win, int n);
  11. int insertln(void);
  12. int winsertln(WINDOW *win);
  13. int mvdeleteln(int y, int x);
  14. int mvwdeleteln(WINDOW *win, int y, int x);
  15. int mvinsertln(int y, int x);
  16. int mvwinsertln(WINDOW *win, int y, int x);
  17. ### Description
  18. With the deleteln() and wdeleteln() functions, the line under the
  19. cursor in the window is deleted. All lines below the current line are
  20. moved up one line. The bottom line of the window is cleared. The
  21. cursor position does not change.
  22. With the insertln() and winsertn() functions, a blank line is
  23. inserted above the current line and the bottom line is lost.
  24. mvdeleteln(), mvwdeleteln(), mvinsertln() and mvwinsertln() allow
  25. moving the cursor and inserting/deleting in one call.
  26. ### Return Value
  27. All functions return OK on success and ERR on error.
  28. ### Portability
  29. X/Open ncurses NetBSD
  30. deleteln Y Y Y
  31. wdeleteln Y Y Y
  32. mvdeleteln - - -
  33. mvwdeleteln - - -
  34. insdelln Y Y Y
  35. winsdelln Y Y Y
  36. insertln Y Y Y
  37. winsertln Y Y Y
  38. mvinsertln - - -
  39. mvwinsertln - - -
  40. **man-end****************************************************************/
  41. int wdeleteln(WINDOW *win)
  42. {
  43. chtype blank, *temp, *ptr;
  44. int y;
  45. PDC_LOG(("wdeleteln() - called\n"));
  46. if (!win)
  47. return ERR;
  48. /* wrs (4/10/93) account for window background */
  49. blank = win->_bkgd;
  50. temp = win->_y[win->_cury];
  51. for (y = win->_cury; y < win->_bmarg; y++)
  52. {
  53. win->_y[y] = win->_y[y + 1];
  54. win->_firstch[y] = 0;
  55. win->_lastch[y] = win->_maxx - 1;
  56. }
  57. for (ptr = temp; (ptr - temp < win->_maxx); ptr++)
  58. *ptr = blank; /* make a blank line */
  59. if (win->_cury <= win->_bmarg)
  60. {
  61. win->_firstch[win->_bmarg] = 0;
  62. win->_lastch[win->_bmarg] = win->_maxx - 1;
  63. win->_y[win->_bmarg] = temp;
  64. }
  65. return OK;
  66. }
  67. int deleteln(void)
  68. {
  69. PDC_LOG(("deleteln() - called\n"));
  70. return wdeleteln(stdscr);
  71. }
  72. int mvdeleteln(int y, int x)
  73. {
  74. PDC_LOG(("mvdeleteln() - called\n"));
  75. if (move(y, x) == ERR)
  76. return ERR;
  77. return wdeleteln(stdscr);
  78. }
  79. int mvwdeleteln(WINDOW *win, int y, int x)
  80. {
  81. PDC_LOG(("mvwdeleteln() - called\n"));
  82. if (wmove(win, y, x) == ERR)
  83. return ERR;
  84. return wdeleteln(win);
  85. }
  86. int winsdelln(WINDOW *win, int n)
  87. {
  88. int i;
  89. PDC_LOG(("winsdelln() - called\n"));
  90. if (!win)
  91. return ERR;
  92. if (n > 0)
  93. {
  94. for (i = 0; i < n; i++)
  95. if (winsertln(win) == ERR)
  96. return ERR;
  97. }
  98. else if (n < 0)
  99. {
  100. n = -n;
  101. for (i = 0; i < n; i++)
  102. if (wdeleteln(win) == ERR)
  103. return ERR;
  104. }
  105. return OK;
  106. }
  107. int insdelln(int n)
  108. {
  109. PDC_LOG(("insdelln() - called\n"));
  110. return winsdelln(stdscr, n);
  111. }
  112. int winsertln(WINDOW *win)
  113. {
  114. chtype blank, *temp, *end;
  115. int y;
  116. PDC_LOG(("winsertln() - called\n"));
  117. if (!win)
  118. return ERR;
  119. /* wrs (4/10/93) account for window background */
  120. blank = win->_bkgd;
  121. temp = win->_y[win->_maxy - 1];
  122. for (y = win->_maxy - 1; y > win->_cury; y--)
  123. {
  124. win->_y[y] = win->_y[y - 1];
  125. win->_firstch[y] = 0;
  126. win->_lastch[y] = win->_maxx - 1;
  127. }
  128. win->_y[win->_cury] = temp;
  129. for (end = &temp[win->_maxx - 1]; temp <= end; temp++)
  130. *temp = blank;
  131. win->_firstch[win->_cury] = 0;
  132. win->_lastch[win->_cury] = win->_maxx - 1;
  133. return OK;
  134. }
  135. int insertln(void)
  136. {
  137. PDC_LOG(("insertln() - called\n"));
  138. return winsertln(stdscr);
  139. }
  140. int mvinsertln(int y, int x)
  141. {
  142. PDC_LOG(("mvinsertln() - called\n"));
  143. if (move(y, x) == ERR)
  144. return ERR;
  145. return winsertln(stdscr);
  146. }
  147. int mvwinsertln(WINDOW *win, int y, int x)
  148. {
  149. PDC_LOG(("mvwinsertln() - called\n"));
  150. if (wmove(win, y, x) == ERR)
  151. return ERR;
  152. return winsertln(win);
  153. }