static char *buffer_edit(char *buf, void (*func) (const char *p)) { int len, c; len = strlen(buf); if (func) prom_printf(buf); else { for (c = 0; c < len; c++) prom_printf("*"); } for (;;) { c = prom_getchar(); if (c == -1) break; if (char_is_newline(c)) break; if (char_is_tab(c) && func) len = tabfunc(buf, len, func); else if (char_is_backspace(c)) { if (len > 0) { --len; buf[len] = 0; prom_printf("\b \b"); } } else { c = char_to_ascii(c); if (c && len < CMD_LENG - 2) { buf[len] = c; buf[len + 1] = 0; if (func) prom_printf(buf + len); else prom_printf("*"); len++; } } } buf[len] = 0; return buf; }
void wrap_cstr( string& wrapped, unsigned int from_column, unsigned int second_indent, const string &orig ) { int next_space = from_column; string next_word; const char * out_buf = orig.c_str(); ostringstream stream; const unsigned int second_line_column = from_column + second_indent; string indent (second_line_column, ' '); int newline_chars = 0; int num_of_newlines = 0; while (*out_buf) { // check for a new line if (*out_buf) if ((newline_chars = char_is_newline(out_buf, num_of_newlines))) { for (int i = 1; i <= num_of_newlines; ++i) stream << "\\n"; out_buf += newline_chars; if (*out_buf) { stream << indent; next_space = second_line_column; continue; } else break; } else { stream << *out_buf++; next_space++; } // search next whitespace, i.e., next word while ((*out_buf) && (*out_buf != ' ') && ! char_is_newline(out_buf, num_of_newlines)) { // num_of_newlines is not used. next_word += *out_buf++; next_space++; } // wrap line if it's too long if (next_space > 79) { stream << "\\n" << indent << next_word; next_space = second_line_column + next_word.size(); } else stream << next_word; // simply write word next_word = ""; } wrapped += stream.str(); }