hirlite 0.0.2 → 0.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/hirlite_ext/extconf.rb +2 -2
- data/lib/hirlite/version.rb +1 -1
- data/vendor/rlite/deps/lua/Makefile +128 -0
- data/vendor/rlite/deps/lua/src/fpconv.c +205 -0
- data/vendor/rlite/deps/lua/src/fpconv.h +22 -0
- data/vendor/rlite/deps/lua/src/lapi.c +1087 -0
- data/vendor/rlite/deps/lua/src/lapi.h +16 -0
- data/vendor/rlite/deps/lua/src/lauxlib.c +652 -0
- data/vendor/rlite/deps/lua/src/lauxlib.h +174 -0
- data/vendor/rlite/deps/lua/src/lbaselib.c +653 -0
- data/vendor/rlite/deps/lua/src/lcode.c +831 -0
- data/vendor/rlite/deps/lua/src/lcode.h +76 -0
- data/vendor/rlite/deps/lua/src/ldblib.c +398 -0
- data/vendor/rlite/deps/lua/src/ldebug.c +638 -0
- data/vendor/rlite/deps/lua/src/ldebug.h +33 -0
- data/vendor/rlite/deps/lua/src/ldo.c +519 -0
- data/vendor/rlite/deps/lua/src/ldo.h +57 -0
- data/vendor/rlite/deps/lua/src/ldump.c +164 -0
- data/vendor/rlite/deps/lua/src/lfunc.c +174 -0
- data/vendor/rlite/deps/lua/src/lfunc.h +34 -0
- data/vendor/rlite/deps/lua/src/lgc.c +710 -0
- data/vendor/rlite/deps/lua/src/lgc.h +110 -0
- data/vendor/rlite/deps/lua/src/linit.c +38 -0
- data/vendor/rlite/deps/lua/src/liolib.c +556 -0
- data/vendor/rlite/deps/lua/src/llex.c +463 -0
- data/vendor/rlite/deps/lua/src/llex.h +81 -0
- data/vendor/rlite/deps/lua/src/llimits.h +128 -0
- data/vendor/rlite/deps/lua/src/lmathlib.c +263 -0
- data/vendor/rlite/deps/lua/src/lmem.c +86 -0
- data/vendor/rlite/deps/lua/src/lmem.h +49 -0
- data/vendor/rlite/deps/lua/src/loadlib.c +666 -0
- data/vendor/rlite/deps/lua/src/lobject.c +214 -0
- data/vendor/rlite/deps/lua/src/lobject.h +381 -0
- data/vendor/rlite/deps/lua/src/lopcodes.c +102 -0
- data/vendor/rlite/deps/lua/src/lopcodes.h +268 -0
- data/vendor/rlite/deps/lua/src/loslib.c +243 -0
- data/vendor/rlite/deps/lua/src/lparser.c +1339 -0
- data/vendor/rlite/deps/lua/src/lparser.h +82 -0
- data/vendor/rlite/deps/lua/src/lstate.c +214 -0
- data/vendor/rlite/deps/lua/src/lstate.h +169 -0
- data/vendor/rlite/deps/lua/src/lstring.c +111 -0
- data/vendor/rlite/deps/lua/src/lstring.h +31 -0
- data/vendor/rlite/deps/lua/src/lstrlib.c +871 -0
- data/vendor/rlite/deps/lua/src/ltable.c +588 -0
- data/vendor/rlite/deps/lua/src/ltable.h +40 -0
- data/vendor/rlite/deps/lua/src/ltablib.c +287 -0
- data/vendor/rlite/deps/lua/src/ltm.c +75 -0
- data/vendor/rlite/deps/lua/src/ltm.h +54 -0
- data/vendor/rlite/deps/lua/src/lua.c +392 -0
- data/vendor/rlite/deps/lua/src/lua.h +388 -0
- data/vendor/rlite/deps/lua/src/lua_bit.c +189 -0
- data/vendor/rlite/deps/lua/src/lua_cjson.c +1427 -0
- data/vendor/rlite/deps/lua/src/lua_cmsgpack.c +957 -0
- data/vendor/rlite/deps/lua/src/lua_struct.c +421 -0
- data/vendor/rlite/deps/lua/src/luac.c +200 -0
- data/vendor/rlite/deps/lua/src/luaconf.h +763 -0
- data/vendor/rlite/deps/lua/src/lualib.h +53 -0
- data/vendor/rlite/deps/lua/src/lundump.c +227 -0
- data/vendor/rlite/deps/lua/src/lundump.h +36 -0
- data/vendor/rlite/deps/lua/src/lvm.c +767 -0
- data/vendor/rlite/deps/lua/src/lvm.h +36 -0
- data/vendor/rlite/deps/lua/src/lzio.c +82 -0
- data/vendor/rlite/deps/lua/src/lzio.h +67 -0
- data/vendor/rlite/deps/lua/src/print.c +227 -0
- data/vendor/rlite/deps/lua/src/strbuf.c +251 -0
- data/vendor/rlite/deps/lua/src/strbuf.h +154 -0
- data/vendor/rlite/src/Makefile +97 -25
- data/vendor/rlite/{deps → src}/crc64.c +0 -0
- data/vendor/rlite/{deps → src}/crc64.h +0 -0
- data/vendor/rlite/src/dump.c +2 -2
- data/vendor/rlite/{deps → src}/endianconv.h +0 -0
- data/vendor/rlite/src/hirlite.c +134 -90
- data/vendor/rlite/src/hirlite.h +34 -1
- data/vendor/rlite/{deps → src}/hyperloglog.c +0 -0
- data/vendor/rlite/{deps → src}/hyperloglog.h +0 -0
- data/vendor/rlite/{deps → src}/lzf.h +0 -0
- data/vendor/rlite/{deps → src}/lzfP.h +0 -0
- data/vendor/rlite/{deps → src}/lzf_c.c +0 -0
- data/vendor/rlite/{deps → src}/lzf_d.c +0 -0
- data/vendor/rlite/src/page_btree.c +10 -10
- data/vendor/rlite/src/page_btree.h +2 -2
- data/vendor/rlite/src/page_list.c +3 -3
- data/vendor/rlite/src/page_list.h +1 -1
- data/vendor/rlite/src/page_multi_string.c +1 -1
- data/vendor/rlite/src/page_skiplist.c +1 -1
- data/vendor/rlite/src/page_skiplist.h +1 -1
- data/vendor/rlite/src/rand.c +93 -0
- data/vendor/rlite/src/rand.h +38 -0
- data/vendor/rlite/src/restore.c +286 -155
- data/vendor/rlite/src/restore.h +6 -0
- data/vendor/rlite/src/rlite.c +30 -30
- data/vendor/rlite/src/rlite.h +1 -1
- data/vendor/rlite/src/scripting.c +1138 -0
- data/vendor/rlite/src/scripting.h +10 -0
- data/vendor/rlite/{deps → src}/sha1.c +0 -0
- data/vendor/rlite/{deps → src}/sha1.h +0 -0
- data/vendor/rlite/src/solarisfixes.h +54 -0
- data/vendor/rlite/src/sort.c +4 -2
- data/vendor/rlite/src/sort.h +1 -1
- data/vendor/rlite/src/type_string.c +1 -1
- data/vendor/rlite/src/util.c +4 -4
- data/vendor/rlite/src/util.h +3 -3
- data/vendor/rlite/{deps → src}/utilfromredis.c +0 -0
- data/vendor/rlite/{deps → src}/utilfromredis.h +0 -0
- metadata +84 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7eceb6d46b38c9d9d22ed2ea358a006d5d9a171
|
4
|
+
data.tar.gz: 1dd36d7c9e07e7af11a1d4ec5fd5440444c78c15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e12c253b12612ff2ded9eb46d303a84da73b639331804842cda4ef5293c2d0411fe71645078479616ae8b2af9d986c1e793b889f4c4555d27c4c688f99d6ac16
|
7
|
+
data.tar.gz: 441ee0d5f6215261e380b0fe720d64b0c28503f3f679d2fdf59f8e8ab2755cf109f73226650a5912a29af4ee26bb4bcd95e06c7936cfbba95cc9d9cf384a0ebb
|
data/ext/hirlite_ext/extconf.rb
CHANGED
@@ -21,13 +21,13 @@ end
|
|
21
21
|
|
22
22
|
# Make sure hirlite is built...
|
23
23
|
Dir.chdir(hirlite_dir) do
|
24
|
-
success = system("#{make_program} libhirlite.a")
|
24
|
+
success = system("#{make_program} libhirlite.a lua")
|
25
25
|
raise "Building hirlite failed" if !success
|
26
26
|
end
|
27
27
|
|
28
28
|
# Statically link to hirlite (mkmf can't do this for us)
|
29
29
|
$CFLAGS << " -I#{hirlite_dir}/src"
|
30
|
-
$LDFLAGS << " #{hirlite_dir}/src/libhirlite.a"
|
30
|
+
$LDFLAGS << " #{hirlite_dir}/src/libhirlite.a #{hirlite_dir}/deps/lua/src/liblua.a"
|
31
31
|
|
32
32
|
have_func("rb_thread_fd_select")
|
33
33
|
create_makefile('hirlite/ext/hirlite_ext')
|
data/lib/hirlite/version.rb
CHANGED
@@ -0,0 +1,128 @@
|
|
1
|
+
# makefile for installing Lua
|
2
|
+
# see INSTALL for installation instructions
|
3
|
+
# see src/Makefile and src/luaconf.h for further customization
|
4
|
+
|
5
|
+
# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
|
6
|
+
|
7
|
+
# Your platform. See PLATS for possible values.
|
8
|
+
PLAT= none
|
9
|
+
|
10
|
+
# Where to install. The installation starts in the src and doc directories,
|
11
|
+
# so take care if INSTALL_TOP is not an absolute path.
|
12
|
+
INSTALL_TOP= /usr/local
|
13
|
+
INSTALL_BIN= $(INSTALL_TOP)/bin
|
14
|
+
INSTALL_INC= $(INSTALL_TOP)/include
|
15
|
+
INSTALL_LIB= $(INSTALL_TOP)/lib
|
16
|
+
INSTALL_MAN= $(INSTALL_TOP)/man/man1
|
17
|
+
#
|
18
|
+
# You probably want to make INSTALL_LMOD and INSTALL_CMOD consistent with
|
19
|
+
# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc).
|
20
|
+
INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
|
21
|
+
INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V
|
22
|
+
|
23
|
+
# How to install. If your install program does not support "-p", then you
|
24
|
+
# may have to run ranlib on the installed liblua.a (do "make ranlib").
|
25
|
+
INSTALL= install -p
|
26
|
+
INSTALL_EXEC= $(INSTALL) -m 0755
|
27
|
+
INSTALL_DATA= $(INSTALL) -m 0644
|
28
|
+
#
|
29
|
+
# If you don't have install you can use cp instead.
|
30
|
+
# INSTALL= cp -p
|
31
|
+
# INSTALL_EXEC= $(INSTALL)
|
32
|
+
# INSTALL_DATA= $(INSTALL)
|
33
|
+
|
34
|
+
# Utilities.
|
35
|
+
MKDIR= mkdir -p
|
36
|
+
RANLIB= ranlib
|
37
|
+
|
38
|
+
# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
|
39
|
+
|
40
|
+
# Convenience platforms targets.
|
41
|
+
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
|
42
|
+
|
43
|
+
# What to install.
|
44
|
+
TO_BIN= lua luac
|
45
|
+
TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
|
46
|
+
TO_LIB= liblua.a
|
47
|
+
TO_MAN= lua.1 luac.1
|
48
|
+
|
49
|
+
# Lua version and release.
|
50
|
+
V= 5.1
|
51
|
+
R= 5.1.5
|
52
|
+
|
53
|
+
all: $(PLAT)
|
54
|
+
|
55
|
+
$(PLATS) clean:
|
56
|
+
cd src && $(MAKE) $@
|
57
|
+
|
58
|
+
test: dummy
|
59
|
+
src/lua test/hello.lua
|
60
|
+
|
61
|
+
install: dummy
|
62
|
+
cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
|
63
|
+
cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
|
64
|
+
cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
|
65
|
+
cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
|
66
|
+
cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
|
67
|
+
|
68
|
+
ranlib:
|
69
|
+
cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB)
|
70
|
+
|
71
|
+
local:
|
72
|
+
$(MAKE) install INSTALL_TOP=..
|
73
|
+
|
74
|
+
none:
|
75
|
+
@echo "Please do"
|
76
|
+
@echo " make PLATFORM"
|
77
|
+
@echo "where PLATFORM is one of these:"
|
78
|
+
@echo " $(PLATS)"
|
79
|
+
@echo "See INSTALL for complete instructions."
|
80
|
+
|
81
|
+
# make may get confused with test/ and INSTALL in a case-insensitive OS
|
82
|
+
dummy:
|
83
|
+
|
84
|
+
# echo config parameters
|
85
|
+
echo:
|
86
|
+
@echo ""
|
87
|
+
@echo "These are the parameters currently set in src/Makefile to build Lua $R:"
|
88
|
+
@echo ""
|
89
|
+
@cd src && $(MAKE) -s echo
|
90
|
+
@echo ""
|
91
|
+
@echo "These are the parameters currently set in Makefile to install Lua $R:"
|
92
|
+
@echo ""
|
93
|
+
@echo "PLAT = $(PLAT)"
|
94
|
+
@echo "INSTALL_TOP = $(INSTALL_TOP)"
|
95
|
+
@echo "INSTALL_BIN = $(INSTALL_BIN)"
|
96
|
+
@echo "INSTALL_INC = $(INSTALL_INC)"
|
97
|
+
@echo "INSTALL_LIB = $(INSTALL_LIB)"
|
98
|
+
@echo "INSTALL_MAN = $(INSTALL_MAN)"
|
99
|
+
@echo "INSTALL_LMOD = $(INSTALL_LMOD)"
|
100
|
+
@echo "INSTALL_CMOD = $(INSTALL_CMOD)"
|
101
|
+
@echo "INSTALL_EXEC = $(INSTALL_EXEC)"
|
102
|
+
@echo "INSTALL_DATA = $(INSTALL_DATA)"
|
103
|
+
@echo ""
|
104
|
+
@echo "See also src/luaconf.h ."
|
105
|
+
@echo ""
|
106
|
+
|
107
|
+
# echo private config parameters
|
108
|
+
pecho:
|
109
|
+
@echo "V = $(V)"
|
110
|
+
@echo "R = $(R)"
|
111
|
+
@echo "TO_BIN = $(TO_BIN)"
|
112
|
+
@echo "TO_INC = $(TO_INC)"
|
113
|
+
@echo "TO_LIB = $(TO_LIB)"
|
114
|
+
@echo "TO_MAN = $(TO_MAN)"
|
115
|
+
|
116
|
+
# echo config parameters as Lua code
|
117
|
+
# uncomment the last sed expression if you want nil instead of empty strings
|
118
|
+
lecho:
|
119
|
+
@echo "-- installation parameters for Lua $R"
|
120
|
+
@echo "VERSION = '$V'"
|
121
|
+
@echo "RELEASE = '$R'"
|
122
|
+
@$(MAKE) echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/'
|
123
|
+
@echo "-- EOF"
|
124
|
+
|
125
|
+
# list targets that do not create files (but not all makes understand .PHONY)
|
126
|
+
.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho
|
127
|
+
|
128
|
+
# (end of Makefile)
|
@@ -0,0 +1,205 @@
|
|
1
|
+
/* fpconv - Floating point conversion routines
|
2
|
+
*
|
3
|
+
* Copyright (c) 2011-2012 Mark Pulford <mark@kyne.com.au>
|
4
|
+
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
* a copy of this software and associated documentation files (the
|
7
|
+
* "Software"), to deal in the Software without restriction, including
|
8
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
* the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be
|
14
|
+
* included in all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
*/
|
24
|
+
|
25
|
+
/* JSON uses a '.' decimal separator. strtod() / sprintf() under C libraries
|
26
|
+
* with locale support will break when the decimal separator is a comma.
|
27
|
+
*
|
28
|
+
* fpconv_* will around these issues with a translation buffer if required.
|
29
|
+
*/
|
30
|
+
|
31
|
+
#include <stdio.h>
|
32
|
+
#include <stdlib.h>
|
33
|
+
#include <assert.h>
|
34
|
+
#include <string.h>
|
35
|
+
|
36
|
+
#include "fpconv.h"
|
37
|
+
|
38
|
+
/* Lua CJSON assumes the locale is the same for all threads within a
|
39
|
+
* process and doesn't change after initialisation.
|
40
|
+
*
|
41
|
+
* This avoids the need for per thread storage or expensive checks
|
42
|
+
* for call. */
|
43
|
+
static char locale_decimal_point = '.';
|
44
|
+
|
45
|
+
/* In theory multibyte decimal_points are possible, but
|
46
|
+
* Lua CJSON only supports UTF-8 and known locales only have
|
47
|
+
* single byte decimal points ([.,]).
|
48
|
+
*
|
49
|
+
* localconv() may not be thread safe (=>crash), and nl_langinfo() is
|
50
|
+
* not supported on some platforms. Use sprintf() instead - if the
|
51
|
+
* locale does change, at least Lua CJSON won't crash. */
|
52
|
+
static void fpconv_update_locale()
|
53
|
+
{
|
54
|
+
char buf[8];
|
55
|
+
|
56
|
+
snprintf(buf, sizeof(buf), "%g", 0.5);
|
57
|
+
|
58
|
+
/* Failing this test might imply the platform has a buggy dtoa
|
59
|
+
* implementation or wide characters */
|
60
|
+
if (buf[0] != '0' || buf[2] != '5' || buf[3] != 0) {
|
61
|
+
fprintf(stderr, "Error: wide characters found or printf() bug.");
|
62
|
+
abort();
|
63
|
+
}
|
64
|
+
|
65
|
+
locale_decimal_point = buf[1];
|
66
|
+
}
|
67
|
+
|
68
|
+
/* Check for a valid number character: [-+0-9a-yA-Y.]
|
69
|
+
* Eg: -0.6e+5, infinity, 0xF0.F0pF0
|
70
|
+
*
|
71
|
+
* Used to find the probable end of a number. It doesn't matter if
|
72
|
+
* invalid characters are counted - strtod() will find the valid
|
73
|
+
* number if it exists. The risk is that slightly more memory might
|
74
|
+
* be allocated before a parse error occurs. */
|
75
|
+
static inline int valid_number_character(char ch)
|
76
|
+
{
|
77
|
+
char lower_ch;
|
78
|
+
|
79
|
+
if ('0' <= ch && ch <= '9')
|
80
|
+
return 1;
|
81
|
+
if (ch == '-' || ch == '+' || ch == '.')
|
82
|
+
return 1;
|
83
|
+
|
84
|
+
/* Hex digits, exponent (e), base (p), "infinity",.. */
|
85
|
+
lower_ch = ch | 0x20;
|
86
|
+
if ('a' <= lower_ch && lower_ch <= 'y')
|
87
|
+
return 1;
|
88
|
+
|
89
|
+
return 0;
|
90
|
+
}
|
91
|
+
|
92
|
+
/* Calculate the size of the buffer required for a strtod locale
|
93
|
+
* conversion. */
|
94
|
+
static int strtod_buffer_size(const char *s)
|
95
|
+
{
|
96
|
+
const char *p = s;
|
97
|
+
|
98
|
+
while (valid_number_character(*p))
|
99
|
+
p++;
|
100
|
+
|
101
|
+
return p - s;
|
102
|
+
}
|
103
|
+
|
104
|
+
/* Similar to strtod(), but must be passed the current locale's decimal point
|
105
|
+
* character. Guaranteed to be called at the start of any valid number in a string */
|
106
|
+
double fpconv_strtod(const char *nptr, char **endptr)
|
107
|
+
{
|
108
|
+
char localbuf[FPCONV_G_FMT_BUFSIZE];
|
109
|
+
char *buf, *endbuf, *dp;
|
110
|
+
int buflen;
|
111
|
+
double value;
|
112
|
+
|
113
|
+
/* System strtod() is fine when decimal point is '.' */
|
114
|
+
if (locale_decimal_point == '.')
|
115
|
+
return strtod(nptr, endptr);
|
116
|
+
|
117
|
+
buflen = strtod_buffer_size(nptr);
|
118
|
+
if (!buflen) {
|
119
|
+
/* No valid characters found, standard strtod() return */
|
120
|
+
*endptr = (char *)nptr;
|
121
|
+
return 0;
|
122
|
+
}
|
123
|
+
|
124
|
+
/* Duplicate number into buffer */
|
125
|
+
if (buflen >= FPCONV_G_FMT_BUFSIZE) {
|
126
|
+
/* Handle unusually large numbers */
|
127
|
+
buf = malloc(buflen + 1);
|
128
|
+
if (!buf) {
|
129
|
+
fprintf(stderr, "Out of memory");
|
130
|
+
abort();
|
131
|
+
}
|
132
|
+
} else {
|
133
|
+
/* This is the common case.. */
|
134
|
+
buf = localbuf;
|
135
|
+
}
|
136
|
+
memcpy(buf, nptr, buflen);
|
137
|
+
buf[buflen] = 0;
|
138
|
+
|
139
|
+
/* Update decimal point character if found */
|
140
|
+
dp = strchr(buf, '.');
|
141
|
+
if (dp)
|
142
|
+
*dp = locale_decimal_point;
|
143
|
+
|
144
|
+
value = strtod(buf, &endbuf);
|
145
|
+
*endptr = (char *)&nptr[endbuf - buf];
|
146
|
+
if (buflen >= FPCONV_G_FMT_BUFSIZE)
|
147
|
+
free(buf);
|
148
|
+
|
149
|
+
return value;
|
150
|
+
}
|
151
|
+
|
152
|
+
/* "fmt" must point to a buffer of at least 6 characters */
|
153
|
+
static void set_number_format(char *fmt, int precision)
|
154
|
+
{
|
155
|
+
int d1, d2, i;
|
156
|
+
|
157
|
+
assert(1 <= precision && precision <= 14);
|
158
|
+
|
159
|
+
/* Create printf format (%.14g) from precision */
|
160
|
+
d1 = precision / 10;
|
161
|
+
d2 = precision % 10;
|
162
|
+
fmt[0] = '%';
|
163
|
+
fmt[1] = '.';
|
164
|
+
i = 2;
|
165
|
+
if (d1) {
|
166
|
+
fmt[i++] = '0' + d1;
|
167
|
+
}
|
168
|
+
fmt[i++] = '0' + d2;
|
169
|
+
fmt[i++] = 'g';
|
170
|
+
fmt[i] = 0;
|
171
|
+
}
|
172
|
+
|
173
|
+
/* Assumes there is always at least 32 characters available in the target buffer */
|
174
|
+
int fpconv_g_fmt(char *str, double num, int precision)
|
175
|
+
{
|
176
|
+
char buf[FPCONV_G_FMT_BUFSIZE];
|
177
|
+
char fmt[6];
|
178
|
+
int len;
|
179
|
+
char *b;
|
180
|
+
|
181
|
+
set_number_format(fmt, precision);
|
182
|
+
|
183
|
+
/* Pass through when decimal point character is dot. */
|
184
|
+
if (locale_decimal_point == '.')
|
185
|
+
return snprintf(str, FPCONV_G_FMT_BUFSIZE, fmt, num);
|
186
|
+
|
187
|
+
/* snprintf() to a buffer then translate for other decimal point characters */
|
188
|
+
len = snprintf(buf, FPCONV_G_FMT_BUFSIZE, fmt, num);
|
189
|
+
|
190
|
+
/* Copy into target location. Translate decimal point if required */
|
191
|
+
b = buf;
|
192
|
+
do {
|
193
|
+
*str++ = (*b == locale_decimal_point ? '.' : *b);
|
194
|
+
} while(*b++);
|
195
|
+
|
196
|
+
return len;
|
197
|
+
}
|
198
|
+
|
199
|
+
void fpconv_init()
|
200
|
+
{
|
201
|
+
fpconv_update_locale();
|
202
|
+
}
|
203
|
+
|
204
|
+
/* vi:ai et sw=4 ts=4:
|
205
|
+
*/
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/* Lua CJSON floating point conversion routines */
|
2
|
+
|
3
|
+
/* Buffer required to store the largest string representation of a double.
|
4
|
+
*
|
5
|
+
* Longest double printed with %.14g is 21 characters long:
|
6
|
+
* -1.7976931348623e+308 */
|
7
|
+
# define FPCONV_G_FMT_BUFSIZE 32
|
8
|
+
|
9
|
+
#ifdef USE_INTERNAL_FPCONV
|
10
|
+
static inline void fpconv_init()
|
11
|
+
{
|
12
|
+
/* Do nothing - not required */
|
13
|
+
}
|
14
|
+
#else
|
15
|
+
extern void fpconv_init();
|
16
|
+
#endif
|
17
|
+
|
18
|
+
extern int fpconv_g_fmt(char*, double, int);
|
19
|
+
extern double fpconv_strtod(const char*, char**);
|
20
|
+
|
21
|
+
/* vi:ai et sw=4 ts=4:
|
22
|
+
*/
|