at work
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,6 +1,8 @@
|
||||
cworker
|
||||
configure
|
||||
libtool
|
||||
Makefile
|
||||
config.h
|
||||
*~
|
||||
*_test
|
||||
*.o
|
||||
@@ -10,3 +12,6 @@ Makefile
|
||||
*.tar.*
|
||||
stamp*
|
||||
autom4te*
|
||||
*.lo
|
||||
*.la
|
||||
.libs
|
||||
|
||||
44
Makefile
44
Makefile
@@ -237,20 +237,20 @@ distuninstallcheck_listfiles = find . -type f -print
|
||||
am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
|
||||
| sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
|
||||
distcleancheck_listfiles = find . -type f -print
|
||||
ACLOCAL = ${SHELL} /home/ziggi/projects/cworker/missing aclocal
|
||||
ACLOCAL = ${SHELL} /home/ziggi/Projects/cworker/missing aclocal
|
||||
AMTAR = $${TAR-tar}
|
||||
AM_DEFAULT_VERBOSITY = 1
|
||||
APP_CACHEDIR = /home/ziggi/projects/cworker/cache
|
||||
APP_CONFIGDIR = /home/ziggi/projects/cworker/
|
||||
APP_DATABASEDIR = /home/ziggi/projects/cworker/data
|
||||
APP_LIBDIR = /home/ziggi/projects/cworker/lib
|
||||
APP_LOGDIR = /home/ziggi/projects/cworker/log
|
||||
APP_RUNDIR = /home/ziggi/projects/cworker/run
|
||||
APP_CACHEDIR = /home/ziggi/Projects/cworker/cache
|
||||
APP_CONFIGDIR = /home/ziggi/Projects/cworker/
|
||||
APP_DATABASEDIR = /home/ziggi/Projects/cworker/data
|
||||
APP_LIBDIR = /home/ziggi/Projects/cworker/lib
|
||||
APP_LOGDIR = /home/ziggi/Projects/cworker/log
|
||||
APP_RUNDIR = /home/ziggi/Projects/cworker/run
|
||||
APP_USER = ziggi
|
||||
AR = ar
|
||||
AUTOCONF = ${SHELL} /home/ziggi/projects/cworker/missing autoconf
|
||||
AUTOHEADER = ${SHELL} /home/ziggi/projects/cworker/missing autoheader
|
||||
AUTOMAKE = ${SHELL} /home/ziggi/projects/cworker/missing automake
|
||||
AUTOCONF = ${SHELL} /home/ziggi/Projects/cworker/missing autoconf
|
||||
AUTOHEADER = ${SHELL} /home/ziggi/Projects/cworker/missing autoheader
|
||||
AUTOMAKE = ${SHELL} /home/ziggi/Projects/cworker/missing automake
|
||||
AWK = gawk
|
||||
CC = clang
|
||||
CCDEPMODE = depmode=none
|
||||
@@ -286,7 +286,7 @@ LIPO =
|
||||
LN_S = ln -s
|
||||
LTLIBOBJS =
|
||||
LT_SYS_LIBRARY_PATH =
|
||||
MAKEINFO = ${SHELL} /home/ziggi/projects/cworker/missing makeinfo
|
||||
MAKEINFO = ${SHELL} /home/ziggi/Projects/cworker/missing makeinfo
|
||||
MANIFEST_TOOL = :
|
||||
MKDIR_P = /usr/local/bin/gmkdir -p
|
||||
NM = /usr/bin/nm
|
||||
@@ -310,10 +310,10 @@ SHELL = /bin/sh
|
||||
STRIP = strip
|
||||
VALGRIND = /usr/local/bin/valgrind
|
||||
VERSION = 0.0.1
|
||||
abs_builddir = /home/ziggi/projects/cworker
|
||||
abs_srcdir = /home/ziggi/projects/cworker
|
||||
abs_top_builddir = /home/ziggi/projects/cworker
|
||||
abs_top_srcdir = /home/ziggi/projects/cworker
|
||||
abs_builddir = /home/ziggi/Projects/cworker
|
||||
abs_srcdir = /home/ziggi/Projects/cworker
|
||||
abs_top_builddir = /home/ziggi/Projects/cworker
|
||||
abs_top_srcdir = /home/ziggi/Projects/cworker
|
||||
ac_ct_AR = ar
|
||||
ac_ct_CC = clang
|
||||
ac_ct_DUMPBIN =
|
||||
@@ -322,13 +322,13 @@ am__leading_dot = .
|
||||
am__quote =
|
||||
am__tar = $${TAR-tar} chof - "$$tardir"
|
||||
am__untar = $${TAR-tar} xf -
|
||||
app_cachedir = /home/ziggi/projects/cworker/cache
|
||||
app_configdir = /home/ziggi/projects/cworker/
|
||||
app_databasedir = /home/ziggi/projects/cworker/data
|
||||
app_libdir = /home/ziggi/projects/cworker/lib
|
||||
app_logdir = /home/ziggi/projects/cworker/log
|
||||
app_cachedir = /home/ziggi/Projects/cworker/cache
|
||||
app_configdir = /home/ziggi/Projects/cworker/
|
||||
app_databasedir = /home/ziggi/Projects/cworker/data
|
||||
app_libdir = /home/ziggi/Projects/cworker/lib
|
||||
app_logdir = /home/ziggi/Projects/cworker/log
|
||||
app_name = cworker
|
||||
app_rundir = /home/ziggi/projects/cworker/run
|
||||
app_rundir = /home/ziggi/Projects/cworker/run
|
||||
app_user = ziggi
|
||||
bindir = ${exec_prefix}/bin
|
||||
build = amd64-unknown-freebsd12.4
|
||||
@@ -350,7 +350,7 @@ host_vendor = unknown
|
||||
htmldir = ${docdir}
|
||||
includedir = ${prefix}/include
|
||||
infodir = ${datarootdir}/info
|
||||
install_sh = ${SHELL} /home/ziggi/projects/cworker/install-sh
|
||||
install_sh = ${SHELL} /home/ziggi/Projects/cworker/install-sh
|
||||
libdir = ${exec_prefix}/lib
|
||||
libexecdir = ${exec_prefix}/libexec
|
||||
localedir = ${datarootdir}/locale
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo
|
||||
AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo
|
||||
|
||||
SUFFIXES = .c .o
|
||||
AM_CFLAGS = -Wall
|
||||
|
||||
@@ -377,7 +377,7 @@ target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo
|
||||
AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo
|
||||
SUFFIXES = .c .o
|
||||
AM_CFLAGS = -Wall
|
||||
AM_LDFLAGS = -pthread
|
||||
|
||||
148
clib/jblock.c
148
clib/jblock.c
@@ -23,6 +23,13 @@ void jblock_init(jblock_t* jb) {
|
||||
jb->kvarr = malloc(sizeof(jkeyval_t) * INIT_CAPA);
|
||||
}
|
||||
|
||||
jblock_t* new_jblock() {
|
||||
jblock_t* jb = malloc(sizeof(jblock_t));
|
||||
if (jb == NULL) return NULL;
|
||||
jblock_init(jb);
|
||||
return jb;
|
||||
}
|
||||
|
||||
static void* jblock_checkalloc(jblock_t* jb) {
|
||||
if (jb->kvsize == jb->kvcapa) {
|
||||
size_t newsize = jb->kvcapa * 2;
|
||||
@@ -161,19 +168,44 @@ void jblock_outjson(jblock_t* jb, char** res) {
|
||||
void jblock_destroy(jblock_t* jb) {
|
||||
if (jb == NULL) return;
|
||||
for (int i = 0; i < jb->kvsize; i++) {
|
||||
free(jb->kvarr[i].key);
|
||||
switch (jb->kvarr[i].type) {
|
||||
case JKVTYPE_BLK: {
|
||||
jblock_destroy(jb->kvarr[i].blk);
|
||||
break;
|
||||
}
|
||||
//case JKVTYPE_BLKARR: {
|
||||
// break;
|
||||
//}
|
||||
case JKVTYPE_STR: {
|
||||
free(jb->kvarr[i].str);
|
||||
break;
|
||||
}
|
||||
case JKVTYPE_INTARR: {
|
||||
//free(jb->kvarr[i].numarr);
|
||||
break;
|
||||
}
|
||||
case JKVTYPE_BOOLARR: {
|
||||
//free(jb->kvarr[i].flagarr);
|
||||
break;
|
||||
}
|
||||
case JKVTYPE_FLTARR: {
|
||||
//free(jb->kvarr[i].fltarr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(jb->kvarr[i].key);
|
||||
}
|
||||
jb->kvsize = 0;
|
||||
jb->kvcapa = 0;
|
||||
jb->kvarr = NULL;
|
||||
}
|
||||
|
||||
void jblock_free(jblock_t* jb) {
|
||||
jblock_destroy(jb);
|
||||
free(jb);
|
||||
}
|
||||
|
||||
/* String container */
|
||||
static void* jstring_init(jstring_t* str) {
|
||||
str->data = malloc(INIT_CAPA + 1);
|
||||
if (str->data == NULL) return NULL;
|
||||
@@ -188,7 +220,7 @@ static void* jstring_append(jstring_t* str, char* add) {
|
||||
size_t addsize = strlen(add);
|
||||
size_t newsize = str->size + addsize;
|
||||
if (newsize > str->capa) {
|
||||
char* newstr = malloc(newsize + 1);
|
||||
char* newstr = realloc(str->data, newsize + 1);
|
||||
if (newstr == NULL) return NULL;
|
||||
}
|
||||
strcpy(&(str->data[str->size]), add);
|
||||
@@ -202,6 +234,118 @@ static char* jstring_getref(jstring_t* str) {
|
||||
return str->data;
|
||||
}
|
||||
|
||||
/* Integer array */
|
||||
jintarr_t* new_jintarr(void) {
|
||||
jintarr_t* arr = malloc(sizeof(jintarr_t));
|
||||
if (arr == NULL) return NULL;
|
||||
if (jintarr_init(arr) == NULL) {
|
||||
jintarr_free(arr);
|
||||
return NULL;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
void* jintarr_init(jintarr_t* array) {
|
||||
array->data = malloc(INIT_CAPA * sizeof(int64_t));
|
||||
if (array->data == NULL) return NULL;
|
||||
memset(array->data, 0, INIT_CAPA);
|
||||
array->capa = INIT_CAPA;
|
||||
array->size = 0;
|
||||
return array->data;
|
||||
}
|
||||
|
||||
void* jintarr_append(jintarr_t* array, int64_t add) {
|
||||
if (array->size + 1 > array->capa) {
|
||||
size_t newcapa = (array->capa * 10) / 6 ;
|
||||
int64_t* newarray = realloc(array->data, newcapa);
|
||||
if (newarray == NULL) return NULL;
|
||||
array->capa = newcapa;
|
||||
array->data = newarray;
|
||||
}
|
||||
array->data[array->size++] = add;
|
||||
return array->data;
|
||||
}
|
||||
|
||||
int64_t* jintarr_getref(jintarr_t* array) {
|
||||
return array->data;
|
||||
}
|
||||
|
||||
void jintarr_destroy(jintarr_t* array) {
|
||||
if (array == NULL) return;
|
||||
free(array->data);
|
||||
}
|
||||
|
||||
void jintarr_free(jintarr_t* array) {
|
||||
jintarr_destroy(array);
|
||||
free(array->data);
|
||||
}
|
||||
|
||||
|
||||
/* Float array */
|
||||
void* jfltarr_init(jfltarr_t* array) {
|
||||
array->data = malloc(INIT_CAPA * sizeof(double));
|
||||
if (array->data == NULL) return NULL;
|
||||
memset(array->data, 0, INIT_CAPA);
|
||||
array->capa = INIT_CAPA;
|
||||
array->size = 0;
|
||||
return array->data;
|
||||
}
|
||||
|
||||
void* jfltarr_append(jfltarr_t* array, double add) {
|
||||
if (array->size + 1 > array->capa) {
|
||||
size_t newcapa = (array->capa * 10) / 6 ;
|
||||
double* newarray = realloc(array->data, newcapa);
|
||||
if (newarray == NULL) return NULL;
|
||||
array->capa = newcapa;
|
||||
array->data = newarray;
|
||||
}
|
||||
array->data[array->size++] = add;
|
||||
return array->data;
|
||||
}
|
||||
|
||||
double* jfltarr_getref(jfltarr_t* array) {
|
||||
return array->data;
|
||||
}
|
||||
|
||||
void jfltarr_destroy(jfltarr_t* array) {
|
||||
if (array == NULL) return;
|
||||
free(array->data);
|
||||
}
|
||||
|
||||
|
||||
/* Bool array */
|
||||
void* jboolarr_init(jboolarr_t* array) {
|
||||
array->data = malloc(INIT_CAPA * sizeof(bool));
|
||||
if (array->data == NULL) return NULL;
|
||||
memset(array->data, 0, INIT_CAPA);
|
||||
array->capa = INIT_CAPA;
|
||||
array->size = 0;
|
||||
return array->data;
|
||||
}
|
||||
|
||||
void* jboolarr_append(jboolarr_t* array, bool add) {
|
||||
if (array->size + 1 > array->capa) {
|
||||
size_t newcapa = (array->capa * 10) / 6 ;
|
||||
bool* newarray = realloc(array->data, newcapa);
|
||||
if (newarray == NULL) return NULL;
|
||||
array->capa = newcapa;
|
||||
array->data = newarray;
|
||||
}
|
||||
array->data[array->size++] = add;
|
||||
return array->data;
|
||||
}
|
||||
|
||||
bool* jboolarr_getref(jboolarr_t* array) {
|
||||
return array->data;
|
||||
}
|
||||
|
||||
void jboolarr_destroy(jboolarr_t* array) {
|
||||
if (array == NULL) return;
|
||||
free(array->data);
|
||||
}
|
||||
|
||||
|
||||
/* Tools */
|
||||
static char* strcopy(char* src) {
|
||||
size_t srcsize = strlen(src) + 1;
|
||||
char* dst = malloc(srcsize);
|
||||
|
||||
@@ -5,56 +5,106 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
char* data;
|
||||
int capa;
|
||||
int size;
|
||||
} jstring_t;
|
||||
|
||||
typedef struct {
|
||||
int64_t* data;
|
||||
int capa;
|
||||
int size;
|
||||
} jintarr_t;
|
||||
|
||||
typedef struct {
|
||||
bool* data;
|
||||
int capa;
|
||||
int size;
|
||||
} jboolarr_t;
|
||||
|
||||
typedef struct {
|
||||
double* data;
|
||||
int capa;
|
||||
int size;
|
||||
} jfltarr_t;
|
||||
|
||||
|
||||
typedef struct jblock jblock_t;
|
||||
|
||||
typedef struct {
|
||||
char* key;
|
||||
int type;
|
||||
union {
|
||||
int64_t num;
|
||||
bool flag;
|
||||
char* str;
|
||||
double flt;
|
||||
int64_t* numarr;
|
||||
char** strarr;
|
||||
double* fltarr;
|
||||
bool* flagarr;
|
||||
int64_t num;
|
||||
bool flag;
|
||||
char* str;
|
||||
double flt;
|
||||
jintarr_t numarr;
|
||||
jfltarr_t fltarr;
|
||||
jboolarr_t flagarr;
|
||||
jblock_t* blk;
|
||||
jblock_t* blkarr;
|
||||
char** strarr;
|
||||
|
||||
};
|
||||
int arrsize;
|
||||
int arrcapa;
|
||||
} jkeyval_t;
|
||||
|
||||
typedef struct {
|
||||
struct jblock {
|
||||
jkeyval_t* kvarr;
|
||||
int kvsize;
|
||||
int kvcapa;
|
||||
} jblock_t;
|
||||
};
|
||||
|
||||
#define JKVTYPE_INT 0x01
|
||||
#define JKVTYPE_STR 0x02
|
||||
#define JKVTYPE_BOOL 0x03
|
||||
#define JKVTYPE_FLT 0x04
|
||||
#define JKVTYPE_BLK 0x05
|
||||
#define JKVTYPE_INTARR 0x11
|
||||
#define JKVTYPE_STRARR 0x12
|
||||
#define JKVTYPE_BOOLARR 0x13
|
||||
#define JKVTYPE_FLTARR 0x14
|
||||
#define JKVTYPE_BLKARR 0x15
|
||||
|
||||
|
||||
#define JB_MALLOCERR -1
|
||||
#define JB_KEYEXISTS -2
|
||||
|
||||
jblock_t* new_jblock();
|
||||
void jblock_init(jblock_t* block);
|
||||
void jblock_outjson(jblock_t* block, char** res);
|
||||
void jblock_destroy(jblock_t* block);
|
||||
void jblock_free(jblock_t* jb);
|
||||
|
||||
void jblock_init(jblock_t* kv);
|
||||
void jblock_outjson(jblock_t* kv, char** res);
|
||||
void jblock_destroy(jblock_t* kv);
|
||||
int jblock_addint(jblock_t* block, char* key, int64_t val);
|
||||
int jblock_addfloat(jblock_t* block, char* key, double val);
|
||||
int jblock_addstr(jblock_t* block, char* key, char* val);
|
||||
int jblock_addbool(jblock_t* block, char* key, bool val);
|
||||
|
||||
jintarr_t* new_jintarr(void);
|
||||
void* jintarr_init(jintarr_t* array);
|
||||
void* jintarr_append(jintarr_t* array, int64_t add);
|
||||
int64_t* jintarr_getref(jintarr_t* array);
|
||||
void jintarr_destroy(jintarr_t* array);
|
||||
void jintarr_free(jintarr_t* array);
|
||||
|
||||
jfltarr_t* new_jfltarr(void);
|
||||
void* jfltarr_init(jfltarr_t* array);
|
||||
void* jfltarr_append(jfltarr_t* array, double add);
|
||||
double* jfltarr_getref(jfltarr_t* array);
|
||||
void jfltarr_destroy(jfltarr_t* array);
|
||||
void jfltarr_free(jfltarr_t* array);
|
||||
|
||||
jboolarr_t* new_jboolarr(void);
|
||||
void* jboolarr_init(jboolarr_t* array);
|
||||
void* jboolarr_append(jboolarr_t* array, bool add);
|
||||
bool* jboolarr_getref(jboolarr_t* array);
|
||||
void jboolarr_destroy(jboolarr_t* array);
|
||||
void jboolarr_free(jboolarr_t* array);
|
||||
|
||||
int jblock_addint(jblock_t* kv, char* key, int64_t val);
|
||||
int jblock_addfloat(jblock_t* kv, char* key, double val);
|
||||
int jblock_addstr(jblock_t* kv, char* key, char* val);
|
||||
int jblock_addbool(jblock_t* kv, char* key, bool val);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,25 +12,54 @@
|
||||
|
||||
|
||||
void test01(void) {
|
||||
jblock_t jb;
|
||||
jblock_t* jb = new_jblock();
|
||||
|
||||
jblock_init(&jb);
|
||||
jblock_addint(&jb, "id1", 12345);
|
||||
jblock_addstr(&jb, "id2", "qwerty");
|
||||
jblock_addbool(&jb, "b1", true);
|
||||
jblock_addbool(&jb, "b2", false);
|
||||
jblock_addfloat(&jb, "f1", (double)123e1);
|
||||
jblock_init(jb);
|
||||
jblock_addint(jb, "id1", 12345);
|
||||
jblock_addstr(jb, "id2", "qwerty");
|
||||
jblock_addbool(jb, "b1", true);
|
||||
jblock_addbool(jb, "b2", false);
|
||||
jblock_addfloat(jb, "f1", (double)123e1);
|
||||
|
||||
char* jsonstr = NULL;
|
||||
jblock_outjson(&jb, &jsonstr);
|
||||
jblock_destroy(&jb);
|
||||
jblock_outjson(jb, &jsonstr);
|
||||
jblock_free(jb);
|
||||
|
||||
printf("%s\n", jsonstr);
|
||||
free(jsonstr);
|
||||
}
|
||||
|
||||
void test02(void) {
|
||||
jintarr_t* arr = new_jintarr();
|
||||
jintarr_init(arr);
|
||||
|
||||
for (int64_t i = 0; i < 1024 + 1; i++) {
|
||||
jintarr_append(arr, i);
|
||||
}
|
||||
printf("size: %d capa: %d\n", arr->size, arr->capa);
|
||||
printf("last: %ld\n", arr->data[arr->size - 1]);
|
||||
|
||||
jintarr_free(arr);
|
||||
|
||||
}
|
||||
|
||||
void test03(void) {
|
||||
jfltarr_t arr;
|
||||
jfltarr_init(&arr);
|
||||
|
||||
for (int64_t i = 0; i < 1024 + 1; i++) {
|
||||
jfltarr_append(&arr, i);
|
||||
}
|
||||
printf("size: %d capa: %d\n", arr.size, arr.capa);
|
||||
printf("last: %f\n", arr.data[arr.size - 1]);
|
||||
|
||||
jfltarr_destroy(&arr);
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
test01();
|
||||
//test01();
|
||||
test02();
|
||||
test03();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -10,25 +10,27 @@
|
||||
#include <rcache.h>
|
||||
#include <jlexer.h>
|
||||
|
||||
#define JLEXCONT_UNDEF 0
|
||||
#define JLEXCONT_WORD 1
|
||||
#define JLEXCONT_BLOCKB 2
|
||||
#define JLEXCONT_BLOCKE 3
|
||||
#define JLEXCONT_SEPAR 4
|
||||
#define JLEXCONT_NUM 5
|
||||
#define JLEXCONT_UNKNOW 6
|
||||
#define JLEXCONT_END 9
|
||||
#define JLEXCONT_UNDEF 0x00
|
||||
#define JLEXCONT_WORD 0x01
|
||||
#define JLEXCONT_BLOCKB 0x02
|
||||
#define JLEXCONT_BLOCKE 0x03
|
||||
#define JLEXCONT_SEPAR 0x04
|
||||
#define JLEXCONT_NUM 0x05
|
||||
#define JLEXCONT_UNKNOW 0x06
|
||||
#define JLEXCONT_END 0x99
|
||||
|
||||
#define JLEXTYPE_UNDEF 0
|
||||
#define JLEXTYPE_BLOCKB 1
|
||||
#define JLEXTYPE_BLOCKE 2
|
||||
#define JLEXTYPE_WORDL 3
|
||||
#define JLEXTYPE_SPACE 4
|
||||
#define JLEXTYPE_SEPAR 5
|
||||
#define JLEXTYPE_NUM 6
|
||||
#define JLEXTYPE_COMMA 7
|
||||
#define JLEXTYPE_CHAR 8
|
||||
#define JLEXTYPE_EOF 9
|
||||
#define JLEXTYPE_UNDEF 0x00
|
||||
#define JLEXTYPE_BLOCKB 0x01
|
||||
#define JLEXTYPE_BLOCKE 0x02
|
||||
#define JLEXTYPE_WORDL 0x03
|
||||
#define JLEXTYPE_SPACE 0x04
|
||||
#define JLEXTYPE_SEPAR 0x05
|
||||
#define JLEXTYPE_NUM 0x06
|
||||
#define JLEXTYPE_COMMA 0x07
|
||||
#define JLEXTYPE_CHAR 0x08
|
||||
#define JLEXTYPE_ARRB 0x11
|
||||
#define JLEXTYPE_ARRE 0x12
|
||||
#define JLEXTYPE_EOF 0x99
|
||||
|
||||
|
||||
static int get_ltype(char letter) {
|
||||
@@ -39,6 +41,10 @@ static int get_ltype(char letter) {
|
||||
return JLEXTYPE_BLOCKB;
|
||||
case '}':
|
||||
return JLEXTYPE_BLOCKE;
|
||||
case '[':
|
||||
return JLEXTYPE_ARRB;
|
||||
case ']':
|
||||
return JLEXTYPE_ARRE;
|
||||
case '"':
|
||||
return JLEXTYPE_WORDL;
|
||||
case ' ':
|
||||
@@ -113,6 +119,16 @@ int jlexer_gettoken(jlexer_t * lexer, char* token) {
|
||||
lexer->context = JLEXCONT_UNDEF;
|
||||
return JLEXTOK_BLOCKE;
|
||||
}
|
||||
case JLEXTYPE_ARRB:{
|
||||
strcpy(token, "ARR BEGIN");
|
||||
lexer->context = JLEXCONT_UNDEF;
|
||||
return JLEXTOK_ARRB;
|
||||
}
|
||||
case JLEXTYPE_ARRE:{
|
||||
strcpy(token, "ARR END");
|
||||
lexer->context = JLEXCONT_UNDEF;
|
||||
return JLEXTOK_ARRE;
|
||||
}
|
||||
case JLEXTYPE_SEPAR:{
|
||||
strcpy(token, "IS");
|
||||
lexer->context = JLEXCONT_UNDEF;
|
||||
|
||||
@@ -16,16 +16,18 @@ typedef struct {
|
||||
|
||||
|
||||
|
||||
#define JLEXTOK_BLOCKB 1
|
||||
#define JLEXTOK_BLOCKE 2
|
||||
#define JLEXTOK_SPACE 4
|
||||
#define JLEXTOK_SEPAR 3
|
||||
#define JLEXTOK_UNDEF 4
|
||||
#define JLEXTOK_WORD 5
|
||||
#define JLEXTOK_NUMB 6
|
||||
#define JLEXTOK_UNKNOW 7
|
||||
#define JLEXTOK_NEXT 8
|
||||
#define JLEXTOK_END 9
|
||||
#define JLEXTOK_BLOCKB 0x01
|
||||
#define JLEXTOK_BLOCKE 0x02
|
||||
#define JLEXTOK_SPACE 0x04
|
||||
#define JLEXTOK_SEPAR 0x03
|
||||
#define JLEXTOK_UNDEF 0x04
|
||||
#define JLEXTOK_WORD 0x05
|
||||
#define JLEXTOK_NUMB 0x06
|
||||
#define JLEXTOK_UNKNOW 0x07
|
||||
#define JLEXTOK_NEXT 0x08
|
||||
#define JLEXTOK_ARRB 0x10
|
||||
#define JLEXTOK_ARRE 0x11
|
||||
#define JLEXTOK_END 0x99
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ int main(void) {
|
||||
int type = 0;
|
||||
|
||||
while ((type = jlexer_gettoken(&lexer, token)) != JLEXTOK_END) {
|
||||
printf("%d: %s\n", type, token);
|
||||
printf("%02x: %s\n", type, token);
|
||||
}
|
||||
printf("%d: %s\n", type, token);
|
||||
printf("%02x: %s\n", type, token);
|
||||
|
||||
rcache_destroy(&cache);
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ void jparser_init(jparser_t * parser, jlexer_t * lexer) {
|
||||
|
||||
#define MAX_TOKEN_SIZE 1024
|
||||
|
||||
|
||||
int jparser_parse(jparser_t * parser) {
|
||||
jlexer_t* lex = parser->lexer;
|
||||
char token[MAX_TOKEN_SIZE];
|
||||
@@ -40,7 +41,7 @@ int jparser_parse(jparser_t * parser) {
|
||||
char* key = "";
|
||||
|
||||
while ((type = jlexer_gettoken(lex, token)) != JLEXTOK_END) {
|
||||
//printf("pos %d %d: %s\n", pos, type, token);
|
||||
printf("pos %d tok 0x%02x: %s\n", pos, type, token);
|
||||
switch (pos) {
|
||||
// POS 0
|
||||
case 0:{
|
||||
|
||||
@@ -23,9 +23,10 @@ typedef struct {
|
||||
jlexer_t* lexer;
|
||||
} jparser_t;
|
||||
|
||||
#define JVALTYPE_STR 1
|
||||
#define JVALTYPE_NUM 2
|
||||
#define JVALTYPE_BOOL 3
|
||||
#define JVALTYPE_STR 0x01
|
||||
#define JVALTYPE_NUM 0x02
|
||||
#define JVALTYPE_BOOL 0x03
|
||||
#define JVALTYPE_BLK 0x04
|
||||
|
||||
|
||||
void jparser_init(jparser_t* parser, jlexer_t* lexer);
|
||||
|
||||
@@ -40,14 +40,14 @@ int main(void) {
|
||||
int64_t id = 0;
|
||||
|
||||
if (jparser_bind(&parser, JVALTYPE_NUM, "id", (void *)&id) < 0) {
|
||||
log_error("cannot bind variable\n");
|
||||
log_error("cannot bind id variable\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* name = "";
|
||||
|
||||
if (jparser_bind(&parser, JVALTYPE_STR, "name", (void *)&name) < 0) {
|
||||
log_error("cannot bind variable\n");
|
||||
log_error("cannot bind name variable\n");
|
||||
}
|
||||
|
||||
printf("id = %ld\n", id);
|
||||
|
||||
6
config.h
6
config.h
@@ -2,8 +2,8 @@
|
||||
#ifndef CONFIG_H_QWER
|
||||
#define CONFIG_H_QWER
|
||||
|
||||
static const char *srv_runpath = "/home/ziggi/projects/cworker/run/cworker.pid";
|
||||
static const char *srv_logpath = "/home/ziggi/projects/cworker/log/cworker.log";
|
||||
static const char *srv_configpath = "/home/ziggi/projects/cworker//cworker.conf";
|
||||
static const char *srv_runpath = "/home/ziggi/Projects/cworker/run/cworker.pid";
|
||||
static const char *srv_logpath = "/home/ziggi/Projects/cworker/log/cworker.log";
|
||||
static const char *srv_configpath = "/home/ziggi/Projects/cworker//cworker.conf";
|
||||
|
||||
#endif
|
||||
|
||||
@@ -430,7 +430,7 @@ Copyright (C) 2021 Free Software Foundation, Inc.
|
||||
This config.status script is free software; the Free Software Foundation
|
||||
gives unlimited permission to copy, distribute and modify it."
|
||||
|
||||
ac_pwd='/home/ziggi/projects/cworker'
|
||||
ac_pwd='/home/ziggi/Projects/cworker'
|
||||
srcdir='.'
|
||||
INSTALL='/usr/bin/install -c'
|
||||
MKDIR_P='/usr/local/bin/gmkdir -p'
|
||||
@@ -811,20 +811,20 @@ S["am__EXEEXT_FALSE"]=""
|
||||
S["am__EXEEXT_TRUE"]="#"
|
||||
S["LTLIBOBJS"]=""
|
||||
S["app_name"]="cworker"
|
||||
S["app_cachedir"]="/home/ziggi/projects/cworker/cache"
|
||||
S["APP_CACHEDIR"]="/home/ziggi/projects/cworker/cache"
|
||||
S["app_databasedir"]="/home/ziggi/projects/cworker/data"
|
||||
S["APP_DATABASEDIR"]="/home/ziggi/projects/cworker/data"
|
||||
S["app_cachedir"]="/home/ziggi/Projects/cworker/cache"
|
||||
S["APP_CACHEDIR"]="/home/ziggi/Projects/cworker/cache"
|
||||
S["app_databasedir"]="/home/ziggi/Projects/cworker/data"
|
||||
S["APP_DATABASEDIR"]="/home/ziggi/Projects/cworker/data"
|
||||
S["app_user"]="ziggi"
|
||||
S["APP_USER"]="ziggi"
|
||||
S["app_libdir"]="/home/ziggi/projects/cworker/lib"
|
||||
S["APP_LIBDIR"]="/home/ziggi/projects/cworker/lib"
|
||||
S["app_rundir"]="/home/ziggi/projects/cworker/run"
|
||||
S["APP_RUNDIR"]="/home/ziggi/projects/cworker/run"
|
||||
S["app_logdir"]="/home/ziggi/projects/cworker/log"
|
||||
S["APP_LOGDIR"]="/home/ziggi/projects/cworker/log"
|
||||
S["app_configdir"]="/home/ziggi/projects/cworker/"
|
||||
S["APP_CONFIGDIR"]="/home/ziggi/projects/cworker/"
|
||||
S["app_libdir"]="/home/ziggi/Projects/cworker/lib"
|
||||
S["APP_LIBDIR"]="/home/ziggi/Projects/cworker/lib"
|
||||
S["app_rundir"]="/home/ziggi/Projects/cworker/run"
|
||||
S["APP_RUNDIR"]="/home/ziggi/Projects/cworker/run"
|
||||
S["app_logdir"]="/home/ziggi/Projects/cworker/log"
|
||||
S["APP_LOGDIR"]="/home/ziggi/Projects/cworker/log"
|
||||
S["app_configdir"]="/home/ziggi/Projects/cworker/"
|
||||
S["APP_CONFIGDIR"]="/home/ziggi/Projects/cworker/"
|
||||
S["SYSTEMD_FALSE"]=""
|
||||
S["SYSTEMD_TRUE"]="#"
|
||||
S["LINUX_OS_FALSE"]=""
|
||||
@@ -898,12 +898,12 @@ S["mkdir_p"]="$(MKDIR_P)"
|
||||
S["MKDIR_P"]="/usr/local/bin/gmkdir -p"
|
||||
S["INSTALL_STRIP_PROGRAM"]="$(install_sh) -c -s"
|
||||
S["STRIP"]="strip"
|
||||
S["install_sh"]="${SHELL} /home/ziggi/projects/cworker/install-sh"
|
||||
S["MAKEINFO"]="${SHELL} /home/ziggi/projects/cworker/missing makeinfo"
|
||||
S["AUTOHEADER"]="${SHELL} /home/ziggi/projects/cworker/missing autoheader"
|
||||
S["AUTOMAKE"]="${SHELL} /home/ziggi/projects/cworker/missing automake"
|
||||
S["AUTOCONF"]="${SHELL} /home/ziggi/projects/cworker/missing autoconf"
|
||||
S["ACLOCAL"]="${SHELL} /home/ziggi/projects/cworker/missing aclocal"
|
||||
S["install_sh"]="${SHELL} /home/ziggi/Projects/cworker/install-sh"
|
||||
S["MAKEINFO"]="${SHELL} /home/ziggi/Projects/cworker/missing makeinfo"
|
||||
S["AUTOHEADER"]="${SHELL} /home/ziggi/Projects/cworker/missing autoheader"
|
||||
S["AUTOMAKE"]="${SHELL} /home/ziggi/Projects/cworker/missing automake"
|
||||
S["AUTOCONF"]="${SHELL} /home/ziggi/Projects/cworker/missing autoconf"
|
||||
S["ACLOCAL"]="${SHELL} /home/ziggi/Projects/cworker/missing aclocal"
|
||||
S["VERSION"]="0.0.1"
|
||||
S["PACKAGE"]="cworker"
|
||||
S["CYGPATH_W"]="echo"
|
||||
@@ -1037,13 +1037,13 @@ D["HAVE_MEMSET"]=" 1"
|
||||
D["HAVE_MKDIR"]=" 1"
|
||||
D["HAVE_SETLOCALE"]=" 1"
|
||||
D["HAVE_SOCKET"]=" 1"
|
||||
D["APP_CONFIGDIR"]=" \"/home/ziggi/projects/cworker/\""
|
||||
D["APP_LOGDIR"]=" \"/home/ziggi/projects/cworker/log\""
|
||||
D["APP_RUNDIR"]=" \"/home/ziggi/projects/cworker/run\""
|
||||
D["APP_LIBDIR"]=" \"/home/ziggi/projects/cworker/lib\""
|
||||
D["APP_CONFIGDIR"]=" \"/home/ziggi/Projects/cworker/\""
|
||||
D["APP_LOGDIR"]=" \"/home/ziggi/Projects/cworker/log\""
|
||||
D["APP_RUNDIR"]=" \"/home/ziggi/Projects/cworker/run\""
|
||||
D["APP_LIBDIR"]=" \"/home/ziggi/Projects/cworker/lib\""
|
||||
D["APP_USER"]=" \"ziggi\""
|
||||
D["APP_DATABASEDIR"]=" \"/home/ziggi/projects/cworker/data\""
|
||||
D["APP_CACHEDIR"]=" \"/home/ziggi/projects/cworker/cache\""
|
||||
D["APP_DATABASEDIR"]=" \"/home/ziggi/Projects/cworker/data\""
|
||||
D["APP_CACHEDIR"]=" \"/home/ziggi/Projects/cworker/cache\""
|
||||
for (key in D) D_is_set[key] = 1
|
||||
FS = ""
|
||||
}
|
||||
|
||||
12
defines.h
12
defines.h
@@ -2,22 +2,22 @@
|
||||
/* defines.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* location of cache dir */
|
||||
#define APP_CACHEDIR "/home/ziggi/projects/cworker/cache"
|
||||
#define APP_CACHEDIR "/home/ziggi/Projects/cworker/cache"
|
||||
|
||||
/* location of configuration files for ${PACKAGE} */
|
||||
#define APP_CONFIGDIR "/home/ziggi/projects/cworker/"
|
||||
#define APP_CONFIGDIR "/home/ziggi/Projects/cworker/"
|
||||
|
||||
/* location of database dir */
|
||||
#define APP_DATABASEDIR "/home/ziggi/projects/cworker/data"
|
||||
#define APP_DATABASEDIR "/home/ziggi/Projects/cworker/data"
|
||||
|
||||
/* location of libs */
|
||||
#define APP_LIBDIR "/home/ziggi/projects/cworker/lib"
|
||||
#define APP_LIBDIR "/home/ziggi/Projects/cworker/lib"
|
||||
|
||||
/* location of ${PACKAGE} logdir */
|
||||
#define APP_LOGDIR "/home/ziggi/projects/cworker/log"
|
||||
#define APP_LOGDIR "/home/ziggi/Projects/cworker/log"
|
||||
|
||||
/* location of pid file */
|
||||
#define APP_RUNDIR "/home/ziggi/projects/cworker/run"
|
||||
#define APP_RUNDIR "/home/ziggi/Projects/cworker/run"
|
||||
|
||||
/* effective user */
|
||||
#define APP_USER "ziggi"
|
||||
|
||||
Reference in New Issue
Block a user