diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-07-31 21:06:52 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-07-31 21:12:07 +0200 |
commit | 356e7d79925f91b9b703ee63e3680694c53a59a4 (patch) | |
tree | bc06b59ee637c2695055b62221abad696d66eb7c /sfeed_plain.c | |
parent | eb586eda26967183de91c314a57d323b124110bb (diff) |
Various improvements
- Only escape characters in "content" field, these can contain newlines.
- Trim newlines and tabs, etc from the title, id and author fields.
- Make decodefield, xmlencode functions easier to "chain" without allocatting
new buffers.
- Move printutf8pad from util (only used by sfeed_plain) to sfeed_plain.
- Update README, still need to update the man-page and improve the documentation
in general.
- Code cleanup.
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]); } } |