Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /* PDCurses */
  2.  
  3. #include <curspriv.h>
  4.  
  5. /*man-start**************************************************************
  6.  
  7. insstr
  8. ------
  9.  
  10. ### Synopsis
  11.  
  12.     int insstr(const char *str);
  13.     int insnstr(const char *str, int n);
  14.     int winsstr(WINDOW *win, const char *str);
  15.     int winsnstr(WINDOW *win, const char *str, int n);
  16.     int mvinsstr(int y, int x, const char *str);
  17.     int mvinsnstr(int y, int x, const char *str, int n);
  18.     int mvwinsstr(WINDOW *win, int y, int x, const char *str);
  19.     int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n);
  20.  
  21.     int ins_wstr(const wchar_t *wstr);
  22.     int ins_nwstr(const wchar_t *wstr, int n);
  23.     int wins_wstr(WINDOW *win, const wchar_t *wstr);
  24.     int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n);
  25.     int mvins_wstr(int y, int x, const wchar_t *wstr);
  26.     int mvins_nwstr(int y, int x, const wchar_t *wstr, int n);
  27.     int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr);
  28.     int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);
  29.  
  30. ### Description
  31.  
  32.    The insstr() functions insert a character string into a window at the
  33.    current cursor position, by repeatedly calling winsch(). When
  34.    PDCurses is built with wide-character support enabled, the narrow-
  35.    character functions treat the string as a multibyte string in the
  36.    current locale, and convert it first. All characters to the right of
  37.    the cursor are moved to the right, with the possibility of the
  38.    rightmost characters on the line being lost. The cursor position
  39.    does not change (after moving to y, x, if specified). The routines
  40.    with n as the last argument insert at most n characters; if n is
  41.    negative, then the entire string is inserted.
  42.  
  43. ### Return Value
  44.  
  45.    All functions return OK on success and ERR on error.
  46.  
  47. ### Portability
  48.                              X/Open  ncurses  NetBSD
  49.     insstr                      Y       Y       Y
  50.     winsstr                     Y       Y       Y
  51.     mvinsstr                    Y       Y       Y
  52.     mvwinsstr                   Y       Y       Y
  53.     insnstr                     Y       Y       Y
  54.     winsnstr                    Y       Y       Y
  55.     mvinsnstr                   Y       Y       Y
  56.     mvwinsnstr                  Y       Y       Y
  57.     ins_wstr                    Y       Y       Y
  58.     wins_wstr                   Y       Y       Y
  59.     mvins_wstr                  Y       Y       Y
  60.     mvwins_wstr                 Y       Y       Y
  61.     ins_nwstr                   Y       Y       Y
  62.     wins_nwstr                  Y       Y       Y
  63.     mvins_nwstr                 Y       Y       Y
  64.     mvwins_nwstr                Y       Y       Y
  65.  
  66. **man-end****************************************************************/
  67.  
  68. #include <string.h>
  69.  
  70. int winsnstr(WINDOW *win, const char *str, int n)
  71. {
  72. #ifdef PDC_WIDE
  73.     wchar_t wstr[513], *p;
  74.     int i;
  75. #endif
  76.     int len;
  77.  
  78.     PDC_LOG(("winsnstr() - called: string=\"%s\" n %d \n", str, n));
  79.  
  80.     if (!win || !str)
  81.         return ERR;
  82.  
  83.     len = strlen(str);
  84.  
  85.     if (n < 0 || n > len)
  86.         n = len;
  87.  
  88. #ifdef PDC_WIDE
  89.     if (n > 512)
  90.         n = 512;
  91.  
  92.     p = wstr;
  93.     i = 0;
  94.  
  95.     while (str[i] && i < n)
  96.     {
  97.         int retval = PDC_mbtowc(p, str + i, n - i);
  98.  
  99.         if (retval <= 0)
  100.             break;
  101.         p++;
  102.         i += retval;
  103.     }
  104.  
  105.     while (p > wstr)
  106.         if (winsch(win, *--p) == ERR)
  107. #else
  108.     while (n)
  109.         if (winsch(win, (unsigned char)(str[--n])) == ERR)
  110. #endif
  111.             return ERR;
  112.  
  113.     return OK;
  114. }
  115.  
  116. int insstr(const char *str)
  117. {
  118.     PDC_LOG(("insstr() - called: string=\"%s\"\n", str));
  119.  
  120.     return winsnstr(stdscr, str, -1);
  121. }
  122.  
  123. int winsstr(WINDOW *win, const char *str)
  124. {
  125.     PDC_LOG(("winsstr() - called: string=\"%s\"\n", str));
  126.  
  127.     return winsnstr(win, str, -1);
  128. }
  129.  
  130. int mvinsstr(int y, int x, const char *str)
  131. {
  132.     PDC_LOG(("mvinsstr() - called: y %d x %d string=\"%s\"\n", y, x, str));
  133.  
  134.     if (move(y, x) == ERR)
  135.         return ERR;
  136.  
  137.     return winsnstr(stdscr, str, -1);
  138. }
  139.  
  140. int mvwinsstr(WINDOW *win, int y, int x, const char *str)
  141. {
  142.     PDC_LOG(("mvwinsstr() - called: string=\"%s\"\n", str));
  143.  
  144.     if (wmove(win, y, x) == ERR)
  145.         return ERR;
  146.  
  147.     return winsnstr(win, str, -1);
  148. }
  149.  
  150. int insnstr(const char *str, int n)
  151. {
  152.     PDC_LOG(("insnstr() - called: string=\"%s\" n %d \n", str, n));
  153.  
  154.     return winsnstr(stdscr, str, n);
  155. }
  156.  
  157. int mvinsnstr(int y, int x, const char *str, int n)
  158. {
  159.     PDC_LOG(("mvinsnstr() - called: y %d x %d string=\"%s\" n %d \n",
  160.              y, x, str, n));
  161.  
  162.     if (move(y, x) == ERR)
  163.         return ERR;
  164.  
  165.     return winsnstr(stdscr, str, n);
  166. }
  167.  
  168. int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n)
  169. {
  170.     PDC_LOG(("mvwinsnstr() - called: y %d x %d string=\"%s\" n %d \n",
  171.              y, x, str, n));
  172.  
  173.     if (wmove(win, y, x) == ERR)
  174.         return ERR;
  175.  
  176.     return winsnstr(win, str, n);
  177. }
  178.  
  179. #ifdef PDC_WIDE
  180. int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
  181. {
  182.     const wchar_t *p;
  183.     int len;
  184.  
  185.     PDC_LOG(("wins_nwstr() - called\n"));
  186.  
  187.     if (!win || !wstr)
  188.         return ERR;
  189.  
  190.     for (len = 0, p = wstr; *p; p++)
  191.         len++;
  192.  
  193.     if (n < 0 || n > len)
  194.         n = len;
  195.  
  196.     while (n)
  197.         if (winsch(win, wstr[--n]) == ERR)
  198.             return ERR;
  199.  
  200.     return OK;
  201. }
  202.  
  203. int ins_wstr(const wchar_t *wstr)
  204. {
  205.     PDC_LOG(("ins_wstr() - called\n"));
  206.  
  207.     return wins_nwstr(stdscr, wstr, -1);
  208. }
  209.  
  210. int wins_wstr(WINDOW *win, const wchar_t *wstr)
  211. {
  212.     PDC_LOG(("wins_wstr() - called\n"));
  213.  
  214.     return wins_nwstr(win, wstr, -1);
  215. }
  216.  
  217. int mvins_wstr(int y, int x, const wchar_t *wstr)
  218. {
  219.     PDC_LOG(("mvins_wstr() - called\n"));
  220.  
  221.     if (move(y, x) == ERR)
  222.         return ERR;
  223.  
  224.     return wins_nwstr(stdscr, wstr, -1);
  225. }
  226.  
  227. int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr)
  228. {
  229.     PDC_LOG(("mvwinsstr() - called\n"));
  230.  
  231.     if (wmove(win, y, x) == ERR)
  232.         return ERR;
  233.  
  234.     return wins_nwstr(win, wstr, -1);
  235. }
  236.  
  237. int ins_nwstr(const wchar_t *wstr, int n)
  238. {
  239.     PDC_LOG(("ins_nwstr() - called\n"));
  240.  
  241.     return wins_nwstr(stdscr, wstr, n);
  242. }
  243.  
  244. int mvins_nwstr(int y, int x, const wchar_t *wstr, int n)
  245. {
  246.     PDC_LOG(("mvinsnstr() - called\n"));
  247.  
  248.     if (move(y, x) == ERR)
  249.         return ERR;
  250.  
  251.     return wins_nwstr(stdscr, wstr, n);
  252. }
  253.  
  254. int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n)
  255. {
  256.     PDC_LOG(("mvwinsnstr() - called\n"));
  257.  
  258.     if (wmove(win, y, x) == ERR)
  259.         return ERR;
  260.  
  261.     return wins_nwstr(win, wstr, n);
  262. }
  263. #endif
  264.