socsvn commit: r271187 - soc2014/zkorchev/freebsd_head/usr.bin/du

zkorchev at FreeBSD.org zkorchev at FreeBSD.org
Mon Jul 21 09:48:15 UTC 2014


Author: zkorchev
Date: Mon Jul 21 09:48:13 2014
New Revision: 271187
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271187

Log:
  libsol support for du

Modified:
  soc2014/zkorchev/freebsd_head/usr.bin/du/Makefile
  soc2014/zkorchev/freebsd_head/usr.bin/du/du.c

Modified: soc2014/zkorchev/freebsd_head/usr.bin/du/Makefile
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/du/Makefile	Mon Jul 21 09:47:53 2014	(r271186)
+++ soc2014/zkorchev/freebsd_head/usr.bin/du/Makefile	Mon Jul 21 09:48:13 2014	(r271187)
@@ -3,6 +3,7 @@
 
 PROG=	du
 DPADD=	${LIBUTIL}
-LDADD=	-lutil
+CFLAGS+= -DSOL_ON -I/usr/local/include
+LDADD=	-lutil -lsol
 
 .include <bsd.prog.mk>

Modified: soc2014/zkorchev/freebsd_head/usr.bin/du/du.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/du/du.c	Mon Jul 21 09:47:53 2014	(r271186)
+++ soc2014/zkorchev/freebsd_head/usr.bin/du/du.c	Mon Jul 21 09:48:13 2014	(r271187)
@@ -60,6 +60,9 @@
 #include <string.h>
 #include <sysexits.h>
 #include <unistd.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 static SLIST_HEAD(ignhead, ignentry) ignores;
 struct ignentry {
@@ -67,6 +70,11 @@
 	SLIST_ENTRY(ignentry)	next;
 };
 
+#if defined(SOL_ON)
+static struct sol_stream sol_stream;
+#endif
+static int sol_format;
+
 static int	linkchk(FTSENT *);
 static void	usage(void);
 static void	prthumanval(int64_t);
@@ -252,6 +260,17 @@
 	if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL)
 		err(1, "fts_open");
 
+#if defined(SOL_ON)
+	sol_format = sol_init(&sol_stream);
+	if (sol_format) {
+		sol_map_start(&sol_stream);
+		if (cflag) {
+			SOL_MAP_KEYL(&sol_stream, "size");
+			sol_map_start(&sol_stream);
+		}
+	}
+#endif
+
 	while ((p = fts_read(fts)) != NULL) {
 		switch (p->fts_info) {
 		case FTS_D:			/* Ignore. */
@@ -271,14 +290,28 @@
 			if (p->fts_level <= depth && threshold <=
 			    threshold_sign * howmany(p->fts_bignum *
 			    cblocksize, blocksize)) {
-				if (hflag) {
-					prthumanval(p->fts_bignum);
-					(void)printf("\t%s\n", p->fts_path);
-				} else {
-					(void)printf("%jd\t%s\n",
-					    (intmax_t)howmany(p->fts_bignum *
-					    cblocksize, blocksize),
-					    p->fts_path);
+#if defined(SOL_ON)
+				if (sol_format)
+				{
+					sol_map_key(&sol_stream, p->fts_path, strlen(p->fts_path));
+					if (hflag)
+						prthumanval(p->fts_bignum);
+					else
+						sol_integer(&sol_stream, howmany(p->fts_bignum *
+							cblocksize, blocksize));
+				}
+				else
+#endif
+				{
+					if (hflag) {
+							prthumanval(p->fts_bignum);
+							(void)printf("\t%s\n", p->fts_path);
+					} else {
+						(void)printf("%jd\t%s\n",
+							(intmax_t)howmany(p->fts_bignum *
+							cblocksize, blocksize),
+							p->fts_path);
+					}
 				}
 			}
 			if (info) {
@@ -307,14 +340,28 @@
 			    howmany(p->fts_statp->st_blocks, cblocksize);
 
 			if (aflag || p->fts_level == 0) {
-				if (hflag) {
-					prthumanval(curblocks);
-					(void)printf("\t%s\n", p->fts_path);
-				} else {
-					(void)printf("%jd\t%s\n",
-					    (intmax_t)howmany(curblocks *
-					    cblocksize, blocksize),
-					    p->fts_path);
+#if defined(SOL_ON)
+				if (sol_format)
+				{
+					sol_map_key(&sol_stream, p->fts_path, strlen(p->fts_path));
+					if (hflag)
+						prthumanval(curblocks);
+					else
+						sol_integer(&sol_stream, howmany(curblocks *
+							cblocksize, blocksize));
+				}
+				else
+#endif
+				{
+					if (hflag) {
+						prthumanval(curblocks);
+						(void)printf("\t%s\n", p->fts_path);
+					} else {
+						(void)printf("%jd\t%s\n",
+							(intmax_t)howmany(curblocks *
+							cblocksize, blocksize),
+							p->fts_path);
+					}
 				}
 			}
 
@@ -327,15 +374,35 @@
 		err(1, "fts_read");
 
 	if (cflag) {
-		if (hflag) {
-			prthumanval(savednumber);
-			(void)printf("\ttotal\n");
-		} else {
-			(void)printf("%jd\ttotal\n", (intmax_t)howmany(
-			    savednumber * cblocksize, blocksize));
+#if defined(SOL_ON)
+		if (sol_format) {
+			sol_map_end(&sol_stream);
+			SOL_MAP_KEYL(&sol_stream, "total");
+			if (hflag)
+				prthumanval(savednumber);
+			else
+				sol_integer(&sol_stream, howmany(savednumber * cblocksize, blocksize));
+		}
+		else
+#endif
+		{
+			if (hflag) {
+				prthumanval(savednumber);
+				(void)printf("\ttotal\n");
+			} else {
+				(void)printf("%jd\ttotal\n", (intmax_t)howmany(
+					savednumber * cblocksize, blocksize));
+			}
 		}
 	}
 
+#if defined(SOL_ON)
+	if (sol_format) {
+		sol_map_end(&sol_stream);
+		sol_term(&sol_stream);
+	}
+#endif
+
 	ignoreclean();
 	exit(rval);
 }
@@ -478,15 +545,21 @@
 prthumanval(int64_t bytes)
 {
 	char buf[5];
+	size_t len;
 
 	bytes *= cblocksize;
 	if (!Aflag)
 		bytes *= DEV_BSIZE;
 
-	humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
+	len = humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
 	    HN_B | HN_NOSPACE | HN_DECIMAL);
 
-	(void)printf("%4s", buf);
+#if defined(SOL_ON)
+	if (sol_format)
+		sol_string(&sol_stream, buf, len);
+	else
+#endif
+		(void)printf("%4s", buf);
 }
 
 static void


More information about the svn-soc-all mailing list