integrate lua-cjson's buildsystem and static library with callisto's
and make some more makefile improvements
This commit is contained in:
parent
55b40a17cd
commit
a6809fe480
7 changed files with 30 additions and 6667 deletions
44
Makefile
44
Makefile
|
@ -1,15 +1,28 @@
|
||||||
include config.mk
|
PREFIX = /usr/local
|
||||||
|
MANPREFIX = ${PREFIX}/man
|
||||||
|
|
||||||
OBJS = csto.o callisto.o lcl.o lenviron.o lextra.o lfs.o ljson.o\
|
CC = cc
|
||||||
lprocess.o util.o
|
CFLAGS = -std=c99 -pedantic -fpic -Oz -Iexternal/lua -Wall -Wextra
|
||||||
LIBS = liblua.a cjson.a
|
CPPFLAGS = -D_DEFAULT_SOURCE
|
||||||
|
LDFLAGS = -lm
|
||||||
|
|
||||||
|
# Enable readline
|
||||||
|
#CPPFLAGS += -DLUA_USE_READLINE
|
||||||
|
#LDFLAGS += -lreadline
|
||||||
|
|
||||||
|
OBJS = callisto.o lcl.o lenviron.o lextra.o lfs.o ljson.o lprocess.o util.o
|
||||||
|
LIBS = libcallisto.a liblua.a
|
||||||
|
|
||||||
|
CJSON_SRC = external/json
|
||||||
|
CJSON_OBJS = fpconv.o lua_cjson.o strbuf.o
|
||||||
|
CJSON_CFLAGS = -Wno-sign-compare -Wno-unused-function
|
||||||
|
|
||||||
all: csto libcallisto.a
|
all: csto libcallisto.a
|
||||||
|
|
||||||
csto: ${LIBS} ${OBJS}
|
csto: ${LIBS} csto.o
|
||||||
${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} ${LDFLAGS}
|
${CC} -o $@ libcallisto.a liblua.a csto.o ${LDFLAGS}
|
||||||
libcallisto.a: ${LIBS} ${OBJS}
|
libcallisto.a: liblua.a ${CJSON_OBJS} ${OBJS}
|
||||||
ar cr $@ ${OBJS} liblua.a
|
ar cr $@ ${OBJS} ${CJSON_OBJS}
|
||||||
|
|
||||||
.SUFFIXES: .o
|
.SUFFIXES: .o
|
||||||
|
|
||||||
|
@ -24,22 +37,25 @@ lenviron.o: lenviron.c callisto.h
|
||||||
lfs.o: lfs.c callisto.h util.h
|
lfs.o: lfs.c callisto.h util.h
|
||||||
ljson.o: ljson.c callisto.h
|
ljson.o: ljson.c callisto.h
|
||||||
lprocess.o: lprocess.c callisto.h util.h
|
lprocess.o: lprocess.c callisto.h util.h
|
||||||
|
${CC} ${CFLAGS} -Wno-override-init ${CPPFLAGS} -c lprocess.c
|
||||||
util.o: util.c
|
util.o: util.c
|
||||||
|
|
||||||
cjson.a: external/json/*.c
|
# cjson
|
||||||
${MAKE} -Cexternal/json
|
fpconv.o: ${CJSON_SRC}/fpconv.c
|
||||||
mv -f external/json/cjson.a cjson.a
|
${CC} ${CFLAGS} ${CJSON_CFLAGS} ${CPPFLAGS} -c $<
|
||||||
|
lua_cjson.o: ${CJSON_SRC}/lua_cjson.c
|
||||||
|
${CC} ${CFLAGS} ${CJSON_CFLAGS} ${CPPFLAGS} -c $<
|
||||||
|
strbuf.o: ${CJSON_SRC}/strbuf.c
|
||||||
|
${CC} ${CFLAGS} ${CJSON_CFLAGS} ${CPPFLAGS} -c $<
|
||||||
|
|
||||||
liblua.a: external/lua/*.c
|
liblua.a: external/lua/*.c
|
||||||
${MAKE} -Cexternal/lua
|
${MAKE} -Cexternal/lua
|
||||||
mv -f external/lua/liblua.a .
|
mv -f external/lua/liblua.a .
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f csto libcallisto.a ${OBJS} ${LIBS}
|
rm -f csto libcallisto.a ${OBJS} ${CJSON_OBJS} ${LIBS}
|
||||||
rm -fr include doc/*.html doc/modules
|
rm -fr include doc/*.html doc/modules
|
||||||
clean-all: clean
|
|
||||||
${MAKE} -s -Cexternal/lua clean
|
${MAKE} -s -Cexternal/lua clean
|
||||||
${MAKE} -s -Cexternal/json clean
|
|
||||||
|
|
||||||
doc:
|
doc:
|
||||||
ldoc -s . -q . >/dev/null
|
ldoc -s . -q . >/dev/null
|
||||||
|
|
11
config.mk
11
config.mk
|
@ -1,11 +0,0 @@
|
||||||
PREFIX = /usr/local
|
|
||||||
MANPREFIX = ${PREFIX}/man
|
|
||||||
|
|
||||||
CC = cc
|
|
||||||
CFLAGS = -std=c99 -pedantic -fpic -O2 -Wall -Wextra -Wno-override-init -Iexternal/lua
|
|
||||||
CPPFLAGS = -D_DEFAULT_SOURCE
|
|
||||||
LDFLAGS = -lm
|
|
||||||
|
|
||||||
# Enable readline
|
|
||||||
#CPPFLAGS += -DLUA_USE_READLINE
|
|
||||||
#LDFLAGS += -lreadline
|
|
40
external/json/Makefile
vendored
40
external/json/Makefile
vendored
|
@ -1,40 +0,0 @@
|
||||||
##### Available defines for CJSON_CFLAGS #####
|
|
||||||
##
|
|
||||||
## USE_INTERNAL_ISINF: Workaround for Solaris platforms missing isinf().
|
|
||||||
## DISABLE_INVALID_NUMBERS: Permanently disable invalid JSON numbers:
|
|
||||||
## NaN, Infinity, hex.
|
|
||||||
##
|
|
||||||
## Optional built-in number conversion uses the following defines:
|
|
||||||
## USE_INTERNAL_FPCONV: Use builtin strtod/dtoa for numeric conversions.
|
|
||||||
## IEEE_BIG_ENDIAN: Required on big endian architectures.
|
|
||||||
## MULTIPLE_THREADS: Must be set when Lua CJSON may be used in a
|
|
||||||
## multi-threaded application. Requries _pthreads_.
|
|
||||||
|
|
||||||
##### Build defaults #####
|
|
||||||
CC = cc
|
|
||||||
AR = ar cr
|
|
||||||
CFLAGS = -std=c99 -O2 -Wall -Wno-unused-function -pedantic -fpic -DNDEBUG -I../lua
|
|
||||||
OBJS = dtoa.o fpconv.o g_fmt.o lua_cjson.o strbuf.o
|
|
||||||
|
|
||||||
##### End customisable sections #####
|
|
||||||
|
|
||||||
.PHONY: all clean
|
|
||||||
|
|
||||||
all: cjson.a
|
|
||||||
|
|
||||||
cjson.a: ${OBJS}
|
|
||||||
${AR} $@ ${OBJS}
|
|
||||||
|
|
||||||
dtoa.o:
|
|
||||||
${CC} ${CFLAGS} -o $@ -c dtoa.c
|
|
||||||
fpconv.o:
|
|
||||||
${CC} ${CFLAGS} -o $@ -c fpconv.c
|
|
||||||
g_fmt.o:
|
|
||||||
${CC} ${CFLAGS} -o $@ -c g_fmt.c
|
|
||||||
lua_cjson.o:
|
|
||||||
${CC} ${CFLAGS} -o $@ -c lua_cjson.c
|
|
||||||
strbuf.o:
|
|
||||||
${CC} ${CFLAGS} -o $@ -c strbuf.c
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f cjson.a ${OBJS}
|
|
208
external/json/README.md
vendored
208
external/json/README.md
vendored
|
@ -1,208 +0,0 @@
|
||||||
Name
|
|
||||||
====
|
|
||||||
|
|
||||||
lua-cjson - Fast JSON encoding/parsing
|
|
||||||
|
|
||||||
Table of Contents
|
|
||||||
=================
|
|
||||||
|
|
||||||
* [Name](#name)
|
|
||||||
* [Description](#description)
|
|
||||||
* [Additions to mpx/lua](#additions)
|
|
||||||
* [encode_empty_table_as_object](#encode_empty_table_as_object)
|
|
||||||
* [empty_array](#empty_array)
|
|
||||||
* [array_mt](#array_mt)
|
|
||||||
* [empty_array_mt](#empty_array_mt)
|
|
||||||
* [encode_number_precision](#encode_number_precision)
|
|
||||||
* [encode_escape_forward_slash](#encode_escape_forward_slash)
|
|
||||||
* [decode_array_with_array_mt](#decode_array_with_array_mt)
|
|
||||||
|
|
||||||
Description
|
|
||||||
===========
|
|
||||||
|
|
||||||
This fork of [mpx/lua-cjson](https://github.com/mpx/lua-cjson) is included in
|
|
||||||
the [OpenResty](https://openresty.org/) bundle and includes a few bugfixes and
|
|
||||||
improvements, especially to facilitate the encoding of empty tables as JSON Arrays.
|
|
||||||
|
|
||||||
Please refer to the [lua-cjson documentation](http://www.kyne.com.au/~mark/software/lua-cjson.php)
|
|
||||||
for standard usage, this README only provides informations regarding this fork's additions.
|
|
||||||
|
|
||||||
See [`mpx/master..openresty/master`](https://github.com/mpx/lua-cjson/compare/master...openresty:master)
|
|
||||||
for the complete history of changes.
|
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
|
||||||
|
|
||||||
Additions
|
|
||||||
=========
|
|
||||||
|
|
||||||
encode_empty_table_as_object
|
|
||||||
----------------------------
|
|
||||||
**syntax:** `cjson.encode_empty_table_as_object(true|false|"on"|"off")`
|
|
||||||
|
|
||||||
Change the default behavior when encoding an empty Lua table.
|
|
||||||
|
|
||||||
By default, empty Lua tables are encoded as empty JSON Objects (`{}`). If this is set to false,
|
|
||||||
empty Lua tables will be encoded as empty JSON Arrays instead (`[]`).
|
|
||||||
|
|
||||||
This method either accepts a boolean or a string (`"on"`, `"off"`).
|
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
|
||||||
|
|
||||||
empty_array
|
|
||||||
-----------
|
|
||||||
**syntax:** `cjson.empty_array`
|
|
||||||
|
|
||||||
A lightuserdata, similar to `cjson.null`, which will be encoded as an empty JSON Array by
|
|
||||||
`cjson.encode()`.
|
|
||||||
|
|
||||||
For example, since `encode_empty_table_as_object` is `true` by default:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local cjson = require "cjson"
|
|
||||||
|
|
||||||
local json = cjson.encode({
|
|
||||||
foo = "bar",
|
|
||||||
some_object = {},
|
|
||||||
some_array = cjson.empty_array
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
This will generate:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"foo": "bar",
|
|
||||||
"some_object": {},
|
|
||||||
"some_array": []
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
|
||||||
|
|
||||||
array_mt
|
|
||||||
--------
|
|
||||||
**syntax:** `setmetatable({}, cjson.array_mt)`
|
|
||||||
|
|
||||||
When lua-cjson encodes a table with this metatable, it will systematically
|
|
||||||
encode it as a JSON Array. The resulting, encoded Array will contain the array
|
|
||||||
part of the table, and will be of the same length as the `#` operator on that
|
|
||||||
table. Holes in the table will be encoded with the `null` JSON value.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local t = { "hello", "world" }
|
|
||||||
setmetatable(t, cjson.array_mt)
|
|
||||||
cjson.encode(t) -- ["hello","world"]
|
|
||||||
```
|
|
||||||
|
|
||||||
Or:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local t = {}
|
|
||||||
t[1] = "one"
|
|
||||||
t[2] = "two"
|
|
||||||
t[4] = "three"
|
|
||||||
t.foo = "bar"
|
|
||||||
setmetatable(t, cjson.array_mt)
|
|
||||||
cjson.encode(t) -- ["one","two",null,"three"]
|
|
||||||
```
|
|
||||||
|
|
||||||
This value was introduced in the `2.1.0.5` release of this module.
|
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
|
||||||
|
|
||||||
empty_array_mt
|
|
||||||
--------------
|
|
||||||
**syntax:** `setmetatable({}, cjson.empty_array_mt)`
|
|
||||||
|
|
||||||
A metatable which can "tag" a table as a JSON Array in case it is empty (that is, if the
|
|
||||||
table has no elements, `cjson.encode()` will encode it as an empty JSON Array).
|
|
||||||
|
|
||||||
Instead of:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local function serialize(arr)
|
|
||||||
if #arr < 1 then
|
|
||||||
arr = cjson.empty_array
|
|
||||||
end
|
|
||||||
|
|
||||||
return cjson.encode({some_array = arr})
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
This is more concise:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local function serialize(arr)
|
|
||||||
setmetatable(arr, cjson.empty_array_mt)
|
|
||||||
|
|
||||||
return cjson.encode({some_array = arr})
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
Both will generate:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"some_array": []
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
|
||||||
|
|
||||||
encode_number_precision
|
|
||||||
-----------------------
|
|
||||||
**syntax:** `cjson.encode_number_precision(precision)`
|
|
||||||
|
|
||||||
This fork allows encoding of numbers with a `precision` up to 16 decimals (vs. 14 in mpx/lua-cjson).
|
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
|
||||||
|
|
||||||
encode_escape_forward_slash
|
|
||||||
---------------------------
|
|
||||||
**syntax:** `cjson.encode_escape_forward_slash(enabled)`
|
|
||||||
|
|
||||||
**default:** true
|
|
||||||
|
|
||||||
If enabled, forward slash '/' will be encoded as '\\/'.
|
|
||||||
|
|
||||||
If disabled, forward slash '/' will be encoded as '/' (no escape is applied).
|
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
|
||||||
|
|
||||||
decode_array_with_array_mt
|
|
||||||
--------------------------
|
|
||||||
**syntax:** `cjson.decode_array_with_array_mt(enabled)`
|
|
||||||
|
|
||||||
**default:** false
|
|
||||||
|
|
||||||
If enabled, JSON Arrays decoded by `cjson.decode` will result in Lua
|
|
||||||
tables with the [`array_mt`](#array_mt) metatable. This can ensure a 1-to-1
|
|
||||||
relationship between arrays upon multiple encoding/decoding of your
|
|
||||||
JSON data with this module.
|
|
||||||
|
|
||||||
If disabled, JSON Arrays will be decoded to plain Lua tables, without
|
|
||||||
the `array_mt` metatable.
|
|
||||||
|
|
||||||
The `enabled` argument is a boolean.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local cjson = require "cjson"
|
|
||||||
|
|
||||||
-- default behavior
|
|
||||||
local my_json = [[{"my_array":[]}]]
|
|
||||||
local t = cjson.decode(my_json)
|
|
||||||
cjson.encode(t) -- {"my_array":{}} back to an object
|
|
||||||
|
|
||||||
-- now, if this behavior is enabled
|
|
||||||
cjson.decode_array_with_array_mt(true)
|
|
||||||
|
|
||||||
local my_json = [[{"my_array":[]}]]
|
|
||||||
local t = cjson.decode(my_json)
|
|
||||||
cjson.encode(t) -- {"my_array":[]} properly re-encoded as an array
|
|
||||||
```
|
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
|
6205
external/json/dtoa.c
vendored
6205
external/json/dtoa.c
vendored
File diff suppressed because it is too large
Load diff
78
external/json/dtoa_config.h
vendored
78
external/json/dtoa_config.h
vendored
|
@ -1,78 +0,0 @@
|
||||||
#ifndef _DTOA_CONFIG_H
|
|
||||||
#define _DTOA_CONFIG_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/* Ensure dtoa.c does not USE_LOCALE. Lua CJSON must not use locale
|
|
||||||
* aware conversion routines. */
|
|
||||||
#undef USE_LOCALE
|
|
||||||
|
|
||||||
/* dtoa.c should not touch errno, Lua CJSON does not use it, and it
|
|
||||||
* may not be threadsafe */
|
|
||||||
#define NO_ERRNO
|
|
||||||
|
|
||||||
#define Long int32_t
|
|
||||||
#define ULong uint32_t
|
|
||||||
#define Llong int64_t
|
|
||||||
#define ULLong uint64_t
|
|
||||||
|
|
||||||
#ifdef IEEE_BIG_ENDIAN
|
|
||||||
#define IEEE_MC68k
|
|
||||||
#else
|
|
||||||
#define IEEE_8087
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MALLOC xmalloc
|
|
||||||
|
|
||||||
static void *xmalloc(size_t size)
|
|
||||||
{
|
|
||||||
void *p;
|
|
||||||
|
|
||||||
p = malloc(size);
|
|
||||||
if (!p) {
|
|
||||||
fprintf(stderr, "Out of memory");
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef MULTIPLE_THREADS
|
|
||||||
|
|
||||||
/* Enable locking to support multi-threaded applications */
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
static pthread_mutex_t private_dtoa_lock[2] = {
|
|
||||||
PTHREAD_MUTEX_INITIALIZER,
|
|
||||||
PTHREAD_MUTEX_INITIALIZER
|
|
||||||
};
|
|
||||||
|
|
||||||
#define dtoa_get_threadno pthread_self
|
|
||||||
void
|
|
||||||
set_max_dtoa_threads(unsigned int n);
|
|
||||||
|
|
||||||
#define ACQUIRE_DTOA_LOCK(n) do { \
|
|
||||||
int r = pthread_mutex_lock(&private_dtoa_lock[n]); \
|
|
||||||
if (r) { \
|
|
||||||
fprintf(stderr, "pthread_mutex_lock failed with %d\n", r); \
|
|
||||||
abort(); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define FREE_DTOA_LOCK(n) do { \
|
|
||||||
int r = pthread_mutex_unlock(&private_dtoa_lock[n]); \
|
|
||||||
if (r) { \
|
|
||||||
fprintf(stderr, "pthread_mutex_unlock failed with %d\n", r);\
|
|
||||||
abort(); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#endif /* MULTIPLE_THREADS */
|
|
||||||
|
|
||||||
#endif /* _DTOA_CONFIG_H */
|
|
||||||
|
|
||||||
/* vi:ai et sw=4 ts=4:
|
|
||||||
*/
|
|
111
external/json/g_fmt.c
vendored
111
external/json/g_fmt.c
vendored
|
@ -1,111 +0,0 @@
|
||||||
/****************************************************************
|
|
||||||
*
|
|
||||||
* The author of this software is David M. Gay.
|
|
||||||
*
|
|
||||||
* Copyright (c) 1991, 1996 by Lucent Technologies.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose without fee is hereby granted, provided that this entire notice
|
|
||||||
* is included in all copies of any software which is or includes a copy
|
|
||||||
* or modification of this software and in all copies of the supporting
|
|
||||||
* documentation for such software.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
|
||||||
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY
|
|
||||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
|
||||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
|
||||||
*
|
|
||||||
***************************************************************/
|
|
||||||
|
|
||||||
/* g_fmt(buf,x) stores the closest decimal approximation to x in buf;
|
|
||||||
* it suffices to declare buf
|
|
||||||
* char buf[32];
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
extern char *dtoa(double, int, int, int *, int *, char **);
|
|
||||||
extern int g_fmt(char *, double, int);
|
|
||||||
extern void freedtoa(char*);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
|
||||||
fpconv_g_fmt(char *b, double x, int precision)
|
|
||||||
{
|
|
||||||
register int i, k;
|
|
||||||
register char *s;
|
|
||||||
int decpt, j, sign;
|
|
||||||
char *b0, *s0, *se;
|
|
||||||
|
|
||||||
b0 = b;
|
|
||||||
#ifdef IGNORE_ZERO_SIGN
|
|
||||||
if (!x) {
|
|
||||||
*b++ = '0';
|
|
||||||
*b = 0;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
s = s0 = dtoa(x, 2, precision, &decpt, &sign, &se);
|
|
||||||
if (sign)
|
|
||||||
*b++ = '-';
|
|
||||||
if (decpt == 9999) /* Infinity or Nan */ {
|
|
||||||
while((*b++ = *s++));
|
|
||||||
/* "b" is used to calculate the return length. Decrement to exclude the
|
|
||||||
* Null terminator from the length */
|
|
||||||
b--;
|
|
||||||
goto done0;
|
|
||||||
}
|
|
||||||
if (decpt <= -4 || decpt > precision) {
|
|
||||||
*b++ = *s++;
|
|
||||||
if (*s) {
|
|
||||||
*b++ = '.';
|
|
||||||
while((*b = *s++))
|
|
||||||
b++;
|
|
||||||
}
|
|
||||||
*b++ = 'e';
|
|
||||||
/* sprintf(b, "%+.2d", decpt - 1); */
|
|
||||||
if (--decpt < 0) {
|
|
||||||
*b++ = '-';
|
|
||||||
decpt = -decpt;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*b++ = '+';
|
|
||||||
for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10);
|
|
||||||
for(;;) {
|
|
||||||
i = decpt / k;
|
|
||||||
*b++ = i + '0';
|
|
||||||
if (--j <= 0)
|
|
||||||
break;
|
|
||||||
decpt -= i*k;
|
|
||||||
decpt *= 10;
|
|
||||||
}
|
|
||||||
*b = 0;
|
|
||||||
}
|
|
||||||
else if (decpt <= 0) {
|
|
||||||
*b++ = '0';
|
|
||||||
*b++ = '.';
|
|
||||||
for(; decpt < 0; decpt++)
|
|
||||||
*b++ = '0';
|
|
||||||
while((*b++ = *s++));
|
|
||||||
b--;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
while((*b = *s++)) {
|
|
||||||
b++;
|
|
||||||
if (--decpt == 0 && *s)
|
|
||||||
*b++ = '.';
|
|
||||||
}
|
|
||||||
for(; decpt > 0; decpt--)
|
|
||||||
*b++ = '0';
|
|
||||||
*b = 0;
|
|
||||||
}
|
|
||||||
done0:
|
|
||||||
freedtoa(s0);
|
|
||||||
#ifdef IGNORE_ZERO_SIGN
|
|
||||||
done:
|
|
||||||
#endif
|
|
||||||
return b - b0;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue