Merge pull request #771 from robertbaldyga/fix-casadm-long-path-printing

casadm: Fix printing long device paths
This commit is contained in:
Robert Baldyga 2021-03-30 09:28:18 +02:00 committed by GitHub
commit 5176ac3359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -702,15 +702,18 @@ static int finish_tree(struct view_t *this)
static int print_word_break_lines(struct view_t *this, static int print_word_break_lines(struct view_t *this,
char *word, char *word,
int word_len, int word_len,
int screen_width) int screen_width,
int *words_in_line)
{ {
struct text_out_prv *prv = this->ctx.text_prv; struct text_out_prv *prv = this->ctx.text_prv;
if (prv->col_ptr + word_len > screen_width) { if (prv->col_ptr + word_len > screen_width && *words_in_line) {
putc('\n', this->outfile); putc('\n', this->outfile);
prv->col_ptr = 1 + vector_get(&prv->col_w, 0); prv->col_ptr = 1 + vector_get(&prv->col_w, 0);
print_spaces(this->outfile, prv->col_ptr); print_spaces(this->outfile, prv->col_ptr);
*words_in_line = 0;
} }
prv->col_ptr += word_len; prv->col_ptr += word_len;
(*words_in_line)++;
return word_len != fwrite(word, 1, word_len, this->outfile); return word_len != fwrite(word, 1, word_len, this->outfile);
} }
@ -743,6 +746,7 @@ static int print_cell_break_lines(struct view_t *this,
if (prv->col_ptr + cell_len > screen_width) { if (prv->col_ptr + cell_len > screen_width) {
int off = 0; int off = 0;
int word_off = 0; int word_off = 0;
int words_in_line = 0;
do { do {
if (' ' == cell[word_off + off] || if (' ' == cell[word_off + off] ||
!cell[word_off + off]) { !cell[word_off + off]) {
@ -750,7 +754,8 @@ static int print_cell_break_lines(struct view_t *this,
print_spaces_state(this, 1, screen_width); print_spaces_state(this, 1, screen_width);
} }
print_word_break_lines(this, cell + off, print_word_break_lines(this, cell + off,
word_off, screen_width); word_off, screen_width,
&words_in_line);
off += word_off + 1; off += word_off + 1;
word_off = 0; word_off = 0;
} else { } else {