[hackers] [sbase] Scrap writerune(), introducing fputrune() || FRIGN
commit f82b8d2ac54ff7d318f951719be62155d6be86e9
Author: FRIGN <dev_AT_frign.de>
Date: Wed Feb 11 20:58:00 2015 +0100
Scrap writerune(), introducing fputrune()
Interface and function as proposed by cls.
Code is also shorter, everything else analogous to fgetrune().
diff --git a/Makefile b/Makefile
index 9d969d3..50db65a 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -24,7 +24,7 @@ LIBUTFSRC =\
libutf/utf.c\
libutf/chartorunearr.c\
libutf/fgetrune.c\
- libutf/writerune.c\
+ libutf/fputrune.c\
libutf/isalnumrune.c\
libutf/isalpharune.c\
libutf/isblankrune.c\
diff --git a/expand.c b/expand.c
index 8adaa24..c643df7 100644
--- a/expand.c
+++ b/expand.c
_AT_@ -72,7 +72,7 @@ expand(const char *file, FILE *fp)
col++;
if (r != ' ')
bol = 0;
- writerune("<stdout>", stdout, &r);
+ efputrune(&r, stdout, "<stdout>");
break;
}
}
diff --git a/libutf/fputrune.c b/libutf/fputrune.c
new file mode 100644
index 0000000..6a393b5
--- /dev/null
+++ b/libutf/fputrune.c
_AT_@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../utf.h"
+
+int
+fputrune(const Rune *r, FILE *fp)
+{
+ char buf[UTFmax];
+
+ return fwrite(buf, runetochar(buf, r), 1, fp);
+}
+
+int
+efputrune(const Rune *r, FILE *fp, const char *file)
+{
+ int ret;
+
+ if ((ret = fputrune(r, fp)) < 0) {
+ fprintf(stderr, "fputrune %s: %s\n", file, strerror(errno));
+ exit(1);
+ }
+ return ret;
+}
diff --git a/libutf/writerune.c b/libutf/writerune.c
deleted file mode 100644
index eb9cfac..0000000
--- a/libutf/writerune.c
+++ /dev/null
_AT_@ -1,23 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "../utf.h"
-
-void
-writerune(const char *file, FILE *fp, Rune *r)
-{
- char buf[UTFmax];
- int n;
-
- if ((n = runetochar(buf, r)) > 0) {
- fwrite(buf, n, 1, fp);
- if (ferror(fp)) {
- fprintf(stderr, "%s: write error: %s\n",
- file, strerror(errno));
- exit(1);
- }
- }
-}
diff --git a/paste.c b/paste.c
index 32832d7..cd7eb3e 100644
--- a/paste.c
+++ b/paste.c
_AT_@ -26,17 +26,17 @@ sequential(struct fdescr *dsc, int fdescrlen, Rune *delim, size_t delimlen)
while (efgetrune(&c, dsc[i].fp, dsc[i].name)) {
if (last == '\n') {
if (delim[d] != '\0')
- writerune("<stdout>", stdout, &delim[d]);
+ efputrune(&delim[d], stdout, "<stdout>");
d = (d + 1) % delimlen;
}
if (c != '\n')
- writerune("<stdout>", stdout, &c);
+ efputrune(&c, stdout, "<stdout>");
last = c;
}
if (last == '\n')
- writerune("<stdout>", stdout, &last);
+ efputrune(&last, stdout, "<stdout>");
}
}
_AT_@ -56,22 +56,22 @@ nextline:
for (; efgetrune(&c, dsc[i].fp, dsc[i].name) ;) {
for (m = last + 1; m < i; m++)
- writerune("<stdout>", stdout, &(delim[m % delimlen]));
+ efputrune(&(delim[m % delimlen]), stdout, "<stdout>");
last = i;
if (c == '\n') {
if (i != fdescrlen - 1)
c = d;
- writerune("<stdout>", stdout, &c);
+ efputrune(&c, stdout, "<stdout>");
break;
}
- writerune("<stdout>", stdout, &c);
+ efputrune(&c, stdout, "<stdout>");
}
if (c == 0 && last != -1) {
if (i == fdescrlen - 1)
putchar('\n');
else
- writerune("<stdout>", stdout, &d);
+ efputrune(&d, stdout, "<stdout>");
last++;
}
}
diff --git a/tail.c b/tail.c
index 8b8dc38..9f7eca3 100644
--- a/tail.c
+++ b/tail.c
_AT_@ -63,7 +63,7 @@ taketail(FILE *fp, const char *str)
fputs(ring[j], stdout);
free(ring[j]);
} else if (r) {
- writerune("<stdout>", stdout, &r[j]);
+ efputrune(&r[j], stdout, "<stdout>");
}
} while ((j = (j + 1) % num) != i);
diff --git a/tr.c b/tr.c
index 2d6d37b..fa3d412 100644
--- a/tr.c
+++ b/tr.c
_AT_@ -271,6 +271,6 @@ read:
goto read;
write:
lastrune = r;
- writerune("<stdout>", stdout, &r);
+ efputrune(&r, stdout, "<stdout>");
goto read;
}
diff --git a/unexpand.c b/unexpand.c
index 0b16f74..17852b6 100644
--- a/unexpand.c
+++ b/unexpand.c
_AT_@ -44,10 +44,10 @@ unexpandspan(size_t last, size_t col)
r = '\t';
for (; last + tablist[i] <= col; last += tablist[i])
- writerune("<stdout>", stdout, &r);
+ efputrune(&r, stdout, "<stdout>");
r = ' ';
for (; last < col; last++)
- writerune("<stdout>", stdout, &r);
+ efputrune(&r, stdout, "<stdout>");
} else {
for (i = 0; i < tablistlen; i++)
if (col < tablist[i])
_AT_@ -57,12 +57,12 @@ unexpandspan(size_t last, size_t col)
break;
r = '\t';
for (; j < i; j++) {
- writerune("<stdout>", stdout, &r);
+ efputrune(&r, stdout, "<stdout>");
last = tablist[j];
}
r = ' ';
for (; last < col; last++)
- writerune("<stdout>", stdout, &r);
+ efputrune(&r, stdout, "<stdout>");
}
}
_AT_@ -115,7 +115,7 @@ unexpand(const char *file, FILE *fp)
break;
}
if ((r != ' ' && r != '\t') || (!aflag && !bol))
- writerune("<stdout>", stdout, &r);
+ efputrune(&r, stdout, "<stdout>");
}
if (last < col && (bol || aflag))
unexpandspan(last, col);
diff --git a/utf.h b/utf.h
index bd58f0a..203849a 100644
--- a/utf.h
+++ b/utf.h
_AT_@ -61,5 +61,7 @@ Rune toupperrune(Rune);
int fgetrune(Rune *, FILE *);
int efgetrune(Rune *, FILE *, const char *);
-void writerune(const char *, FILE *, Rune *);
+int fputrune(const Rune *, FILE *);
+int efputrune(const Rune *, FILE *, const char *);
+
int chartorunearr(const char*, Rune **);
Received on Wed Feb 11 2015 - 23:09:14 CET
This archive was generated by hypermail 2.3.0
: Wed Feb 11 2015 - 23:12:09 CET