X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fu8-line.c;h=34e650952a2c201da5e7b3080e25b60989aecda4;hb=b745220f07d9ea7d4196318a79835563bbcbad6f;hp=33442ba287644fe09f7e2458bc113147cebecd75;hpb=b2518c70cc5b55bb630b07ddcda5dfd7a3613da4;p=pspp diff --git a/src/libpspp/u8-line.c b/src/libpspp/u8-line.c index 33442ba287..34e650952a 100644 --- a/src/libpspp/u8-line.c +++ b/src/libpspp/u8-line.c @@ -193,3 +193,29 @@ u8_line_put (struct u8_line *line, int x0, int x1, const char *s, int n) { memcpy (u8_line_reserve (line, x0, x1, n), s, n); } + +/* Changes the width of LINE to X column widths. If X is longer than LINE's + previous width, LINE is extended by appending spaces. If X is shorter than + LINE's previous width, LINE is shortened by removing trailing characters. */ +void +u8_line_set_length (struct u8_line *line, int x) +{ + if (x > line->width) + { + ds_put_byte_multiple (&line->s, ' ', x - line->width); + line->width = x; + } + else if (x < line->width) + { + struct u8_pos pos; + + u8_line_find_pos (line, x, &pos); + ds_truncate (&line->s, pos.ofs0); + line->width = pos.x0; + if (x > line->width) + { + ds_put_byte_multiple (&line->s, '?', x - line->width); + line->width = x; + } + } +}