1
0

addchstr.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. addchstr
  5. --------
  6. ### Synopsis
  7. int addchstr(const chtype *ch);
  8. int addchnstr(const chtype *ch, int n);
  9. int waddchstr(WINDOW *win, const chtype *ch);
  10. int waddchnstr(WINDOW *win, const chtype *ch, int n);
  11. int mvaddchstr(int y, int x, const chtype *ch);
  12. int mvaddchnstr(int y, int x, const chtype *ch, int n);
  13. int mvwaddchstr(WINDOW *, int y, int x, const chtype *ch);
  14. int mvwaddchnstr(WINDOW *, int y, int x, const chtype *ch, int n);
  15. int add_wchstr(const cchar_t *wch);
  16. int add_wchnstr(const cchar_t *wch, int n);
  17. int wadd_wchstr(WINDOW *win, const cchar_t *wch);
  18. int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n);
  19. int mvadd_wchstr(int y, int x, const cchar_t *wch);
  20. int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n);
  21. int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch);
  22. int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch,
  23. int n);
  24. ### Description
  25. These routines write a chtype or cchar_t string directly into the
  26. window structure, starting at the current or specified position. The
  27. four routines with n as the last argument copy at most n elements,
  28. but no more than will fit on the line. If n == -1 then the whole
  29. string is copied, up to the maximum number that will fit on the line.
  30. The cursor position is not advanced. These routines do not check for
  31. newline or other special characters, nor does any line wrapping
  32. occur.
  33. ### Return Value
  34. All functions return OK or ERR.
  35. ### Portability
  36. X/Open ncurses NetBSD
  37. addchstr Y Y Y
  38. waddchstr Y Y Y
  39. mvaddchstr Y Y Y
  40. mvwaddchstr Y Y Y
  41. addchnstr Y Y Y
  42. waddchnstr Y Y Y
  43. mvaddchnstr Y Y Y
  44. mvwaddchnstr Y Y Y
  45. add_wchstr Y Y Y
  46. wadd_wchstr Y Y Y
  47. mvadd_wchstr Y Y Y
  48. mvwadd_wchstr Y Y Y
  49. add_wchnstr Y Y Y
  50. wadd_wchnstr Y Y Y
  51. mvadd_wchnstr Y Y Y
  52. mvwadd_wchnstr Y Y Y
  53. **man-end****************************************************************/
  54. #include <string.h>
  55. int waddchnstr(WINDOW *win, const chtype *ch, int n)
  56. {
  57. int y, x, maxx, minx;
  58. chtype *ptr;
  59. PDC_LOG(("waddchnstr() - called: win=%p n=%d\n", win, n));
  60. if (!win || !ch || !n || n < -1)
  61. return ERR;
  62. x = win->_curx;
  63. y = win->_cury;
  64. ptr = &(win->_y[y][x]);
  65. if (n == -1 || n > win->_maxx - x)
  66. n = win->_maxx - x;
  67. minx = win->_firstch[y];
  68. maxx = win->_lastch[y];
  69. for (; n && *ch; n--, x++, ptr++, ch++)
  70. {
  71. if (*ptr != *ch)
  72. {
  73. if (x < minx || minx == _NO_CHANGE)
  74. minx = x;
  75. if (x > maxx)
  76. maxx = x;
  77. PDC_LOG(("y %d x %d minx %d maxx %d *ptr %x *ch"
  78. " %x firstch: %d lastch: %d\n",
  79. y, x, minx, maxx, *ptr, *ch,
  80. win->_firstch[y], win->_lastch[y]));
  81. *ptr = *ch;
  82. }
  83. }
  84. win->_firstch[y] = minx;
  85. win->_lastch[y] = maxx;
  86. return OK;
  87. }
  88. int addchstr(const chtype *ch)
  89. {
  90. PDC_LOG(("addchstr() - called\n"));
  91. return waddchnstr(stdscr, ch, -1);
  92. }
  93. int addchnstr(const chtype *ch, int n)
  94. {
  95. PDC_LOG(("addchnstr() - called\n"));
  96. return waddchnstr(stdscr, ch, n);
  97. }
  98. int waddchstr(WINDOW *win, const chtype *ch)
  99. {
  100. PDC_LOG(("waddchstr() - called: win=%p\n", win));
  101. return waddchnstr(win, ch, -1);
  102. }
  103. int mvaddchstr(int y, int x, const chtype *ch)
  104. {
  105. PDC_LOG(("mvaddchstr() - called: y %d x %d\n", y, x));
  106. if (move(y, x) == ERR)
  107. return ERR;
  108. return waddchnstr(stdscr, ch, -1);
  109. }
  110. int mvaddchnstr(int y, int x, const chtype *ch, int n)
  111. {
  112. PDC_LOG(("mvaddchnstr() - called: y %d x %d n %d\n", y, x, n));
  113. if (move(y, x) == ERR)
  114. return ERR;
  115. return waddchnstr(stdscr, ch, n);
  116. }
  117. int mvwaddchstr(WINDOW *win, int y, int x, const chtype *ch)
  118. {
  119. PDC_LOG(("mvwaddchstr() - called:\n"));
  120. if (wmove(win, y, x) == ERR)
  121. return ERR;
  122. return waddchnstr(win, ch, -1);
  123. }
  124. int mvwaddchnstr(WINDOW *win, int y, int x, const chtype *ch, int n)
  125. {
  126. PDC_LOG(("mvwaddchnstr() - called: y %d x %d n %d \n", y, x, n));
  127. if (wmove(win, y, x) == ERR)
  128. return ERR;
  129. return waddchnstr(win, ch, n);
  130. }
  131. #ifdef PDC_WIDE
  132. int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n)
  133. {
  134. PDC_LOG(("wadd_wchnstr() - called: win=%p n=%d\n", win, n));
  135. return waddchnstr(win, wch, n);
  136. }
  137. int add_wchstr(const cchar_t *wch)
  138. {
  139. PDC_LOG(("add_wchstr() - called\n"));
  140. return wadd_wchnstr(stdscr, wch, -1);
  141. }
  142. int add_wchnstr(const cchar_t *wch, int n)
  143. {
  144. PDC_LOG(("add_wchnstr() - called\n"));
  145. return wadd_wchnstr(stdscr, wch, n);
  146. }
  147. int wadd_wchstr(WINDOW *win, const cchar_t *wch)
  148. {
  149. PDC_LOG(("wadd_wchstr() - called: win=%p\n", win));
  150. return wadd_wchnstr(win, wch, -1);
  151. }
  152. int mvadd_wchstr(int y, int x, const cchar_t *wch)
  153. {
  154. PDC_LOG(("mvadd_wchstr() - called: y %d x %d\n", y, x));
  155. if (move(y, x) == ERR)
  156. return ERR;
  157. return wadd_wchnstr(stdscr, wch, -1);
  158. }
  159. int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n)
  160. {
  161. PDC_LOG(("mvadd_wchnstr() - called: y %d x %d n %d\n", y, x, n));
  162. if (move(y, x) == ERR)
  163. return ERR;
  164. return wadd_wchnstr(stdscr, wch, n);
  165. }
  166. int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch)
  167. {
  168. PDC_LOG(("mvwadd_wchstr() - called:\n"));
  169. if (wmove(win, y, x) == ERR)
  170. return ERR;
  171. return wadd_wchnstr(win, wch, -1);
  172. }
  173. int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch, int n)
  174. {
  175. PDC_LOG(("mvwadd_wchnstr() - called: y %d x %d n %d \n", y, x, n));
  176. if (wmove(win, y, x) == ERR)
  177. return ERR;
  178. return wadd_wchnstr(win, wch, n);
  179. }
  180. #endif