本文整理汇总了C++中read_command函数的典型用法代码示例。如果您正苦于以下问题:C++ read_command函数的具体用法?C++ read_command怎么用?C++ read_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_command函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cria_pipe
void cria_pipe(){
int pipe(int fd[2]);
int fd[2];
int fd1[2];
pipe(fd);
pipe(fd1);
printf("Contador: %i\n", cont);
if (fork() != 0){
waitpid(-1,status,0);
if(cont>0){
close(fd1[1]);
dup2(fd1[0], 0);
read(fd1[0], &i, sizeof(i));
close(fd1[0]);
printf("Valor de i pai: %i\n",i);
printf("%c\n",str[i]);
//se encontrar algum espaço ou | passa para a próxima posição de str
if(str[i] != '\n' && (str[i] == '|' || str[i] == ' '))
while(str[i] != '\n' && (str[i] == '|' || str[i] == ' '))
i++;
read_command(str, command, parameters);
}
//processo pai executa esses comandos
waitpid(-1,status,0);
close(fd[1]); //o processo 1 precisa ler o pipe
dup2(fd[0], 0); //configura a saída padrão para fd[0]
execvp(command, parameters);
close(fd[0]); //este descritor de arquivo não é mais necessário
}
else{
//o processo filho executa estes comandos
read_command(str, command, parameters);
if(cont>0){
close(fd1[0]);
dup2(fd1[1],1);
write(fd1[1], &i, sizeof(i));
close(fd1[1]);
}
//pipe de entrada
close(fd[0]);
dup2(fd[1],1);
printf("Valor de i filho: %i\n",i);
execvp(command, parameters);
close(fd[1]);
}
}
示例2: main
int main(int argc, char** argv)
{
if(argc < 2) error("Uso: server porta\n");
buffer = (DATA*) malloc(DEFAULT_SIZE);
char command_str[16];
char address_str[16];
IPV4_Address address;
SOCKET socket;
socket = create_socket(IPV4,TCP,DEFAULT);
address = ipv4_address("",atoi(argv[1]));
bind_socket(socket,(Address*)&address);
man_socket = listen_socket(
socket,(struct sockaddr*)&address);
is_terminated = FALSE;
puts("Waiting for players...");
forever{
//memset(buffer,' ',DEFAULT_SIZE);
read(man_socket,buffer,DEFAULT_SIZE);
strcpy(command_str,buffer->command);
strcpy(address_str,buffer->address);
printf("command: %s",command_str);
read_command(command_str,address_str);
if(is_terminated == TRUE) break;
}
strcpy(buffer->results,"Terminated");
write(man_socket,buffer,DEFAULT_SIZE);
close(man_socket);
close(socket);
return 0;
}
示例3: main
int main(int argc, char *argv[])
{
read_history(history_file);
load_tab_completion();
signal(SIGINT, &sighandler); // Don't die on sigint
FILE * fd_sig = fdopen(5, "r"); // get signals to read from fd5
if(!fd_sig)
exit(0);
FILE * fd_out = fdopen(6, "w"); // output lines on fd6
if(!fd_out)
exit(0);
if(argc > 1) // load the prompt if available
prompt = argv[1];
do
{
read_command(fd_sig, fd_out);
} while(command);
free(command);
command = NULL;
fclose(fd_sig);
fclose(fd_out);
write_history(history_file);
return 0;
}
示例4: proc
void proc(void)
{
int status,i;
char *command = NULL;
char **parameters;
char prompt[MAX_PROMPT];
parameters = malloc(sizeof(char *)*(MAXARG+2));
buffer = malloc(sizeof(char) * MAXLINE);
if(parameters == NULL || buffer == NULL)
{
printf("Rshell error:malloc failed.\n");
return;
}
//arg[0] is command
//arg[MAXARG+1] is NULL
while(TRUE)
{
type_prompt(prompt);
if(-1 == read_command(&command,parameters,prompt))
continue;
if(builtin_command(command,parameters))
continue;
if(fork()!=0)
{
waitpid(-1,&status,0);
}
else
{
execvp(command,parameters);
}
}
}
示例5: while
void ForkWrapper::run()
{
int result = 0;
const int debug = 0;
while(!done)
{
if(debug) printf("ForkWrapper::run %d this=%p parent_fd=%d child_fd=%d\n",
__LINE__, this, parent_fd, child_fd);
result = read_command();
if(debug) printf("ForkWrapper::run %d this=%p result=%d command_token=%d\n",
__LINE__, this, result, command_token);
if(!result && command_token == EXIT_CODE)
done = 1;
else
if(!result)
{
handle_command();
}
}
}
示例6: read_and_execute_command
static void
read_and_execute_command(void)
{
int ret;
char *command_line, *command, *next_command;
command = command_line = read_command();
do {
next_command = strchr(command, ';');
if (next_command != NULL) {
*next_command = '\0';
next_command++;
}
strip_unneeded_whitespace(command, 1024);
if (strlen(command) > 0) {
ret = execute_command(command);
if (ret)
g_warning("Command finished with error.");
}
command = next_command;
} while (command);
free(command_line);
}
示例7: process
static void process(ErlDrvData handle, ErlIOVec *ev) {
spidermonkey_drv_t *dd = (spidermonkey_drv_t *) handle;
char *data = ev->binv[1]->orig_bytes;
char *command = read_command(&data);
if (strncmp(command, "ij", 2) == 0) {
char *call_id = read_string(&data);
int thread_stack = read_int32(&data);
if (thread_stack < 8) {
thread_stack = 8;
}
thread_stack = thread_stack * (1024 * 1024);
int heap_size = read_int32(&data) * (1024 * 1024);
dd->vm = sm_initialize(thread_stack, heap_size);
send_ok_response(dd, call_id);
driver_free(call_id);
}
else {
js_call *call_data = (js_call *) driver_alloc(sizeof(js_call));
call_data->driver_data = dd;
call_data->args = ev->binv[1];
driver_binary_inc_refc(call_data->args);
ErlDrvPort port = dd->port;
unsigned long thread_key = (unsigned long) port;
driver_async(dd->port, (unsigned int *) &thread_key, (asyncfun) run_js, (void *) call_data, NULL);
}
driver_free(command);
}
示例8: ft_minishell
int ft_minishell(t_env *e)
{
int len;
prompt(e);
while ((len = read(e->fd, e->buf, READ_SIZE)) > 0)
{
//printf("%d %d %d %d %d %d %d %d\n", e->buf[0], e->buf[1], e->buf[2], e->buf[3], e->buf[4], e->buf[5], e->buf[6], e->buf[7]);
if (KEYPAD(e) || K_SUPPR(e) || CTRL_C(e))
keypad_command(e);
else if (COPY_KEY(e))
copy_command(e);
else if (CTRL_D(e))
{
if (*e->hist->cmd == '\0')
break ;
}
else
read_command(len, e->buf, e);
if (!SHFT_KEY(e) && !CT_SH_KEY(e) && e->cpy.cpy != 0)
rewrite_command(e);
ft_memset(e->buf, 0, len);
}
return (len);
}
示例9: myshell
int myshell(char *args[], int size){
FILE *fp;
char command[100];
char *argv[1000];
char s[1000];
if(size == 0){//必须有一个参数
printf("myshell:没有参数\n");
return false;
}
fp = fopen(args[0], "r");
if(fp == NULL){
printf("打开文件失败\n");
return false;
}
while(!feof(fp)){
//逐行读取指令
size = read_command(command, argv, fp);
//判断是否已经读取到文件末尾
if(size == -1) break;
//调用指令
backstage(command, argv, size);
//释放内存
clear_command(argv, size);
}
fclose(fp);
return 1;
}
示例10: main
int main(){ //主函数
char command[100];
char *args[1000];
int size, i;
char value[1050];
char shellname[1050];
//初始化,增加环境变量
getcwd(first, 999); //获取当前目录
strcpy(value, "shell=");
strcpy(shellname, first);
strcat(shellname, "/myshell");
strcat(value, shellname);
putenv(value);
while(true){
type_prompt(); //输出命令提示符
//读取指令
size = read_command(command, args, stdin);
//分词并调用指令
backstage(command, args, size);
//释放内存
clear_command(args, size);
}
}
示例11: repl
void repl() {
SqlParser parser;
while (true) {
std::string command = read_command();
std::string::size_type first_space = command.find_first_of(" ");
std::string fst_token = first_space == string::npos ? command : command.substr(0, first_space);
capitalize(&fst_token);
#ifdef MAIN_DBG
Utils::info("[REPL] execute \"" + command +"\"");
#endif
if (fst_token.compare("QUIT") == 0 || fst_token.compare("EXIT") == 0) {
return;
} else if (fst_token.compare("PURGE") == 0) {
BufferManager &bm = BufferManager::get_instance();
bm.purge();
std::cout << "Purge has been done" << std::endl;
} else if (fst_token.compare("BMST") == 0) {
std::cout << "BufferManager state:" << std::endl;
std::cout << " Pinned pages: " + std::to_string(BufferManager::get_instance().get_pinned_page_count()) << std::endl;
BufferManager::get_instance().print_pinned_page();
} else if (fst_token.compare("ABOUT") == 0) {
std::string table_name = command.substr(6);
#ifdef MAIN_DBG
Utils::info("[REPL] 'about' was called for " + table_name);
#endif
describe_table(table_name);
} else {
SqlStatement const * stmt = parser.parse(command);
DBFacade::get_instance()->execute_statement(stmt);
delete stmt;
}
}
}
示例12: simple_terminal
int simple_terminal() {
puts("Shell is started");
puts("===========================");
while(1) {
char command[100];
char* parameters[100];
int status = 0;
type_porompt();
read_command(command, parameters);
printf("%s%s%d%d\n",parameters[0],parameters[1],parameters[2],parameters[3]);
if (fork() != 0) { //Parent
waitpid(-1, &status, 0);
} else { //Child
if (execvp(command, parameters) == -1) {
puts("Command invalid.");
return -1;
}
}
}
return 0;
}
示例13: main
int main(int argc, char *argv[]) {
int status;
while(TRUE){
printf("FERNANDO&[email protected]$ ");
str = (char *)calloc(MAX_COM, sizeof (char));
command = (char *)calloc(MAX_PAR, sizeof (char));
parameters = aloca(MAX_PAR, MAX_PAR);
read_commandline(str);
if(!strcasecmp("exit\n", str)) break;
if(!strcasecmp("\n", str)) continue;
if(fork()==0){
cont = conta_pipe(str);
if(cont > 0){
cria_pipe();
}
else{
read_command(str, command, parameters);
execvp(command, parameters);
}
}
else
wait(&status);
}
return 0;
}
示例14: main
/* main program controls all the action
*/
int
main(int argc, char *argv[]) {
int fileinput=0;
command_t comd;
csv_t D;
/* first argument on commandline is the data file name */
read_csv_file(argv[1], &D);
/* second argument, if it exists, is file of input commands */
if (argc==3) {
fileinput = 1;
reassign_input(argv[2]);
}
/* start the main execution loop */
print_prompt();
while (read_command(&comd, fileinput, D.ncols)) {
process_line(&comd, &D);
/* then round we go */
print_prompt();
}
/* all done, so pack up and go home */
printf("bye\n");
return 0;
}
示例15: init_disp_comond
static void init_disp_comond(void)
{
unsigned char value;
//init pin.
printk("[%s][%d]\r\n",__FUNCTION__,__LINE__);
cs_pin = gp_gpio_request(MK_GPIO_INDEX(0,0,48,15), NULL ); //IOA15
data_pin = gp_gpio_request(MK_GPIO_INDEX(1,0,12,0), NULL ); //IOB0
clk_pin = gp_gpio_request(MK_GPIO_INDEX(1,0,13,1), NULL ); //IOB1
gp_gpio_set_output(cs_pin,1,0);
gp_gpio_set_output(data_pin,1,0);
gp_gpio_set_output(clk_pin,1,0);
sent_command(0x05,0x5f);
read_command(0x05,&value);
sent_command(0x05,0x1f);
read_command(0x05,&value);
sent_command(0x05,0x5f);
read_command(0x05,&value);
sent_command(0x2b,0x01);
read_command(0x2b,&value);
sent_command(0x00,0x09);
read_command(0x00,&value);
sent_command(0x01,0x9f);
read_command(0x01,&value);
//m-sent_command(0x03,0x60);
sent_command(0x03,0x2e);
read_command(0x03,&value);
//m-sent_command(0x0d,0x60);
sent_command(0x0d,0x50);
read_command(0x0d,&value);
//m-sent_command(0x04,0x1b);
sent_command(0x04,0x18);
read_command(0x04,&value);
sent_command(0x16,0x04);
read_command(0x16,&value);
gp_gpio_release(cs_pin);
gp_gpio_release(data_pin);
gp_gpio_release(clk_pin);
}