void handle_message(message_t* msg, node_t* sender) { node_update_time(&sender->time); switch(msg->type) { case 'M': handle_normal(msg, sender); break; case 'A': handle_ack((message_t*)msg, sender); break; case 'H': // Received heartbeat break; default: PRINT("Unknown type"); break; } }
/*call by main*/ int next_cmd(char *out_cmd) { unsigned char c = 0; int key_no = 0; int seq_char = 0; int str_valid = 0; /*set terminal new attrib */ term_config(); /*termial initial */ term_init(out_cmd); /*main loop */ while ((c = getc(stdin)) != '\n') { key_no = 0; seq_char = 0; if (!_isspace(c)) { str_valid = 1; } if (c == 27) { /*escape sequence */ if ((c = getc(stdin)) == '[' || c == 'O') { c = getc(stdin); seq_char = 1; } } /*search for bind key handle function */ while (key_no < sizeof (key_bind) / sizeof (key_bind[0])) { if ((seq_char == key_bind[key_no].is_eseq) && (c == key_bind[key_no].key_last)) { key_bind[key_no].func(); break; } key_no++; } if (key_no == sizeof (key_bind) / sizeof (key_bind[0])) handle_normal(out_cmd, c); } /*handle enter when at the end of a line */ if (term_cursor) putchar('\n'); /* record command history without '\n' */ history_record(out_cmd); #if 0 /* add '\n' to out_cmd */ if (str_valid) { out_cmd[cmd_strlen++] = '\n'; } else { cmd_strlen = 0; out_cmd[cmd_strlen++] = '\n'; } if (cmd_strlen > 1 && out_cmd[cmd_strlen - 1] == '\n') out_cmd[cmd_strlen - 1] = 0; #else if (!str_valid) cmd_strlen = 0; #endif /*retore terminal to orginal status */ term_restore(); fflush(stdout); return cmd_strlen; }