Commit cdd13b1a authored by funshine's avatar funshine
Browse files

source file first commit, folder structure refact

parent 13c69796
/*
* Copyright (c) 2011-2012, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*/
#ifdef JSON_FORMAT
#include "json/jsonparse.h"
#include "osapi.h"
//#include <stdlib.h>
//#include <string.h>
/*--------------------------------------------------------------------*/
static int ICACHE_FLASH_ATTR
push(struct jsonparse_state *state, char c)
{
state->stack[state->depth] = c;
state->depth++;
state->vtype = 0;
return state->depth < JSONPARSE_MAX_DEPTH;
}
/*--------------------------------------------------------------------*/
static char ICACHE_FLASH_ATTR
pop(struct jsonparse_state *state)
{
if(state->depth == 0) {
return JSON_TYPE_ERROR;
}
state->depth--;
return state->stack[state->depth];
}
/*--------------------------------------------------------------------*/
/* will pass by the value and store the start and length of the value for
atomic types */
/*--------------------------------------------------------------------*/
static void ICACHE_FLASH_ATTR
atomic(struct jsonparse_state *state, char type)
{
char c;
state->vstart = state->pos;
state->vtype = type;
if(type == JSON_TYPE_STRING || type == JSON_TYPE_PAIR_NAME) {
while((c = state->json[state->pos++]) && c != '"') {
if(c == '\\') {
state->pos++; /* skip current char */
}
}
state->vlen = state->pos - state->vstart - 1;
} else if(type == JSON_TYPE_NUMBER) {
do {
c = state->json[state->pos];
if((c < '0' || c > '9') && c != '.') {
c = 0;
} else {
state->pos++;
}
} while(c);
/* need to back one step since first char is already gone */
state->vstart--;
state->vlen = state->pos - state->vstart;
}
/* no other types for now... */
}
/*--------------------------------------------------------------------*/
static void ICACHE_FLASH_ATTR
skip_ws(struct jsonparse_state *state)
{
char c;
while(state->pos < state->len &&
((c = state->json[state->pos]) == ' ' || c == '\n')) {
state->pos++;
}
}
/*--------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsonparse_setup(struct jsonparse_state *state, const char *json, int len)
{
state->json = json;
state->len = len;
state->pos = 0;
state->depth = 0;
state->error = 0;
state->stack[0] = 0;
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_next(struct jsonparse_state *state)
{
char c;
char s;
skip_ws(state);
c = state->json[state->pos];
s = jsonparse_get_type(state);
state->pos++;
switch(c) {
case '{':
push(state, c);
return c;
case '}':
if(s == ':' && state->vtype != 0) {
/* printf("Popping vtype: '%c'\n", state->vtype); */
pop(state);
s = jsonparse_get_type(state);
}
if(s == '{') {
pop(state);
} else {
state->error = JSON_ERROR_SYNTAX;
return JSON_TYPE_ERROR;
}
return c;
case ']':
if(s == '[') {
pop(state);
} else {
state->error = JSON_ERROR_UNEXPECTED_END_OF_ARRAY;
return JSON_TYPE_ERROR;
}
return c;
case ':':
push(state, c);
return c;
case ',':
/* if x:y ... , */
if(s == ':' && state->vtype != 0) {
pop(state);
} else if(s == '[') {
/* ok! */
} else {
state->error = JSON_ERROR_SYNTAX;
return JSON_TYPE_ERROR;
}
return c;
case '"':
if(s == '{' || s == '[' || s == ':') {
atomic(state, c = (s == '{' ? JSON_TYPE_PAIR_NAME : c));
} else {
state->error = JSON_ERROR_UNEXPECTED_STRING;
return JSON_TYPE_ERROR;
}
return c;
case '[':
if(s == '{' || s == '[' || s == ':') {
push(state, c);
} else {
state->error = JSON_ERROR_UNEXPECTED_ARRAY;
return JSON_TYPE_ERROR;
}
return c;
default:
if(s == ':' || s == '[') {
if(c <= '9' && c >= '0') {
atomic(state, JSON_TYPE_NUMBER);
return JSON_TYPE_NUMBER;
}
}
}
return 0;
}
/*--------------------------------------------------------------------*/
/* get the json value of the current position
* works only on "atomic" values such as string, number, null, false, true
*/
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_copy_value(struct jsonparse_state *state, char *str, int size)
{
int i;
char z = 0;
char y = 0;
if(state->vtype == 0) {
return 0;
}
size = size <= state->vlen ? (size - 1) : state->vlen;
for(i = 0; i < size; i++) {
if (y == 0 && state->json[state->vstart + i] == '\\') {
y = 1;
z++;
continue;
}
y = 0;
str[i - z] = state->json[state->vstart + i];
}
str[i - z] = 0;
return state->vtype;
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_get_value_as_int(struct jsonparse_state *state)
{
if(state->vtype != JSON_TYPE_NUMBER) {
return 0;
}
return atoi(&state->json[state->vstart]);
}
/*--------------------------------------------------------------------*/
long ICACHE_FLASH_ATTR
jsonparse_get_value_as_long(struct jsonparse_state *state)
{
if(state->vtype != JSON_TYPE_NUMBER) {
return 0;
}
return atol(&state->json[state->vstart]);
}
/*--------------------------------------------------------------------*/
unsigned long ICACHE_FLASH_ATTR
jsonparse_get_value_as_ulong(struct jsonparse_state *state)
{
if(state->vtype != JSON_TYPE_NUMBER) {
return 0;
}
return strtoul(&state->json[state->vstart], '\0', 0);
}
/*--------------------------------------------------------------------*/
/* strcmp - assume no strange chars that needs to be stuffed in string... */
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_strcmp_value(struct jsonparse_state *state, const char *str)
{
if(state->vtype == 0) {
return -1;
}
return os_strncmp(str, &state->json[state->vstart], state->vlen);
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_get_len(struct jsonparse_state *state)
{
return state->vlen;
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_get_type(struct jsonparse_state *state)
{
if(state->depth == 0) {
return 0;
}
return state->stack[state->depth - 1];
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_has_next(struct jsonparse_state *state)
{
return state->pos < state->len;
}
/*--------------------------------------------------------------------*/
#endif
/*
* Copyright (c) 2011-2012, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*/
/**
* \file
* JSON output generation
* \author
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
#ifdef JSON_FORMAT
//#include "contiki.h"
#include "json/jsontree.h"
#include "json/jsonparse.h"
#include "osapi.h"
//#include <string.h>
#define DEBUG 0
#if DEBUG
//#include <stdio.h>
#define PRINTF(...) os_printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_write_atom(const struct jsontree_context *js_ctx, const char *text)
{
if(text == NULL) {
js_ctx->putchar('0');
} else {
while(*text != '\0') {
js_ctx->putchar(*text++);
}
}
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_write_string(const struct jsontree_context *js_ctx, const char *text)
{
js_ctx->putchar('"');
if(text != NULL) {
while(*text != '\0') {
if(*text == '"') {
js_ctx->putchar('\\');
}
js_ctx->putchar(*text++);
}
}
js_ctx->putchar('"');
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_write_int(const struct jsontree_context *js_ctx, int value)
{
char buf[10];
int l;
if(value < 0) {
js_ctx->putchar('-');
value = -value;
}
l = sizeof(buf) - 1;
do {
buf[l--] = '0' + (value % 10);
value /= 10;
} while(value > 0 && l >= 0);
while(++l < sizeof(buf)) {
js_ctx->putchar(buf[l]);
}
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_write_int_array(const struct jsontree_context *js_ctx, const int *text, uint32 length)
{
uint32 i = 0;
if(text == NULL) {
js_ctx->putchar('0');
} else {
for (i = 0; i < length - 1; i ++) {
jsontree_write_int(js_ctx, *text++);
js_ctx->putchar(',');
}
jsontree_write_int(js_ctx, *text);
}
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_setup(struct jsontree_context *js_ctx, struct jsontree_value *root,
int (* putchar)(int))
{
js_ctx->values[0] = root;
js_ctx->putchar = putchar;
js_ctx->path = 0;
jsontree_reset(js_ctx);
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_reset(struct jsontree_context *js_ctx)
{
js_ctx->depth = 0;
js_ctx->index[0] = 0;
}
/*---------------------------------------------------------------------------*/
const char *ICACHE_FLASH_ATTR
jsontree_path_name(const struct jsontree_context *js_ctx, int depth)
{
if(depth < js_ctx->depth && js_ctx->values[depth]->type == JSON_TYPE_OBJECT) {
return ((struct jsontree_object *)js_ctx->values[depth])->
pairs[js_ctx->index[depth]].name;
}
return "";
}
/*---------------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsontree_print_next(struct jsontree_context *js_ctx)
{
struct jsontree_value *v;
int index;
v = js_ctx->values[js_ctx->depth];
/* Default operation after switch is to back up one level */
switch(v->type) {
case JSON_TYPE_OBJECT:
case JSON_TYPE_ARRAY: {
struct jsontree_array *o = (struct jsontree_array *)v;
struct jsontree_value *ov;
index = js_ctx->index[js_ctx->depth];
if(index == 0) {
js_ctx->putchar(v->type);
js_ctx->putchar('\n');
}
if(index >= o->count) {
js_ctx->putchar('\n');
js_ctx->putchar(v->type + 2);
/* Default operation: back up one level! */
break;
}
if(index > 0) {
js_ctx->putchar(',');
js_ctx->putchar('\n');
}
if(v->type == JSON_TYPE_OBJECT) {
jsontree_write_string(js_ctx,
((struct jsontree_object *)o)->pairs[index].name);
js_ctx->putchar(':');
ov = ((struct jsontree_object *)o)->pairs[index].value;
} else {
ov = o->values[index];
}
/* TODO check max depth */
js_ctx->depth++; /* step down to value... */
js_ctx->index[js_ctx->depth] = 0; /* and init index */
js_ctx->values[js_ctx->depth] = ov;
/* Continue on this new level */
return 1;
}
case JSON_TYPE_STRING:
jsontree_write_string(js_ctx, ((struct jsontree_string *)v)->value);
/* Default operation: back up one level! */
break;
case JSON_TYPE_INT:
jsontree_write_int(js_ctx, ((struct jsontree_int *)v)->value);
/* Default operation: back up one level! */
break;
case JSON_TYPE_CALLBACK: { /* pre-formatted json string currently */
struct jsontree_callback *callback;
callback = (struct jsontree_callback *)v;
if(js_ctx->index[js_ctx->depth] == 0) {
/* First call: reset the callback status */
js_ctx->callback_state = 0;
}
if(callback->output == NULL) {
jsontree_write_string(js_ctx, "");
} else if(callback->output(js_ctx)) {
/* The callback wants to output more */
js_ctx->index[js_ctx->depth]++;
return 1;
}
/* Default operation: back up one level! */
break;
}
default:
PRINTF("\nError: Illegal json type:'%c'\n", v->type);
return 0;
}
/* Done => back up one level! */
if(js_ctx->depth > 0) {
js_ctx->depth--;
js_ctx->index[js_ctx->depth]++;
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static struct jsontree_value *ICACHE_FLASH_ATTR
find_next(struct jsontree_context *js_ctx)
{
struct jsontree_value *v;
int index;
do {
v = js_ctx->values[js_ctx->depth];
/* Default operation after switch is to back up one level */
switch(v->type) {
case JSON_TYPE_OBJECT:
case JSON_TYPE_ARRAY: {
struct jsontree_array *o = (struct jsontree_array *)v;
struct jsontree_value *ov;
index = js_ctx->index[js_ctx->depth];
if(index >= o->count) {
/* Default operation: back up one level! */
break;
}
if(v->type == JSON_TYPE_OBJECT) {
ov = ((struct jsontree_object *)o)->pairs[index].value;
} else {
ov = o->values[index];
}
/* TODO check max depth */
js_ctx->depth++; /* step down to value... */
js_ctx->index[js_ctx->depth] = 0; /* and init index */
js_ctx->values[js_ctx->depth] = ov;
/* Continue on this new level */
return ov;
}
default:
/* Default operation: back up one level! */
break;
}
/* Done => back up one level! */
if(js_ctx->depth > 0) {
js_ctx->depth--;
js_ctx->index[js_ctx->depth]++;
} else {
return NULL;
}
} while(1);
}
/*---------------------------------------------------------------------------*/
struct jsontree_value *ICACHE_FLASH_ATTR
jsontree_find_next(struct jsontree_context *js_ctx, int type)
{
struct jsontree_value *v;
while((v = find_next(js_ctx)) != NULL && v->type != type &&
js_ctx->path < js_ctx->depth) {
/* search */
}
js_ctx->callback_state = 0;
return js_ctx->path < js_ctx->depth ? v : NULL;
}
/*---------------------------------------------------------------------------*/
#endif
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = liblibc.a
endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../wofs
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
#include "c_ctype.h"
#include "c_types.h"
// int ICACHE_FLASH_ATTR isalnum(int c){}
// int ICACHE_FLASH_ATTR isalpha(int c){}
// int ICACHE_FLASH_ATTR iscntrl(int c){}
// int ICACHE_FLASH_ATTR isdigit(int c){}
// // int ICACHE_FLASH_ATTR isgraph(int c){}
// int ICACHE_FLASH_ATTR islower(int c){}
// int ICACHE_FLASH_ATTR isprint(int c){}
// int ICACHE_FLASH_ATTR ispunct(int c){}
// int ICACHE_FLASH_ATTR isspace(int c){}
// int ICACHE_FLASH_ATTR isupper(int c){}
// int ICACHE_FLASH_ATTR isxdigit(int c){}
// int ICACHE_FLASH_ATTR tolower(int c){}
// int ICACHE_FLASH_ATTR toupper(int c){}
#ifndef _C_CTYPE_H_
#define _C_CTYPE_H_
#if 0
int isalnum(int);
int isalpha(int);
int iscntrl(int);
int isdigit(int);
// int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);
int tolower(int);
int toupper(int);
#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
// int isblank(int);
#endif
#ifndef __STRICT_ANSI__
// int isascii(int);
// int toascii(int);
#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
#define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
#endif
#define _U 01
#define _L 02
#define _N 04
#define _S 010
#define _P 020
#define _C 040
#define _X 0100
#define _B 0200
/* For C++ backward-compatibility only. */
// extern char _ctype_[];
#endif
#endif /* _C_CTYPE_H_ */
#ifndef __c_errno_h
#define __c_errno_h
#include <errno.h>
// #ifndef errno
// extern int errno;
// #endif
// #define EDOM 1
// #define ERANGE 2
// #define EILSEQ 4
// #define ESIGNUM 3
// #define EINVAL 5
// #define ENOMEM 6
#endif
/* end of c_errno.h */
#ifndef __c_fcntl_h
#define __c_fcntl_h
#include <fcntl.h>
#endif
/* end of c_fcntl.h */
#ifndef __c_limits_h
#define __c_limits_h
#include <limits.h>
#if 0
#define CHAR_BIT 8
/* max number of bits for smallest object that is not a bit-field (byte) */
#define SCHAR_MIN (-128)
/* mimimum value for an object of type signed char */
#define SCHAR_MAX 127
/* maximum value for an object of type signed char */
#define UCHAR_MAX 255
/* maximum value for an object of type unsigned char */
#ifdef __FEATURE_SIGNED_CHAR
#define CHAR_MIN (-128)
/* minimum value for an object of type char */
#define CHAR_MAX 127
/* maximum value for an object of type char */
#else
#define CHAR_MIN 0
/* minimum value for an object of type char */
#define CHAR_MAX 255
/* maximum value for an object of type char */
#endif
#define SHRT_MIN (-0x8000)
/* minimum value for an object of type short int */
#define SHRT_MAX 0x7fff
/* maximum value for an object of type short int */
#define USHRT_MAX 65535
/* maximum value for an object of type unsigned short int */
#define INT_MIN (~0x7fffffff) /* -2147483648 and 0x80000000 are unsigned */
/* minimum value for an object of type int */
#define INT_MAX 0x7fffffff
/* maximum value for an object of type int */
#define UINT_MAX 0xffffffffU
/* maximum value for an object of type unsigned int */
#define LONG_MIN (~0x7fffffffL)
/* minimum value for an object of type long int */
#define LONG_MAX 0x7fffffffL
/* maximum value for an object of type long int */
#define ULONG_MAX 0xffffffffUL
/* maximum value for an object of type unsigned long int */
#if !defined(__STRICT_ANSI__) || (defined(__STDC_VERSION__) && 199901L <= __STDC_VERSION__)
#define LLONG_MIN (~0x7fffffffffffffffLL)
/* minimum value for an object of type long long int */
#define LLONG_MAX 0x7fffffffffffffffLL
/* maximum value for an object of type long long int */
#define ULLONG_MAX 0xffffffffffffffffULL
/* maximum value for an object of type unsigned long int */
#endif
#endif
#endif
/* end of c_limits.h */
/*
c_locale.h
Values appropriate for the formatting of monetary and other
numberic quantities.
*/
#ifndef _C_LOCALE_H_
#define _C_LOCALE_H_
#include <locale.h>
#if 0
#ifndef NULL
#define NULL 0
#endif
#define LC_ALL 0
#define LC_COLLATE 1
#define LC_CTYPE 2
#define LC_MONETARY 3
#define LC_NUMERIC 4
#define LC_TIME 5
#define LC_MESSAGES 6
struct lconv
{
char *decimal_point;
char *thousands_sep;
char *grouping;
char *int_curr_symbol;
char *currency_symbol;
char *mon_decimal_point;
char *mon_thousands_sep;
char *mon_grouping;
char *positive_sign;
char *negative_sign;
char int_frac_digits;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char p_sign_posn;
char n_sign_posn;
char int_n_cs_precedes;
char int_n_sep_by_space;
char int_n_sign_posn;
char int_p_cs_precedes;
char int_p_sep_by_space;
char int_p_sign_posn;
};
#ifndef _REENT_ONLY
// char *setlocale(int category, const char *locale);
struct lconv *localeconv(void);
#endif
// struct _reent;
// char *_setlocale_r(struct _reent *, int category, const char *locale);
// struct lconv *_localeconv_r(struct _reent *);
#endif
#endif /* _C_LOCALE_H_ */
#include "c_math.h"
#include "c_types.h"
#if 0
#ifndef __math_68881
double ICACHE_FLASH_ATTR atan(double x){
return x;
}
double ICACHE_FLASH_ATTR cos(double x){
return x;
}
double ICACHE_FLASH_ATTR sin(double x){
return x;
}
double ICACHE_FLASH_ATTR tan(double x){
return x;
}
double ICACHE_FLASH_ATTR tanh(double x){
return x;
}
double ICACHE_FLASH_ATTR frexp(double x, int *y){
return x;
}
double ICACHE_FLASH_ATTR modf(double x, double *y){
return x;
}
double ICACHE_FLASH_ATTR ceil(double x){
return x;
}
double ICACHE_FLASH_ATTR fabs(double x){
return x;
}
double ICACHE_FLASH_ATTR floor(double x){
return x;
}
#endif /* ! defined (__math_68881) */
/* Non reentrant ANSI C functions. */
#ifndef _REENT_ONLY
#ifndef __math_68881
double ICACHE_FLASH_ATTR acos(double x){
return x;
}
double ICACHE_FLASH_ATTR asin(double x){
return x;
}
double ICACHE_FLASH_ATTR atan2(double x, double y){
return x;
}
double ICACHE_FLASH_ATTR cosh(double x){
return x;
}
double ICACHE_FLASH_ATTR sinh(double x){
return x;
}
double ICACHE_FLASH_ATTR exp(double x){
return x;
}
double ICACHE_FLASH_ATTR ldexp(double x, int y){
return x;
}
double ICACHE_FLASH_ATTR log(double x){
return x;
}
double ICACHE_FLASH_ATTR log10(double x){
return x;
}
double ICACHE_FLASH_ATTR pow(double x, double y){
return x;
}
double ICACHE_FLASH_ATTR sqrt(double x){
return x;
}
double ICACHE_FLASH_ATTR fmod(double x, double y){
return x;
}
#endif /* ! defined (__math_68881) */
#endif /* ! defined (_REENT_ONLY) */
#endif
#ifndef _C_MATH_H_
#define _C_MATH_H_
#include <math.h>
#if 0
#ifndef HUGE_VAL
#define HUGE_VAL (1.0e99)
#endif
#ifndef HUGE_VALF
#define HUGE_VALF (1.0e999999999F)
#endif
#if !defined(HUGE_VALL) && defined(_HAVE_LONG_DOUBLE)
#define HUGE_VALL (1.0e999999999L)
#endif
#if !defined(INFINITY)
#define INFINITY (HUGE_VALF)
#endif
/* Reentrant ANSI C functions. */
#ifndef __math_68881
// double atan(double);
// double cos(double);
// double sin(double);
// double tan(double);
// double tanh(double);
// double frexp(double, int *);
// double modf(double, double *);
// double ceil(double);
// double fabs(double);
// double floor(double);
#endif /* ! defined (__math_68881) */
/* Non reentrant ANSI C functions. */
#ifndef _REENT_ONLY
#ifndef __math_68881
// double acos(double);
// double asin(double);
// double atan2(double, double);
// double cosh(double);
// double sinh(double);
// double exp(double);
// double ldexp(double, int);
// double log(double);
// double log10(double);
// double pow(double, double);
// double sqrt(double);
// double fmod(double, double);
#endif /* ! defined (__math_68881) */
#endif /* ! defined (_REENT_ONLY) */
#endif
#endif /* _MATH_H_ */
#ifndef _C_SIGNAL_H_
#define _C_SIGNAL_H_
#include <signal.h>
#endif /* _C_SIGNAL_H_ */
#ifndef __c_stdarg_h
#define __c_stdarg_h
typedef char * va_list;
#define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))
#define va_start(ap,v) (ap = (va_list)&v + _INTSIZEOF(v))
#define va_arg(ap,t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
#define va_end(ap) (ap = (va_list)0)
#endif
/* end of c_stdarg.h */
#ifndef __c_stddef_h
#define __c_stddef_h
typedef signed int ptrdiff_t;
#if !defined(offsetof)
#define offsetof(s, m) (size_t)&(((s *)0)->m)
#endif
#if !defined(__size_t)
#define __size_t 1
typedef unsigned int size_t; /* others (e.g. <stdio.h>) also define */
/* the unsigned integral type of the result of the sizeof operator. */
#endif
#undef NULL /* others (e.g. <stdio.h>) also define */
#define NULL 0
/* null pointer constant. */
#endif
/* end of c_stddef.h */
#ifndef __c_stdint_h
#define __c_stdint_h
#include "c_types.h"
#if 0
/*
* Depending on compiler version __int64 or __INT64_TYPE__ should be defined.
*/
#ifndef __int64
#ifdef __INT64_TYPE__
#define __int64 __INT64_TYPE__
#else
#define __int64 long long
#endif
/* On some architectures neither of these may be defined - if so, fall
through and error out if used. */
#endif
#ifndef __STDINT_DECLS
#define __STDINT_DECLS
#undef __CLIBNS
#ifdef __cplusplus
namespace std {
#define __CLIBNS std::
extern "C" {
#else
#define __CLIBNS
#endif /* __cplusplus */
/*
* 'signed' is redundant below, except for 'signed char' and if
* the typedef is used to declare a bitfield.
* '__int64' is used instead of 'long long' so that this header
* can be used in --strict mode.
*/
/* 7.18.1.1 */
/* exact-width signed integer types */
typedef signed char int8_t;
typedef signed short int int16_t;
typedef signed int int32_t;
typedef signed __int64 int64_t;
/* exact-width unsigned integer types */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
/* 7.18.1.2 */
/* smallest type of at least n bits */
/* minimum-width signed integer types */
typedef signed char int_least8_t;
typedef signed short int int_least16_t;
typedef signed int int_least32_t;
typedef signed __int64 int_least64_t;
/* minimum-width unsigned integer types */
typedef unsigned char uint_least8_t;
typedef unsigned short int uint_least16_t;
typedef unsigned int uint_least32_t;
typedef unsigned __int64 uint_least64_t;
/* 7.18.1.3 */
/* fastest minimum-width signed integer types */
typedef signed int int_fast8_t;
typedef signed int int_fast16_t;
typedef signed int int_fast32_t;
typedef signed __int64 int_fast64_t;
/* fastest minimum-width unsigned integer types */
typedef unsigned int uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
typedef unsigned __int64 uint_fast64_t;
/* 7.18.1.4 integer types capable of holding object pointers */
typedef signed int intptr_t;
typedef unsigned int uintptr_t;
/* 7.18.1.5 greatest-width integer types */
typedef signed __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
/* 7.18.2.1 */
/* minimum values of exact-width signed integer types */
#define INT8_MIN -128
#define INT16_MIN -32768
#define INT32_MIN (~0x7fffffff) /* -2147483648 is unsigned */
#define INT64_MIN __ESCAPE__(~0x7fffffffffffffffll) /* -9223372036854775808 is unsigned */
/* maximum values of exact-width signed integer types */
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX __ESCAPE__(9223372036854775807ll)
/* maximum values of exact-width unsigned integer types */
#define UINT8_MAX 255
#define UINT16_MAX 65535
#define UINT32_MAX 4294967295u
#define UINT64_MAX __ESCAPE__(18446744073709551615ull)
/* 7.18.2.2 */
/* minimum values of minimum-width signed integer types */
#define INT_LEAST8_MIN -128
#define INT_LEAST16_MIN -32768
#define INT_LEAST32_MIN (~0x7fffffff)
#define INT_LEAST64_MIN __ESCAPE__(~0x7fffffffffffffffll)
/* maximum values of minimum-width signed integer types */
#define INT_LEAST8_MAX 127
#define INT_LEAST16_MAX 32767
#define INT_LEAST32_MAX 2147483647
#define INT_LEAST64_MAX __ESCAPE__(9223372036854775807ll)
/* maximum values of minimum-width unsigned integer types */
#define UINT_LEAST8_MAX 255
#define UINT_LEAST16_MAX 65535
#define UINT_LEAST32_MAX 4294967295u
#define UINT_LEAST64_MAX __ESCAPE__(18446744073709551615ull)
/* 7.18.2.3 */
/* minimum values of fastest minimum-width signed integer types */
#define INT_FAST8_MIN (~0x7fffffff)
#define INT_FAST16_MIN (~0x7fffffff)
#define INT_FAST32_MIN (~0x7fffffff)
#define INT_FAST64_MIN __ESCAPE__(~0x7fffffffffffffffll)
/* maximum values of fastest minimum-width signed integer types */
#define INT_FAST8_MAX 2147483647
#define INT_FAST16_MAX 2147483647
#define INT_FAST32_MAX 2147483647
#define INT_FAST64_MAX __ESCAPE__(9223372036854775807ll)
/* maximum values of fastest minimum-width unsigned integer types */
#define UINT_FAST8_MAX 4294967295u
#define UINT_FAST16_MAX 4294967295u
#define UINT_FAST32_MAX 4294967295u
#define UINT_FAST64_MAX __ESCAPE__(18446744073709551615ull)
/* 7.18.2.4 */
/* minimum value of pointer-holding signed integer type */
#define INTPTR_MIN (~0x7fffffff)
/* maximum value of pointer-holding signed integer type */
#define INTPTR_MAX 2147483647
/* maximum value of pointer-holding unsigned integer type */
#define UINTPTR_MAX 4294967295u
/* 7.18.2.5 */
/* minimum value of greatest-width signed integer type */
#define INTMAX_MIN __ESCAPE__(~0x7fffffffffffffffll)
/* maximum value of greatest-width signed integer type */
#define INTMAX_MAX __ESCAPE__(9223372036854775807ll)
/* maximum value of greatest-width unsigned integer type */
#define UINTMAX_MAX __ESCAPE__(18446744073709551615ull)
/* 7.18.3 */
/* limits of ptrdiff_t */
#define PTRDIFF_MIN (~0x7fffffff)
#define PTRDIFF_MAX 2147483647
/* limits of sig_atomic_t */
#define SIG_ATOMIC_MIN (~0x7fffffff)
#define SIG_ATOMIC_MAX 2147483647
/* limit of size_t */
#define SIZE_MAX 4294967295u
/* limits of wchar_t */
/* NB we have to undef and redef because they're defined in both
* stdint.h and wchar.h */
#undef WCHAR_MIN
#undef WCHAR_MAX
#if defined(__WCHAR32) || (defined(__ARM_SIZEOF_WCHAR_T) && __ARM_SIZEOF_WCHAR_T == 4)
#define WCHAR_MIN 0
#define WCHAR_MAX 0xffffffffU
#else
#define WCHAR_MIN 0
#define WCHAR_MAX 65535
#endif
/* limits of wint_t */
#define WINT_MIN (~0x7fffffff)
#define WINT_MAX 2147483647
#endif /* __STDC_LIMIT_MACROS */
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
/* 7.18.4.1 macros for minimum-width integer constants */
#define INT8_C(x) (x)
#define INT16_C(x) (x)
#define INT32_C(x) (x)
#define INT64_C(x) __ESCAPE__(x ## ll)
#define UINT8_C(x) (x ## u)
#define UINT16_C(x) (x ## u)
#define UINT32_C(x) (x ## u)
#define UINT64_C(x) __ESCAPE__(x ## ull)
/* 7.18.4.2 macros for greatest-width integer constants */
#define INTMAX_C(x) __ESCAPE__(x ## ll)
#define UINTMAX_C(x) __ESCAPE__(x ## ull)
#endif /* __STDC_CONSTANT_MACROS */
#ifdef __cplusplus
} /* extern "C" */
} /* namespace std */
#endif /* __cplusplus */
#endif /* __STDINT_DECLS */
#ifdef __cplusplus
#ifndef __STDINT_NO_EXPORTS
using ::std::int8_t;
using ::std::int16_t;
using ::std::int32_t;
using ::std::int64_t;
using ::std::uint8_t;
using ::std::uint16_t;
using ::std::uint32_t;
using ::std::uint64_t;
using ::std::int_least8_t;
using ::std::int_least16_t;
using ::std::int_least32_t;
using ::std::int_least64_t;
using ::std::uint_least8_t;
using ::std::uint_least16_t;
using ::std::uint_least32_t;
using ::std::uint_least64_t;
using ::std::int_fast8_t;
using ::std::int_fast16_t;
using ::std::int_fast32_t;
using ::std::int_fast64_t;
using ::std::uint_fast8_t;
using ::std::uint_fast16_t;
using ::std::uint_fast32_t;
using ::std::uint_fast64_t;
using ::std::intptr_t;
using ::std::uintptr_t;
using ::std::intmax_t;
using ::std::uintmax_t;
#endif
#endif /* __cplusplus */
#endif
#endif /* __c_stdint_h */
/* end of c_stdint.h */
#include "c_stdio.h"
// #include "driver/uart.h"
unsigned char __print_buf[BUFSIZ];
int c_stdin = 999;
int c_stdout = 1000;
int c_stderr = 1001;
// FILE *c_fopen(const char *_name, const char *_type){
// }
// FILE *c_freopen(const char *_name, const char *_type, FILE *_f){
// }
// FILE *c_tmpfile(void){
// }
// int c_putchar(int c){
// }
// int c_printf(const char *c, ...){
// }
// int c_sprintf(char *c, const char *s, ...){
// }
// int c_fprintf(FILE *f, const char *s, ...){
// }
// int c_fscanf(FILE *f, const char *s, ...){
// }
// int c_fclose(FILE *f){
// }
// int c_fflush(FILE *f){
// }
// int c_setvbuf(FILE *f, char *c, int d, size_t t){
// }
// void c_clearerr(FILE *f){
// }
// int c_fseek(FILE *f, long l, int d){
// }
// long c_ftell( FILE *f){
// }
// int c_fputs(const char *c, FILE *f){
// }
// char *c_fgets(char *c, int d, FILE *f){
// }
// int c_ungetc(int d, FILE *f){
// }
// size_t c_fread(void *p, size_t _size, size_t _n, FILE *f){
// }
// size_t c_fwrite(const void *p, size_t _size, size_t _n, FILE *f){
// }
// int c_feof(FILE *f){
// }
// int c_ferror(FILE *f){
// }
// int c_getc(FILE *f){
// }
#ifndef _C_STDIO_H_
#define _C_STDIO_H_
#define __need_size_t
#include "c_stddef.h"
#include "osapi.h"
// #include "driver/uart.h"
// #define __need___va_list
//#include "c_stdarg.h"
//struct __sFILE{
// int _r; /* read space left for getc() */
// int _w; /* write space left for putc() */
//};
// typedef struct __sFILE __FILE;
// typedef __FILE FILE;
extern int c_stdin;
extern int c_stdout;
extern int c_stderr;
// #define _IOFBF 0 /* setvbuf should set fully buffered */
// #define _IOLBF 1 /* setvbuf should set line buffered */
// #define _IONBF 2 /* setvbuf should set unbuffered */
// #ifndef NULL
// #define NULL 0
// #endif
#define EOF (-1)
#ifdef __BUFSIZ__
#define BUFSIZ __BUFSIZ__
#else
#define BUFSIZ 1024
#endif
#ifndef SEEK_SET
#define SEEK_SET 0 /* set file offset to offset */
#endif
#ifndef SEEK_CUR
#define SEEK_CUR 1 /* set file offset to current plus offset */
#endif
#ifndef SEEK_END
#define SEEK_END 2 /* set file offset to EOF plus offset */
#endif
extern void output_redirect(const char *str);
#define c_puts output_redirect
extern unsigned char __print_buf[BUFSIZ];
// #define c_printf os_printf
// int c_printf(const char *c, ...);
#define c_sprintf os_sprintf
// #define c_vsprintf ets_vsprintf
#define c_printf(...) do { \
c_sprintf(__print_buf, __VA_ARGS__); \
c_puts(__print_buf); \
} while(0)
// #define c_getc ets_getc
// #define c_getchar ets_getc
// note: contact esp to ensure the real getchar function..
// FILE *c_fopen(const char *_name, const char *_type);
// FILE *c_freopen(const char *, const char *, FILE *);
// FILE *c_tmpfile(void);
// int c_putchar(int);
// int c_printf(const char *, ...);
// int c_sprintf(char *, const char *, ...);
// int c_getc(FILE *);
// int c_ungetc(int, FILE *);
// int c_fprintf(FILE *, const char *, ...);
// int c_fscanf(FILE *, const char *, ...);
// int c_fclose(FILE *);
// int c_fflush(FILE *);
// int c_setvbuf(FILE *, char *, int, size_t);
// void c_clearerr(FILE *);
// int c_fseek(FILE *, long, int);
// long c_ftell( FILE *);
// int c_fputs(const char *, FILE *);
// char *c_fgets(char *, int, FILE *);
// size_t c_fread(void *, size_t _size, size_t _n, FILE *);
// size_t c_fwrite(const void * , size_t _size, size_t _n, FILE *);
// int c_feof(FILE *);
// int c_ferror(FILE *);
#endif /* _C_STDIO_H_ */
#include "c_stdlib.h"
#include "c_stdio.h"
#include "c_types.h"
#include "c_string.h"
#include "user_interface.h"
// const char *lua_init_value = "print(\"Hello world\")";
const char *lua_init_value = "@init.lua";
// int ICACHE_FLASH_ATTR c_abs(int x){
// return x>0?x:0-x;
// }
// void ICACHE_FLASH_ATTR c_exit(int e){
// }
const char *ICACHE_FLASH_ATTR c_getenv(const char *__string){
if (c_strcmp(__string, "LUA_INIT") == 0){
return lua_init_value;
}
return NULL;
}
// make sure there is enough memory before real malloc, otherwise malloc will panic and reset
void *ICACHE_FLASH_ATTR c_malloc(size_t __size){
if(__size>system_get_free_heap_size()){
NODE_ERR("malloc: not enough memory\n");
return NULL;
}
return (void *)os_malloc(__size);
}
void *ICACHE_FLASH_ATTR c_zalloc(size_t __size){
if(__size>system_get_free_heap_size()){
NODE_ERR("zalloc: not enough memory\n");
return NULL;
}
return (void *)os_zalloc(__size);
}
void ICACHE_FLASH_ATTR c_free(void *p){
// NODE_ERR("free1: %d\n", system_get_free_heap_size());
os_free(p);
// NODE_ERR("-free1: %d\n", system_get_free_heap_size());
}
// int ICACHE_FLASH_ATTR c_rand(void){
// }
// void ICACHE_FLASH_ATTR c_srand(unsigned int __seed){
// }
// int ICACHE_FLASH_ATTR c_atoi(const char *__nptr){
// }
// double ICACHE_FLASH_ATTR c_strtod(const char *__n, char **__end_PTR){
// }
// long ICACHE_FLASH_ATTR c_strtol(const char *__n, char **__end_PTR, int __base){
// }
// unsigned long ICACHE_FLASH_ATTR c_strtoul(const char *__n, char **__end_PTR, int __base){
// }
// long long ICACHE_FLASH_ATTR c_strtoll(const char *__n, char **__end_PTR, int __base){
// }
/*
* c_stdlib.h
*
* Definitions for common types, variables, and functions.
*/
#ifndef _C_STDLIB_H_
#define _C_STDLIB_H_
#include "c_stddef.h"
#include "mem.h"
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
#define __INT_MAX__ 2147483647
#undef __RAND_MAX
#if __INT_MAX__ == 32767
#define __RAND_MAX 32767
#else
#define __RAND_MAX 0x7fffffff
#endif
#define RAND_MAX __RAND_MAX
#ifndef mem_realloc
#define mem_realloc pvPortRealloc
#endif
#ifndef os_realloc
#define os_realloc(p, s) mem_realloc((p), (s))
#endif
// #define c_free os_free
// #define c_malloc os_malloc
// #define c_zalloc os_zalloc
#define c_realloc os_realloc
#define c_abs abs
#define c_atoi atoi
// #define c_strtod strtod
#define c_strtol strtol
#define c_strtoul strtoul
// int c_abs(int);
// void c_exit(int);
// c_getenv() get env "LUA_INIT" string for lua initialization.
const char *c_getenv(const char *__string);
void *c_malloc(size_t __size);
void *c_zalloc(size_t __size);
void c_free(void *);
// int c_rand(void);
// void c_srand(unsigned int __seed);
// int c_atoi(const char *__nptr);
// double c_strtod(const char *__n, char **__end_PTR);
// // long c_strtol(const char *__n, char **__end_PTR, int __base);
// unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base);
// // long long c_strtoll(const char *__n, char **__end_PTR, int __base);
#endif /* _C_STDLIB_H_ */
#include "c_string.h"
// const char *c_strstr(const char * __s1, const char * __s2){
// }
// char *c_strncat(char * s1, const char * s2, size_t n){
// }
// size_t c_strcspn(const char * s1, const char * s2){
// }
// const char *c_strpbrk(const char * s1, const char * s2){
// }
// int c_strcoll(const char * s1, const char * s2){
// }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment