inchstr.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. inchstr
  5. -------
  6. ### Synopsis
  7. int inchstr(chtype *ch);
  8. int inchnstr(chtype *ch, int n);
  9. int winchstr(WINDOW *win, chtype *ch);
  10. int winchnstr(WINDOW *win, chtype *ch, int n);
  11. int mvinchstr(int y, int x, chtype *ch);
  12. int mvinchnstr(int y, int x, chtype *ch, int n);
  13. int mvwinchstr(WINDOW *, int y, int x, chtype *ch);
  14. int mvwinchnstr(WINDOW *, int y, int x, chtype *ch, int n);
  15. int in_wchstr(cchar_t *wch);
  16. int in_wchnstr(cchar_t *wch, int n);
  17. int win_wchstr(WINDOW *win, cchar_t *wch);
  18. int win_wchnstr(WINDOW *win, cchar_t *wch, int n);
  19. int mvin_wchstr(int y, int x, cchar_t *wch);
  20. int mvin_wchnstr(int y, int x, cchar_t *wch, int n);
  21. int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wch);
  22. int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wch, int n);
  23. ### Description
  24. These routines read a chtype or cchar_t string from the window,
  25. starting at the current or specified position, and ending at the
  26. right margin, or after n elements, whichever is less.
  27. ### Return Value
  28. All functions return the number of elements read, or ERR on error.
  29. ### Portability
  30. X/Open ncurses NetBSD
  31. inchstr Y Y Y
  32. winchstr Y Y Y
  33. mvinchstr Y Y Y
  34. mvwinchstr Y Y Y
  35. inchnstr Y Y Y
  36. winchnstr Y Y Y
  37. mvinchnstr Y Y Y
  38. mvwinchnstr Y Y Y
  39. in_wchstr Y Y Y
  40. win_wchstr Y Y Y
  41. mvin_wchstr Y Y Y
  42. mvwin_wchstr Y Y Y
  43. in_wchnstr Y Y Y
  44. win_wchnstr Y Y Y
  45. mvin_wchnstr Y Y Y
  46. mvwin_wchnstr Y Y Y
  47. **man-end****************************************************************/
  48. int winchnstr(WINDOW *win, chtype *ch, int n)
  49. {
  50. chtype *src;
  51. int i;
  52. PDC_LOG(("winchnstr() - called\n"));
  53. if (!win || !ch || n < 0)
  54. return ERR;
  55. if ((win->_curx + n) > win->_maxx)
  56. n = win->_maxx - win->_curx;
  57. src = win->_y[win->_cury] + win->_curx;
  58. for (i = 0; i < n; i++)
  59. *ch++ = *src++;
  60. *ch = (chtype)0;
  61. return OK;
  62. }
  63. int inchstr(chtype *ch)
  64. {
  65. PDC_LOG(("inchstr() - called\n"));
  66. return winchnstr(stdscr, ch, stdscr->_maxx - stdscr->_curx);
  67. }
  68. int winchstr(WINDOW *win, chtype *ch)
  69. {
  70. PDC_LOG(("winchstr() - called\n"));
  71. return winchnstr(win, ch, win->_maxx - win->_curx);
  72. }
  73. int mvinchstr(int y, int x, chtype *ch)
  74. {
  75. PDC_LOG(("mvinchstr() - called: y %d x %d\n", y, x));
  76. if (move(y, x) == ERR)
  77. return ERR;
  78. return winchnstr(stdscr, ch, stdscr->_maxx - stdscr->_curx);
  79. }
  80. int mvwinchstr(WINDOW *win, int y, int x, chtype *ch)
  81. {
  82. PDC_LOG(("mvwinchstr() - called:\n"));
  83. if (wmove(win, y, x) == ERR)
  84. return ERR;
  85. return winchnstr(win, ch, win->_maxx - win->_curx);
  86. }
  87. int inchnstr(chtype *ch, int n)
  88. {
  89. PDC_LOG(("inchnstr() - called\n"));
  90. return winchnstr(stdscr, ch, n);
  91. }
  92. int mvinchnstr(int y, int x, chtype *ch, int n)
  93. {
  94. PDC_LOG(("mvinchnstr() - called: y %d x %d n %d\n", y, x, n));
  95. if (move(y, x) == ERR)
  96. return ERR;
  97. return winchnstr(stdscr, ch, n);
  98. }
  99. int mvwinchnstr(WINDOW *win, int y, int x, chtype *ch, int n)
  100. {
  101. PDC_LOG(("mvwinchnstr() - called: y %d x %d n %d \n", y, x, n));
  102. if (wmove(win, y, x) == ERR)
  103. return ERR;
  104. return winchnstr(win, ch, n);
  105. }
  106. #ifdef PDC_WIDE
  107. int win_wchnstr(WINDOW *win, cchar_t *wch, int n)
  108. {
  109. PDC_LOG(("win_wchnstr() - called\n"));
  110. return winchnstr(win, wch, n);
  111. }
  112. int in_wchstr(cchar_t *wch)
  113. {
  114. PDC_LOG(("in_wchstr() - called\n"));
  115. return win_wchnstr(stdscr, wch, stdscr->_maxx - stdscr->_curx);
  116. }
  117. int win_wchstr(WINDOW *win, cchar_t *wch)
  118. {
  119. PDC_LOG(("win_wchstr() - called\n"));
  120. return win_wchnstr(win, wch, win->_maxx - win->_curx);
  121. }
  122. int mvin_wchstr(int y, int x, cchar_t *wch)
  123. {
  124. PDC_LOG(("mvin_wchstr() - called: y %d x %d\n", y, x));
  125. if (move(y, x) == ERR)
  126. return ERR;
  127. return win_wchnstr(stdscr, wch, stdscr->_maxx - stdscr->_curx);
  128. }
  129. int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wch)
  130. {
  131. PDC_LOG(("mvwin_wchstr() - called:\n"));
  132. if (wmove(win, y, x) == ERR)
  133. return ERR;
  134. return win_wchnstr(win, wch, win->_maxx - win->_curx);
  135. }
  136. int in_wchnstr(cchar_t *wch, int n)
  137. {
  138. PDC_LOG(("in_wchnstr() - called\n"));
  139. return win_wchnstr(stdscr, wch, n);
  140. }
  141. int mvin_wchnstr(int y, int x, cchar_t *wch, int n)
  142. {
  143. PDC_LOG(("mvin_wchnstr() - called: y %d x %d n %d\n", y, x, n));
  144. if (move(y, x) == ERR)
  145. return ERR;
  146. return win_wchnstr(stdscr, wch, n);
  147. }
  148. int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wch, int n)
  149. {
  150. PDC_LOG(("mvwinchnstr() - called: y %d x %d n %d \n", y, x, n));
  151. if (wmove(win, y, x) == ERR)
  152. return ERR;
  153. return win_wchnstr(win, wch, n);
  154. }
  155. #endif