diff options
Diffstat (limited to 'sfeed_plain.c')
-rw-r--r-- | sfeed_plain.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/sfeed_plain.c b/sfeed_plain.c index 4942d92..ff54df5 100644 --- a/sfeed_plain.c +++ b/sfeed_plain.c @@ -1,8 +1,10 @@ +#include <ctype.h> #include <err.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> +#include <wchar.h> #include "util.h" @@ -10,6 +12,32 @@ static time_t comparetime; static char *line = NULL; static size_t size = 0; +/* print `len' columns of characters. If string is shorter pad the rest + * with characters `pad`. */ +static void +printutf8pad(FILE *fp, const char *s, size_t len, int pad) +{ + wchar_t w; + size_t n = 0, i; + int r; + + for (i = 0; *s && n < len; i++, s++) { + /* skip control characters */ + if (iscntrl(*s)) + continue; + if (ISUTF8(*s)) { + if ((r = mbtowc(&w, s, 4)) == -1) + break; + if ((r = wcwidth(w)) == -1) + r = 1; + n += (size_t)r; + } + putc(*s, fp); + } + for (; n < len; n++) + putc(pad, fp); +} + static void printfeed(FILE *fp, const char *feedname) { @@ -27,9 +55,7 @@ printfeed(FILE *fp, const char *feedname) printf("%-15.15s ", feedname); printf(" %-30.30s ", fields[FieldTimeFormatted]); printutf8pad(stdout, fields[FieldTitle], 70, ' '); - fputs(" ", stdout); - fputs(fields[FieldLink], stdout); - putchar('\n'); + printf(" %s\n", fields[FieldLink]); } } |