socsvn commit: r270818 - soc2014/zkorchev/freebsd_head/usr.bin/wc
zkorchev at FreeBSD.org
zkorchev at FreeBSD.org
Mon Jul 14 10:16:30 UTC 2014
Author: zkorchev
Date: Mon Jul 14 10:16:28 2014
New Revision: 270818
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=270818
Log:
libsol support for wc
Modified:
soc2014/zkorchev/freebsd_head/usr.bin/wc/Makefile
soc2014/zkorchev/freebsd_head/usr.bin/wc/wc.c
Modified: soc2014/zkorchev/freebsd_head/usr.bin/wc/Makefile
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/wc/Makefile Mon Jul 14 10:16:11 2014 (r270817)
+++ soc2014/zkorchev/freebsd_head/usr.bin/wc/Makefile Mon Jul 14 10:16:28 2014 (r270818)
@@ -2,4 +2,8 @@
# $FreeBSD$
PROG= wc
+
+LDADD+= -lsol
+CFLAGS+=-DSOL_ON -I/usr/local/include
+
.include <bsd.prog.mk>
Modified: soc2014/zkorchev/freebsd_head/usr.bin/wc/wc.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/wc/wc.c Mon Jul 14 10:16:11 2014 (r270817)
+++ soc2014/zkorchev/freebsd_head/usr.bin/wc/wc.c Mon Jul 14 10:16:28 2014 (r270818)
@@ -57,11 +57,19 @@
#include <unistd.h>
#include <wchar.h>
#include <wctype.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
static uintmax_t tlinect, twordct, tcharct, tlongline;
static int doline, doword, dochar, domulti, dolongline;
static volatile sig_atomic_t siginfo;
+#if defined(SOL_ON)
+static struct sol_stream sol_stream;
+#endif
+static int sol_format;
+
static void show_cnt(const char *file, uintmax_t linect, uintmax_t wordct,
uintmax_t charct, uintmax_t llct);
static int cnt(const char *);
@@ -78,6 +86,7 @@
main(int argc, char *argv[])
{
int ch, errors, total;
+ int ismap = 0;
(void) setlocale(LC_CTYPE, "");
@@ -113,12 +122,22 @@
if (doline + doword + dochar + domulti + dolongline == 0)
doline = doword = dochar = 1;
+#if defined(SOL_ON)
+ sol_format = sol_init(&sol_stream);
+#endif
+
errors = 0;
total = 0;
if (!*argv) {
if (cnt((char *)NULL) != 0)
++errors;
} else {
+#if defined(SOL_ON)
+ if (sol_format) {
+ sol_map_start(&sol_stream);
+ ismap = 1;
+ }
+#endif
do {
if (cnt(*argv) != 0)
++errors;
@@ -128,6 +147,13 @@
if (total > 1)
show_cnt("total", tlinect, twordct, tcharct, tlongline);
+#if defined(SOL_ON)
+ if (sol_format) {
+ if (ismap)
+ sol_map_end(&sol_stream);
+ sol_term(&sol_stream);
+ }
+#endif
exit(errors == 0 ? 0 : 1);
}
@@ -144,18 +170,45 @@
siginfo = 0;
}
- if (doline)
- (void)fprintf(out, " %7ju", linect);
- if (doword)
- (void)fprintf(out, " %7ju", wordct);
- if (dochar || domulti)
- (void)fprintf(out, " %7ju", charct);
- if (dolongline)
- (void)fprintf(out, " %7ju", llct);
- if (file != NULL)
- (void)fprintf(out, " %s\n", file);
- else
- (void)fprintf(out, "\n");
+ if (sol_format) {
+#if defined(SOL_ON)
+ if (file != NULL)
+ sol_map_key(&sol_stream, file, strlen(file));
+
+ sol_map_start(&sol_stream);
+ if (doline) {
+ SOL_MAP_KEYL(&sol_stream, "lines");
+ sol_uinteger(&sol_stream, linect);
+ }
+ if (doword) {
+ SOL_MAP_KEYL(&sol_stream, "words");
+ sol_uinteger(&sol_stream, wordct);
+ }
+ if (dochar || domulti) {
+ SOL_MAP_KEYL(&sol_stream, "chars");
+ sol_uinteger(&sol_stream, charct);
+ }
+ if (dolongline) {
+ SOL_MAP_KEYL(&sol_stream, "longest");
+ sol_uinteger(&sol_stream, llct);
+ }
+ sol_map_end(&sol_stream);
+#endif
+ }
+ else {
+ if (doline)
+ (void)fprintf(out, " %7ju", linect);
+ if (doword)
+ (void)fprintf(out, " %7ju", wordct);
+ if (dochar || domulti)
+ (void)fprintf(out, " %7ju", charct);
+ if (dolongline)
+ (void)fprintf(out, " %7ju", llct);
+ if (file != NULL)
+ (void)fprintf(out, " %s\n", file);
+ else
+ (void)fprintf(out, "\n");
+ }
}
static int
More information about the svn-soc-all
mailing list