Merge branch 'master' of github.com:urbit/urbit

This commit is contained in:
C. Guy Yarvin 2014-04-04 15:36:21 -07:00
commit 038f0ea47b
5 changed files with 19 additions and 257 deletions

View File

@ -34,7 +34,7 @@ LIB=$(PWD)/lib
RM=rm -f
CC=gcc
CLD=gcc -O3 -L/usr/local/lib -L/opt/local/lib
CLD=gcc -O2 -g -L/usr/local/lib -L/opt/local/lib
YACC=bison -v -b$(GENERATED)/y
LEX=lex
@ -56,7 +56,7 @@ INCLUDE=include
GENERATED=generated
MDEFINES=-DU2_OS_$(OS) -DU2_OS_ENDIAN_$(ENDIAN) -D U2_LIB=\"$(LIB)\"
CFLAGS=-O3 \
CFLAGS=-O2 -g \
-I/usr/local/include \
-I/opt/local/include \
-I$(INCLUDE) \

View File

@ -90,5 +90,9 @@
} while (0)
/* c3_malloc(): asserting malloc
*/
void*
c3_malloc(size_t s);
#define c3_malloc(s) ({ \
void* rut = malloc(s); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
rut;})

View File

@ -407,27 +407,14 @@
/* u2_utty: unix tty.
*/
typedef struct _u2_utty {
#if 0
uv_tty_t wax_u; // event handler state
#else
union {
uv_poll_t wax_u;
uv_pipe_t pop_u;
};
#endif
uv_pipe_t pop_u;
struct termios bak_u; // cooked terminal state
struct termios raw_u; // raw terminal state
c3_i fid_i; // file descriptor
# if 1
c3_i cug_i; // blocking fcntl flags
c3_i nob_i; // nonblocking fcntl flags
# endif
c3_w tid_l; // terminal identity number
u2_utfo ufo_u; // terminfo strings
# if 1
u2_ubuf* tou_u; // entry of output queue
u2_ubuf* out_u; // exit of output queue
# endif
u2_utat tat_u; // control state
struct _u2_utty* nex_u; // next in host list
} u2_utty;

View File

@ -256,16 +256,6 @@ static void _main_cont(void *arg1, void *arg2, void *arg3)
siglongjmp(Signal_buf, 1);
}
void*
c3_malloc(size_t s)
{
void* rut = malloc(s);
if ( u2_nul == rut ) {
c3_assert(!"memory lost");
}
return rut;
}
static void
overflow_handler(int emergency, stackoverflow_context_t scp)
{

239
v/term.c
View File

@ -22,15 +22,8 @@
#include "all.h"
#include "v/vere.h"
#if 0
static void _term_read_cb(uv_stream_t*, ssize_t, uv_buf_t);
#endif
#if 1
static void _term_poll_cb(uv_poll_t*, c3_i, c3_i);
#endif
static void _term_it_do_writes(u2_utty*);
#if 0
/* _term_alloc(): libuv buffer allocator.
*/
static uv_buf_t
@ -38,7 +31,6 @@ _term_alloc(uv_handle_t* had_u, size_t len_i)
{
return uv_buf_init(c3_malloc(len_i), len_i);
}
#endif
/* u2_term_io_init(): initialize terminal.
*/
@ -50,7 +42,7 @@ u2_term_io_init()
if ( u2_yes == u2_Host.ops_u.dem ) {
uty_u->fid_i = 1;
uv_pipe_init(u2L, &(uty_u->pop_u), uty_u->fid_i);
uv_pipe_init(u2L, &(uty_u->pop_u), 0);
uv_pipe_open(&(uty_u->pop_u), uty_u->fid_i);
}
else {
@ -59,10 +51,9 @@ u2_term_io_init()
{
uty_u->fid_i = 0; // stdin, yes we write to it...
uv_poll_init(u2L, &(uty_u->wax_u), uty_u->fid_i);
uv_poll_start(&(uty_u->wax_u),
UV_READABLE | UV_WRITABLE,
_term_poll_cb);
uv_pipe_init(u2L, &(uty_u->pop_u), 0);
uv_pipe_open(&(uty_u->pop_u), uty_u->fid_i);
uv_read_start((uv_stream_t*)&(uty_u->pop_u), _term_alloc, _term_read_cb);
}
// Configure horrible stateful terminfo api.
@ -197,8 +188,6 @@ u2_term_io_init()
//
{
uty_u->tid_l = 1;
uty_u->out_u = 0;
uty_u->tou_u = 0;
uty_u->nex_u = u2_Host.uty_u;
u2_Host.uty_u = uty_u;
@ -247,26 +236,6 @@ u2_term_io_poll(void)
{
}
#if 1
/* _term_it_clip(): remove sent bytes from buffer.
**
** XX unify with ubuf in term.c
*/
static void
_term_it_clip(u2_ubuf* buf_u, c3_i siz_i)
{
if ( siz_i ) {
c3_assert(siz_i < buf_u->len_w);
{
c3_w res_w = (buf_u->len_w - siz_i);
memmove(buf_u->hun_y, (buf_u->hun_y + siz_i), res_w);
buf_u->len_w = res_w;
}
}
}
#endif
/* _term_it_buf(): create a data buffer.
*/
static u2_ubuf*
@ -288,7 +257,6 @@ _term_it_buf(c3_w len_w, const c3_y* hun_y)
c3_y* buf_y;
} _u2_write_t;
#if 0
/* _term_write_cb(): general write callback.
*/
static void
@ -313,14 +281,13 @@ _term_it_write_buf(u2_utty* uty_u, uv_buf_t buf_u)
ruq_u->buf_y = (c3_y*)buf_u.base;
if ( 0 != uv_write(&ruq_u->wri_u,
(uv_stream_t*)&(uty_u->wax_u),
(uv_stream_t*)&(uty_u->pop_u),
&buf_u, 1,
_term_write_cb) )
{
uL(fprintf(uH, "terminal: %s\n", uv_strerror(uv_last_error(u2L))));
}
}
#endif
/* _term_it_write_old(): write buffer, transferring pointer.
*/
@ -328,15 +295,6 @@ static void
_term_it_write_old(u2_utty* uty_u,
u2_ubuf* old_u)
{
#if 1
if ( !uty_u->tou_u ) {
uty_u->out_u = uty_u->tou_u = old_u;
}
else {
uty_u->tou_u->nex_u = old_u;
uty_u->tou_u = old_u;
}
#else
uv_buf_t buf_u;
// XX extra copy here due to old code. Use hbod as base directly.
@ -350,7 +308,6 @@ _term_it_write_old(u2_utty* uty_u,
free(old_u);
}
_term_it_write_buf(uty_u, buf_u);
#endif
}
/* _term_it_write_bytes(): write bytes, retaining pointer.
@ -381,20 +338,6 @@ _term_it_write_str(u2_utty* uty_u,
_term_it_write_txt(uty_u, (const c3_y*) str_c);
}
#if 0
/* _term_it_write_strnum(): write string with terminal parameter, retaining.
*/
static void
_term_it_write_strnum(u2_utty* uty_u, const c3_c* str_c, c3_w num_w)
{
c3_c buf_c[16];
snprintf(buf_c, 16, "#%ud", num_w); // XX slow
_term_it_write_str(uty_u, str_c);
_term_it_write_str(uty_u, buf_c);
}
#endif
/* _term_it_show_wide(): show wide text, retaining.
*/
static void
@ -668,106 +611,6 @@ _term_io_suck_char(u2_utty* uty_u, c3_y cay_y)
}
}
/* _term_ef_poll(): update poll flags.
*/
static void
_term_ef_poll(u2_utty* uty_u)
{
if ( u2_no == u2_Host.ops_u.dem ) {
c3_i evt_i = ( ((u2_yes == u2_Host.ops_u.dem) ? 0 : UV_READABLE)
| ((0 == uty_u->out_u) ? 0 : UV_WRITABLE));
// fprintf(stderr, "ef_poll out_u %p\r\n", uty_u->out_u);
uv_poll_start(&(uty_u->wax_u), evt_i, _term_poll_cb);
}
}
/* _term_it_do_writes():
*/
static void
_term_it_do_writes(u2_utty* uty_u)
{
u2_lo_open();
while ( uty_u->out_u ) {
u2_ubuf* out_u = uty_u->out_u;
c3_i siz_i;
if ( (siz_i = write(uty_u->fid_i,
uty_u->out_u->hun_y,
uty_u->out_u->len_w)) < 0 ) {
#if 0
if ( EAGAIN == errno ) {
break;
} else {
c3_assert(!"term: write");
}
#else
break;
#endif
}
if ( siz_i < out_u->len_w ) {
_term_it_clip(out_u, siz_i);
break;
}
else {
uty_u->out_u = uty_u->out_u->nex_u;
if ( 0 == uty_u->out_u ) {
c3_assert(out_u == uty_u->tou_u);
uty_u->tou_u = 0;
}
free(out_u);
}
}
u2_lo_shut(u2_yes);
}
/* _term_poll_cb(): polling with old libev code.
*/
static void
_term_poll_cb(uv_poll_t* pol_u, c3_i sas_i, c3_i evt_i)
{
u2_utty* uty_u = (void*)pol_u;
#if 0
fprintf(stderr, "poll_cb read %d, write %d\r\n",
!!(UV_READABLE & evt_i),
!!(UV_WRITABLE & evt_i));
#endif
if ( sas_i != 0 ) {
uL(fprintf(uH, "term: poll: %s\n", uv_strerror(uv_last_error(u2L))));
}
else {
if ( UV_READABLE & evt_i ) {
u2_lo_open();
while ( 1 ) {
c3_y buf_y[4096];
c3_i siz_i, i;
if ( (siz_i = read(uty_u->fid_i, buf_y, 4096)) < 0) {
if ( EAGAIN == errno ) {
break;
} else {
c3_assert(!"term: read");
}
}
for ( i=0; i < siz_i; i++ ) {
_term_io_suck_char(uty_u, buf_y[i]);
}
if ( 4096 != siz_i ) {
break;
}
}
u2_lo_shut(u2_yes);
}
if ( UV_WRITABLE & evt_i ) {
_term_it_do_writes(uty_u);
}
}
_term_ef_poll(uty_u);
}
#if 0
/* _term_read_cb(): server read callback.
*/
static void
@ -791,10 +634,13 @@ _term_read_cb(uv_stream_t* str_u,
_term_io_suck_char(uty_u, buf_u.base[i]);
}
}
if ( buf_u.base ) {
free(buf_u.base);
}
}
u2_lo_shut(u2_yes);
}
#endif
/* _term_main(): return main or console terminal.
*/
@ -862,39 +708,6 @@ u2_term_get_blew(c3_l tid_l)
return u2nc(col_l, row_l);
}
#if 0
/* u2_term_ef_boil(): initial effects for loaded servers.
*/
void
u2_term_ef_boil(c3_l old_l,
c3_l ono_l)
{
if ( ono_l ) {
u2_noun oan = u2_dc("scot", c3__uv, old_l);
u2_noun tid_l;
for ( tid_l = 1; tid_l <= ono_l; tid_l++ ) {
u2_noun tin = u2_dc("scot", c3__ud, tid_l);
u2_noun pax = u2nc(c3__gold, u2nq(c3__term, u2k(oan), tin, u2_nul));
u2_noun hud = u2nc(c3__wipe, u2_nul);
u2_reck_plan(u2A, pax, hud);
}
u2z(oan);
}
{
u2_noun pax = u2nc(c3__gold, u2nq(c3__term, u2k(u2A->sen), '1', u2_nul));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__init, u2k(u2h(u2A->own))));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__blew, u2_term_get_blew(u2A, 1)));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul));
u2z(pax);
}
}
#else
/* u2_term_ef_winc(): window change. Just console right now.
*/
void
@ -942,23 +755,7 @@ u2_term_ef_boil(c3_l ono_l)
u2z(pax);
}
}
#endif
#if 0
/* u2_term_ef_bake(): initial effects for new terminal.
*/
void
u2_term_ef_bake(u2_noun fav)
{
u2_noun pax = u2nc(c3__gold, u2nq(c3__term, u2k(u2A->sen), '1', u2_nul));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__boot, fav));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__blew, u2_term_get_blew(u2A, 1)));
u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul));
u2z(pax);
}
#else
/* u2_term_ef_bake(): initial effects for new terminal.
*/
void
@ -972,7 +769,6 @@ u2_term_ef_bake(u2_noun fav)
u2z(pax);
}
#endif
/* _term_ef_blit(): send blit to terminal.
*/
@ -1018,26 +814,12 @@ _term_ef_blit(u2_utty* uty_u,
_term_it_show_clear(uty_u);
_term_it_show_line(uty_u, lin_w, len_w);
} else {
while ( uty_u->out_u ) {
u2_ubuf* out_u = uty_u->out_u;
uty_u->out_u = uty_u->out_u->nex_u;
if ( 0 == uty_u->out_u ) {
c3_assert(out_u == uty_u->tou_u);
uty_u->tou_u = 0;
}
free(out_u);
}
_term_it_show_line(uty_u, lin_w, len_w);
}
} break;
case c3__mor: {
if ( u2_no == u2_Host.ops_u.dem ) {
_term_it_show_more(uty_u);
} else {
_term_it_show_more(uty_u);
_term_it_do_writes(uty_u);
}
_term_it_show_more(uty_u);
} break;
case c3__sav: {
@ -1073,7 +855,6 @@ u2_term_ef_blit(c3_l tid_l,
}
u2z(bls);
}
_term_ef_poll(uty_u);
}
/* u2_term_io_hija(): hijack console for fprintf, returning FILE*.