summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2014-11-11 19:56:05 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2014-11-11 19:56:05 +0100
commit9a52f59fc546d509dc1a859c6cce92f99e31f46d (patch)
tree2095b7fcc079d78b91d298a3913508bfd69489da /util.c
parenta855f803fd27af9ec1d19c5d7444ef0ad3d91b0b (diff)
code style, use actual column width of char
Diffstat (limited to 'util.c')
-rw-r--r--util.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/util.c b/util.c
index 618080e..a993bd6 100644
--- a/util.c
+++ b/util.c
@@ -1,9 +1,10 @@
+#include <ctype.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-#include <time.h>
-#include <ctype.h>
+#include <string.h>
#include <sys/types.h>
+#include <time.h>
+#include <wchar.h>
#include "util.h"
@@ -14,7 +15,8 @@
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
-strlcpy(char *dst, const char *src, size_t siz) {
+strlcpy(char *dst, const char *src, size_t siz)
+{
char *d = dst;
const char *s = src;
size_t n = siz;
@@ -38,7 +40,8 @@ strlcpy(char *dst, const char *src, size_t siz) {
/* print link; if link is relative use baseurl to make it absolute */
void
-printlink(const char *link, const char *baseurl, FILE *fp) {
+printlink(const char *link, const char *baseurl, FILE *fp)
+{
const char *ebaseproto, *ebasedomain, *p;
int isrelative;
@@ -105,7 +108,8 @@ parseline(char **line, size_t *size, char **fields,
/* print feed name for id; spaces and tabs in string as "-"
* (spaces in anchors are not valid). */
void
-printfeednameid(const char *s, FILE *fp) {
+printfeednameid(const char *s, FILE *fp)
+{
for(; *s; s++)
fputc(isspace((int)*s) ? '-' : tolower((int)*s), fp);
}
@@ -124,7 +128,8 @@ printhtmlencoded(const char *s, FILE *fp) {
}
void
-feedsfree(struct feed *f) {
+feedsfree(struct feed *f)
+{
struct feed *next = NULL;
for(; f; f = next) {
@@ -137,14 +142,21 @@ feedsfree(struct feed *f) {
}
void
-printutf8pad(FILE *fp, const char *s, size_t len, int pad) {
+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[i] && n < len; i++) {
- /* start of character */
- if((s[i] & 0xc0) != 0x80)
- n++;
- putc(s[i], fp);
+ for(i = 0; *s && n < len; i++, s++) {
+ 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);