static int
p4_k12_wait_for_stdin ()
{
register k12_priv* k12p = K12PRIV(p4TH);
if (k12p->answering && k12p->frm_putback == '\n' )
{
k12p->rx_data = "\n" ;
k12p->rx_datalen = 1;
k12p->rx_dataIN = 0;
k12p->frm_putback = 0;
return 1;
}else{
k12p->answering = FALSE;
k12p->frm_putback = 0;
}
if (k12p->state == K12_EMU_NOT_LOADED && ! k12p->validation_req)
k12p->state = K12_EMU_IDLE;
while (1)
{
if (k12p->frm_putback) { k12p->frm_putback = 0; }
else{
k12EmuLowEventGet (k12p->emu,
&k12p->frm_input,
&k12p->frm_data,
&k12p->frm_datalen,
&k12p->frm_option);
K12LogMsg2 (K12_LOG_DEBUG_L(0),
"got>" , "event via %i len %i\n" ,
k12p->frm_input, k12p->frm_datalen);
}
if (k12p->rx_dataSAP == k12p->frm_input
|| (k12p->rx_link && k12p->rx_link == k12p->frm_input))
{
register k12_emu_msg_subhead_t* msg = (void*)k12p->frm_data;
switch (msg->type)
{
case K12_EMU_VALIDATION_REQ:
if (k12p->validation_req)
k12p->validation_req --;
if (k12p->state == K12_EMU_NOT_LOADED)
k12p->state = K12_EMU_IDLE;
break;
case K12_EMU_DATA_REQ:
K12LogMsg2 ( K12_LOG_DEBUG_L(11), "got>" ,
"K12_EMU_DATA_REQ(%i) len=%i\n" ,
msg->type, k12p->frm_datalen - sizeof(*msg));
k12p->rx_data = k12p->frm_data + sizeof(*msg);
k12p->rx_datalen = k12p->frm_datalen - sizeof(*msg);
k12p->rx_dataIN = 0;
k12LogString(K12_LOG_DEBUG_L(10),
"got>" , k12p->rx_data, k12p->rx_datalen);
if (! k12p->rx_datalen || ! k12p->rx_data[0])
{
if (k12p->bufidx)
p4_put_flush ();
if (msg->para2)
return 0;
}else{
if (k12p->state == K12_EMU_ERROR_CASE ||
k12p->state == K12_EMU_WARNING)
k12p->state = K12_EMU_IDLE;
return 1;
}
break;
case K12_EMU_XDAT_REQ:
K12LogMsg2 (K12_LOG_DEBUG_L(11),
"got>" , "K12_EMU_XDAT_REQ(%i) len=%i\n" ,
msg->type, k12p->frm_datalen - sizeof(*msg));
k12p->rx_data = k12p->frm_data + sizeof(*msg);
k12p->rx_datalen = k12p->frm_datalen - sizeof(*msg);
k12p->rx_dataIN = 0;
k12LogString (K12_LOG_DEBUG_L(10),
"cmd>" , k12p->rx_data, k12p->rx_datalen);
k12p->answering = TRUE;
if (!k12p->rx_datalen || !k12p->rx_data[0])
{
k12p->rx_data = "\n" ;
k12p->rx_datalen = 1;
k12p->rx_dataIN = 0;
}
strcpy (k12p->answerbuf, "\\ " );
k12p->answeridx = strlen (k12p->answerbuf);
if (k12p->state == K12_EMU_ERROR_CASE)
k12p->state = K12_EMU_WARNING;
return 1;
case K12_EMU_CONN_REQ:
K12LogMsg2 (K12_LOG_DEBUG_L(11),
"got>" , "K12_EMU_CONN_REQ(%i) handle=%i\n" ,
msg->type, msg->handle);
k12p->rx_data = 0;
k12p->rx_datalen = k12p->frm_datalen;
k12p->rx_dataIN = 0;
# if defined HOST_CPU_I960 || defined __target_cpu_i960
if (!(msg->handle&1))
{
msg->handle = ntohl(msg->handle);
K12LogMsg1 (K12_LOG_SEVERE,
"got>" ,
"PANIC: byte-swapping queue id (now %08x) !!!!!!!!\n" ,
msg->handle);
}
# endif
if (!(msg->handle&1))
{
K12LogMsg1 (K12_LOG_SEVERE,
"got>" ,
"PANIC: can't be a global queue id !!!!!!!! (%08x)\n" ,
msg->handle);
break;
}
k12p->tx_qid = msg->handle;
K12LogMsg1 (K12_LOG_INFO, "got:" ,
"terminal opened (tqid %08lx)\n" ,
(long)k12p->tx_qid);
{
int i;
for (i=0; i<K12_TERM_FKKEYS_MAX; i++)
{
p4_set_fkey_name (i, 0);
}
}
break;
case K12_EMU_DISC_REQ:
K12LogMsg2 (K12_LOG_DEBUG_L(11),
"got>" , "K12_EMU_DISC_REQ(%i) handle=%i\n" ,
msg->type, msg->handle);
k12p->rx_data = 0;
k12p->rx_datalen = k12p->frm_datalen;
k12p->rx_dataIN = 0;
k12p->tx_qid = msg->handle;
K12LogMsg1 (K12_LOG_INFO, "got:" , "terminal closed (%08lx)\n" ,
(long)k12p->tx_qid);
break;
default:
K12LogMsg2 (K12_LOG_DEBUG_L(11),
"got>" ," K12_EMU_UnKnOwN(%i) handle=%i;\n" ,
msg->type, msg->handle);
if (k12p->eventHook && FORTHTYPE(msg->type))
{ (*k12p->eventHook)(k12p->frm_input,
k12p->frm_data, k12p->frm_datalen);
}
}
}
else if (k12p->qx_link && k12p->qx_link == k12p->frm_input)
{
register k12_emu_msg_subhead_t* msg = (void*)k12p->frm_data;
switch (msg->type)
{
case K12_EMU_DATA_REQ:
K12LogMsg2 (K12_LOG_DEBUG_L(11),
"got>" , "K12_EMU_DATA_REQ(%i) len=%i to-forth\n" ,
msg->type, k12p->frm_datalen - sizeof(*msg));
k12p->rx_data = k12p->frm_data + sizeof(*msg);
k12p->rx_datalen = k12p->frm_datalen - sizeof(*msg);
k12p->rx_dataIN = 0;
k12LogString (K12_LOG_DEBUG_L(10),
"cmd>" , k12p->rx_data, k12p->rx_datalen);
k12p->answering = TRUE;
k12p->answeridx = 0;
k12p->frm_putback = '\n' ;
return 1;
default:
K12LogMsg2 (K12_LOG_DEBUG_L(11),
"got>" ," K12_EMU_UnKnOwN(%i) handle=%i;\n" ,
msg->type, msg->handle);
if (k12p->eventHook && FORTHTYPE(msg->type))
{ (*k12p->eventHook)(k12p->frm_input,
k12p->frm_data, k12p->frm_datalen);
}
}
}else{
if (K12_EMU_VALIDATION_REQ ==
((k12_emu_msg_subhead_t*)k12p->frm_data)->type)
{
if (k12p->validation_req)
k12p->validation_req --;
if (k12p->state == K12_EMU_NOT_LOADED)
k12p->state = K12_EMU_IDLE;
}
else if (k12p->eventHook)
{
if ( (*k12p->eventHook)(k12p->frm_input,
k12p->frm_data, k12p->frm_datalen))
{ continue; }
}else{
K12LogMsg1 (K12_LOG_WARNING,
"got>" , "unknown input - skipped event via %i\n" ,
k12p->frm_input);
}
}
}
# undef _sizeof_subhead_t
} |