1 #define _POSIX_C_SOURCE 200809L
11 #define ERR(str) { perror(str); err = EXIT_FAILURE; goto end; }
15 if (setlocale(LC_ALL, "") == NULL) {
23 int err = EXIT_SUCCESS;
25 while ((len = getline(&buf, &siz, stdin)) > 0) {
27 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) ERR("ioctl")
29 int term_width = ws.ws_col;
39 size_t adv = mbrtowc(&wc, ptr, len, &mbs);
40 if (adv == (size_t) -1 || adv == (size_t) -2) ERR("mbrtowc")
45 int width = wcwidth(wc);
49 if (*ptr == '\n' || str_width >= term_width - 12) {
50 for (int i = (term_width - str_width) / 2; i > 0; i--)
52 fwrite(last, 1, ptr - last + 1, stdout);