Esempio n. 1
0
static muse_cell json_read_key( muse_port_t p )
{
	muse_env *env = p->env;
	int sp = _spos();
	muse_cell str = json_read_string(p);

	int len = 0;
	const muse_char *strptr = muse_text_contents( env, str, &len );
	str = muse_symbol( env, strptr, strptr + len );
	_unwind(sp);
	return str;
}
Esempio n. 2
0
static muse_cell json_read_object_expr_items( muse_env *env, muse_port_t p, muse_cell h, muse_cell t, int sp )
{
	json_skip_whitespace(p);

	if ( port_eof(p) ) 
		return muse_raise_error( env, _csymbol(L"json:end-of-file-in-object"), MUSE_NIL );
	else {
		muse_char c = port_getchar(p);
		if ( c == '}' ) {
			return h;
		} else {
			muse_cell key, value;
			port_ungetchar(c,p);

			key = json_read_key(p);
			json_skip_whitespace(p);
			if ( port_eof(p) ) {
				return muse_raise_error( env, _csymbol(L"json:end-of-file-in-object"), MUSE_NIL );
			} else {
				muse_char c = port_getchar(p);
				if ( c == ':' ) {
					muse_cell assoc;
					value = json_read_expr(p);
					if ( json_is_constant(env, value) ) {
						assoc = _cons( muse_quote( env, _cons( key, value ) ), MUSE_NIL );
					} else {
						assoc = _cons( _cons( _mk_nativefn(fn_cons,NULL), _cons( muse_quote(env,key), _cons( value, MUSE_NIL ) ) ), MUSE_NIL );
					}
					_sett( t, assoc );
					t = assoc;
					_unwind(sp);

					json_skip_whitespace(p);

					{
						muse_char c = port_getchar(p);
						if ( c == ',' ) {
							return json_read_object_expr_items( env, p, h, t, sp );
						} else if ( c == '}' ) {
							return h;
						} else {
							return muse_raise_error( env, _csymbol(L"json:object-syntax-error"), h );
						}
					}
				} else {
					return muse_raise_error( env, _csymbol(L"json:object-syntax-error"), h );
				}
			}
		}
	}
}
Esempio n. 3
0
static muse_cell json_read_object_expr( muse_port_t p )
{
	muse_env *env = p->env;
	muse_debug_only(muse_char c =) port_getchar(p);
	assert( c == '{' );
	json_skip_whitespace(p);
	
	{
		muse_cell h = _cons( MUSE_NIL, MUSE_NIL );
		int sp = _spos();
		muse_cell t = _cons( _mk_nativefn(fn_list,NULL), MUSE_NIL );
		_setht( h, _mk_nativefn(fn_alist_to_hashtable,NULL), _cons( t, MUSE_NIL ) );
		_unwind(sp);
		return json_share_object_expr( env, json_read_object_expr_items( env, p, h, t, sp ) );
	}
}
Esempio n. 4
0
static void json_write_hash( muse_port_t p, muse_cell obj )
{
	muse_env *env = p->env;
	int sp = _spos();
	muse_cell alist = fn_hashtable_to_alist( env, NULL, _cons(obj,MUSE_NIL) );
	_unwind(sp);
	port_putc( '{', p );
	while ( alist ) {
		muse_cell ht = _next(&alist);
		json_write_string(p, _symname(_head(ht)));
		port_putc(':',p);
		json_write(p,_tail(ht));
		if ( alist )
			port_putc( ',', p );
	}
	port_putc( '}', p );
}
Esempio n. 5
0
static muse_cell json_read_array_items( muse_env *env, muse_port_t p, muse_cell h, muse_cell t, int N )
{
	int i;
	if ( port_eof(p) ) {
		return muse_raise_error( env, _csymbol(L"json:end-of-file-in-array"), MUSE_NIL );
	} else {
		muse_char c = port_getchar(p);
		if ( c == ']' ) {
			muse_cell v = muse_mk_vector( env, N );
			for ( i = 0; i < N; ++i ) {
				muse_vector_put( env, v, i, _next(&h) );
			}
			return v;
		} else {
			port_ungetchar( c, p );
		}
	}

	if ( h ) {
		int sp = _spos();
		muse_cell n = _cons( json_read(p), MUSE_NIL );
		_sett( t, n );
		t = n;
		_unwind(sp);
	} else { 
		h = t = _cons( json_read(p), MUSE_NIL );
	}

	json_skip_whitespace(p);

	if ( port_eof(p) ) {
		return muse_raise_error( env, _csymbol(L"json:end-of-file-in-array"), h );
	} else {
		muse_char c = port_getchar(p);
		if ( c == ',' ) {
			return json_read_array_items( env, p, h, t, N+1 );
		} else if ( c == ']' ) {
			port_ungetc( c, p );
			return json_read_array_items( env, p, h, t, N+1 );
		} else {
			return muse_raise_error( env, _csymbol(L"json:array-syntax-error"), h );
		}
	}
}
Esempio n. 6
0
static muse_cell json_read_object_items( muse_env *env, muse_port_t p, muse_cell table )
{
	json_skip_whitespace(p);

	if ( port_eof(p) ) 
		return muse_raise_error( env, _csymbol(L"json:end-of-file-in-object"), MUSE_NIL );
	else {
		muse_char c = port_getchar(p);
		if ( c == '}' ) {
			return table;
		} else {
			int sp = _spos();
			muse_cell key, value;
			port_ungetchar(c,p);

			key = json_read_key(p);
			json_skip_whitespace(p);
			if ( port_eof(p) ) {
				return muse_raise_error( env, _csymbol(L"json:end-of-file-in-object"), MUSE_NIL );
			} else {
				muse_char c = port_getchar(p);
				if ( c == ':' ) {
					value = json_read(p);
					muse_hashtable_put( env, table, key, value );
					_unwind(sp);

					{
						muse_char c = port_getchar(p);
						if ( c == ',' ) {
							return json_read_object_items( env, p, table );
						} else if ( c == '}' ) {
							return table;
						} else {
							return muse_raise_error( env, _csymbol(L"json:object-syntax-error"), table );
						}
					}
				} else {
					return muse_raise_error( env, _csymbol(L"json:object-syntax-error"), table );
				}
			}
		}
	}
}
Esempio n. 7
0
static muse_cell json_read_array_expr_items( muse_env *env, muse_port_t p, muse_cell h, muse_cell t, int N )
{
	if ( port_eof(p) ) {
		return muse_raise_error( env, _csymbol(L"json:end-of-file-in-array"), MUSE_NIL );
	} else {
		muse_char c = port_getchar(p);
		if ( c == ']' ) {
			return h;
		} else {
			port_ungetchar( c, p );
		}
	}

	if ( h ) {
		int sp = _spos();
		muse_cell n = _cons( json_read_expr(p), MUSE_NIL );
		_sett( t, n );
		t = n;
		_unwind(sp);
	} else { 
		h = t = _cons( json_read_expr(p), MUSE_NIL );
	}

	json_skip_whitespace(p);

	if ( port_eof(p) ) {
		return muse_raise_error( env, _csymbol(L"json:end-of-file-in-array"), h );
	} else {
		muse_char c = port_getchar(p);
		if ( c == ',' ) {
			return json_read_array_expr_items( env, p, h, t, N+1 );
		} else if ( c == ']' ) {
			port_ungetchar( c, p );
			return json_read_array_expr_items( env, p, h, t, N+1 );
		} else {
			return muse_raise_error( env, _csymbol(L"json:array-syntax-error"), h );
		}
	}
}
Esempio n. 8
0
static void       _trapSIG(int sig, siginfo_t *info, void *secret)
{
    // 2 - Interrupt (ANSI), Ctrl-C
    if (SIGINT == sig) {
        PRINTF("NOTE: Signal SIGINT(%i) cought .. setting up atomic to abort\n", sig);
        g_atomic_int_set(&_atomicAbort, TRUE);

        // continue with normal sig handling
        if (NULL != _old_signal_handler_SIGINT.sa_sigaction)
            _old_signal_handler_SIGINT.sa_sigaction(sig, info, secret);

        return;
    }

    //  3  - Quit (POSIX), Ctrl + D
    if (SIGQUIT == sig) {
        PRINTF("NOTE: Signal SIGQUIT(%i) cought .. Quit\n", sig);

        // continue with normal sig handling
        if (NULL != _old_signal_handler_SIGQUIT.sa_sigaction)
            _old_signal_handler_SIGQUIT.sa_sigaction(sig, info, secret);

        return;
    }

    //  5  - Trap (ANSI)
    if (SIGTRAP == sig) {
        PRINTF("NOTE: Signal SIGTRAP(%i) cought .. debugger\n", sig);

        // continue with normal sig handling
        if (NULL != _old_signal_handler_SIGTRAP.sa_sigaction)
            _old_signal_handler_SIGTRAP.sa_sigaction(sig, info, secret);

        return;
    }

    //  6  - Abort (ANSI)
    if (SIGABRT == sig) {
        PRINTF("NOTE: Signal SIGABRT(%i) cought .. Abort\n", sig);

        // continue with normal sig handling
        if (NULL != _old_signal_handler_SIGABRT.sa_sigaction)
            _old_signal_handler_SIGABRT.sa_sigaction(sig, info, secret);

        return;
    }

    //  9  - Kill, unblock-able (POSIX)
    if (SIGKILL == sig) {
        PRINTF("NOTE: Signal SIGKILL(%i) cought .. Kill\n", sig);

        // continue with normal sig handling
        if (NULL != _old_signal_handler_SIGKILL.sa_sigaction)
            _old_signal_handler_SIGKILL.sa_sigaction(sig, info, secret);

        return;
    }

    // 11 - Segmentation violation
    if (SIGSEGV == sig) {
        PRINTF("NOTE: Segmentation violation cought (%i) ..\n", sig);

#ifdef S52_USE_BACKTRACE
#ifdef S52_USE_ANDROID
        _unwind();

        // break loop - android debuggerd rethrow SIGSEGV
        exit(0);

#endif  // S52_USE_ANDROID


        S52_utils_backtrace();

#endif  //S52_USE_BACKTRACE

        // continue with normal sig handling
        if (NULL != _old_signal_handler_SIGSEGV.sa_sigaction)
            _old_signal_handler_SIGSEGV.sa_sigaction(sig, info, secret);

        return;
    }

    // 15 - Termination (ANSI)
    if (SIGTERM == sig) {
        PRINTF("NOTE: Signal SIGTERM(%i) cought .. Termination\n", sig);

        // continue with normal sig handling
        if (NULL != _old_signal_handler_SIGTERM.sa_sigaction)
            _old_signal_handler_SIGTERM.sa_sigaction(sig, info, secret);

        return;
    }

    // 10
    if (SIGUSR1 == sig) {
        PRINTF("NOTE: Signal 'User-defined 1' cought - SIGUSR1(%i)\n", sig);

        // debug
        S52_utils_backtrace();

        return;
    }
    // 12
    if (SIGUSR2 == sig) {
        PRINTF("NOTE: Signal 'User-defined 2' cought - SIGUSR2(%i)\n", sig);
        return;
    }



//#ifdef S52_USE_ANDROID
        // break loop - android debuggerd rethrow SIGSEGV
        //exit(0);
//#endif


    // shouldn't reach this !?
    PRINTF("WARNING: Signal not hangled (%i)\n", sig);
    g_assert_not_reached();  // turn off via G_DISABLE_ASSERT

/*
#ifdef S52_USE_BREAKPAD
    // experimental
    MinidumpFileWriter writer;
    writer.Open("/tmp/minidump.dmp");
    TypedMDRVA<MDRawHeader> header(&writer_);
    header.Allocate();
    header->get()->signature = MD_HEADER_SIGNATURE;
    writer.Close();
#endif
*/

}