MCPcopy Create free account
hub / github.com/NetHack/NetHack / curses_break_str

Function curses_break_str

win/curses/cursmisc.c:285–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283given width */
284
285char *
286curses_break_str(const char *str, int width, int line_num)
287{
288 int last_space, count;
289 char *retstr;
290 int curline = 0;
291 int strsize = (int) strlen(str) + 1;
292#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) && !defined(_MSC_VER)
293 char substr[strsize];
294 char curstr[strsize];
295 char tmpstr[strsize];
296
297 strcpy(substr, str);
298#else
299#ifndef BUFSZ
300#define BUFSZ 256
301#endif
302 char substr[BUFSZ * 2];
303 char curstr[BUFSZ * 2];
304 char tmpstr[BUFSZ * 2];
305
306 if (strsize > (BUFSZ * 2) - 1) {
307 paniclog("curses", "curses_break_str() string too long.");
308 strncpy(substr, str, (BUFSZ * 2) - 2);
309 substr[(BUFSZ * 2) - 1] = '\0';
310 } else
311 strcpy(substr, str);
312#endif
313
314 while (curline < line_num) {
315 if (strlen(substr) == 0) {
316 break;
317 }
318 curline++;
319 last_space = 0;
320 for (count = 0; count <= width; count++) {
321 if (substr[count] == ' ') {
322 last_space = count;
323 } else if (substr[count] == '\0') {
324 last_space = count;
325 break;
326 }
327 }
328 if (last_space == 0) { /* No spaces found */
329 last_space = count - 1;
330 }
331 for (count = 0; count < last_space; count++) {
332 curstr[count] = substr[count];
333 }
334 curstr[count] = '\0';
335 if (substr[count] == '\0') {
336 break;
337 }
338 for (count = (last_space + 1); count < (int) strlen(substr); count++) {
339 tmpstr[count - (last_space + 1)] = substr[count];
340 }
341 tmpstr[count - (last_space + 1)] = '\0';
342 strcpy(substr, tmpstr);

Callers 6

curses_message_win_putsFunction · 0.85
curses_line_input_dialogFunction · 0.85
get_menuitem_yFunction · 0.85
menu_display_pageFunction · 0.85

Calls 2

paniclogFunction · 0.85
curses_copy_ofFunction · 0.85

Tested by

no test coverage detected