- /* Write the buffer to stdout, wrapping at 60 chars.
- * This looks overly complex, but it gets tricky as
- * the line has to continue to wrap correctly if we
- * have to refill the buffer
- *
- * Improvments most welcome
- */
-
- /* Initialise values for the new buffer */
- remaining = 4 * ((size + 2) / 3);
- buffer_offset = 0;
-
- /* Write the buffer to stdout, wrapping at 60 chars
- * starting from the column the last buffer ran out
- */
- do {
- if (remaining > (60 - column)) {
- write_size = 60 - column;
- }
- else if (remaining < 60) {
- write_size = remaining;
- } else {
- write_size = 60;
- }
-
- /* Setup a new row if required */
- if (column == 0) {
- putchar('\n');
- if (tbl == tbl_std) {
- putchar('M');
- }
- }
- /* Write to the 60th column */
- if (fwrite(&dst_buf[buffer_offset], 1, write_size, stdout) != write_size) {
- perror("Couldnt finish writing");
- }
- /* Update variables based on last write */
- buffer_offset += write_size;
- remaining -= write_size;
- column += write_size;
- if (column % 60 == 0) {
- column = 0;
- }
- } while (remaining > 0);
+ putchar('\n');
+ if (tbl == tbl_std) {
+ putchar(tbl[size]);
+ }
+ if (fwrite(dst_buf, 1, write_size, stdout) != write_size) {
+ bb_perror_msg_and_die(bb_msg_write_error);
+ }