char *parser(char *tab, t_env *env) { char **command; int *pipe_fd; t_command *tmp; t_list list; int nb_exec; char *error; nb_exec = 0; init_list(&list); command = separe_wordtab(tab, '|'); if ((error = list_command(&list, command, &pipe_fd)) != 0) return (error); tmp = list.first; while (tmp != NULL) { if (my_execve(tmp, tmp->redirection, env, pipe_fd) != 42) nb_exec += 1; tmp = tmp->next; } close_fd(pipe_fd); loop_wait(nb_exec); return (0); }
void _list_menu(QSP_ARG_DECL const Menu *mp) { List *lp; Node *np; lp = MENU_LIST(mp); np = QLIST_HEAD(lp); while( np != NULL ){ Command *cp; cp = (Command *) NODE_DATA(np); list_command(QSP_ARG cp); np = NODE_NEXT(np); } }
/** * \brief Main method */ int main(int argc, char *argv[]) { debug(LOG_DEBUG, DEBUG_LOG, 0, "mount utility"); int c; int longindex; putenv((char *)"POSIXLY_CORRECT=1"); // cast to silence compiler while (EOF != (c = getopt_long(argc, argv, "c:dh", longopts, &longindex))) { switch (c) { case 'c': Configuration::set_default(std::string(optarg)); break; case 'd': debuglevel = LOG_DEBUG; break; case 'h': usage(argv[0]); return EXIT_SUCCESS; case 'n': dryrun = true; break; case 'f': decimal = true; break; case 'w': await_completion = true; break; case 1: switch (longindex) { } break; } } // next argument must be the command if (argc <= optind) { throw std::runtime_error("missing command argument"); } std::string command(argv[optind++]); // call the command specific functions if (command == "help") { return help_command(); } // the other commands need a repository astro::module::Repository repository; astro::module::Devices devices(repository); // list command if (command == "list") { return list_command(devices); } // other commands need a mount url if (argc <= optind) { throw std::runtime_error("missing mount URL"); } DeviceName mountname(argv[optind++]); if (!mountname.hasType(DeviceName::Mount)) { throw std::runtime_error("not a mount device name"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "mount device name: %s", mountname.toString().c_str()); // use the Devices class to get the mount associated with this name MountPtr mount = devices.getMount(mountname); if (command == "get") { return get_command(mount); } if (command == "cancel") { return cancel_command(mount); } if (command == "wait") { return wait_command(mount, true); } if (command == "set") { if (argc < optind + 2) { throw std::runtime_error("two angle arguments missing"); } RaDec radec; radec.ra() = Angle::hms_to_angle(argv[optind++]); radec.dec() = Angle::dms_to_angle(argv[optind++]); return set_command(mount, radec); } throw std::runtime_error("unknown command"); }
int main( int argc , char * argv[] ) { ksock_t server; int rc; unsigned char buf[16]; unsigned char a,b,c,d; int clntSocket; char echoBuffer[RCVBUFSIZE]; /* Buffer for echo string */ int recvMsgSize; /* Size of received message */ int port; /* The server port to open */ pthread_t sensor_task; pthread_t sound_task; if(argc > 1) port = atoi(argv[1]); else port = 344; /* Various initialization */ /* Set the libkorebot debug level - Highly recommended for development. */ kb_set_debug_level( 2 ); /* Global libkorebot init */ if((rc = kb_init( argc , argv )) < 0 ) return 1; /* Korebot socket module init */ if((rc = ksock_init('\n')) < 0 ) return 1; /* Open the motor devices */ motor1 = knet_open( "KoreMotor:PriMotor1", KNET_BUS_ANY, 0 , NULL ); if(!motor1) { printf("Cannot open motor 0\r\n"); return 1; } motor0 = knet_open( "KoreMotor:PriMotor2", KNET_BUS_ANY, 0 , NULL ); if(!motor0) { printf("Cannot open motor 1\r\n"); return 1; } motor3 = knet_open( "KoreMotor:PriMotor3", KNET_BUS_ANY, 0 , NULL ); if(!motor3) { printf("Cannot open motor 2\r\n"); return 1; } motor2 = knet_open( "KoreMotor:PriMotor4", KNET_BUS_ANY, 0 , NULL ); if(!motor2) { printf("Cannot open motor 3\r\n"); return 1; } /* KoreMotor Comm test */ kmot_GetFWVersion( motor1, &rc); printf("Motor 1 Firmware v%u.%u\n" , KMOT_VERSION(rc) , KMOT_REVISION(rc)); /* Intialize motor controller */ InitMotor(motor0); InitMotor(motor1); InitMotor(motor2); InitMotor(motor3); kmot_SearchLimits(motor0, 10, 3, &minpos0, &maxpos0,100000); printf("motor0: min:%ld max:%ld\n\r",minpos0, maxpos0); kmot_SearchLimits(motor1, 10, 3, &minpos1, &maxpos1,100000); printf("motor1: min:%ld max:%ld\n\r",minpos1, maxpos1); kmot_SearchLimits(motor2, 10, 3, &minpos2, &maxpos2,100000); printf("motor2: min:%ld max:%ld\n\r",minpos2, maxpos2); kmot_SearchLimits(motor3, 10, 3, &minpos3, &maxpos3,100000); printf("motor3: min:%ld max:%ld\n\r",minpos3, maxpos3); kmot_SetBlockedTime(motor0,5); kmot_SetBlockedTime(motor2,5); /* Network setup - Create a ksock server */ ksock_server_open(&server, port); ksock_add_command("movecamera",2,2,koa_net_camera); ksock_add_command("movecamera2",2,2,koa_net_camera2); ksock_add_command("moveboth",2,2,koa_net_bothcam); ksock_add_command("initcamera",0,0,koa_net_init); list_command(); /* Network connection handling */ clntSocket = ksock_next_connection(&server); for(;;) { rc = ksock_get_command(clntSocket, echoBuffer, RCVBUFSIZE); if(rc>0) { ksock_exec_command(echoBuffer); /* Echo message back to client */ if (send(clntSocket, echoBuffer, rc, 0) != rc) DieWithError("send() failed"); } else switch(rc) { case 0 : break; case -3 : printf("Client disconnected\r\n"); clntSocket = ksock_next_connection(&server); break; default : printf("Socket error: %d\r\n",rc); clntSocket = ksock_next_connection(&server); break; } } close(clntSocket); /* Close client socket */ return 0; }
static void console_task(layer_t* layer, unsigned int mem_total) { #define INPUT_BEG_POS_X (24) #define INPUT_BEG_POS_Y (28) #define PROMPT_CHAR ("> ") #define PROMPT_LEN (2) timer_t* timer; task_t* task = task_now(); int data, fifobuf[128]; int cursor_x = INPUT_BEG_POS_X, cursor_y = INPUT_BEG_POS_Y; int cursor_c = -1; char buf[32], cmdline[32]; mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR; fifo_init(&task->fifo, fifobuf, 128, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settimer(timer, 50); /* display the prompt of console window */ drawstring_and_refresh(layer, 8, 28, COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN); for ( ; ; ) { io_cli(); if (0 == fifo_size(&task->fifo)) { task_sleep(task); io_sti(); } else { data = fifo_get(&task->fifo); io_sti(); if (data <= 1) { /* timer for cursor */ if (0 != data) { timer_init(timer, &task->fifo, 0); if (cursor_c >= 0) cursor_c = COLOR8_FFFFFF; } else { timer_init(timer, &task->fifo, 1); if (cursor_c >= 0) cursor_c = COLOR8_000000; } timer_settimer(timer, 50); } if (2 == data) /* cursor ON */ cursor_c = COLOR8_FFFFFF; if (3 == data) { /* cursor OFF */ fill_box8(layer->buf, layer->w_size, COLOR8_000000, cursor_x, 28, cursor_x + 7, cursor_y + 15); cursor_c = -1; } if (256 <= data && data <= 511) { /* keyboard data */ if ((8 + 256) == data) { /* backspace */ if (cursor_x > INPUT_BEG_POS_X) { /* erase the cursor and move forward one character */ drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, " ", 1); cursor_x -= 8; } } else if ((10 + 256) == data) { /* Enter Key */ /* erase cursor by space */ drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, " ", 1); cmdline[cursor_x / 8 - 3] = 0; cursor_y = console_newline(cursor_y, layer); /* execute command */ if (0 == strcmp("mem", cmdline)) { /* check memory command */ cursor_y = memory_command(layer, memmgr, mem_total, cursor_y); } else if (0 == strcmp("clear", cmdline)) { /* clear command */ cursor_y = clear_command(layer); } else if (0 == strcmp("ls", cmdline)) { /* ls(dir) command */ cursor_y = list_command(layer, cursor_y); } else if (0 == strncmp("cat ", cmdline, 4)) { /* cat command */ cursor_y = cat_command(layer, cursor_x, cursor_y, cmdline); } else if (0 != cmdline[0]) { /* neither command nor null string */ drawstring_and_refresh(layer, 8, cursor_y, COLOR8_FFFFFF, COLOR8_000000, "Bad Command.", 12); cursor_y = console_newline(cursor_y, layer); cursor_y = console_newline(cursor_y, layer); } /* show prompt */ drawstring_and_refresh(layer, 8, cursor_y, COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN); cursor_x = INPUT_BEG_POS_X; } else { /* general character */ if (cursor_x < 240) { /* display one character and move backward one character */ buf[0] = data - 256; buf[1] = 0; cmdline[cursor_x / 8 - 3] = data - 256; drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, buf, 1); cursor_x += 8; } } } /* show the cursor again */ if (cursor_c >= 0) { fill_box8(layer->buf, layer->w_size, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); } layers_refresh(layer, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16); } } }
int main(void) { entry* entry_head = calloc(sizeof(entry), 1); snapshot* snapshot_head = calloc(sizeof(snapshot), 1); int latest_snapshotID = 1; char buffer[MAX_LINE_LENGTH]; printf("> "); while(fgets(buffer, sizeof(buffer), stdin)) { struct command_struct *command = get_command_struct(buffer); if(!command) continue; if(strcmp(command->args_malloc_ptr[0], "bye") == 0) { bye_command(snapshot_head, entry_head); free_command(command); printf("bye"); return 0; } else if(strcmp(command->args_malloc_ptr[0], "help") == 0) { print_help_string(); } else if(strcmp(command->args_malloc_ptr[0], "list") == 0) { list_command(command, entry_head, snapshot_head); } else if(strcmp(command->args_malloc_ptr[0], "get") == 0) { get_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "del") == 0) { del_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "purge") == 0) { purge_command(command, entry_head, snapshot_head); } else if(strcmp(command->args_malloc_ptr[0], "set") == 0) { set_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "push") == 0) { push_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "append") == 0) { append_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "pick") == 0) { pick_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "pluck") == 0) { pluck_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "pop") == 0) { pop_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "drop") == 0) { drop_command(command, snapshot_head); } else if(strcmp(command->args_malloc_ptr[0], "rollback") == 0) { rollback_command(command, snapshot_head, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "checkout") == 0) { checkout_command(command, snapshot_head, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "snapshot") == 0) { snapshot_command(snapshot_head, entry_head, &latest_snapshotID); } else if(strcmp(command->args_malloc_ptr[0], "min") == 0) { min_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "max") == 0) { max_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "sum") == 0) { sum_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "len") == 0) { len_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "rev") == 0) { rev_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "uniq") == 0) { uniq_command(command, entry_head); } else if(strcmp(command->args_malloc_ptr[0], "sort") == 0) { sort_command(command, entry_head); } printf("\n> "); free_command(command); } bye_command(snapshot_head, entry_head); return 0; }
int main( int argc , char * argv[] ) { int rc; unsigned char a,b,c,d; int clntSocket; ksock_t server; char echoBuffer[RCVBUFSIZE]; /* Buffer for echo string */ int port; /* The server port to open */ pthread_t lrf_task; /* Set signal handler */ signal(SIGINT, handle_kill); if(argc > 1) port = atoi(argv[1]); else port = 344; /* Set the libkorebot debug level - Highly recommended for development. */ kb_set_debug_level(2); if((rc = kb_init( argc , argv )) < 0 ) return 1; printf("Koala Demo Program\r\n"); /* Korebot socket module init */ if((rc = ksock_init('\n')) < 0 ) return 1; /* Open a device for the koala robot */ koala = knet_open( "Koala:Robot", KNET_BUS_ANY, 0 , NULL ); if(!koala) { printf("Open Koala device failed\r\n"); return 1; } /* Koala Comm test */ koa_getOSVersion(koala,&a,&b,&c,&d); printf("OS revision %d.%d protocol %d.%d\r\n",a,b,c,d); koa_setSpeed(koala,0,0); /* Network setup - Create a ksock server */ ksock_server_open(&server, port); ksock_add_command("setspeed",2,2,koa_net_setspeed); ksock_add_command("stop",0,0,koa_net_stop); list_command(); /* Task creation */ rc = pthread_create(&lrf_task, NULL, koa_lrf_task, NULL); if (rc) { printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } /* Network connection handling */ clntSocket = ksock_next_connection(&server); for(;;) { #if 1 rc = ksock_get_command(clntSocket, echoBuffer, RCVBUFSIZE); if(rc>0) { cmd_received = 1; ksock_exec_command(echoBuffer); /* Echo message back to client */ if (send(clntSocket, echoBuffer, rc, 0) != rc) DieWithError("send() failed"); } else switch(rc) { case 0 : break; case -3 : printf("Client disconnected\r\n"); clntSocket = ksock_next_connection(&server); break; default : printf("Socket error: %d\r\n",rc); clntSocket = ksock_next_connection(&server); break; } #endif } close(clntSocket); /* Close client socket */ }
void request_check(int index, char* buf){ char tokens[MAX_MSG_TOKENS][MAX_MSG_LEN+1]; int arg_num = tokenize(buf,tokens); int type,connfd; connfd = p.clientfd[index]; if (!strcmp(tokens[0],"USER")) type = USER_CMD; else if(!strcmp(tokens[0],"NICK")) type = NICK_CMD; else if(!strcmp(tokens[0],"JOIN")) type = JOIN_CMD; else if(!strcmp(tokens[0],"QUIT")) type = QUIT_CMD; else if(!strcmp(tokens[0],"PART")) type = PART_CMD; else if(!strcmp(tokens[0],"LIST")) type = LIST_CMD; else if(!strcmp(tokens[0],"WHO")) type = WHO_CMD; else if(!strcmp(tokens[0],"PRIVMSG")) type = PRIVMSG_CMD; else type = UNKONWN_CMD; //DEBUG int i; printf(" # CMD:%s\t ARG_NUM:%d\t",tokens[0],arg_num); for(i=0;i<4;i++) printf(" ARG%d:%s\t",i,tokens[i+1]); printf("\n"); if(type == UNKONWN_CMD) unknown_command(connfd,tokens[0]); else if(arg_num < ARG_NUM[type]){ char msg[MAX_MSG_LEN]; if(type == NICK_CMD) /* NICK ERRRO TYPE: ERR_NOERR_NONICKNAMEGIVEN */ snprintf(msg,MAX_MSG_LEN,":No nickname given\n"); else if(type == PRIVMSG_CMD){ /* PRIVMSG ERRRO TYPE: ERR_NORECIPIENT */ if(!arg_num) snprintf(msg,MAX_MSG_LEN,":No recipient given PRIVMSG\n"); /* PRIVMSG ERRRO TYPE: ERR_NOTEXTTOSEND */ else snprintf(msg,MAX_MSG_LEN,":No text to send\n"); }else snprintf(msg,MAX_MSG_LEN,"%s:Not enough parameters\n", tokens[0]); send_msg_back(connfd,msg); } else switch(type){ case QUIT_CMD: quit_command(index); break; case USER_CMD: user_command(connfd,tokens[1],tokens[4]); break; case NICK_CMD: nick_command(connfd,tokens[1]); break; default: if(check_register(connfd)){ switch(type){ case JOIN_CMD: join_command(connfd,tokens[1]); break; case PART_CMD: part_command(connfd,tokens[1],1); break; case LIST_CMD: list_command(connfd); break; case WHO_CMD: who_command(connfd,tokens[1]); break; case PRIVMSG_CMD: privmsg_command(connfd,tokens[1],tokens[2]); } }else send_msg_back(connfd,":You have not registered\n"); } }