addstr.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. addstr
  5. ------
  6. ### Synopsis
  7. int addstr(const char *str);
  8. int addnstr(const char *str, int n);
  9. int waddstr(WINDOW *win, const char *str);
  10. int waddnstr(WINDOW *win, const char *str, int n);
  11. int mvaddstr(int y, int x, const char *str);
  12. int mvaddnstr(int y, int x, const char *str, int n);
  13. int mvwaddstr(WINDOW *win, int y, int x, const char *str);
  14. int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);
  15. int addwstr(const wchar_t *wstr);
  16. int addnwstr(const wchar_t *wstr, int n);
  17. int waddwstr(WINDOW *win, const wchar_t *wstr);
  18. int waddnwstr(WINDOW *win, const wchar_t *wstr, int n);
  19. int mvaddwstr(int y, int x, const wchar_t *wstr);
  20. int mvaddnwstr(int y, int x, const wchar_t *wstr, int n);
  21. int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr);
  22. int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);
  23. ### Description
  24. These routines write all the characters of the null-terminated string
  25. str or wide-character string wstr to the given window. The
  26. functionality is similar to calling waddch() once for each character
  27. in the string; except that, when PDCurses is built with wide-
  28. character support enabled, the narrow-character functions treat the
  29. string as a multibyte string in the current locale, and convert it.
  30. The routines with n as the last argument write at most n characters;
  31. if n is negative, then the entire string will be added.
  32. ### Return Value
  33. All functions return OK or ERR.
  34. ### Portability
  35. X/Open ncurses NetBSD
  36. addstr Y Y Y
  37. waddstr Y Y Y
  38. mvaddstr Y Y Y
  39. mvwaddstr Y Y Y
  40. addnstr Y Y Y
  41. waddnstr Y Y Y
  42. mvaddnstr Y Y Y
  43. mvwaddnstr Y Y Y
  44. addwstr Y Y Y
  45. waddwstr Y Y Y
  46. mvaddwstr Y Y Y
  47. mvwaddwstr Y Y Y
  48. addnwstr Y Y Y
  49. waddnwstr Y Y Y
  50. mvaddnwstr Y Y Y
  51. mvwaddnwstr Y Y Y
  52. **man-end****************************************************************/
  53. int waddnstr(WINDOW *win, const char *str, int n)
  54. {
  55. int i = 0;
  56. PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n));
  57. if (!win || !str)
  58. return ERR;
  59. while (str[i] && (i < n || n < 0))
  60. {
  61. #ifdef PDC_WIDE
  62. wchar_t wch;
  63. int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6);
  64. if (retval <= 0)
  65. return OK;
  66. i += retval;
  67. #else
  68. chtype wch = (unsigned char)(str[i++]);
  69. #endif
  70. if (waddch(win, wch) == ERR)
  71. return ERR;
  72. }
  73. return OK;
  74. }
  75. int addstr(const char *str)
  76. {
  77. PDC_LOG(("addstr() - called: string=\"%s\"\n", str));
  78. return waddnstr(stdscr, str, -1);
  79. }
  80. int addnstr(const char *str, int n)
  81. {
  82. PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n));
  83. return waddnstr(stdscr, str, n);
  84. }
  85. int waddstr(WINDOW *win, const char *str)
  86. {
  87. PDC_LOG(("waddstr() - called: string=\"%s\"\n", str));
  88. return waddnstr(win, str, -1);
  89. }
  90. int mvaddstr(int y, int x, const char *str)
  91. {
  92. PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str));
  93. if (move(y, x) == ERR)
  94. return ERR;
  95. return waddnstr(stdscr, str, -1);
  96. }
  97. int mvaddnstr(int y, int x, const char *str, int n)
  98. {
  99. PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
  100. y, x, str, n));
  101. if (move(y, x) == ERR)
  102. return ERR;
  103. return waddnstr(stdscr, str, n);
  104. }
  105. int mvwaddstr(WINDOW *win, int y, int x, const char *str)
  106. {
  107. PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str));
  108. if (wmove(win, y, x) == ERR)
  109. return ERR;
  110. return waddnstr(win, str, -1);
  111. }
  112. int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n)
  113. {
  114. PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
  115. y, x, str, n));
  116. if (wmove(win, y, x) == ERR)
  117. return ERR;
  118. return waddnstr(win, str, n);
  119. }
  120. #ifdef PDC_WIDE
  121. int waddnwstr(WINDOW *win, const wchar_t *wstr, int n)
  122. {
  123. int i = 0;
  124. PDC_LOG(("waddnwstr() - called\n"));
  125. if (!win || !wstr)
  126. return ERR;
  127. while (wstr[i] && (i < n || n < 0))
  128. {
  129. chtype wch = wstr[i++];
  130. if (waddch(win, wch) == ERR)
  131. return ERR;
  132. }
  133. return OK;
  134. }
  135. int addwstr(const wchar_t *wstr)
  136. {
  137. PDC_LOG(("addwstr() - called\n"));
  138. return waddnwstr(stdscr, wstr, -1);
  139. }
  140. int addnwstr(const wchar_t *wstr, int n)
  141. {
  142. PDC_LOG(("addnwstr() - called\n"));
  143. return waddnwstr(stdscr, wstr, n);
  144. }
  145. int waddwstr(WINDOW *win, const wchar_t *wstr)
  146. {
  147. PDC_LOG(("waddwstr() - called\n"));
  148. return waddnwstr(win, wstr, -1);
  149. }
  150. int mvaddwstr(int y, int x, const wchar_t *wstr)
  151. {
  152. PDC_LOG(("mvaddstr() - called\n"));
  153. if (move(y, x) == ERR)
  154. return ERR;
  155. return waddnwstr(stdscr, wstr, -1);
  156. }
  157. int mvaddnwstr(int y, int x, const wchar_t *wstr, int n)
  158. {
  159. PDC_LOG(("mvaddnstr() - called\n"));
  160. if (move(y, x) == ERR)
  161. return ERR;
  162. return waddnwstr(stdscr, wstr, n);
  163. }
  164. int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr)
  165. {
  166. PDC_LOG(("mvwaddstr() - called\n"));
  167. if (wmove(win, y, x) == ERR)
  168. return ERR;
  169. return waddnwstr(win, wstr, -1);
  170. }
  171. int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n)
  172. {
  173. PDC_LOG(("mvwaddnstr() - called\n"));
  174. if (wmove(win, y, x) == ERR)
  175. return ERR;
  176. return waddnwstr(win, wstr, n);
  177. }
  178. #endif