instr.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. instr
  5. -----
  6. ### Synopsis
  7. int instr(char *str);
  8. int innstr(char *str, int n);
  9. int winstr(WINDOW *win, char *str);
  10. int winnstr(WINDOW *win, char *str, int n);
  11. int mvinstr(int y, int x, char *str);
  12. int mvinnstr(int y, int x, char *str, int n);
  13. int mvwinstr(WINDOW *win, int y, int x, char *str);
  14. int mvwinnstr(WINDOW *win, int y, int x, char *str, int n);
  15. int inwstr(wchar_t *wstr);
  16. int innwstr(wchar_t *wstr, int n);
  17. int winwstr(WINDOW *win, wchar_t *wstr);
  18. int winnwstr(WINDOW *win, wchar_t *wstr, int n);
  19. int mvinwstr(int y, int x, wchar_t *wstr);
  20. int mvinnwstr(int y, int x, wchar_t *wstr, int n);
  21. int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr);
  22. int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n);
  23. ### Description
  24. These functions take characters (or wide characters) from the current
  25. or specified position in the window, and return them as a string in
  26. str (or wstr). Attributes are ignored. The functions with n as the
  27. last argument return a string at most n characters long.
  28. ### Return Value
  29. Upon successful completion, innstr(), mvinnstr(), mvwinnstr() and
  30. winnstr() return the number of characters actually read into the
  31. string; instr(), mvinstr(), mvwinstr() and winstr() return OK.
  32. Otherwise, all these functions return ERR.
  33. ### Portability
  34. X/Open ncurses NetBSD
  35. instr Y Y Y
  36. winstr Y Y Y
  37. mvinstr Y Y Y
  38. mvwinstr Y Y Y
  39. innstr Y Y Y
  40. winnstr Y Y Y
  41. mvinnstr Y Y Y
  42. mvwinnstr Y Y Y
  43. inwstr Y Y Y
  44. winwstr Y Y Y
  45. mvinwstr Y Y Y
  46. mvwinwstr Y Y Y
  47. innwstr Y Y Y
  48. winnwstr Y Y Y
  49. mvinnwstr Y Y Y
  50. mvwinnwstr Y Y Y
  51. **man-end****************************************************************/
  52. int winnstr(WINDOW *win, char *str, int n)
  53. {
  54. #ifdef PDC_WIDE
  55. wchar_t wstr[513];
  56. if (n < 0 || n > 512)
  57. n = 512;
  58. if (winnwstr(win, wstr, n) == ERR)
  59. return ERR;
  60. return PDC_wcstombs(str, wstr, n);
  61. #else
  62. chtype *src;
  63. int i;
  64. PDC_LOG(("winnstr() - called: n %d \n", n));
  65. if (!win || !str)
  66. return ERR;
  67. if (n < 0 || (win->_curx + n) > win->_maxx)
  68. n = win->_maxx - win->_curx;
  69. src = win->_y[win->_cury] + win->_curx;
  70. for (i = 0; i < n; i++)
  71. str[i] = src[i] & A_CHARTEXT;
  72. str[i] = '\0';
  73. return i;
  74. #endif
  75. }
  76. int instr(char *str)
  77. {
  78. PDC_LOG(("instr() - called: string=\"%s\"\n", str));
  79. return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK;
  80. }
  81. int winstr(WINDOW *win, char *str)
  82. {
  83. PDC_LOG(("winstr() - called: \n"));
  84. return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK;
  85. }
  86. int mvinstr(int y, int x, char *str)
  87. {
  88. PDC_LOG(("mvinstr() - called: y %d x %d \n", y, x));
  89. if (move(y, x) == ERR)
  90. return ERR;
  91. return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK;
  92. }
  93. int mvwinstr(WINDOW *win, int y, int x, char *str)
  94. {
  95. PDC_LOG(("mvwinstr() - called: y %d x %d \n", y, x));
  96. if (wmove(win, y, x) == ERR)
  97. return ERR;
  98. return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK;
  99. }
  100. int innstr(char *str, int n)
  101. {
  102. PDC_LOG(("innstr() - called: n %d \n", n));
  103. return winnstr(stdscr, str, n);
  104. }
  105. int mvinnstr(int y, int x, char *str, int n)
  106. {
  107. PDC_LOG(("mvinnstr() - called: y %d x %d n %d \n", y, x, n));
  108. if (move(y, x) == ERR)
  109. return ERR;
  110. return winnstr(stdscr, str, n);
  111. }
  112. int mvwinnstr(WINDOW *win, int y, int x, char *str, int n)
  113. {
  114. PDC_LOG(("mvwinnstr() - called: y %d x %d n %d \n", y, x, n));
  115. if (wmove(win, y, x) == ERR)
  116. return ERR;
  117. return winnstr(win, str, n);
  118. }
  119. #ifdef PDC_WIDE
  120. int winnwstr(WINDOW *win, wchar_t *wstr, int n)
  121. {
  122. chtype *src;
  123. int i;
  124. PDC_LOG(("winnstr() - called: n %d \n", n));
  125. if (!win || !wstr)
  126. return ERR;
  127. if (n < 0 || (win->_curx + n) > win->_maxx)
  128. n = win->_maxx - win->_curx;
  129. src = win->_y[win->_cury] + win->_curx;
  130. for (i = 0; i < n; i++)
  131. wstr[i] = src[i] & A_CHARTEXT;
  132. wstr[i] = L'\0';
  133. return i;
  134. }
  135. int inwstr(wchar_t *wstr)
  136. {
  137. PDC_LOG(("inwstr() - called\n"));
  138. return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK;
  139. }
  140. int winwstr(WINDOW *win, wchar_t *wstr)
  141. {
  142. PDC_LOG(("winwstr() - called\n"));
  143. return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK;
  144. }
  145. int mvinwstr(int y, int x, wchar_t *wstr)
  146. {
  147. PDC_LOG(("mvinwstr() - called\n"));
  148. if (move(y, x) == ERR)
  149. return ERR;
  150. return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK;
  151. }
  152. int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr)
  153. {
  154. PDC_LOG(("mvwinstr() - called\n"));
  155. if (wmove(win, y, x) == ERR)
  156. return ERR;
  157. return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK;
  158. }
  159. int innwstr(wchar_t *wstr, int n)
  160. {
  161. PDC_LOG(("innwstr() - called\n"));
  162. return winnwstr(stdscr, wstr, n);
  163. }
  164. int mvinnwstr(int y, int x, wchar_t *wstr, int n)
  165. {
  166. PDC_LOG(("mvinnstr() - called\n"));
  167. if (move(y, x) == ERR)
  168. return ERR;
  169. return winnwstr(stdscr, wstr, n);
  170. }
  171. int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n)
  172. {
  173. PDC_LOG(("mvwinnwstr() - called\n"));
  174. if (wmove(win, y, x) == ERR)
  175. return ERR;
  176. return winnwstr(win, wstr, n);
  177. }
  178. #endif