void process_input(void) { if (HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_SGA) && !HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_ECHO)) { read_key(); } else { read_line(); } if (!HAS_BIT(gtd->flags, TINTIN_FLAG_PROCESSINPUT)) { return; } DEL_BIT(gtd->flags, TINTIN_FLAG_PROCESSINPUT); if (gtd->chat && gtd->chat->paste_time) { chat_paste(gtd->input_buf, NULL); return; } if (HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_ECHO)) { add_line_history(gtd->ses, gtd->input_buf); } if (HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_ECHO)) { echo_command(gtd->ses, gtd->input_buf); } else { echo_command(gtd->ses, ""); } if (gtd->ses->scroll_line != -1) { buffer_end(gtd->ses, ""); } check_all_events(gtd->ses, SUB_ARG|SUB_SEC, 0, 1, "RECEIVED INPUT", gtd->input_buf); gtd->ses = script_driver(gtd->ses, LIST_COMMAND, gtd->input_buf); if (IS_SPLIT(gtd->ses)) { erase_toeol(); } gtd->input_buf[0] = 0; }
int main(void) { char msg[1024]; echo_command(msg, sizeof(msg), "/bin/echo", "datel", "strakapoud", NULL); msg(L_INFO, "Running <%s>", msg); run_command("/bin/echo", "datel", "strakapoud", NULL); return 0; }
/*! * @brief IRQハンドラ * @param[in] なし * @param[out] なし * @return なし * @note UART関連のレジスタであるIIRレジスタから割込みタイプの取得 * (IIRレジスタは下位5ビットで割込みタイプを保持している) * シリアル受信割込み : 0x2 * タイムアウト割込み(シリアル受信割込みを有効化すると同時に有効化される) : 0x6 */ void uart_handler(void) { unsigned char c; static char buf[32]; static int len; int it_type; it_type = (REG8_READ(UIIR) & 0x3E) >> 1; if (it_type == 2 || it_type == 6) { c = getc(); /* 受信FIFOからデータを読み出す事によって,割込み要因をクリア */ if (c != '\n') { buf[len++] = c; } else { buf[len++] = '\0'; /* echoコマンドの場合 */ if (!strncmp(buf, "echo ", 5)) { echo_command(buf); /* echoコマンド(標準出力にテキストを出力する)呼び出し */ } /* helpコマンドの場合 */ else if (!strncmp(buf, "help", 4)) { help_command(&buf[4]); /* helpコマンド呼び出し */ } #ifdef TSK_LIBRARY /* runコマンドの場合 */ else if (!strncmp(buf, "run", 3)) { run_command(&buf[3]); /* runコマンド(タスクセットの起動)呼び出し */ } #endif /* sendlogの場合 */ else if (!strncmp(buf, "sendlog", 7)) { sendlog_command(); /* sendlogコマンド(xmodem送信モード)呼び出し */ } /* 本システムに存在しないコマンド */ else { puts("command unknown.\n"); } puts("> "); len = 0; } } else { DEBUG_LEVEL1_OUTMSG(" not uart3 handler : uart_handler().\n"); } }
/*********************** Main **********************/ int main(int argc, char *argv[]) { setup_home(); int g = 0; int x = 0; int V = 0; int c = 0; int l = 0; int e = 0; int d = 0; int u = 0; int h = 0; int G = 0; int T = 0; int C = 0; int M = 0; int N = 0; char * group; char * label; char * content; int opt ; while((opt= getopt(argc,argv, "V(verbose)g:x(execute)c(create)l(list)e(echo):d(drop):u(edit):h(help)G(group):T(template):C(command)::M(macro)::N(note)::"))!= -1) { switch(opt) { case 'g': g=1; group = optarg; break; case 'V': V = 1; break; case 'x': x = 1; break; case 'c': c = 1; break; case 'l': l = 1; break; case 'e': e = 1; label = argv[optind]; break; case 'd': d = 1; label = argv[optind]; break; case 'u': u = 1; label = argv[optind]; break; case 'h': h = 1; break; case 'G': G = 1; label = argv[optind]; break; case 'T': T = 1; label = argv[optind]; break; case 'C': C = 1; label = argv[optind]; content = argv[optind+1]; break; case 'N': N = 1; label = argv[optind]; content = argv[optind+1]; break; default: puts("test"); break; } } if(g == 1) { if(c == 1) { if(G ==1) { create_group(label); //break; } else if(N == 1) { create_note(group, label, content); //break; } else if(C == 1) { create_command(label,group,content); //break; } else if(T == 1) { create_template_from_current(group,label); //break; } else { puts("Invalid Command"); return -1; } } if(e == 1) { if(N == 1) { echo_note(group,label); } else if( C == 1) { echo_command(label, group); } else if (T == 1) { echo_template(label, group); } } else if(l == 1) { if(N == 1) { list_notes(group); //break; } else if(C == 1) { list_commands(group); //break; } else if(T == 1) { list_templates(group); } else { puts("Invalid Command"); return -1; } } else if(x == 1) { if(C == 1) { execute_command(group,label); //break; } else if(T == 1) { execute_template(group,label); } else { puts("Invalid Command"); return -1; } } } else if(c == 1) { if(G == 1) { create_group(label); //break; } else { puts("Invalid Command"); return -1; } } else if(e == 1) { if(G == 1) { echo_group(label); } } return 0; }
static opcode_status_ty execute(const opcode_ty *op, opcode_context_ty *ocp) { const opcode_command_ty *this; opcode_status_ty status; string_list_ty *wlp; string_list_ty *flags_words; string_ty *isp; char *cmd; flag_ty *flags; /* * pop the arguments off the value stack */ trace(("opcode_command::execute()\n{\n")); this = (const opcode_command_ty *)op; status = opcode_status_success; isp = 0; flags_words = 0; flags = 0; wlp = 0; if (ocp->pid) { ocp->pid = 0; wlp = ocp->wlp; ocp->wlp = 0; goto resume; } if (this->input) { string_list_ty *islp; islp = opcode_context_string_list_pop(ocp); isp = wl2str(islp, 0, islp->nstrings - 1, (char *)0); string_list_delete(islp); } flags_words = opcode_context_string_list_pop(ocp); wlp = opcode_context_string_list_pop(ocp); /* * take care of the options */ flags = flag_recognize(flags_words, &this->pos); if (!flags) { /* * Error message already printed. */ status = opcode_status_error; goto done; } string_list_delete(flags_words); flags_words = 0; flag_set_options(flags, OPTION_LEVEL_EXECUTE); flag_delete(flags); flags = 0; /* * echo the command if required */ if (!option_test(OPTION_SILENT)) { string_ty *cp; /* * If the command has not been silenced, * form it into a string and echo it. */ cp = wl2str(wlp, 0, wlp->nstrings - 1, (char *)0); if (option_test(OPTION_TELL_POSITION)) { error_raw ( "%s: %d: %s", this->pos.pos_name->str_text, this->pos.pos_line, cp->str_text ); } else { error_raw("%s", cp->str_text); } str_free(cp); } /* * execute the command if required */ if (option_test(OPTION_ACTION)) { /* * emit suitable progress stars */ if (option_test(OPTION_SILENT)) { if (echo_command(wlp)) star_eoln(); else star_bang(); } else star_sync(); /* * invalidate the stat cache */ if (option_test(OPTION_INVALIDATE_STAT_CACHE)) { size_t j; for (j = 0; j < wlp->nstrings; ++j) if (os_clear_stat(wlp->string[j])) status = opcode_status_error; } /* * prepare for metering */ #ifdef HAVE_WAIT3 if (option_test(OPTION_METER)) { if (!ocp->meter_p) ocp->meter_p = meter_alloc(); meter_begin(ocp->meter_p); } #endif /* * run the command */ status = spawn(wlp, isp, &ocp->pid, ocp->host_binding, ocp); if (status == opcode_status_wait) { trace(("...wait\n")); ocp->wlp = wlp; wlp = 0; goto done; } if (status == opcode_status_error) goto done; resume: /* * Finish metering. */ #ifdef HAVE_WAIT3 if (option_test(OPTION_METER)) { assert(ocp->meter_p); meter_print(ocp->meter_p); } #endif /* * Echo the exit status of the command, if it was not * successful. The error flag will also be examined (it * changes the text of the message, too) to see if we * should terminate successfully or with and error. */ cmd = (wlp->nstrings ? wlp->string[0]->str_text : ""); if ( exit_status ( cmd, ocp->exit_status, option_test(OPTION_ERROK) ) ) { status = opcode_status_error; } } /* * rescind the flag settings */ option_undo_level(OPTION_LEVEL_EXECUTE); /* * release the arguments and exit */ done: if (flags_words) string_list_delete(flags_words); if (flags) flag_delete(flags); if (wlp) string_list_delete(wlp); if (isp) str_free(isp); trace(("return %s;\n", opcode_status_name(status))); trace(("}\n")); return status; }