| 112 | The first column is 0. */ |
| 113 | |
| 114 | static size_t |
| 115 | adjust_column (size_t column, mcel_t g) |
| 116 | { |
| 117 | if (counting_mode != COUNT_BYTES) |
| 118 | { |
| 119 | if (g.ch == '\b') |
| 120 | { |
| 121 | if (column > 0) |
| 122 | column -= last_character_width; |
| 123 | } |
| 124 | else if (g.ch == '\r') |
| 125 | column = 0; |
| 126 | else if (g.ch == '\t') |
| 127 | column += TAB_WIDTH - column % TAB_WIDTH; |
| 128 | else |
| 129 | { |
| 130 | if (counting_mode == COUNT_CHARACTERS) |
| 131 | last_character_width = 1; |
| 132 | else |
| 133 | { |
| 134 | int width = c32width (g.ch); |
| 135 | /* Default to a width of 1 if there is an invalid character. */ |
| 136 | last_character_width = width < 0 ? 1 : width; |
| 137 | } |
| 138 | column += last_character_width; |
| 139 | } |
| 140 | } |
| 141 | else |
| 142 | column += g.len; |
| 143 | return column; |
| 144 | } |
| 145 | |
| 146 | static void |
| 147 | write_out (char const *line, size_t line_len, bool newline) |