Skip to content

Commit

Permalink
Move json into part.
Browse files Browse the repository at this point in the history
  • Loading branch information
weetmuts committed Nov 19, 2023
1 parent 56996c1 commit 7e8a81b
Show file tree
Hide file tree
Showing 12 changed files with 1,378 additions and 491 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ help:
@echo " make release linux64"

BUILDDIRS:=$(dir $(realpath $(wildcard build/*/spec.mk)))
FIRSTDIR:=$(word 1,$(BUILDDIRS))

ifeq (,$(BUILDDIRS))
ifneq (clean,$(findstring clean,$(MAKECMDGOALS)))
Expand Down Expand Up @@ -118,6 +119,11 @@ lcov:
@echo Generating code coverage $(words $(BUILDDIRS)) host\(s\).
@for x in $(BUILDDIRS); do echo; echo Bulding $$(basename $$x) ; $(MAKE) --no-print-directory -C $$x debug lcov ; done

dist:
@$(MAKE) --no-print-directory -C $(FIRSTDIR) release $(shell pwd)/dist/xmq.c $(shell pwd)/dist/xmq.h

.PHONY: dist

test: test_release
testd: test_debug
testa: test_asan
Expand Down
44 changes: 41 additions & 3 deletions dist/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#include"xmq.h"

#include<stdio.h>
#include<string.h>

void expect(const char *s, const char *e);
void expect_int(int32_t i, int32_t e);
void expect_double(double d, double e);

int main(int argc, char **argv)
{
Expand All @@ -10,17 +15,50 @@ int main(int argc, char **argv)

bool ok = xmqParseFile(doc, file, "car");
if (!ok) {
printf("Could not load file %s.\n", file);
printf("Parse error in %s\n%s",
file,
xmqDocError(doc));
return 1;
}
const char *model = xmqGetString(doc, NULL, "/car/model");
int32_t speed = xmqGetInt(doc, NULL, "/car/speed");
int32_t num_wheels = xmqGetInt(doc, NULL, "/car/num_wheels");
double weight = xmqGetDouble(doc, NULL, "/car/weight");
const char *registration = xmqGetString(doc, NULL, "/car/registration");
const char *not_found = xmqGetString(doc, NULL, "/car/not_found");
const char *color = xmqGetString(doc, NULL, "/car/color");
const char *history = xmqGetString(doc, NULL, "/car/history");

expect(model, "EsCarGo");
expect_int(num_wheels, 36);
expect_double(weight, 999.123);

xmqFreeDoc(doc);

return ok ? 0 : 1;
}

void expect(const char *s, const char *e)
{
if (strcmp(s, e))
{
printf("Expected %s but got %s\n", e, s);
exit(1);
}
}

void expect_int(int32_t i, int32_t e)
{
if (i != e)
{
printf("Expected %d but got %d\n", e, i);
exit(1);
}
}

void expect_double(double d, double e)
{
if (d != e)
{
printf("Expected %f but got %f\n", e, d);
exit(1);
}
}
10 changes: 10 additions & 0 deletions dist/example.xmq
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
car {
model = 'EsCarGo'
num_wheels = 36
weight = 999.123
registration = 'abc 123'
quote = '''The 'slowest' "car" ´ever´ `sold`'''
history = '1911 Founded
1936 First car sold
1977 Second car sold'
}
Loading

0 comments on commit 7e8a81b

Please sign in to comment.