static int do_cmd(char **cmd, int *i) { char **tab; int j; int ac; j = -1; if (cmd) while (cmd[++j]) { tab = ft_strsplit3(cmd[j], ' ', '\t', '"'); if (tab && *tab) { ac = cmd_exit(tab, i); if (*i == 2) { ft_freetab(&tab); return (ac); } ac = builtins(tab); if (ac < 0) launch_bin(tab, g_env, 0); } ft_freetab(&tab); } return (0); }
static void parse_line(char *line_read) { gchar **argvp; int argcp; int i; if (line_read == NULL) { printf("\n"); cmd_exit(0, NULL); return; } line_read = g_strstrip(line_read); if (*line_read == '\0') return; add_history(line_read); g_shell_parse_argv(line_read, &argcp, &argvp, NULL); for (i = 0; commands[i].cmd; i++) if (strcasecmp(commands[i].cmd, argvp[0]) == 0) break; if (commands[i].cmd) commands[i].func(argcp, argvp); else printf("%s: command not found\n", argvp[0]); g_strfreev(argvp); }
int main(int argc, char **argv) { if (geteuid()) { fprintf(stderr, "You must be root to run this program or this program should be setuid root.\n"); return -1; } if (seteuid(getuid())) { /* drop root privs */ fprintf(stderr, "failed to drop root privileges\n"); exit(-1); } if (!isatty(fileno(stdin))) { fprintf(stderr, "pconsole: not a tty\n"); return -1; } printf("pconsole WJ101\n"); signal(SIGTERM, sig_exit); signal(SIGINT, sig_exit); if (argc > 1) cmd_attach(&argv[1]); pconsole(); cmd_exit(NULL); return 0; }
void handle_cli_commands(const std::string& line) { SWSS_LOG_ENTER(); SWSS_LOG_NOTICE("cli: %s", line.c_str()); // TODO this must be more smart, to split multiple spaces auto tokens = swss::tokenize(trim(line), ' '); if (tokens.size() < 1) { return; } const std::string& cmd = tokens[0]; if (cmd == "exit" || cmd == "quit") { cmd_exit(); } else if (cmd == "loglevel") { cmd_loglevel(tokens); } else if (cmd == "help") { cmd_help(tokens); } else { sendtoclient("unknown command: " + line + "\n"); } }
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal) { if (strcmp(cmdline, "mem") == 0 && cons->sht != 0) { cmd_mem(cons, memtotal); } else if (strcmp(cmdline, "cls") == 0 && cons->sht != 0) { cmd_cls(cons); } else if (strcmp(cmdline, "dir") == 0 && cons->sht != 0) { cmd_dir(cons, cmdline); } else if (strcmp(cmdline, "task") == 0) { cmd_task(); } else if (strcmp(cmdline, "exit") == 0) { cmd_exit(cons, fat); } else if (strncmp(cmdline, "start ", 6) == 0) { cmd_start(cons, cmdline, memtotal); } else if (strncmp(cmdline, "ncst ", 5) == 0) { cmd_ncst(cons, cmdline, memtotal); } else if (strncmp(cmdline, "langmode ", 9) == 0) { cmd_langmode(cons, cmdline); } else if (strncmp(cmdline, "taskmgr", 7) == 0) { open_taskmgr(memtotal); } else if (cmdline[0] != 0) { if (cmd_app(cons, fat, cmdline) == 0) { /* Ŀ�ǵ嵵 �ƴϰ�, ���ø����̼ǵ� �ƴϰ�, �� �൵ �ƴϴ� */ cons_putstr0(cons, "Bad command or file name.\n\n"); } } return; }
int main(int argc, const char *argv[]) { char cmd_str[CMDSTR_BUF_SIZE]; cmd_init(); if(argc > 1) { memset(cmd_str, 0, sizeof(cmd_str)); cmd_args(cmd_str, argc, argv); cmd_exit(); return 0; } cmd_welcome(); /*main loop*/ while (1) { memset(cmd_str, 0, sizeof(cmd_str)); if(next_cmd(cmd_str) == 0)/*loop through if '\n'*/ continue; if (cmd_is_exit(cmd_str)) break; if(cmd_is_batch(cmd_str)) { if(cmd_run_batch(cmd_str)!= SW_OK) cmd_batch_help(); } else { cmd_run_one(cmd_str); } } cmd_exit(); return 0; }
int main() { char input[CMD_MAX_LENGTH]; Command cmd; int exit_code = 0; char prompt[1024]; char hostname[256]; char cwd[256]; char *fgetsret = NULL; signal(SIGCHLD, sigchld_handler); gethostname(hostname, 256); getcwd(cwd, 256); setup_prompt(prompt, hostname, cwd); while(1) { printf("%s", prompt); fgetsret = fgets(input, CMD_MAX_LENGTH, stdin); if(fgetsret == NULL) return 0; delete_ending_newline(input); if(strlen(input) != 0) { if(cmd_exit(input, &exit_code)) return exit_code; init_command(&cmd); if(parse_members(input, &cmd) == 0 && parse_args(&cmd) == 0) { /* aff_members(&cmd); aff_args(&cmd); aff_redirect(&cmd); printf("----------\n"); */ exec_command(&cmd); } destroy_command(&cmd); } *input = '\0'; } return 0; }
void cmd_fun(int cmd_num) { if (cmd_num==0) { char *remote_addr= malloc(sizeof(char)*16); unsigned short int remote_port; printf("[cmd][enter ip] "); scanf("%s",&remote_addr); printf("\n[cmd][enter port] "); scanf("%u",&remote_port); printf("\n[info] Trying to connect to %s on port %u\n",remote_addr,remote_port); estb_conn(remote_addr,remote_port); } if (cmd_num==1) cmd_exit(); }
void inter_instr() { char opt; idx_cmd = 0; if (cmd == NULL || cmd[idx_cmd] == '\0') notif_error("No option"); opt = cmd[idx_cmd++]; if (opt == 'E') return cmd_exit(); next_arg(); if (opt == 'D') return cmd_delete(); if (opt == 'I') return cmd_insert(); if (opt == 'R') return cmd_replace(); notif_error("Invalid option"); }
/** * Handle the built in commands: cd and exit. */ int handle_builtin(char *args[ARGS_SIZE]) { if (strcmp(args[0], BI_CD) == 0) { cmd_cd(args); return TRUE; } else if (strcmp(args[0], BI_EXIT) == 0) { cmd_exit(); return TRUE; } else if (strcmp(args[0], BI_CHKENV) == 0) { cmd_check_env(args); return TRUE; } return FALSE; }
void parse_input(char *cmd) { if(strcmp("ps", cmd) == 0) { cmd_ps(); } else if (strcmp("lsdev", cmd) == 0) { cmd_lsdev(); } else if (strncmp("ls ", cmd, 3) == 0) { cmd_ls(cmd + 3); } else if (strcmp("exit", cmd) == 0) { cmd_exit(); } else if (strcmp("testmt", cmd) == 0) { cmd_testmt(); } else if (strncmp("cat ", cmd, 4) == 0) { cmd_cat(cmd + 4); } else if (strncmp("stat ", cmd, 5) == 0) { cmd_stat(cmd + 5); } else if (strncmp("elf ", cmd, 4) == 0) { cmd_elf(cmd + 4); } }
/********************************************************************** * %FUNCTION: cmd_handler * %ARGUMENTS: * es -- event selector * fd -- file descriptor * buf -- buffer which was read * len -- length of data * flag -- flags * data -- not used * %RETURNS: * Nothing * %DESCRIPTION: * Processes a command from the user ***********************************************************************/ static void cmd_handler(EventSelector *es, int fd, char *buf, int len, int flag, void *data) { char word[512]; if (flag == EVENT_TCP_FLAG_IOERROR || flag == EVENT_TCP_FLAG_TIMEOUT) { close(fd); return; } if (len < 511) { buf[len+1] = 0; } else { buf[len] = 0; } /* Chop off newline */ if (len && (buf[len-1] == '\n')) { buf[len-1] = 0; } /* Get first word */ buf = (char *) l2tp_chomp_word(buf, word); if (!strcmp(word, "exit")) { cmd_exit(es, fd); } else if (!strcmp(word, "start-session")) { cmd_start_session(es, fd, buf); } else if (!strcmp(word, "stop-session")) { cmd_stop_session(es, fd, buf); } else if (!strcmp(word, "dump-sessions")) { cmd_dump_sessions(es, fd, buf); } else { cmd_reply(es, fd, "ERR Unknown command"); } }
static void parse_line(char *line_read) { gchar *argvp[10]; int argcp; int i; if (line_read == NULL) { printf("\n"); cmd_exit(0, NULL); return; } line_read = g_strstrip(line_read); if (*line_read == '\0') return; for (i = 0; i < 10; i++) { if (*line_read) { argvp[i] = line_read++; while (*line_read && *line_read != ' ') line_read++; while (*line_read && *line_read == ' ') *line_read++ = '\0'; } else break; } argcp = i; for (i = 0; commands[i].cmd; i++) if (strcasecmp(commands[i].cmd, argvp[0]) == 0) break; if (commands[i].cmd) commands[i].func(argcp, argvp); else printf("%s: command not found\n", argvp[0]); }
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal) { if (strcmp(cmdline, "mem") == 0 && cons->sht != 0) { cmd_mem(cons, memtotal); } else if (strcmp(cmdline, "cls") == 0 && cons->sht != 0) { cmd_cls(cons); } else if (strcmp(cmdline, "dir") == 0 && cons->sht != 0) { cmd_dir(cons); } else if (strncmp(cmdline, "type ", 5) == 0 && cons->sht != 0) { cmd_type(cons, fat, cmdline); } else if (strcmp(cmdline, "exit") == 0) { cmd_exit(cons, fat); } else if (strncmp(cmdline, "start ", 6) == 0) { cmd_start(cons, cmdline, memtotal); } else if (strncmp(cmdline, "ncst ", 5) == 0) { cmd_ncst(cons, cmdline, memtotal); } else if (cmdline[0] != 0) { if (cmd_app(cons, fat, cmdline) == 0) { /* コマンドではなく、アプリでもなく、さらに空行でもない */ cons_putstr0(cons, "Bad command.\n\n"); } } return; }
LRESULT FAR PASCAL _export MainWndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; int keys; extern int ser_ver,xmove; keys=0; if (GetAsyncKeyState(VK_SHIFT)&0x8000) keys|=1; if (GetAsyncKeyState(VK_CONTROL)&0x8000) keys|=2; switch (message) { case WM_SYSKEYDOWN: case WM_KEYDOWN: switch ((int)wParam) { case 27: cmd(CL_CMD_RESET,0,0); show_shop=0; noshop=QSIZE*12; xmove=0; break; //ESC case 'p': if (keys) button_command(16); else cmd(CL_CMD_MODE,2,0); break; //F1 case 'q': if (keys) button_command(17); else cmd(CL_CMD_MODE,1,0); break; //F2 case 'r': if (keys) button_command(18); else cmd(CL_CMD_MODE,0,0); break; //F3 case 's': if (keys) button_command(19); else pdata.show_proz=1-pdata.show_proz; break; //F4 case 't': if (keys) button_command(20); //F5 else do_alpha++; if (do_alpha==3) do_alpha=0; dd_invalidate_alpha(); break; case 'u': if (keys) button_command(21); else pdata.hide=1-pdata.hide; break; //F6 case 'v': if (keys) button_command(22); else pdata.show_names=1-pdata.show_names; break;//F7 case 'w': if (keys) button_command(23);break; //F8 case 'x': if (keys) button_command(24); else dd_savescreen(); break; //F9 case 'y': if (keys) button_command(25); else { gamma+=250; if (gamma>6000) gamma=5000; xlog(2,"Set gamma correction to %1.2f",gamma/5000.0); dd_invalidate_cache(); } break; // F10 case 'z': if (keys) button_command(26); else { xlog(2," "); //F11 xlog(2,"Client Version %d.%02d.%02d",VERSION>>16,(VERSION>>8)&255,VERSION&255); xlog(2,"Server Version %d.%02d.%02d",ser_ver>>16,(ser_ver>>8)&255,ser_ver&255); xlog(2,"MAXX=%d, MAXY=%d, MAXXO=%d",MAXX,MAXY,MAXXOVER); xlog(2,"R=%04X, G=%04X, B=%04X",RED,GREEN,BLUE); xlog(2,"RGBM=%d",RGBM); xlog(2,"MAXCACHE=%d",MAXCACHE); xlog(2,"Hit=%d, Miss=%d, Invis=%d",dd_cache_hit,dd_cache_miss,invisible); xlog(2,"Ratio=%.2f%%",100.0/(dd_cache_hit+dd_cache_miss)*dd_cache_hit); xlog(2,"Skip=%d%% Idle=%d%%",pskip,pidle); xlog(2,"MaxMem=%dK, UsedMem=%dK",maxmem>>10,usedmem>>10); xlog(2,"MemBlocks=%d (T=%d,GC=%d)",blockcnt,blocktot,blockgc); xlog(2,"MaxVid=%dK, UsedVid=%dK",(maxvid*32*32*2)>>10,(usedvid*32*32*2)>>10); xlog(2,"cachex=%d, cachey=%d, MAXXOVER=%d",cachex,cachey,MAXXOVER); xlog(2,"usedvidmemflag=%d",usedvidmem); xlog(2,"alphapix=%d, fullpix=%d, ratio=%.2f",alphapix,fullpix,100.0/(alphapix+fullpix+1)*alphapix); // do_ticker=1-do_ticker; } break; case '{': if (keys) button_command(27); else cmd_exit(); break; //F12 // text editor case 9: complete_word(); break; case 8: if (cur_pos && in_len) { //BACKSPACE if (tabmode) { in_len=cur_pos; tabmode=0; tabstart=0; } if (cur_pos>in_len) cur_pos=in_len; memmove(input+cur_pos-1,input+cur_pos,120-cur_pos); in_len--; cur_pos--; } break; case 46: if (in_len) { // DEL if (tabmode) { in_len=cur_pos; tabmode=0; tabstart=0; } else { memmove(input+cur_pos,input+cur_pos+1,120-cur_pos); in_len--; } } break; case 33: if (logstart<22*8) { logstart+=11; logtimer=TICKS*30; } break; case 34: if (logstart>0) { logstart-=11; logtimer=TICKS*30; } break; case 36: cur_pos=0; tabmode=0; tabstart=0; break; // HOME case 35: cur_pos=in_len; tabmode=0; tabstart=0; break; // END case 37: if (cur_pos) cur_pos--; tabmode=0; tabstart=0; break; case 39: if (cur_pos<115) cur_pos++; tabmode=0; tabstart=0; break; case 38: if (hist_nr<19) { memcpy(history[hist_nr],input,128); hist_len[hist_nr]=in_len; hist_nr++; memcpy(input,history[hist_nr],128); in_len=cur_pos=hist_len[hist_nr]; tabmode=0; tabstart=0; } break; case 40: if (hist_nr>0) { memcpy(history[hist_nr],input,128); hist_len[hist_nr]=in_len; hist_nr--; memcpy(input,history[hist_nr],128); in_len=cur_pos=hist_len[hist_nr]; tabmode=0; tabstart=0; } break; /* default: xlog(3,"key=%d",(int)wParam); break;*/ } break; case WM_CHAR: switch ((int)wParam) { case 13: if (in_len==0) break; if (tabmode) { tabmode=0; tabstart=0; in_len--; } memmove(history[2],history[1],18*128); memmove(&hist_len[2],&hist_len[1],sizeof(int)*18); memcpy(history[1],input,128); hist_len[1]=in_len; input[in_len]=0; in_len=0; cur_pos=0; view_pos=0; hist_nr=0; add_words(); say(input); break; default: if ((int)wParam>31 && (int)wParam<128 && in_len<115) { if (tabmode) { if (!isalnum((char)wParam)) in_len--; cur_pos=in_len; tabmode=0; tabstart=0; } if (cur_pos>in_len) cur_pos=in_len; memmove(input+cur_pos+1,input+cur_pos,120-cur_pos); input[cur_pos]=(char)wParam; in_len++; cur_pos++; } break; } break; case WM_PAINT: BeginPaint(hWnd,&ps); EndPaint(hWnd,&ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_MOUSEMOVE: mouse(LOWORD(lParam),HIWORD(lParam),MS_MOVE); mx=LOWORD(lParam); my=HIWORD(lParam); break; case WM_LBUTTONDOWN: mouse(LOWORD(lParam),HIWORD(lParam),MS_LB_DOWN); break; case WM_LBUTTONUP: mouse(LOWORD(lParam),HIWORD(lParam),MS_LB_UP); break; case WM_RBUTTONDOWN: mouse(LOWORD(lParam),HIWORD(lParam),MS_RB_DOWN); break; case WM_RBUTTONUP: mouse(LOWORD(lParam),HIWORD(lParam),MS_RB_UP); break; default: return(DefWindowProc(hWnd, message, wParam, lParam)); } return 0; }
void console_task(struct SHEET *sheet, int memtotal) { struct TASK *task = task_now(); struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; int i, *fat = (int *) memman_alloc_4k(memman, 4 * 2880); struct CONSOLE cons; struct FILEHANDLE fhandle[8]; char cmdline[30]; cons.sht = sheet; cons.cur_x = 8; cons.cur_y = 28; cons.cur_c = -1; task->cons = &cons; if (cons.sht != 0) { cons.timer = timer_alloc(); timer_init(cons.timer, &task->fifo, 1); timer_settime(cons.timer, 50); } file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); for (i = 0; i < 8; i++) { fhandle[i].buf = 0; /* 未使用マーク */ } task->fhandle = fhandle; task->fat = fat; /* プロンプト表示 */ cons_putchar(&cons, '>', 1); for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { task_sleep(task); io_sti(); } else { i = fifo32_get(&task->fifo); io_sti(); if (i <= 1 && cons.sht != 0) { /* カーソル用タイマ */ if (i != 0) { timer_init(cons.timer, &task->fifo, 0); /* 次は0を */ if (cons.cur_c >= 0) { cons.cur_c = COL8_FFFFFF; } } else { timer_init(cons.timer, &task->fifo, 1); /* 次は1を */ if (cons.cur_c >= 0) { cons.cur_c = COL8_000000; } } timer_settime(cons.timer, 50); } if (i == 2) { /* カーソルON */ cons.cur_c = COL8_FFFFFF; } if (i == 3) { /* カーソルOFF */ if (cons.sht != 0) { boxfill8(cons.sht->buf, cons.sht->bxsize, COL8_000000, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15); } cons.cur_c = -1; } if (i == 4) { /* コンソールの「×」ボタンクリック */ cmd_exit(&cons, fat); } if (256 <= i && i <= 511) { /* キーボードデータ(タスクA経由) */ if (i == 8 + 256) { /* バックスペース */ if (cons.cur_x > 16) { /* カーソルをスペースで消してから、カーソルを1つ戻す */ cons_putchar(&cons, ' ', 0); cons.cur_x -= 8; } } else if (i == 10 + 256) { /* Enter */ /* カーソルをスペースで消してから改行する */ cons_putchar(&cons, ' ', 0); cmdline[cons.cur_x / 8 - 2] = 0; cons_newline(&cons); cons_runcmd(cmdline, &cons, fat, memtotal); /* コマンド実行 */ if (cons.sht == 0) { cmd_exit(&cons, fat); } /* プロンプト表示 */ cons_putchar(&cons, '>', 1); } else { /* 一般文字 */ if (cons.cur_x < 240) { /* 一文字表示してから、カーソルを1つ進める */ cmdline[cons.cur_x / 8 - 2] = i - 256; cons_putchar(&cons, i - 256, 1); } } } /* カーソル再表示 */ if (cons.sht != 0) { if (cons.cur_c >= 0) { boxfill8(cons.sht->buf, cons.sht->bxsize, cons.cur_c, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15); } sheet_refresh(cons.sht, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16); } } } }
/* Menu */ static int menu_run(void) { adv_bool done; int userkey; menu_base = 0; menu_rel = 0; menu_rel_max = MENU_DY; menu_max = crtc_container_max(&the_modes); menu_base_max = menu_max - menu_rel_max; if (menu_base_max < 0) menu_base_max = 0; done = 0; while (!done) { draw_text_index(BAR_X, BAR_Y1+1, BAR_DX); draw_text_bar(BAR_X, BAR_Y1, BAR_Y2, BAR_DX); draw_text_info(INFO_X, INFO_Y, INFO_DX, INFO_DY, menu_base + menu_rel); menu_draw(MENU_X, MENU_Y, MENU_DX, MENU_DY); video_wait_vsync(); target_idle(); os_poll(); userkey = inputb_get(); switch (userkey) { case INPUTB_UP: cmd_gotopos(menu_base + menu_rel - 1); break; case INPUTB_DOWN: cmd_gotopos(menu_base + menu_rel + 1); break; case INPUTB_HOME: { int i = menu_base + menu_rel - 1; if (i<0) i = 0; while (i>0 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0)) --i; cmd_gotopos(i); break; } case INPUTB_END: { int i = menu_base + menu_rel + 1; if (i >= menu_max) i = menu_max - 1; while (i < menu_max - 1 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0)) ++i; cmd_gotopos(i); break; } case INPUTB_PGDN: cmd_gotopos(menu_base + menu_rel + menu_rel_max); break; case INPUTB_PGUP: cmd_gotopos(menu_base + menu_rel - menu_rel_max); break; case INPUTB_F2: cmd_save(); break; case INPUTB_LEFT : case INPUTB_RIGHT : cmd_type(userkey); break; case INPUTB_ESC: done = cmd_exit(); break; case INPUTB_SPACE: cmd_select(); cmd_gotopos(menu_base + menu_rel + 1); break; case INPUTB_ENTER: if (cmd_onvideo_test() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F9: if (cmd_onvideo_calib() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F10: if (cmd_onvideo_animate() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_TAB : cmd_rename(); break; case INPUTB_F5 : if (cmd_modeline_create(1) !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F6 : if (cmd_modeline_create(0) !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F7 : cmd_copy(); break; case INPUTB_F8 : if (cmd_mode_clock() !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_DEL : cmd_del(); cmd_gotopos(menu_base + menu_rel); break; case INPUTB_F1: draw_text_help(); break; default: if (cmd_offvideo_test(userkey) != 0) { draw_text_error(); } break; } } return userkey; }
void console_task(struct SHEET *sheet, int memtotal) { struct TASK *task = task_now(); struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; int i, *fat = (int *) memman_alloc_4k(memman, 4 * 2880); struct CONSOLE cons; struct FILEHANDLE fhandle[8]; char cmdline[30]; unsigned char *nihongo = (char *) *((int *) 0x0fe8); cons.sht = sheet; cons.cur_x = 8; cons.cur_y = 28; cons.cur_c = -1; task->cons = &cons; task->cmdline = cmdline; if (cons.sht != 0) { cons.timer = timer_alloc(); timer_init(cons.timer, &task->fifo, 1); timer_settime(cons.timer, 50); } file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); for (i = 0; i < 8; i++) { fhandle[i].buf = 0; /* �̻�� ��ũ */ } task->fhandle = fhandle; task->fat = fat; if (nihongo[4096] != 0xff) { /* �Ϻ��� ��Ʈ ������ �о���� �� �־�����? */ task->langmode = 1; } else { task->langmode = 0; } task->langbyte1 = 0; /* prompt ǥ�� */ cons_putchar(&cons, '>', 1); for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { task_sleep(task); io_sti(); } else { i = fifo32_get(&task->fifo); io_sti(); if (i <= 1 && cons.sht != 0) { /* Ŀ���� Ÿ�̸� */ if (i != 0) { timer_init(cons.timer, &task->fifo, 0); /* ������ 0�� */ if (cons.cur_c >= 0) { cons.cur_c = COL8_FFFFFF; } } else { timer_init(cons.timer, &task->fifo, 1); /* ������ 1�� */ if (cons.cur_c >= 0) { cons.cur_c = COL8_000000; } } timer_settime(cons.timer, 50); } if (i == 2) { /* Ŀ�� ON */ cons.cur_c = COL8_FFFFFF; } if (i == 3) { /* Ŀ�� OFF */ if (cons.sht != 0) { boxfill8(cons.sht->buf, cons.sht->bxsize, COL8_000000, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15); } cons.cur_c = -1; } if (i == 4) { /* �ܼ��� ��������ư Ŭ�� */ cmd_exit(&cons, fat); } if (256 <= i && i <= 511) { /* Ű���� ������(�½�ũ A����) */ if (i == 8 + 256) { /* �� �����̽� */ if (cons.cur_x > 16) { /* �����̽��� ����� ���� Ŀ���� 1�� back */ cons_putchar(&cons, ' ', 0); cons.cur_x -= 8; } } else if (i == 10 + 256) { /* Enter */ /* �����̽��� ����� ���� �����Ѵ� */ cons_putchar(&cons, ' ', 0); cmdline[cons.cur_x / 8 - 2] = 0; cons_newline(&cons); cons_runcmd(cmdline, &cons, fat, memtotal); /* Ŀ�ǵ� ���� */ if (cons.sht == 0) { cmd_exit(&cons, fat); } /* prompt ǥ�� */ cons_putchar(&cons, '>', 1); } else { /* �Ϲ� ���� */ if (cons.cur_x < 240) { /* �� ���� ǥ���ϰ� ����, Ŀ���� 1�� �����Ѵ� */ cmdline[cons.cur_x / 8 - 2] = i - 256; cons_putchar(&cons, i - 256, 1); } } } /* Ŀ����ǥ�� */ if (cons.sht != 0) { if (cons.cur_c >= 0) { boxfill8(cons.sht->buf, cons.sht->bxsize, cons.cur_c, cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15); } sheet_refresh(cons.sht, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16); } } } }
void LGNetwork::set_mode(network_mode_t newMode) { cmd_enter(); cmd_reset(); cmd_setup(); cmd_set_channel(newMode); if(newMode == LGNETWORK_OPERATE) { #ifdef USE_NETWORK_SERVER cmd_set_short_address(-1); cmd_set_target_short_address(-1); cmd_set_coordinator(); #elif USE_NETWORK_CLIENT uint16_t short_addr = LGDB::read_address(); cmd_set_short_address(short_addr); // It will either be something we want, or -1 cmd_set_coordinator(); #endif } else { // LGNETWORK_DISCOVER #ifdef USE_NETWORK_SERVER cmd_set_short_address(-1); cmd_set_target_short_address(-1); cmd_set_coordinator(); // Get my uuid // Read the UUID (serial address) char ascii_id[17]; for(int i=0; i < sizeof(ascii_id); i++) ascii_id[i] = '0'; ascii_id[16] = 0; LGSerial::print_pgm( PSTR("ATSH") ); // Starting with the upper bits uint8_t high_chars_to_write = LGSerial::get(response_buf, '\r', 16) - 1; memcpy(ascii_id + (8 - high_chars_to_write), response_buf, high_chars_to_write); // Now the lower bits LGSerial::print_pgm( PSTR("ATSL") ); uint8_t low_chars_to_write = LGSerial::get(response_buf, '\r', 16) - 1; memcpy(ascii_id + 8 + (8 - low_chars_to_write), response_buf, low_chars_to_write); uint8_t *p = (uint8_t*)&(LGNetwork::myUUID); // Ptr to current byte for(int i=0; i < 16; i+=2) { // Convert to bin *(p++) = asciis_to_byte(ascii_id + i); } #elif USE_NETWORK_CLIENT cmd_set_short_address(-1); cmd_set_target_short_address(-1); cmd_set_coordinator(); #ifdef CLIENT_SENSOR LGSerial::print_pgm( PSTR("ATNIs") ); cmd_wait_for_ok(); #elif CLIENT_ACTUATOR LGSerial::print_pgm( PSTR("ATNIa") ); cmd_wait_for_ok(); #endif #endif } cmd_exit(); currentMode = newMode; }
void LGNetwork::loop() { if(currentMode == LGNETWORK_DISCOVER) { #ifdef USE_NETWORK_SERVER if(pending_is_empty()){ cmd_enter(); cmd_get_one_unassociated_device(); cmd_exit(); } else { // We can operate on the pending device, by assigning it an address int8_t next_address = (int8_t)get_next_free_address(); if(next_address >= 0 && next_address < 100) { // We found a valid address // Send it the association packet dhcp_packet_t p; p.packet.base_address = LGNetwork::myUUID; p.packet.short_address = next_address; // Point ourselves to our target. cmd_enter(); cmd_set_target_long_address(next_client.address); cmd_exit(); sleep(3000); // Packet header LGSerial::slow_put("SYN"); // Send the packet body for(int i=0; i < sizeof(dhcp_packet_t); i++) { LGSerial::slow_put(p.bytes[i]); } bool response = scan_for_header("SAK", 10000); if(response) { // Now commit it to EEPROM if(next_client.identifier == 's') LGDB::write_device_table_entry(next_address, 1); else LGDB::write_device_table_entry(next_address, 0); for(uint8_t i=0; i < 7; i++) { LGDB::write_schedule_table_entry(next_address, i, 0); } // Send final ack sleep(1000); LGSerial::slow_put("ACK"); } // We clear it since we're done pending_clear(); } } #endif #if USE_NETWORK_CLIENT if(LGSerial::available()) { bool matches = scan_for_header("SYN", 1000); if(matches) { // Receive packet char *ptr = (char*)&(LGNetwork::baseUUID); for(uint8_t i=0; i < sizeof(LGNetwork::baseUUID); i++) { char c = LGSerial::get();; *(ptr++) = c; } LGNetwork::myShortAddr = LGSerial::get(); // Reply to the server cmd_enter(); cmd_set_long_address_to_basestation(); cmd_set_short_address(LGNetwork::myShortAddr); cmd_dissociate(); cmd_exit(); // Give it time to associate sleep(3000); // SYN-ACK LGSerial::slow_put_pgm( PSTR("SAK") ); // Hopefully the server saw us matches = scan_for_header("ACK", 3000); if(matches) { // Persist to eeprom LGDB::write_address(LGNetwork::myShortAddr); LGDB::write_basestation_address(LGNetwork::baseUUID); currentMode = LGNETWORK_DISCOVER_READY; } else { cmd_enter(); cmd_set_short_address(-1); cmd_exit(); } } } #endif } else { // LGNETWORK_OPERATE #ifdef USE_NETWORK_SERVER // See if anybody's up uint8_t hour = GetHour(); if(GetAmPm()) hour += 12; // Convert to 24 hour time uint8_t minute = GetMinute(); uint16_t theTime = hour*60 + minute; uint8_t day = GetDay(); // LGSerial::put("Time is "); // LGSerial::print(hour); // LGSerial::print(minute); // LGSerial::print(theTime); uint8_t motion_sensor_idx = 0xFF; if(LGSerial::available()) { // We got a byte motion_sensor_idx = LGSerial::get(); } for(uint8_t i=0; i < sizeof(lgdb_device_table); i++) { if(LGDB::read_device_table_entry(i) != 0) { continue; } uint16_t device_on = 60*LGDB::read_hour(i, day, true) + LGDB::read_minute(i, day, true); // Read ontime uint16_t device_off = 60*LGDB::read_hour(i, day, false) + LGDB::read_minute(i, day, false); uint8_t autodevice = LGDB::read_sensor_table_entry(i, day); // LGSerial::put("Device "); // LGSerial::print(i); // LGSerial::put("On "); // LGSerial::print(device_on); // LGSerial::put("Off "); // LGSerial::print(device_off); // Events: Turn Off, Turn On, Respond to Auto if(device_off == theTime) { // Turn off // LGSerial::put("OFF "); // LGSerial::print(i); set_remote(i, SYSTEM_OFF); } else if(device_on == theTime) { if(autodevice == 0xFF) { // Turn on // LGSerial::put("ON "); // LGSerial::print(i); set_remote(i, SYSTEM_ON); } else { // LGSerial::put("AUTO "); // LGSerial::print(i); set_remote(i, SYSTEM_AUTO_OFF); } } else if(theTime >= device_on && theTime < device_off) { if(autodevice != 0xFF) { // LGSerial::print("Auto"); // LGSerial::put("Entry "); // LGSerial::print(LGDB::read_schedule_table_entry(autodevice, day)); if(motion_sensor_idx == autodevice) { // LGSerial::print("We got a sensor reading"); // We got a byte from the sensor set_remote(i, SYSTEM_AUTO_ON); LGDB::write_schedule_table_entry(autodevice, day, theTime); // Remember the time } else if( (LGDB::read_schedule_table_entry(autodevice, day) + 5) < theTime ) { // It's been an hour // LGSerial::print("It's been an hour"); set_remote(i, SYSTEM_AUTO_OFF); } } } } // } // int8_t next_to_program = get_next_target_address(); // LGSerial::put("Next: "); // LGSerial::print(next_to_program); // if(next_to_program >= 0) { // uint16_t data = LGDB::read_device_table_entry(next_to_program); // command_packet_t p; // p.packet.short_address = next_to_program; // p.packet.system_mode = SYSTEM_ON; // // Header // LGSerial::slow_put_pgm( PSTR("CMD") ); // // Body // for(uint8_t i=0; i < sizeof(command_packet_t); i++) { // LGSerial::slow_put(p.bytes[i]); // } // // Remember our success // last_commanded_device_address = next_to_program; // } #endif } }
int main (int argc, char *argv[]) { setvbuf(stdout, NULL, _IONBF, 0); // need this to see i/o at all char *buf, *init_name, *output_name, *p; const char *cmdpnt; FILE *init_file; int i, len, rdonly, recover, siz; String *cmdstr; uLong sts; if (argc > 0) pn = argv[0]; fprintf (stderr, "Copyright (C) 2001,2002,2003,2004 Mike Rieker, Beverly, MA USA\n" "Version 2004-06-10, EDT comes with ABSOLUTELY NO WARRANTY\n" "EXPECT it to FAIL when someone's HeALTh or PROpeRTy is at RISk\n\n"); fflush (stderr); /* Parse command line */ init_name = NULL; input_name = NULL; journal_file = NULL; journal_name = NULL; output_name = NULL; rdonly = 0; recover = 0; recover_file = NULL; recover_name = NULL; for (i = 1; i < argc; i ++) { /* -init <file> : process the given initialization file */ if (strcasecmp (argv[i], "-init") == 0) { if (++ i >= argc) goto usage; if (argv[i][0] == '-') goto usage; if (init_name != NULL) goto usage; init_name = argv[i]; continue; } /* -journal <file> : write journal to specified file */ /* by default, it gets written to <output_file>.edtj */ if (strcasecmp (argv[i], "-journal") == 0) { if (++ i >= argc) goto usage; if (argv[i][0] == '-') goto usage; journal_name = argv[i]; continue; } /* -noinit : don't process default init file */ if (strcasecmp (argv[i], "-noinit") == 0) { if (init_name != NULL) goto usage; init_name = ""; continue; } /* -output <file> : write output to specified file */ /* by default, it gets written to <input_file> */ if (strcasecmp (argv[i], "-output") == 0) { if (++ i >= argc) goto usage; if (argv[i][0] == '-') goto usage; output_name = argv[i]; continue; } /* -readonly : don't write an output file */ if (strcasecmp (argv[i], "-readonly") == 0) { if (output_name == input_name) output_name = NULL; rdonly = 1; continue; } /* -recover [<file>] : process recovery from file */ /* by default, recovery is processed from <input_file>.edtj */ if (strcasecmp (argv[i], "-recover") == 0) { recover = 1; if (i + 1 == argc) continue; if (argv[i+1][0] == '-') continue; if ((input_name != NULL) || (i + 2 <= argc)) recover_name = argv[++i]; continue; } /* No more options */ if (argv[i][0] == '-') goto usage; /* first and only parameter <file> : input filename */ if (input_name == NULL) { input_name = argv[i]; if (!rdonly) output_name = input_name; continue; } goto usage; } /* Open recovery file */ if (recover && (input_name == NULL)) { fprintf (stderr, "no input file specified to recover\n"); return (-1); } if (recover && (recover_name == NULL)) recover_name = os_makejnlname (input_name); if (recover_name != NULL) { recover_file = fopen (recover_name, "r"); if (recover_file == NULL) { fprintf (stderr, "error opening recovery file %s: %s\n", recover_name, strerror (errno)); return (-1); } } /* Create journal file */ if ((output_name != NULL) && (journal_name == NULL)) journal_name = os_makejnlname (output_name); if (journal_name != NULL) { journal_file = os_crenewfile (journal_name); if (journal_file == NULL) { fprintf (stderr, "error creating journal file %s: %s\n", journal_name, strerror (errno)); return (-1); } } /* Initialize os dependent routines. No using stdin/stdout/stderr from now on. */ os_initialization (); /* If input file was given, read it into a buffer and mark that buffer for writing on exit */ if (input_name != NULL) { p = input_name; if (rdonly) { p = malloc (strlen (input_name) + 12); strcpy (p, "-readonly "); strcat (p, input_name); } cmd_open (p); if (p != input_name) free (p); cur_position.line = buffer_first_line (cur_position.buffer); cur_position.offset = 0; } /* Otherwise, allocate initial 'MAIN' buffer with no lines in it */ else { cur_position.buffer = buffer_create (4, "MAIN"); cur_position.line = NULL; cur_position.offset = 0; } /* Either way, that is the one used by the EXIT command */ main_buffer = cur_position.buffer; if (output_name != NULL) buffer_setfile (main_buffer, output_name); /* Process initialization file */ if (init_name == NULL) init_name = os_defaultinitname (); /* if no -noinit or -init, get default name */ if ((init_name != NULL) && (init_name[0] != 0)) { init_file = fopen (init_name, "r"); /* try to open init file */ if (init_file != NULL) { siz = 256; /* start with 256 byte buffer */ buf = malloc (siz); len = 0; /* don't have anything in it */ while (fgets (buf + len, siz - len, init_file) != NULL) { /* read onto end of what's there */ len += strlen (buf + len); /* get total length */ if (len == 0) break; /* stop if nothing there (eof?) */ if (buf[len-1] != '\n') { /* check for line terminator */ siz += 256; /* didn't get the whole thing, increase buffer */ buf = realloc (buf, siz); /* ... then loop to read more of the line */ } else { buf[--len] = 0; /* got terminator, remove it from buffer */ cmdpnt = skipspaces (buf); /* skip leading spaces */ if (*cmdpnt != 0) ln_command (cmdpnt); /* process command line */ len = 0; /* empty line buffer for next read */ } } fclose (init_file); free (buf); } else if (errno != ENOENT) { outerr (strlen (init_name) + strlen (strerror (errno)), "error opening init file %s: %s\n", init_name, strerror (errno)); exit (-1); } } /* Type out line at current position to begin with */ cmd_type ("."); /* Read and process commands until eof */ i = 0; while (1) { cmdstr = jnl_readprompt ("\r\n*"); if (cmdstr == NULL) { /* prompt then read command line */ if (++ i < 3) outerr (0, "use either EXIT or QUIT to terminate\n"); else { outerr (12, "%d EOF's in a row or fatal terminal error, exiting ...\n", i); cmd_exit (""); exit (-1); } continue; } i = 0; for (cmdpnt = string_getval (cmdstr); *cmdpnt != 0; cmdpnt ++) if (*cmdpnt > ' ') break; if (*cmdpnt == 0) cmd_type (".+1"); /* blank line means 'type .+1' */ else ln_command (cmdpnt); /* process command */ string_delete (cmdstr); /* free the command string off */ } /* Bad command line parameter */ usage: fprintf (stderr, "usage: %s [-init <init_file>] [-journal <journal_output>] [-noinit] [-output <output_file>] [-readonly] [-recover [<journal_input>]] [<input_file>]\n", pn); return (-1); }
static void console_command_mode_run(void) { char szTemp[256]; char *str = NULL; int len = 0, i = 0; OS_PRINTF("\nEnter command mode. 'help' to show command list(non specific)\n"); OS_PRINTF("\nEnter command mode. 'spechelp' to show specific command list\n"); while (1) { if(get_console_mode() == DOWNLOAD_MODE) { OS_PRINTF("> "); } else { OS_PRINTF("Cmd > "); } get_command(szTemp); #ifdef ENABLE_CMD_HISTORY save_command(szTemp); #endif len = strlen(szTemp); if(len <= 0) { // do nothing continue; } // trim the space at the begin of the input for(i = 0; i < len; i++) { if(szTemp[i] != ' ') { str = &szTemp[i]; break; } } // trim the space at the end of the input for(i = len-1; i >= 0; i--) { if(szTemp[i] != ' ') { szTemp[i+1] = 0; break; } } len = strlen(str); if(len <= 0) { continue; // do nothing } else { int i = 0, j =0; int showhelp = 0; testfm_p_suite_t pSuite = NULL; testfm_p_cmd_t pTest = NULL; testfm_error_code_t res = TESTFM_SUCCESS; if(!(((str[0] >= 'a') && (str[0] <= 'z')) || ((str[0] >= 'A') && (str[0] <= 'Z')))) { OS_PRINTF("CMD should start with 'a-z' and 'A-Z'.\n"); continue; } for(i = 0; i < len-1; i++) { if((j == 0) && (str[i] == ' ')) { j = i; memset(parameter_str, 0, 256); memcpy(parameter_str, &str[i+1], strlen(&str[i+1])); } if((str[i] == '-') && (str[i+1] == 'h') && (str[i-1] == ' ') && (((i+2) == len) || (str[i+2] == ' '))) { showhelp = 1; break; } } if(j != 0) str[j] = 0; if(0 == memcmp(str, "help", 4)) { // list all non specific command cmd_help(); continue; } if(0 == memcmp(str, "wizardshelp", 11)) { // list all specific command cmd_help_specific(PLATFORM_WIZARD); continue; } if(0 == memcmp(str, "magichelp", 9)) { // list all specific command cmd_help_specific(PLATFORM_MAGIC); continue; } if(0 == memcmp(str, "warriorshelp", 12)) { // list all specific command cmd_help_specific(PLATFORM_WARRIORS); continue; } if(0 == memcmp(str, "anyhelp", 7)) { // list all specific command cmd_help_specific(PLATFORM_ANY); continue; } if(0 == memcmp(str, "read", 4)) { cmd_read(); continue; } if(0 == memcmp(str, "write", 5)) { //cmd_write(); continue; } if(get_console_mode() == DOWNLOAD_MODE) { if(0 == memcmp(str, "download", 8)) { cmd_download(); continue; } if(0 == memcmp(str, "go", 2)) { cmd_go(); continue; } if(0 == memcmp(str, "reboot", 6)) { cmd_reboot(); continue; } OS_PRINTF("'%s' is not recognized as an internal or external command.\n", str); continue; } if(0 == memcmp(str, "exit", 4)) { cmd_exit(); continue; } if(0 == memcmp(str, "runall", 6)) { cmd_runall(); continue; } if(0 == memcmp(str, "statistic", 9)) { cmd_statistic(); continue; } if(0 == memcmp(str, "autorun", 7)) { //cmd_autorun(); continue; } // add the reboot cmd for white box test if(0 == memcmp(str, "reboot", 6)) { cmd_reboot(); continue; } if(testfm_find_cmd(str, &pSuite, &pTest) == FALSE) { OS_PRINTF("'%s' is not recognized as an internal or external command.\n", str); } else { if(showhelp == 1) { pTest->pHelpFunc(); } else { //OS_PRINTF(", name: %s\n", pTest->pName); res = testfm_run_cmd(pSuite, pTest); if(res != TESTFM_SUCCESS) OS_PRINTF("error code: %d\n", res); } } } } }
int execCommand(char *cmd) { if (*cmd == '#') return 0; // remove comments int currentlyInString = 0; char *commentScan = cmd; while (*commentScan != 0) { if ((*commentScan) == '"') currentlyInString = !currentlyInString; else if (((*commentScan) == '#') && (!currentlyInString)) { *commentScan = 0; break; }; commentScan++; }; if (*cmd == 0) return 0; char processedCommand[1024]; char *put = processedCommand; char *scan = cmd; while (*scan != 0) { if (*scan == '\\') { scan++; if (*scan == 0) break; *put++ = *scan++; continue; } else if (*scan == '$') { char envname[256]; char *envnameput = envname; scan++; while (isalnum(*scan)) { *envnameput++ = *scan++; }; *envnameput = 0; char *value = getenv(envname); if (value != NULL) { strcpy(put, value); put += strlen(value); }; } else { *put++ = *scan++; }; }; *put = 0; int argc = 0; char **argv = NULL; char *nextToStrtok = processedCommand; while (1) { //char *token = strtok(nextToStrtok, nextSplitString); char *token = nextToStrtok; #if 0 nextToStrtok = NULL; if (token != NULL) { if (strlen(token) == 0) continue; }; #endif if (token != NULL) { while (isspace(*token)) token++; if (*token == 0) { token = NULL; } else { const char *termString = " \t"; if (*token == '"') { termString = "\""; token++; }; char *endpos = strpbrk(token, termString); if (endpos == NULL) { nextToStrtok = NULL; } else { *endpos = 0; nextToStrtok = endpos+1; }; }; }; int shouldAdd = 0; if (token == NULL) { shouldAdd = 1; } else { if (strlen(token) > 0) { shouldAdd = 1; }; }; if (shouldAdd) { argv = realloc(argv, sizeof(char*)*(argc+1)); argv[argc++] = token; }; if (token == NULL) break; }; if (argc == 1) return 0; if (strcmp(argv[0], "cd") == 0) { int status = cmd_cd(argc-1, argv); free(argv); return status; } else if (strcmp(argv[0], "exit") == 0) { int status = cmd_exit(argc-1, argv); free(argv); return status; } else if (strcmp(argv[0], "echo") == 0) { int status = cmd_echo(argc-1, argv); free(argv); return status; } else if (strcmp(argv[0], "diag") == 0) { _glidix_diag(); free(argv); return 0; }; char execpath[256]; if (findCommand(execpath, argv[0]) == -1) { free(argv); fprintf(stderr, "%s: command not found\n", argv[0]); return 1; }; pid_t pid = fork(); if (pid == 0) { if (execv(execpath, argv) != 0) { perror(argv[0]); return 1; }; // the compiler won't stop moaning otherwise. // even though execv() obviously doesn't return. return 0; } else { free(argv); shellChildPid = pid; int status; while (1) { int ret = waitpid(pid, &status, 0); // EINTR is the only possible error here, so if it occurs, try again. if (ret != -1) { break; }; }; shellChildPid = 0; if (WIFSIGNALLED(status)) { int termsig = WTERMSIG(status); switch (termsig) { case SIGSEGV: fprintf(stderr, "Invalid memory access\n"); break; case SIGSYS: fprintf(stderr, "Invalid system call\n"); break; }; }; return status; }; };
RETSIGTYPE sig_exit(int sig) { cmd_exit(NULL); exit(127 + sig); /* never reached... but hey */ }