socsvn commit: r271838 - soc2014/zkorchev/freebsd_head/lib/libsol

zkorchev at FreeBSD.org zkorchev at FreeBSD.org
Mon Aug 4 09:31:41 UTC 2014


Author: zkorchev
Date: Mon Aug  4 09:31:39 2014
New Revision: 271838
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271838

Log:
  libsol configuration format support; reduced include dependencies by libraries using libsol

Modified:
  soc2014/zkorchev/freebsd_head/lib/libsol/Makefile
  soc2014/zkorchev/freebsd_head/lib/libsol/sol.c
  soc2014/zkorchev/freebsd_head/lib/libsol/sol.h

Modified: soc2014/zkorchev/freebsd_head/lib/libsol/Makefile
==============================================================================
--- soc2014/zkorchev/freebsd_head/lib/libsol/Makefile	Mon Aug  4 09:30:19 2014	(r271837)
+++ soc2014/zkorchev/freebsd_head/lib/libsol/Makefile	Mon Aug  4 09:31:39 2014	(r271838)
@@ -5,7 +5,7 @@
 SHLIBDIR?= /lib
 SHLIB_MAJOR= 0
 SRCS=	sol.c
-INCS=	sol.h
+INCS=	sol.h sol_internal.h
 
 #MAN=	vmstat.8
 LDFLAGS+=	-L/usr/local/lib -lyajl

Modified: soc2014/zkorchev/freebsd_head/lib/libsol/sol.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/lib/libsol/sol.c	Mon Aug  4 09:30:19 2014	(r271837)
+++ soc2014/zkorchev/freebsd_head/lib/libsol/sol.c	Mon Aug  4 09:31:39 2014	(r271838)
@@ -28,7 +28,24 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "sol.h"
+#include <yajl/yajl_gen.h>	// libyajl
+
+#include "sol_internal.h"
+
+struct sol_stream
+{
+	enum sol_format f;
+	union
+	{
+		yajl_gen g;
+		struct
+		{
+			unsigned char stack[SOL_DEPTH_MAX];
+			unsigned depth;
+			int first;
+		} c;
+	} ctx;
+};
 
 // TODO error checks
 
@@ -69,6 +86,10 @@
 		stream->ctx.c.depth = 0;
 		stream->ctx.c.first = 0;
 	}
+	else if (!strcmp(format, "xml"))
+	{
+		stream->f = SOL_XML;
+	}
 	else return 0;
 
 	return stream->f;
@@ -88,6 +109,7 @@
 		break;
 
 	case SOL_CONF:
+	case SOL_XML:
 		fflush(stdout);
 		break;
 	}
@@ -104,6 +126,7 @@
 		break;
 
 	case SOL_CONF:
+	case SOL_XML:
 		write(1, "\n", 1); // TODO change this
 		break;
 	}
@@ -124,6 +147,9 @@
 		stream->ctx.c.stack[stream->ctx.c.depth++] = 0;
 		stream->ctx.c.first = 1;
 		break;
+
+	case SOL_XML:
+		break;
 	}
 
 	return 0;
@@ -204,7 +230,7 @@
 
 	case SOL_CONF:
 		padding(stream);
-		printf("%s", key);
+		printf("%s", key); // TODO escape special chars
 		break;
 	}
 

Modified: soc2014/zkorchev/freebsd_head/lib/libsol/sol.h
==============================================================================
--- soc2014/zkorchev/freebsd_head/lib/libsol/sol.h	Mon Aug  4 09:30:19 2014	(r271837)
+++ soc2014/zkorchev/freebsd_head/lib/libsol/sol.h	Mon Aug  4 09:31:39 2014	(r271838)
@@ -23,27 +23,24 @@
  * SUCH DAMAGE.
  */
 
-#include <inttypes.h>
-
-#include <yajl/yajl_gen.h>	// libyajl
+#include "sol_internal.h"
 
 #define SOL_MAP_KEYL(stream, key) sol_map_key(stream, key, sizeof(key) - 1)
 
-#define SOL_DEPTH_MAX 32
-
+// WARNING: This is not the real layout of the struct. It just defines the size of the struct.
 struct sol_stream
 {
-	enum {SOL_JSON = 1, SOL_CONF} f;
-	union
-	{
-		yajl_gen g;
-		struct
+	char _[sizeof(struct
 		{
-			unsigned char stack[SOL_DEPTH_MAX];
-			unsigned depth;
-			int first;
-		} c;
-	} ctx;
+			enum sol_format f;
+			struct
+			{
+				unsigned char stack[SOL_DEPTH_MAX];
+				unsigned depth;
+				int first;
+			} c;
+		}
+	)];
 };
 
 int sol_init(struct sol_stream *restrict stream);


More information about the svn-soc-all mailing list