Towards emscripten build fix (update sdb) ##build

This commit is contained in:
radare 2019-07-07 16:52:41 +02:00 committed by GitHub
parent c1abcbe5e3
commit dc0892a1a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 219 additions and 187 deletions

View File

@ -11,6 +11,7 @@ include ../../libr/main/deps.mk
include ../../shlr/zip/deps.mk include ../../shlr/zip/deps.mk
include ../../shlr/gdb/deps.mk include ../../shlr/gdb/deps.mk
include ../../shlr/java/deps.mk include ../../shlr/java/deps.mk
include ../../shlr/grub/deps.mk
include ../../shlr/bochs/deps.mk include ../../shlr/bochs/deps.mk
include ../../shlr/qnx/deps.mk include ../../shlr/qnx/deps.mk
include ../../shlr/ar/deps.mk include ../../shlr/ar/deps.mk

View File

@ -19,7 +19,7 @@ ifeq (${COMPILER},emscripten)
# https://kripken.github.io/emscripten-site/docs/optimizing/Optimizing-Code.html # https://kripken.github.io/emscripten-site/docs/optimizing/Optimizing-Code.html
# -s INLINING_LIMIT=1 # -s INLINING_LIMIT=1
# --memory-init-file 0 # --memory-init-file 0
CFLAGS+=-s EXPORTED_FUNCTIONS='["_r2_asmjs_new", "_r2_asmjs_cmd", "_r2_asmjs_free", "_r2_asmjs_openurl"]' CFLAGS+=-s EXPORTED_FUNCTIONS='["_r_core_new", "_r_core_free", "_r_cmd_str"]'
CFLAGS+=-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap", "addOnInit"]' CFLAGS+=-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap", "addOnInit"]'
CFLAGS+=-s TOTAL_MEMORY=33554432 CFLAGS+=-s TOTAL_MEMORY=33554432
CFLAGS+=-s ALLOW_MEMORY_GROWTH=1 CFLAGS+=-s ALLOW_MEMORY_GROWTH=1

View File

@ -8,7 +8,15 @@ endif
CFLAGS+=-I$(LTOP)/include CFLAGS+=-I$(LTOP)/include
ifeq (${COMPILER},emscripten) ifeq (${COMPILER},emscripten)
EXT_EXE=.js LINK+=../../libr/libr.a
LINK+=../../shlr/sdb/src/libsdb.a
LINK+=../../shlr/capstone/libcapstone.a
CFLAGS+= -s SIDE_MODULE=1
#CFLAGS+=-s ERROR_ON_UNDEFINED_SYMBOLS=0
#EXT_EXE=.js
#EXT_EXE=.html
EXT_EXE=.bc
#EXT_EXE=.wasm
endif endif
ifeq ($(USE_RPATH),1) ifeq ($(USE_RPATH),1)

View File

@ -95,7 +95,7 @@ _libr.${EXT_AR}: .libr
BN=`basename $$LIB` ; \ BN=`basename $$LIB` ; \
echo $$BN ; \ echo $$BN ; \
mkdir -p .libr2/$$BN ; \ mkdir -p .libr2/$$BN ; \
( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ar x ../../$$LIB ) ; \ ( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} x ../../$$LIB ) ; \
done done
libr.${EXT_AR}: .libr2 libr.${EXT_AR}: .libr2
@ -122,10 +122,14 @@ E+=../shlr/capstone/libcapstone.${EXT_AR}
endif endif
libr.${EXT_SO}: .libr2 libr.${EXT_SO}: .libr2
ifeq (${COMPILER},emscripten)
echo nothing to do here
else
$(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -shared -dynamiclib -o libr.${EXT_SO} \ $(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -shared -dynamiclib -o libr.${EXT_SO} \
.libr2/*/*.o \ .libr2/*/*.o \
../shlr/gdb/lib/libgdbr.${EXT_AR} ../shlr/java/libr_java.${EXT_AR} \ ../shlr/gdb/lib/libgdbr.${EXT_AR} ../shlr/java/libr_java.${EXT_AR} \
../shlr/libr_shlr.${EXT_AR} $(E) ../shlr/libr_shlr.${EXT_AR} $(E)
endif
#libr.${EXT_SO}: .libr #libr.${EXT_SO}: .libr
# $(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -shared -dynamiclib -o libr.${EXT_SO} \ # $(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -shared -dynamiclib -o libr.${EXT_SO} \

View File

@ -99,8 +99,6 @@ R_API void r_fs_del(RFS* fs, RFSPlugin* p) {
R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 delta) { R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 delta) {
RFSPlugin* p; RFSPlugin* p;
RFSRoot* root; RFSRoot* root;
RFSFile* file;
RList* list;
RListIter* iter; RListIter* iter;
char* str; char* str;
int len, lenstr; int len, lenstr;
@ -147,7 +145,7 @@ R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 de
return NULL; return NULL;
} }
} }
file = r_fs_open (fs, str, false); RFSFile* file = r_fs_open (fs, str, false);
if (file) { if (file) {
r_fs_close (fs, file); r_fs_close (fs, file);
eprintf ("r_fs_mount: Invalid mount point\n"); eprintf ("r_fs_mount: Invalid mount point\n");
@ -155,7 +153,7 @@ R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 de
free (str); free (str);
return NULL; return NULL;
} }
list = r_fs_dir (fs, str); RList *list = r_fs_dir (fs, str);
if (!r_list_empty (list)) { if (!r_list_empty (list)) {
//XXX: list need free ?? //XXX: list need free ??
eprintf ("r_fs_mount: Invalid mount point\n"); eprintf ("r_fs_mount: Invalid mount point\n");
@ -552,7 +550,10 @@ static RFSPartitionType partitions[] = {
{"dos", &fs_part_dos, fs_parhook}, {"dos", &fs_part_dos, fs_parhook},
#if USE_GRUB #if USE_GRUB
/* WARNING GPL code */ /* WARNING GPL code */
#if !__EMSCRIPTEN__
// wtf for some reason is not available on emscripten
{"msdos", &grub_msdos_partition_map, grub_parhook}, {"msdos", &grub_msdos_partition_map, grub_parhook},
#endif
{"apple", &grub_apple_partition_map, grub_parhook}, {"apple", &grub_apple_partition_map, grub_parhook},
{"sun", &grub_sun_partition_map, grub_parhook}, {"sun", &grub_sun_partition_map, grub_parhook},
{"sunpc", &grub_sun_pc_partition_map, grub_parhook}, {"sunpc", &grub_sun_pc_partition_map, grub_parhook},

View File

@ -110,6 +110,10 @@
# define UNUSED_FUNCTION(x) UNUSED_ ## x # define UNUSED_FUNCTION(x) UNUSED_ ## x
#endif #endif
#ifdef __EMSCRIPTEN__
# define __UNIX__ 1
#endif
#ifdef __HAIKU__ #ifdef __HAIKU__
# define __UNIX__ 1 # define __UNIX__ 1
#endif #endif

View File

@ -1,5 +1,9 @@
/* radare2 - BSD 3 Clause License - 2016 - crowell */ /* radare2 - BSD 3 Clause License - 2016 - crowell */
#ifndef HT_TYPE
#error HT_TYPE should be defined before including this header
#endif
#undef HtName_ #undef HtName_
#undef Ht_ #undef Ht_
#undef HT_ #undef HT_
@ -8,10 +12,6 @@
#undef KEY_TO_HASH #undef KEY_TO_HASH
#undef HT_NULL_VALUE #undef HT_NULL_VALUE
#ifndef HT_TYPE
#error HT_TYPE should be defined before including this header
#endif
#if HT_TYPE == 1 #if HT_TYPE == 1
#define HtName_(name) name##PP #define HtName_(name) name##PP
#define Ht_(name) ht_pp_##name #define Ht_(name) ht_pp_##name
@ -106,5 +106,3 @@ SDB_API void Ht_(foreach)(HtName_(Ht) *ht, HT_(ForeachCallback) cb, void *user);
SDB_API HT_(Kv)* Ht_(find_kv)(HtName_(Ht)* ht, const KEY_TYPE key, bool* found); SDB_API HT_(Kv)* Ht_(find_kv)(HtName_(Ht)* ht, const KEY_TYPE key, bool* found);
SDB_API bool Ht_(insert_kv)(HtName_(Ht) *ht, HT_(Kv) *kv, bool update); SDB_API bool Ht_(insert_kv)(HtName_(Ht) *ht, HT_(Kv) *kv, bool update);
#undef HT_TYPE

View File

@ -11,5 +11,6 @@
SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new0)(void);
SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
#undef HT_TYPE
#endif #endif

View File

@ -11,5 +11,6 @@
SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new0)(void);
SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
#undef HT_TYPE
#endif #endif

View File

@ -9,5 +9,6 @@
#include "ht_inc.h" #include "ht_inc.h"
SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new0)(void);
#undef HT_TYPE
#endif #endif

View File

@ -5,7 +5,7 @@
#include <r_util.h> #include <r_util.h>
#include "./x509.h" #include "./x509.h"
extern void *r_x509_name_json (PJ *pj, RX509Name *name); extern void r_x509_name_json (PJ *pj, RX509Name *name);
extern void r_x509_free_crl (RX509CertificateRevocationList *crl); extern void r_x509_free_crl (RX509CertificateRevocationList *crl);
extern void r_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb); extern void r_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb);
static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object); static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object);

View File

@ -1,6 +1,7 @@
/* radare - LGPL - Copyright 2009-2012 - pancake */ /* radare - LGPL - Copyright 2009-2019 - pancake */
#include "r_util.h" #include "r_util.h"
typedef struct timeval tv; typedef struct timeval tv;
// Subtract the 'tv' values begin from end, storing result in RESULT // Subtract the 'tv' values begin from end, storing result in RESULT

2
shlr/grub/deps.mk Normal file
View File

@ -0,0 +1,2 @@
LINK+=$(SHLR)/grub/libgrubfs.$(EXT_AR)
#CFLAGS+=-I$(SHLR)/zip/include

View File

@ -1,5 +1,9 @@
/* radare2 - BSD 3 Clause License - 2016 - crowell */ /* radare2 - BSD 3 Clause License - 2016 - crowell */
#ifndef HT_TYPE
#error HT_TYPE should be defined before including this header
#endif
#undef HtName_ #undef HtName_
#undef Ht_ #undef Ht_
#undef HT_ #undef HT_
@ -8,10 +12,6 @@
#undef KEY_TO_HASH #undef KEY_TO_HASH
#undef HT_NULL_VALUE #undef HT_NULL_VALUE
#ifndef HT_TYPE
#error HT_TYPE should be defined before including this header
#endif
#if HT_TYPE == 1 #if HT_TYPE == 1
#define HtName_(name) name##PP #define HtName_(name) name##PP
#define Ht_(name) ht_pp_##name #define Ht_(name) ht_pp_##name
@ -106,5 +106,3 @@ SDB_API void Ht_(foreach)(HtName_(Ht) *ht, HT_(ForeachCallback) cb, void *user);
SDB_API HT_(Kv)* Ht_(find_kv)(HtName_(Ht)* ht, const KEY_TYPE key, bool* found); SDB_API HT_(Kv)* Ht_(find_kv)(HtName_(Ht)* ht, const KEY_TYPE key, bool* found);
SDB_API bool Ht_(insert_kv)(HtName_(Ht) *ht, HT_(Kv) *kv, bool update); SDB_API bool Ht_(insert_kv)(HtName_(Ht) *ht, HT_(Kv) *kv, bool update);
#undef HT_TYPE

View File

@ -1,6 +1,5 @@
#include "ht_pp.h"
#include "sdb.h" #include "sdb.h"
#include "ht_pp.h"
#include "ht_inc.c" #include "ht_inc.c"
static HtName_(Ht)* internal_ht_default_new(ut32 size, ut32 prime_idx, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) calcsizeV) { static HtName_(Ht)* internal_ht_default_new(ut32 size, ut32 prime_idx, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) calcsizeV) {

View File

@ -11,5 +11,6 @@
SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new0)(void);
SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
#undef HT_TYPE
#endif #endif

View File

@ -1,5 +1,4 @@
#include "ht_up.h" #include "ht_up.h"
#include "ht_inc.c" #include "ht_inc.c"
static HtName_(Ht)* internal_ht_default_new(ut32 size, ut32 prime_idx, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) calcsizeV) { static HtName_(Ht)* internal_ht_default_new(ut32 size, ut32 prime_idx, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) calcsizeV) {

View File

@ -11,5 +11,6 @@
SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new0)(void);
SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize);
#undef HT_TYPE
#endif #endif

View File

@ -9,5 +9,6 @@
#include "ht_inc.h" #include "ht_inc.h"
SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new0)(void);
#undef HT_TYPE
#endif #endif

View File

@ -9,141 +9,15 @@
#define CAP(i) if(depth == 1) prev = *out++ = ((cur+i) - (js + prev) + 1) #define CAP(i) if(depth == 1) prev = *out++ = ((cur+i) - (js + prev) + 1)
#ifdef _MSC_VER #ifdef _MSC_VER
#define GO_DOWN (1) #define HAVE_COMPUTED_GOTOS 0
#define GO_UP (1 << 1) #elif __EMSCRIPTEN__
#define GO_Q_DOWN (1 << 2) #define HAVE_COMPUTED_GOTOS 0
#define GO_Q_UP (1 << 3)
#define GO_BARE (1 << 4)
#define GO_UNBARE (1 << 5)
#define GO_ESCAPE (1 << 6)
#define GO_UNESCAPE (1 << 7)
#define GO_UTF8 (1 << 8)
#define GO_UTF8_CONTINUE (1 << 9)
int sdb_js0n(const ut8 *js, RangstrType len, RangstrType *out) {
ut32 prev = 0;
const ut8 *cur, *end;
int depth = 0, utf8_remain = 0, what_did = 1;
for (cur = js, end = js + len; cur < end; cur++) {
if (what_did & GO_BARE) {
switch (*cur) {
case ' ':
case '\t':
case '\r':
case '\n':
case ',':
case ']':
case '}':
what_did = GO_UNBARE;
CAP (-1);
break;
default:
if (*cur >= 32 && *cur <= 126) {
continue;
}
return 1;
}
// Same *cur
}
if (what_did & GO_UTF8) {
if (*cur < 128 || (*cur >=192 && *cur <= 255)) {
return 1;
}
if (!--utf8_remain) {
what_did = GO_UTF8_CONTINUE;
}
continue;
}
if (what_did & GO_ESCAPE) {
switch (*cur) {
case '"':
case '\\':
case '/':
case 'b':
case 'f':
case 'n':
case 'r':
case 't':
case 'u':
what_did = GO_UNESCAPE;
break;
default:
return 1;
}
continue;
}
if (what_did & GO_Q_UP || what_did & GO_UTF8_CONTINUE || what_did & GO_UNESCAPE) {
switch (*cur) {
case '\\':
what_did = GO_ESCAPE;
break;
case '"':
what_did = GO_Q_DOWN;
CAP (-1);
break;
default:
if (*cur <= 31 || (*cur >= 127 && *cur <= 191) || (*cur >= 248 && *cur <= 255)) {
return 1;
}
if (*cur < 127) {
continue;
}
what_did = GO_UTF8;
if (*cur < 224) {
utf8_remain = 1;
continue;
}
if (*cur < 239) {
utf8_remain = 2;
continue;
}
utf8_remain = 3;
break;
}
continue;
}
switch (*cur) {
case '\t':
case ' ':
case '\r':
case '\n':
case ',':
case ':':
break;
case '"':
PUSH (1);
what_did = GO_Q_UP;
break;
case '[':
case '{':
PUSH (0);
++depth;
what_did = GO_UP;
break;
case ']':
case '}':
--depth;
CAP (0);
what_did = GO_DOWN;
break;
case '-':
case 't':
case 'f':
case 'n':
what_did = GO_BARE;
PUSH (0);
break;
default:
if (*cur >= 48 && *cur <= 57) { // 0-9
what_did = GO_BARE;
PUSH (0);
break;
}
return 1;
}
}
return depth;
}
#else #else
#define HAVE_COMPUTED_GOTOS 1
#endif
#if HAVE_COMPUTED_GOTOS
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic push #pragma GCC diagnostic push
#endif #endif
@ -281,4 +155,141 @@ l_utf_continue:
go = gostring; go = gostring;
goto l_loop; goto l_loop;
} }
#endif
#else // HAVE_COMPUTED_GOTOS
#define GO_DOWN (1)
#define GO_UP (1 << 1)
#define GO_Q_DOWN (1 << 2)
#define GO_Q_UP (1 << 3)
#define GO_BARE (1 << 4)
#define GO_UNBARE (1 << 5)
#define GO_ESCAPE (1 << 6)
#define GO_UNESCAPE (1 << 7)
#define GO_UTF8 (1 << 8)
#define GO_UTF8_CONTINUE (1 << 9)
int sdb_js0n(const ut8 *js, RangstrType len, RangstrType *out) {
ut32 prev = 0;
const ut8 *cur, *end;
int depth = 0, utf8_remain = 0, what_did = 1;
for (cur = js, end = js + len; cur < end; cur++) {
if (what_did & GO_BARE) {
switch (*cur) {
case ' ':
case '\t':
case '\r':
case '\n':
case ',':
case ']':
case '}':
what_did = GO_UNBARE;
CAP (-1);
break;
default:
if (*cur >= 32 && *cur <= 126) {
continue;
}
return 1;
}
// Same *cur
}
if (what_did & GO_UTF8) {
if (*cur < 128 || (*cur >=192 && *cur <= 255)) {
return 1;
}
if (!--utf8_remain) {
what_did = GO_UTF8_CONTINUE;
}
continue;
}
if (what_did & GO_ESCAPE) {
switch (*cur) {
case '"':
case '\\':
case '/':
case 'b':
case 'f':
case 'n':
case 'r':
case 't':
case 'u':
what_did = GO_UNESCAPE;
break;
default:
return 1;
}
continue;
}
if (what_did & GO_Q_UP || what_did & GO_UTF8_CONTINUE || what_did & GO_UNESCAPE) {
switch (*cur) {
case '\\':
what_did = GO_ESCAPE;
break;
case '"':
what_did = GO_Q_DOWN;
CAP (-1);
break;
default:
if (*cur <= 31 || (*cur >= 127 && *cur <= 191) || (*cur >= 248 && *cur <= 255)) {
return 1;
}
if (*cur < 127) {
continue;
}
what_did = GO_UTF8;
if (*cur < 224) {
utf8_remain = 1;
continue;
}
if (*cur < 239) {
utf8_remain = 2;
continue;
}
utf8_remain = 3;
break;
}
continue;
}
switch (*cur) {
case '\t':
case ' ':
case '\r':
case '\n':
case ',':
case ':':
break;
case '"':
PUSH (1);
what_did = GO_Q_UP;
break;
case '[':
case '{':
PUSH (0);
++depth;
what_did = GO_UP;
break;
case ']':
case '}':
--depth;
CAP (0);
what_did = GO_DOWN;
break;
case '-':
case 't':
case 'f':
case 'n':
what_did = GO_BARE;
PUSH (0);
break;
default:
if (*cur >= 48 && *cur <= 57) { // 0-9
what_did = GO_BARE;
PUSH (0);
break;
}
return 1;
}
}
return depth;
}
#endif // HAVE_COMPUTED_GOTOS

View File

@ -1,4 +1,4 @@
/* sdb - MIT - Copyright 2011-2017 - pancake */ /* sdb - MIT - Copyright 2011-2019 - pancake */
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
@ -24,7 +24,7 @@ static void terminate(int sig UNUSED) {
exit (1); exit (1);
} }
sdb_free (s); sdb_free (s);
exit (0); exit (sig<2?sig:0);
} }
#define BS 128 #define BS 128
@ -142,11 +142,9 @@ static char *stdin_slurp(int *sz) {
if (sz) { if (sz) {
*sz = len; *sz = len;
} }
//eprintf ("LEN %d (%s)\n", len, buf);
if (len < 1) { if (len < 1) {
free (buf); free (buf);
buf = NULL; return buf = NULL;
return NULL;
} }
buf[len] = 0; buf[len] = 0;
return buf; return buf;
@ -155,9 +153,8 @@ static char *stdin_slurp(int *sz) {
#if USE_MMAN #if USE_MMAN
static void synchronize(int sig UNUSED) { static void synchronize(int sig UNUSED) {
// TODO: must be in sdb_sync() or wat? // TODO: must be in sdb_sync() or wat?
Sdb *n;
sdb_sync (s); sdb_sync (s);
n = sdb_new (s->path, s->name, s->lock); Sdb *n = sdb_new (s->path, s->name, s->lock);
if (n) { if (n) {
sdb_config (n, options); sdb_config (n, options);
sdb_free (s); sdb_free (s);
@ -165,23 +162,22 @@ static void synchronize(int sig UNUSED) {
} }
} }
#endif #endif
static int sdb_grep_dump(const char *db, int fmt, bool grep,
static int sdb_grep_dump(const char *dbname, int fmt, bool grep,
const char *expgrep) { const char *expgrep) {
char *v; char *v, k[SDB_MAX_KEY] = { 0 };
char k[SDB_MAX_KEY] = {
0
};
const char *comma = ""; const char *comma = "";
Sdb *s = sdb_new (NULL, db, 0); // local db beacuse is readonly and we dont need to finalize in case of ^C
if (!s) { Sdb *db = sdb_new (NULL, dbname, 0);
if (!db) {
return 1; return 1;
} }
sdb_config (s, options); sdb_config (db, options);
sdb_dump_begin (s); sdb_dump_begin (db);
if (fmt == MODE_JSON) { if (fmt == MODE_JSON) {
printf ("{"); printf ("{");
} }
while (sdb_dump_dupnext (s, k, &v, NULL)) { while (sdb_dump_dupnext (db, k, &v, NULL)) {
if (grep && !strstr (k, expgrep) && !strstr (v, expgrep)) { if (grep && !strstr (k, expgrep) && !strstr (v, expgrep)) {
free (v); free (v);
continue; continue;
@ -218,9 +214,10 @@ static int sdb_grep_dump(const char *db, int fmt, bool grep,
printf ("}\n"); printf ("}\n");
break; break;
} }
sdb_free (s); sdb_free (db);
return 0; return 0;
} }
static int sdb_grep(const char *db, int fmt, const char *grep) { static int sdb_grep(const char *db, int fmt, const char *grep) {
return sdb_grep_dump (db, fmt, true, grep); return sdb_grep_dump (db, fmt, true, grep);
} }
@ -401,7 +398,7 @@ int showcount(const char *db) {
int main(int argc, const char **argv) { int main(int argc, const char **argv) {
char *line; char *line;
const char *arg, *grep = NULL; const char *arg, *grep = NULL;
int i, ret, fmt = MODE_DFLT; int i, fmt = MODE_DFLT;
int db0 = 1, argi = 1; int db0 = 1, argi = 1;
bool interactive = false; bool interactive = false;
@ -484,7 +481,7 @@ int main(int argc, const char **argv) {
signal (SIGINT, terminate); signal (SIGINT, terminate);
signal (SIGHUP, synchronize); signal (SIGHUP, synchronize);
#endif #endif
ret = 0; int ret = 0;
if (interactive || !strcmp (argv[db0 + 1], "-")) { if (interactive || !strcmp (argv[db0 + 1], "-")) {
if ((s = sdb_new (NULL, argv[db0], 0))) { if ((s = sdb_new (NULL, argv[db0], 0))) {
sdb_config (s, options); sdb_config (s, options);
@ -517,6 +514,6 @@ int main(int argc, const char **argv) {
} }
} }
} }
terminate (0); terminate (ret);
return ret; return ret;
} }

View File

@ -307,13 +307,15 @@ next_quote:
SdbListIter *it; SdbListIter *it;
SdbNs *ns; SdbNs *ns;
ls_foreach (s->ns, it, ns) { ls_foreach (s->ns, it, ns) {
int len = strlen (ns->name); int name_len = strlen (ns->name);
if (len<(long)sizeof (root)) { if (name_len < (long)sizeof (root)) {
memcpy (root, ns->name, len+1); memcpy (root, ns->name, name_len + 1);
walk_namespace (out, root, walk_namespace (out, root,
sizeof (root)-len, sizeof (root) - name_len,
root+len, ns, encode); root + name_len, ns, encode);
} else eprintf ("TODO: Namespace too long\n"); } else {
eprintf ("TODO: Namespace too long\n");
}
} }
goto fail; goto fail;
} else } else

View File

@ -947,7 +947,7 @@ SDB_API bool sdb_dump_dupnext(Sdb* s, char *key, char **value, int *_vlen) {
} }
if (value) { if (value) {
*value = 0; *value = 0;
if (vlen >= SDB_MIN_VALUE && vlen < SDB_MAX_VALUE) { if (vlen < SDB_MAX_VALUE) {
*value = malloc (vlen + 10); *value = malloc (vlen + 10);
if (!*value) { if (!*value) {
return false; return false;

View File

@ -33,6 +33,7 @@
#include <unistd.h>
#include "zipint.h" #include "zipint.h"