summaryrefslogtreecommitdiff
path: root/payloads/libpayload/curses/PDCurses/pdcurses/addstr.c
blob: ca19fd02937885c51a65dcc5a3fb3d4eb1f6103b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* Public Domain Curses */

#include <curspriv.h>

RCSID("$Id: addstr.c,v 1.44 2008/07/13 16:08:17 wmcbrine Exp $")

/*man-start**************************************************************

  Name:                                                         addstr

  Synopsis:
        int addstr(const char *str);
        int addnstr(const char *str, int n);
        int waddstr(WINDOW *win, const char *str);
        int waddnstr(WINDOW *win, const char *str, int n);
        int mvaddstr(int y, int x, const char *str);
        int mvaddnstr(int y, int x, const char *str, int n);
        int mvwaddstr(WINDOW *win, int y, int x, const char *str);
        int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);

        int addwstr(const wchar_t *wstr);
        int addnwstr(const wchar_t *wstr, int n);
        int waddwstr(WINDOW *win, const wchar_t *wstr);
        int waddnwstr(WINDOW *win, const wchar_t *wstr, int n);
        int mvaddwstr(int y, int x, const wchar_t *wstr);
        int mvaddnwstr(int y, int x, const wchar_t *wstr, int n);
        int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr);
        int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);

  Description:
        These routines write all the characters of the null-terminated
        string str or wide-character string wstr to the given window.
        The functionality is similar to calling waddch() once for each
        character in the string; except that, when PDCurses is built
        with wide-character support enabled, the narrow-character
        functions treat the string as a multibyte string in the current
        locale, and convert it. The routines with n as the last
        argument write at most n characters; if n is negative, then the
        entire string will be added.

  Return Value:
        All functions return OK or ERR.

  Portability                                X/Open    BSD    SYS V
        addstr                                  Y       Y       Y
        waddstr                                 Y       Y       Y
        mvaddstr                                Y       Y       Y
        mvwaddstr                               Y       Y       Y
        addnstr                                 Y       -      4.0
        waddnstr                                Y       -      4.0
        mvaddnstr                               Y       -      4.0
        mvwaddnstr                              Y       -      4.0
        addwstr                                 Y
        waddwstr                                Y
        mvaddwstr                               Y
        mvwaddwstr                              Y
        addnwstr                                Y
        waddnwstr                               Y
        mvaddnwstr                              Y
        mvwaddnwstr                             Y

**man-end****************************************************************/

int waddnstr(WINDOW *win, const char *str, int n)
{
    int i = 0;

    PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n));

    if (!win || !str)
        return ERR;

    while (str[i] && (i < n || n < 0))
    {
#ifdef PDC_WIDE
        wchar_t wch;
        int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6);

        if (retval <= 0)
            return OK;

        i += retval;
#else
        chtype wch = (unsigned char)(str[i++]);
#endif
        if (waddch(win, wch) == ERR)
            return ERR;
    }

    return OK;
}

int addstr(const char *str)
{
    PDC_LOG(("addstr() - called: string=\"%s\"\n", str));

    return waddnstr(stdscr, str, -1);
}

int addnstr(const char *str, int n)
{
    PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n));

    return waddnstr(stdscr, str, n);
}

int waddstr(WINDOW *win, const char *str)
{
    PDC_LOG(("waddstr() - called: string=\"%s\"\n", str));

    return waddnstr(win, str, -1);
}

int mvaddstr(int y, int x, const char *str)
{
    PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str));

    if (move(y, x) == ERR)
        return ERR;

    return waddnstr(stdscr, str, -1);
}

int mvaddnstr(int y, int x, const char *str, int n)
{
    PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
             y, x, str, n));

    if (move(y, x) == ERR)
        return ERR;

    return waddnstr(stdscr, str, n);
}

int mvwaddstr(WINDOW *win, int y, int x, const char *str)
{
    PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str));

    if (wmove(win, y, x) == ERR)
        return ERR;

    return waddnstr(win, str, -1);
}

int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n)
{
    PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
             y, x, str, n));

    if (wmove(win, y, x) == ERR)
        return ERR;

    return waddnstr(win, str, n);
}

#ifdef PDC_WIDE
int waddnwstr(WINDOW *win, const wchar_t *wstr, int n)
{
    int i = 0;

    PDC_LOG(("waddnwstr() - called\n"));

    if (!win || !wstr)
        return ERR;

    while (wstr[i] && (i < n || n < 0))
    {
        chtype wch = wstr[i++];

        if (waddch(win, wch) == ERR)
            return ERR;
    }

    return OK;
}

int addwstr(const wchar_t *wstr)
{
    PDC_LOG(("addwstr() - called\n"));

    return waddnwstr(stdscr, wstr, -1);
}

int addnwstr(const wchar_t *wstr, int n)
{
    PDC_LOG(("addnwstr() - called\n"));

    return waddnwstr(stdscr, wstr, n);
}

int waddwstr(WINDOW *win, const wchar_t *wstr)
{
    PDC_LOG(("waddwstr() - called\n"));

    return waddnwstr(win, wstr, -1);
}

int mvaddwstr(int y, int x, const wchar_t *wstr)
{
    PDC_LOG(("mvaddstr() - called\n"));

    if (move(y, x) == ERR)
        return ERR;

    return waddnwstr(stdscr, wstr, -1);
}

int mvaddnwstr(int y, int x, const wchar_t *wstr, int n)
{
    PDC_LOG(("mvaddnstr() - called\n"));

    if (move(y, x) == ERR)
        return ERR;

    return waddnwstr(stdscr, wstr, n);
}

int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr)
{
    PDC_LOG(("mvwaddstr() - called\n"));

    if (wmove(win, y, x) == ERR)
        return ERR;

    return waddnwstr(win, wstr, -1);
}

int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n)
{
    PDC_LOG(("mvwaddnstr() - called\n"));

    if (wmove(win, y, x) == ERR)
        return ERR;

    return waddnwstr(win, wstr, n);
}
#endif