Permalink
Browse files

- updated readme

  • Loading branch information...
1 parent df51c7f commit 9e0f435ad9161a288306cf12e9abcc86a700219f @penduin penduin committed Oct 17, 2012
Showing with 6 additions and 111 deletions.
  1. +3 −3 README
  2. +3 −3 README.md
  3. +0 −105 example/validate.c
View
6 README
@@ -7,7 +7,7 @@ on top of the lower-level WJReader and WJWriter libraries (also included).
WJReader and WJWriter are optimized for speed and memory-efficiency.
WJElement focuses on flexibility and handy features, allowing C code to
manipulate JSON documents with as few statements (fewer, sometimes!) as
-JavaScript itself.
+JavaScript itself. WJElement is also capable of json-schema validation.
WJElement has grown into a generally-useful library, and is used across
Messaging Architects' netmail and related projects. It is loved enough by
@@ -19,5 +19,5 @@ in ways we haven't thought of. Read the docs/headers, have fun, and if you
use it for something awesome, let us know about it! :^)
-Owen Swerkstrom <owens@netmail.com> - community/repository front-man
-Micah N Gorrell <micahg@netmail.com> - primary author of WJElement code
+Owen Swerkstrom <owens@netmail.com> - community/repo front-man, WJESchema
+Micah N Gorrell <micahg@netmail.com> - primary author of WJElement
View
@@ -12,7 +12,7 @@ and full [API](wjelement/wiki/WJElement-API) reference.
WJReader and WJWriter are optimized for speed and memory-efficiency.
WJElement focuses on flexibility and handy features, allowing C code to
manipulate JSON documents with as few statements (fewer, sometimes!) as
-JavaScript itself.
+JavaScript itself. WJElement is also capable of json-schema validation.
WJElement has grown into a generally-useful library, and is used across
Messaging Architects' netmail and related projects. It is loved enough by
@@ -24,5 +24,5 @@ in ways we haven't thought of. Read the docs/headers, have fun, and if you
use it for something awesome, let us know about it! :^)
-* Owen Swerkstrom <<owens@netmail.com>> - community/repository front-man
-* Micah N Gorrell <<micahg@netmail.com>> - primary author of WJElement code
+* Owen Swerkstrom <owens@netmail.com> - community/repo front-man, WJESchema
+* Micah N Gorrell micahg@netmail.com - primary author of WJElement
View
@@ -1,105 +0,0 @@
-/*
- validate.c: a proof-of-concept json-schema validator
- thanks to xiaoping.x.liu@intel.com
-
- after installing libwjelement (and running ldconfig if needed)...
- gcc -o validate -lwjelement validate.c
-*/
-
-
-#include <wjelement.h>
-#include <stdarg.h>
-
-
-/*
- callback: load more schema from files based on "name" and a pattern argument
-*/
-static WJElement schema_load(const char *name, void *client,
- const char *file, const int line) {
- char *format;
- char *path;
- WJReader readschema;
- WJElement schema;
-
- schema = NULL;
- if(client && name) {
- format = (char *)client;
- asprintf(&path, format, name);
- if((readschema = WJROpenFILEDocument(path, NULL, 0))) {
- schema = WJEOpenDocument(readschema, NULL, NULL, NULL);
- }
- }
-
- return schema;
-}
-
-/*
- callback: plop validation errors to stderr
-*/
-static void schema_error(void *client, const char *format, ...) {
- va_list ap;
- va_start(ap, format);
- vfprintf(stderr, format, ap);
- va_end(ap);
- fprintf(stderr, "\n");
-}
-
-
-int main(int argc, char **argv) {
- FILE *jsonfile;
- FILE *schemafile;
- WJReader readjson;
- WJReader readschema;
- WJElement json;
- WJElement schema;
- XplBool succ;
- char *format;
-
- if(argc != 3 && argc != 4) {
- printf("usage:\n");
- printf("\t%s <json-file> <schema-file>\n", argv[0]);
- printf("\t%s <json-file> <schema-file> <schema-pattern>\n", argv[0]);
- printf("<schema-pattern>: \"path/to/%%s.json\" additional schemas\n");
- return 255;
- }
-
- if(!(jsonfile = fopen(argv[1], "r"))) {
- fprintf(stderr, "json file not found: '%s'\n", argv[1]);
- return 1;
- }
- if(!(schemafile = fopen(argv[2], "r"))) {
- fprintf(stderr, "schema file not found: '%s'\n", argv[2]);
- return 2;
- }
- if(argc == 4) {
- format = argv[3];
- } else {
- format = NULL;
- }
-
- if(!(readjson = WJROpenFILEDocument(jsonfile, NULL, 0)) ||
- !(json = WJEOpenDocument(readjson, NULL, NULL, NULL))) {
- fprintf(stderr, "json could not be read.\n");
- return 3;
- }
- if(!(readschema = WJROpenFILEDocument(schemafile, NULL, 0)) ||
- !(schema = WJEOpenDocument(readschema, NULL, NULL, NULL))) {
- fprintf(stderr, "schema could not be read.\n");
- WJECloseDocument(json);
- return 4;
- }
-
- WJEDump(json);
- WJEDump(schema);
-
- if(WJESchemaValidate(schema, json, schema_error, schema_load, NULL,
- format)) {
- printf("validation: PASS\n");
- } else {
- printf("validation: FAIL\n");
- }
-
- WJECloseDocument(json);
- WJECloseDocument(schema);
- return 0;
-}

0 comments on commit 9e0f435

Please sign in to comment.