Skip to content

Commit 866dde8

Browse files
author
Micah N Gorrell
committed
Merge branch 'wjelement++' of https://github.com/petehug/wjelement into petehug-wjelement++
Added a cmake build option to enable distinguishing integers, and added missing #ifdef lines needed for the option to behave properly.
2 parents f785426 + 7769645 commit 866dde8

File tree

12 files changed

+776
-25
lines changed

12 files changed

+776
-25
lines changed

.gitignore

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,46 @@ install_manifest.txt
1212
wjelement.pc
1313
wjecli
1414
wjeunit
15-
libxpl.so
16-
libxpl.so.*
17-
libwjelement.so
18-
libwjelement.so.*
19-
libwjreader.so
20-
libwjreader.so.*
21-
libwjwriter.so
22-
libwjwriter.so.*
15+
16+
# Compiled Object files
17+
*.slo
18+
*.lo
19+
*.o
20+
*.obj
21+
22+
# Precompiled Headers
23+
*.gch
24+
*.pch
25+
26+
# Compiled Dynamic libraries
27+
*.so
28+
*.so.*
29+
*.dylib
30+
*.dll
31+
32+
# Fortran module files
33+
*.mod
34+
35+
# Compiled Static libraries
36+
*.lai
37+
*.la
38+
*.a
39+
*.lib
40+
41+
# Executables
42+
*.exe
43+
*.out
44+
*.app
45+
46+
# Log files
47+
*.log
48+
49+
# Visual Studio specific files
50+
Win32/
51+
x64/
52+
ipch/
53+
*.suo
54+
*.sdf
55+
*.user
56+
*.tlog
57+

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ else(STATIC_LIB)
1212
set(BUILD_SHARED_LIBS ON)
1313
endif(STATIC_LIB)
1414

15+
option(DISTINGUISH_INTEGERS "Distinguish between integer and non-integer numbers" OFF)
16+
if(DISTINGUISH_INTEGERS)
17+
add_definitions(-DWJE_DISTINGUISH_INTEGER_TYPE)
18+
endif()
19+
1520
if("${CMAKE_SYSTEM}" MATCHES "Linux")
1621
add_definitions(-D_GNU_SOURCE)
1722
endif()

Makefile-all

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
CC=gcc
2+
MAKEDIR=@mkdir -p $(@D)
3+
BUILDDIR=unix/release
4+
#CFLAGS=-c -Wall -DWJE_DISTINGUISH_INTEGER_TYPE -O3 -Iinclude
5+
CFLAGS=-c -Wall -DWJE_DISTINGUISH_INTEGER_TYPE -g -DDEBUG -Iinclude
6+
7+
all: $(BUILDDIR)/libwjelement.a
8+
9+
$(BUILDDIR)/libwjelement.a: $(BUILDDIR)/xpl.o $(BUILDDIR)/element.o $(BUILDDIR)/hash.o $(BUILDDIR)/search.o $(BUILDDIR)/types.o $(BUILDDIR)/wjreader.o $(BUILDDIR)/wjwriter.o
10+
$(MAKEDIR)
11+
ar rvs $@ $(BUILDDIR)/xpl.o $(BUILDDIR)/element.o $(BUILDDIR)/hash.o $(BUILDDIR)/search.o $(BUILDDIR)/types.o $(BUILDDIR)/wjreader.o $(BUILDDIR)/wjwriter.o
12+
13+
$(BUILDDIR)/xpl.o: src/lib/xpl.c
14+
$(MAKEDIR)
15+
$(CC) $(CFLAGS) $< -o $@
16+
17+
$(BUILDDIR)/element.o: src/wjelement/element.c
18+
$(MAKEDIR)
19+
$(CC) $(CFLAGS) $< -o $@
20+
21+
$(BUILDDIR)/hash.o: src/wjelement/hash.c
22+
$(MAKEDIR)
23+
$(CC) $(CFLAGS) $< -o $@
24+
25+
$(BUILDDIR)/search.o: src/wjelement/search.c
26+
$(MAKEDIR)
27+
$(CC) $(CFLAGS) $< -o $@
28+
29+
$(BUILDDIR)/types.o: src/wjelement/types.c
30+
$(MAKEDIR)
31+
$(CC) $(CFLAGS) $< -o $@
32+
33+
$(BUILDDIR)/wjreader.o: src/wjreader/wjreader.c
34+
$(MAKEDIR)
35+
$(CC) $(CFLAGS) $< -o $@
36+
37+
$(BUILDDIR)/wjwriter.o: src/wjwriter/wjwriter.c
38+
$(MAKEDIR)
39+
$(CC) $(CFLAGS) $< -o $@
40+
41+
clean:
42+
rm $(BUILDDIR)/*

include/memmgr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#include <stdlib.h>
2828
#include <stdio.h>
2929

30+
#ifndef asprintf
31+
int asprintf(char **strp, const char *fmt, ...);
32+
#else
33+
#define HAS_ASPRINTF
34+
#endif
3035

3136
#define MemAssert(p)
3237

include/wjreader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ typedef enum {
8383
WJR_TYPE_STRING = 'S',
8484
WJR_TYPE_NUMBER = 'N',
8585

86+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
87+
WJR_TYPE_INTEGER = 'I',
88+
#endif
89+
8690
WJR_TYPE_BOOL = 'B',
8791
WJR_TYPE_TRUE = 'T',
8892
WJR_TYPE_FALSE = 'F',

src/wjelement/element.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,20 @@ static WJElement _WJELoad(_WJElement *parent, WJReader reader, char *where, WJEL
281281
break;
282282

283283
case WJR_TYPE_NUMBER:
284+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
285+
case WJR_TYPE_INTEGER:
286+
#endif
284287
l->value.number.hasDecimalPoint = WJRIntOrDouble(reader,
285288
&l->value.number.i,
286289
&l->value.number.d);
287290

291+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
292+
if (l->value.number.hasDecimalPoint) {
293+
l->pub.type = WJR_TYPE_NUMBER;
294+
} else {
295+
l->pub.type = WJR_TYPE_INTEGER;
296+
}
297+
#endif
288298

289299
if (WJRNegative(reader)) {
290300
/*
@@ -510,10 +520,22 @@ static WJElement _WJECopy(_WJElement *parent, WJElement original, WJECopyCB copy
510520
break;
511521

512522
case WJR_TYPE_NUMBER:
523+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
524+
case WJR_TYPE_INTEGER:
525+
#endif
513526
l->value.number.negative = o->value.number.negative;
514527
l->value.number.i = o->value.number.i;
515528
l->value.number.d = o->value.number.d;
516529
l->value.number.hasDecimalPoint = o->value.number.hasDecimalPoint;
530+
531+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
532+
if (l->value.number.hasDecimalPoint) {
533+
l->pub.type = WJR_TYPE_NUMBER;
534+
} else {
535+
l->pub.type = WJR_TYPE_INTEGER;
536+
}
537+
#endif
538+
517539
break;
518540

519541
case WJR_TYPE_TRUE:
@@ -630,17 +652,24 @@ EXPORT XplBool _WJEWriteDocument(WJElement document, WJWriter writer, char *name
630652
break;
631653

632654
case WJR_TYPE_NUMBER:
655+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
656+
case WJR_TYPE_INTEGER:
657+
#endif
633658
if (current->value.number.hasDecimalPoint) {
659+
current->pub.type = WJR_TYPE_NUMBER;
634660
if (!current->value.number.negative) {
635661
WJWDouble(name, current->value.number.d, writer);
636662
} else {
637663
WJWDouble(name, -current->value.number.d, writer);
638664
}
639665
} else {
666+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
667+
current->pub.type = WJR_TYPE_INTEGER;
668+
#endif
640669
if (!current->value.number.negative) {
641670
WJWUInt64(name, current->value.number.i, writer);
642671
} else {
643-
WJWInt64(name, -current->value.number.i, writer);
672+
WJWInt64(name, -((int64) current->value.number.i), writer);
644673
}
645674
}
646675
break;

src/wjelement/hash.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ static void _WJEHash(WJElement document, int depth, WJEHashCB update, void *cont
7070
break;
7171

7272
case WJR_TYPE_NUMBER:
73+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
74+
case WJR_TYPE_INTEGER:
75+
#endif
7376
n = WJENumber(document, NULL, WJE_GET, 0);
7477
update(context, &n, sizeof(n));
7578

src/wjelement/types.c

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,23 @@ EXPORT XplBool __WJEBool(WJElement container, const char *path, WJEAction action
7070
return(e->value.boolean);
7171

7272
case WJR_TYPE_NUMBER:
73+
return(e->value.number.d != 0);
74+
75+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
76+
case WJR_TYPE_INTEGER:
77+
return(e->value.number.i != 0);
78+
#endif
79+
80+
/*
81+
case WJR_TYPE_NUMBER:
82+
case WJR_TYPE_INTEGER:
7383
if (e->value.number.hasDecimalPoint) {
7484
return(e->value.number.d != 0);
7585
} else {
7686
return(e->value.number.i != 0);
7787
}
7888
break;
79-
89+
*/
8090
default:
8191
case WJR_TYPE_UNKNOWN:
8292
case WJR_TYPE_NULL:
@@ -118,7 +128,7 @@ static void _WJESetNum(void *dest, size_t size, XplBool issigned, uint64 src, Xp
118128
if (!negative) {
119129
(*((int64 *) dest)) = src;
120130
} else {
121-
(*((int64 *) dest)) = -src;
131+
(*((int64 *) dest)) = -((int64) src);
122132
}
123133
} else {
124134
(*((uint64 *) dest)) = src;
@@ -128,7 +138,7 @@ static void _WJESetNum(void *dest, size_t size, XplBool issigned, uint64 src, Xp
128138
if (!negative) {
129139
(*((int32 *) dest)) = src;
130140
} else {
131-
(*((int32 *) dest)) = -src;
141+
(*((int32 *) dest)) = -((int64) src);
132142
}
133143
} else {
134144
(*((uint32 *) dest)) = src;
@@ -200,6 +210,9 @@ static void _WJENum(WJElement container, const char *path, WJEAction action, WJE
200210
break;
201211

202212
case WJR_TYPE_NUMBER:
213+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
214+
case WJR_TYPE_INTEGER:
215+
#endif
203216
negative = FALSE;
204217

205218
if ((e->value.number.i == _WJEGetNum(value, size, issigned, &negative)) &&
@@ -228,6 +241,9 @@ static void _WJENum(WJElement container, const char *path, WJEAction action, WJE
228241

229242
switch (e->pub.type) {
230243
case WJR_TYPE_NUMBER:
244+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
245+
case WJR_TYPE_INTEGER:
246+
#endif
231247
_WJESetNum(value, size, issigned, e->value.number.i, e->value.number.negative);
232248
return;
233249

@@ -274,6 +290,11 @@ static void _WJENum(WJElement container, const char *path, WJEAction action, WJE
274290

275291
e->value.number.i = _WJEGetNum(value, size, issigned, &e->value.number.negative);
276292
e->value.number.d = (double) e->value.number.i;
293+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
294+
e->pub.type = WJR_TYPE_INTEGER;
295+
#else
296+
e->pub.type = WJR_TYPE_NUMBER;
297+
#endif
277298
return;
278299
} else {
279300
/* Negate the value - It must NOT match the original */
@@ -368,6 +389,9 @@ EXPORT char * __WJEStringN(WJElement container, const char *path, WJEAction acti
368389

369390
default:
370391
case WJR_TYPE_NUMBER:
392+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
393+
case WJR_TYPE_INTEGER:
394+
#endif
371395
case WJR_TYPE_UNKNOWN:
372396
case WJR_TYPE_NULL:
373397
case WJR_TYPE_OBJECT:
@@ -602,7 +626,11 @@ EXPORT double __WJEDouble(WJElement container, const char *path, WJEAction actio
602626
break;
603627

604628
case WJR_TYPE_NUMBER:
605-
if (e->value.number.hasDecimalPoint) {
629+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
630+
case WJR_TYPE_INTEGER:
631+
#endif
632+
if (e->pub.type == WJR_TYPE_NUMBER)
633+
{
606634
if (e->value.number.negative) {
607635
if (e->value.number.d * -1.0 == value) {
608636
break;
@@ -612,7 +640,9 @@ EXPORT double __WJEDouble(WJElement container, const char *path, WJEAction actio
612640
break;
613641
}
614642
}
615-
} else {
643+
}
644+
else
645+
{
616646
if (e->value.number.negative) {
617647
if ((double) e->value.number.i * -1.0 == value) {
618648
break;
@@ -641,21 +671,23 @@ EXPORT double __WJEDouble(WJElement container, const char *path, WJEAction actio
641671

642672
switch (e->pub.type) {
643673
case WJR_TYPE_NUMBER:
644-
if (e->value.number.hasDecimalPoint) {
645-
if (e->value.number.negative) {
646-
return(e->value.number.d * -1.0);
647-
} else {
648-
return(e->value.number.d);
649-
}
674+
if (e->value.number.negative) {
675+
return(e->value.number.d * -1.0);
650676
} else {
651-
if (e->value.number.negative) {
652-
return((double) e->value.number.i * -1.0);
653-
} else {
654-
return((double) e->value.number.i);
655-
}
677+
return(e->value.number.d);
656678
}
657679
break;
658680

681+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
682+
case WJR_TYPE_INTEGER:
683+
if (e->value.number.negative) {
684+
return((double) e->value.number.i * -1.0);
685+
} else {
686+
return((double) e->value.number.i);
687+
}
688+
break;
689+
#endif
690+
659691
case WJR_TYPE_BOOL:
660692
case WJR_TYPE_TRUE:
661693
case WJR_TYPE_FALSE:
@@ -686,7 +718,13 @@ EXPORT double __WJEDouble(WJElement container, const char *path, WJEAction actio
686718

687719
if (e->value.number.d != (double) e->value.number.i) {
688720
e->value.number.hasDecimalPoint = TRUE;
721+
e->pub.type = WJR_TYPE_NUMBER;
689722
} else {
723+
#ifdef WJE_DISTINGUISH_INTEGER_TYPE
724+
e->pub.type = WJR_TYPE_INTEGER;
725+
#else
726+
e->pub.type = WJR_TYPE_NUMBER;
727+
#endif
690728
e->value.number.hasDecimalPoint = FALSE;
691729
}
692730

windows/wjelement-VC100.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual C++ Express 2010
4+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wjelement", "wjelement-VC100.vcxproj", "{978C7161-A255-4C13-8B2B-910F9A7FA557}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Win32 = Debug|Win32
9+
Debug|x64 = Debug|x64
10+
Release|Win32 = Release|Win32
11+
Release|x64 = Release|x64
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{978C7161-A255-4C13-8B2B-910F9A7FA557}.Debug|Win32.ActiveCfg = Debug|Win32
15+
{978C7161-A255-4C13-8B2B-910F9A7FA557}.Debug|Win32.Build.0 = Debug|Win32
16+
{978C7161-A255-4C13-8B2B-910F9A7FA557}.Debug|x64.ActiveCfg = Debug|x64
17+
{978C7161-A255-4C13-8B2B-910F9A7FA557}.Debug|x64.Build.0 = Debug|x64
18+
{978C7161-A255-4C13-8B2B-910F9A7FA557}.Release|Win32.ActiveCfg = Release|Win32
19+
{978C7161-A255-4C13-8B2B-910F9A7FA557}.Release|Win32.Build.0 = Release|Win32
20+
{978C7161-A255-4C13-8B2B-910F9A7FA557}.Release|x64.ActiveCfg = Release|x64
21+
{978C7161-A255-4C13-8B2B-910F9A7FA557}.Release|x64.Build.0 = Release|x64
22+
EndGlobalSection
23+
GlobalSection(SolutionProperties) = preSolution
24+
HideSolutionNode = FALSE
25+
EndGlobalSection
26+
EndGlobal

0 commit comments

Comments
 (0)