void loop_states(void) { char c; for(;;) { for(;robot_state == CONNECTED;) { //wait for commands if(!bt_rx_empty()) { c = bt_get_block(); if (is_endchar(c)) { char buffer[128]; if (bt_get_command(buffer)) { // interpret command if (interpret_command(buffer) && robot_state == CONNECTED) { tty_puts("COMMAND: "); tty_puts(buffer); tty_puts("\r\n"); } } } } } for(;robot_state == DISCONNECTED;) { //loopback BLUETOOTH <--> UART1 interface (ttyUSB) if (!tty_rx_empty()) { c = tty_get_noblock(); bt_put(c); } if(!bt_rx_empty()) { c = bt_get_noblock(); tty_put(c); //still check for commands as connected disconnected if (is_endchar(c)) { char buffer[128]; if (bt_get_command(buffer)) { interpret_command(buffer); } } } } } }
void undo_command(){ int n; n =0; while (strcmp(history[n],"undo\n") != 0){ n++; } free(history[n]); int com,m; const char *canvas_file = "canvas.txt"; FILE *fp; if ((fp = fopen(canvas_file, "w")) == NULL) { fprintf(stderr, "error: cannot open %s.\n", canvas_file); } init_canvas(); print_canvas(fp); for(m = 0; m < n-1; m ++){ com = interpret_command(history[m]); if(strcmp(history[m],"undo\n") == 0) break; } }
int handle_command(char *command, char *response, int len) { if (command[0] == EOF) { strncpy(response, "all done", len - 1); return 0; } interpret_command(command, response, len); return 1; }
int #ifndef __WATCOMC__ __FrCDECL #endif main(int argc, char **argv) { #ifdef __WATCOMC__ FrDestroyWindow() ; // for Watcom, run as raw console app #endif /* __WATCOMC__ */ if (argc > 1) cout << argv[0] << " does not require any arguments." << endl << endl ; cout << "\tFramepaC " FramepaC_Version_string " Test Program" << endl << "\t==========================" << endl << "Use \"* ?\" to list the available commands." << endl ; // deliberately start with a tiny symbol table, to force table expansion as // we use the test program (in fact, the first expansion will happen during // initialization) #if 0 //#ifdef FrMOTIF Widget main_window = XtVaAppInitialize( &app_context, "Framepac Test Program", NULL, 0, &argc, argv, NULL, NULL); FrInitializeMotif("FramepaC Messages",main_window,16) ; #else initialize_FramepaC(16) ; #endif /* FrMOTIF */ FramepaC_set_userinfo_dir(0) ; // set default location FrObject *obj = 0 ; FrSymbol *symbolEOF = FrSymbolTable::add("*EOF*") ; do { if (obj) { obj->freeObject() ; // free the object from prev pass thru the loop obj = 0 ; } FramepaC_bgproc() ; // handle any asynchronous operations cout << "\nEnter a FrObject, NIL to end: " ; cin >> obj ; FramepaC_bgproc() ; // handle any asynchronous operations if (obj && obj->symbolp() && obj == FrSymbolTable::add("*")) interpret_command(cout,cin,True) ; else display_object_info(cout,obj) ; FramepaC_bgproc() ; // handle any asynchronous operations } while (!NIL_symbol(obj) && obj != symbolEOF) ; #if 0 //#ifdef FrMOTIF FrShutdownMotif() ; #else FrShutdown() ; #endif return 0 ; }
int main(int argc, char* argv[]){ char buf[MAXLINE + 3];//Extra 3 chars used for testing long lines FILE* input; if (argc > 2) { fprintf(stderr, "Usage: itsh [script]\n"); exit(1); } //Set up read - either stdin or script file if (argc == 2) { //Open file input = fopen(argv[1], "r"); if (!input) { fprintf(stderr, "File %s not found\n", argv[1]); exit(2); } } else { input = stdin; } //Set up signal handling //Ignore ctrl-c signals for parent and background children signal(SIGINT, SIG_IGN); //Use handler for child signal signal(SIGCHLD, background_handler); prompt(); while (fgets(buf, MAXLINE + 3, input) != NULL) { if (strlen(buf) > 129) { //Line too long fprintf(stderr, "Line too long - input limited to %d characters.\n", MAXLINE); //Read until newline - finish off too long line do { fgets(buf, MAXLINE, input); } while (!count_char(buf, '\n')); prompt(); continue; } //Cut off the newline character (for a properly sized command) buf[strlen(buf) - 1] = '\0'; if (strlen(buf) > 0) { interpret_command(buf); } prompt(); } return(0); }
int main(int ac, char **av, char **env) { t_cmd cmd; t_dict *dicts[DICT_COUNT]; (void)ac; (void)av; init_tokens(&dicts[TOKENS]); init_binaries(&dicts[BIN]); dicts[ENV] = envcpy(env); signals(); interpret_command(dicts, &cmd); destroy_array_dict(dicts, DICT_COUNT); cmd_free(&cmd); return (0); }
int main(int ac, char **av, char **env) { t_cmd cmd; t_dict *envc; (void)ac; (void)av; signal(SIGINT, sig_handler); envc = envcpy(env); init_tokens(); interpret_command(envc, &cmd); dict_destroy(g_tokens); dict_destroy(envc); cmd_free(&cmd); return (0); }
void main(int argc) { char input = 0; read(); while (1) { input = read_key(); /* blocking */ if (insert_mode == 1) { switch (input) { case '\n': insert_character(input); break_line(); break; case 0x7f: if (current_column > 0) { int current_char = 0; current_column -= 1; current_char = buffer[C(current_line, current_column)]; if (current_column >= 0 && current_char != EOF && current_char != EOL) { move_memory(buffer + C(current_line, current_column), -1, COLS - current_column - 1); buffer[C(current_line, COLS-1)] = 0; } } break; case 27: // esc insert_mode = 0; // set_string(notifications, "COMMAND"); break; default: if (input != 0) { insert_character(input); } break; } } else { if (interpret_command(input) == 1) { return 0; } } // update_notification_line(); send_display(buffer); /* give pointer to assembly function */ display(C(current_line, current_column), '_'); } }
void input_thread(void const * args) { keyboard->prompt(); keyboard->reset_command(); while(1) { keyboard->last_keyboard = pc.getc(); keyboard->read_char(keyboard->last_keyboard); if (keyboard->last_keyboard != '\r') { pc.putc(keyboard->last_keyboard); } if (keyboard->last_keyboard == '\r' || keyboard->command_complete()) { interpret_command(); keyboard->reset_command(); keyboard->prompt(); } } }
int main(void) { OSCCONbits.IRCF = 0b1111; // 0b1111 = 16MHz HFINTOSC postscaler ANSELA = 0x00; // digital I/O on PORTA ANSELB = 0x00; // digital I/O on PORTB ANSELC = 0x00; // digital I/O on PORTC APFCON = 0x00; // a little bit of voodoo MODE_SW_TRIS = PIN_OUTPUT; MODE_SW = POTENTIOSTATIC; // initialize mode to potentiostatic CELL_ON_TRIS = PIN_OUTPUT; CELL_ON_PIN = CELL_OFF; // initialize cell to off position TRISC = 0x00; // all outputs on PORTC LATC = RANGE1; // initialize range to range 1 // Enable Active clock-tuning from the USB ACTCONbits.ACTSRC = 1; // 1=USB ACTCONbits.ACTEN = 1; // Configure interrupts INTCONbits.PEIE = 1; INTCONbits.GIE = 1; // Initialize USB usb_init(); while (1) { if (usb_is_configured() && usb_out_endpoint_has_data(1)) // wait for data received from host { if (!usb_in_endpoint_halted(1)) { while (usb_in_endpoint_busy(1)) // wait for EP1 IN to become free ; received_data_length = usb_get_out_buffer(1, &received_data); transmit_data = usb_get_in_buffer(1); interpret_command(); // this reads received_data and sets transmit_data and transmit_data_length usb_send_in_buffer(1, transmit_data_length); // send the data back } usb_arm_out_endpoint(1); } } return 0; }
void keyboardHandler(bool released, KbKey key){ if (released){ if (key.code == 156){ kprintf("\n"); command[command_offset]='\0'; interpret_command(command); command_offset = 0; kprint('>'); } else if (key.code== 142){ kBackspace(); command_offset--; } else{ command[command_offset++]=key.c; kprint(key.c); } } }
void pc_link_check(void) { if (!cmd_event) return; char cmd[10]; // copy the command and free up the receive buffer cli(); // disable interrupts memcpy(cmd, recv_buf, recv_buf_ptr); cmd[recv_buf_ptr] = 0; cmd_event = 0; recv_buf_ptr = 0; sei(); // reenable interrupts // trim all trailing newlines from the command buffer: uint8_t i = 0; while (cmd[i]) i++; while (i > 0 && (cmd[i - 1] == '\n' || cmd[i - 1] == '\r')) cmd[--i] = 0; // interpret the command: interpret_command(cmd); }
int main() { int com, n, i; const char *canvas_file = "canvas.txt"; FILE *fp; char buf[BUFSIZE]; if ((fp = fopen(canvas_file, "w")) == NULL) { fprintf(stderr, "error: cannot open %s.\n", canvas_file); return 1; } init_canvas(); print_canvas(fp); n = 0; while (1) { printf("%d > ", n); fgets(buf, BUFSIZE, stdin); history[n] = (char*)malloc(sizeof(char) * strlen(buf)); strcpy(history[n], buf); if (++n >= HISTORY_SIZE) break; com = interpret_command(buf); if (com == COM_QUIT) break; print_canvas(fp); } fclose(fp); if ((fp = fopen("history.txt", "w")) != NULL) { for (i = 0; i < n; i++) fprintf(fp, "%s", history[i]); fclose(fp); } }
int read_client(t_server *server, t_client *client) { if (!read512_socket(client->fd, client->buffer_in) || !strncmp("QUIT", client->buffer_in, strlen("QUIT"))) { #ifdef DEBUG fprintf(stdout, "--CLIENT DISCONNECT-- (fd: %d)\n", client->fd); #endif pop_client(server->root_clients, client); } else { #ifdef DEBUG puts_telnet(client->buffer_in); #endif clean_telnet(client->buffer_in); if ((client->tab_cmd = my_str_to_wordtab(client->buffer_in))) { interpret_command(server, client); free_wordtab(&(client->tab_cmd)); } } return (0); }
/* * Parse the command in command, execute it on the DB rooted at head and return * a string describing the results. Response must be a writable string that * can hold len characters. The response is stored in response. */ void interpret_command(char *command, char *response, int len) { char value[256]; char ibuf[256]; char name[256]; static int initialized = 0; if (!initialized) { pthread_mutex_init(&g_coarse_mutex, NULL); initialized = 1; } if (strlen(command) <= 1) { strncpy(response, "ill-formed command", len - 1); return; } switch (command[0]) { case 'q': /* Query */ sscanf(&command[1], "%255s", name); if (strlen(name) == 0) { strncpy(response, "ill-formed command", len - 1); return; } query(name, response, len); if (strlen(response) == 0) { strncpy(response, "not found", len - 1); } return; case 'a': /* Add to the database */ sscanf(&command[1], "%255s %255s", name, value); if ((strlen(name) == 0) || (strlen(value) == 0)) { strncpy(response, "ill-formed command", len - 1); return; } if (add(name, value)) { strncpy(response, "added", len - 1); } else { strncpy(response, "already in database", len - 1); } return; case 'd': /* Delete from the database */ sscanf(&command[1], "%255s", name); if (strlen(name) == 0) { strncpy(response, "ill-formed command", len - 1); return; } if (xremove(name)) { strncpy(response, "removed", len - 1); } else { strncpy(response, "not in database", len - 1); } return; case 'f': /* process the commands in a file (silently) */ sscanf(&command[1], "%255s", name); if (name[0] == '\0') { strncpy(response, "ill-formed command", len - 1); return; } { FILE *finput = fopen(name, "r"); if (!finput) { strncpy(response, "bad file name", len - 1); return; } while (fgets(ibuf, sizeof(ibuf), finput) != 0) { interpret_command(ibuf, response, len); } fclose(finput); } strncpy(response, "file processed", len - 1); return; default: strncpy(response, "ill-formed command", len - 1); return; } }
int main(int argc, char ** argv) { SECTREE_MANAGER sectree_manager; DESC_MANAGER desc_manager; CHARACTER_MANAGER char_manager; quest::CQuestManager quest_manager; // CHARACTER::Intiailize에서 필요함 CArenaManager arena_manager; CPVPManager pvp_manager; LZOManager lzo; if (!start(argc, argv)) return 0; signal_timer_disable(); char buf[256]; char last_cmd[256]; char * p; bool bEnd = false; while (!bEnd && fgets(buf, 256, stdin)) { while ((p = strrchr(buf, '\r'))) *p = '\0'; while ((p = strrchr(buf, '\n'))) *p = '\0'; if (buf[0] == '!') strlcpy(buf, last_cmd, sizeof(buf)); strlcpy(last_cmd, buf, sizeof(last_cmd)); char arg1[64], arg2[64];//, arg3[64], arg4[64]; const char * line = one_argument(buf, arg1, sizeof(arg1)); switch (arg1[0]) { case 'a': { two_arguments(line, arg1, sizeof(arg1), arg2, sizeof(arg2)); if (!*arg1 || !*arg2) { printf("Syntax: a <collision data filename> <map directory>\n"); break; } ConvertAttribute(arg1, arg2); puts("build server_attr done"); } break; case 'c': { one_argument(line, arg1, sizeof(arg1)); if (!*arg1) { printf("Syntax: c <filename>\n"); break; } ConvertAttribute2(arg1); } //ReadColorMapRecursive(line); break; case 'b': { // Buffer overflow test (must use with valgrind or gdb at least) LPCHARACTER ch = CHARACTER_MANAGER::instance().CreateCharacter("test"); // 스택에 할당하면 valgrind가 제대로 오류를 잡지 못함 size_t bufsize = 512 + 1; size_t linesize = 1024 + 1; if (bufsize > 0 && linesize > 0) { char *buf = (char *) malloc(bufsize); char *line = (char *) malloc(linesize); memset(buf, 0, bufsize); memset(line, 0, linesize); for (size_t i = 0; i < bufsize - 1; ++i) { buf[i] = '$'; int linelen = snprintf(line, linesize, "pvp %s", buf); if (linelen < 0 || linelen >= (int) linesize) linelen = linesize - 1; printf("%d %s\n", i, line); interpret_command(ch, line, linelen); } free(buf); free(line); } else { printf("size error!\n"); abort(); } printf("Buffer overflow test finished\n"); } break; case 'q': bEnd = true; break; } } thecore_destroy(); event_destroy(); return 0; }
int main(int argc, char **argv) { unsigned char buf[256]; int size, s, cntrl_s, cntrl_fd; socklen_t cntrl_len; struct sockaddr_un cntrl_addr; fd_set read_fds, write_fds; int fd_max; if (ax25_config_load_ports() == 0) { fprintf(stderr, "ax25rtd: no AX.25 port configured\n"); return 1; } load_config(); load_cache(); if (fork()) return 0; if ((s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_AX25))) == -1) { perror("AX.25 socket"); return 1; } if ((cntrl_s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { perror("Control socket"); return 1; } unlink(DATA_AX25ROUTED_CTL_SOCK); cntrl_addr.sun_family = AF_UNIX; strcpy(cntrl_addr.sun_path, DATA_AX25ROUTED_CTL_SOCK); cntrl_len = sizeof(cntrl_addr.sun_family) + strlen(DATA_AX25ROUTED_CTL_SOCK); if (bind(cntrl_s, (struct sockaddr *) &cntrl_addr, cntrl_len) < 0) { perror("bind Control socket"); daemon_shutdown(1); } chmod(DATA_AX25ROUTED_CTL_SOCK, 0600); listen(cntrl_s, 1); signal(SIGUSR1, sig_debug); signal(SIGHUP, sig_reload); signal(SIGTERM, sig_term); cntrl_fd = -1; for (;;) { fd_max = 0; FD_ZERO(&read_fds); FD_ZERO(&write_fds); FD_MAX(s); if (cntrl_fd > 0) { FD_MAX(cntrl_fd); FD_SET(cntrl_fd, &write_fds); } else { FD_MAX(cntrl_s); } if (select(fd_max + 1, &read_fds, NULL, &write_fds, NULL) < 0) { if (errno == EINTR) /* woops! */ continue; if (!FD_ISSET(cntrl_fd, &write_fds)) { perror("select"); save_cache(); daemon_shutdown(1); } else { close(cntrl_fd); cntrl_fd = -1; continue; } } if (cntrl_fd > 0) { if (FD_ISSET(cntrl_fd, &read_fds)) { size = read(cntrl_fd, buf, sizeof(buf)); if (size > 0) { buf[size] = '\0'; interpret_command(cntrl_fd, buf); } else { close(cntrl_fd); cntrl_fd = -1; } } } else if (FD_ISSET(cntrl_s, &read_fds)) { if ((cntrl_fd = accept(cntrl_s, (struct sockaddr *) &cntrl_addr, &cntrl_len)) < 0) { perror("accept Control"); save_cache(); daemon_shutdown(1); } } if (reload) reload_config(); if (FD_ISSET(s, &read_fds)) ax25_receive(s); } return 0; /* what ?! */ }