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]); } }
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; }
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; }
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); } } }
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(); } } }
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); }
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); }
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); }
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; }
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); } }
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; } } }
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; }
int main(int argc, char *argv[]) { int status; while(TRUE){ printf("FERNANDO&BRUNO@SHELL$ "); 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; }
/* 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; }
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); }
int main() { prepare(); reset_grid(); while (read_command()); return 0; }
void interactive(){ while (TRUE){ char *command; int i; char *parameters[32]; struct timeval initial_clock; struct timeval final_clock; int num_params; do{ type_prompt();// displays prompt num_params = read_command(command, parameters);//get input from user and parse it into command and parameters if(num_params > 32){ printf("\nOnly 32 arguments allowed.\n"); } } while(num_params > 32 || num_params == -2); char **params = malloc((num_params + 1) * sizeof(char *)); for(i = 0; i < num_params; i++) params[i] = parameters[i]; params[i] = NULL; command = params[0]; if(strcmp("exit", command) == 0) exit(4); if(strcmp("cd", command) == 0){ chdir(params[1]); continue; } if(gettimeofday(&initial_clock, NULL) == -1) printf("\nCould not get time.\n"); pid_t pId = fork(); if(pId == -1){ //fork failed printf("Fork failed. Please try running again. %s\n", strerror(errno)); } if(pId != 0){ //parent process int status; if(waitpid(pId,&status, 0) != pId) printf("waitpid failed\n"); // once child process is done, print usage statistics if(gettimeofday(&final_clock, NULL) == -1) printf("\nCould not get time.\n"); long seconds_elapsed = final_clock.tv_sec - initial_clock.tv_sec; long microseconds_elapsed = final_clock.tv_usec - initial_clock.tv_usec; long milliseconds_elapsed = seconds_elapsed*1000 + microseconds_elapsed*0.001; printf("\nWall clock time for the command to execute:\n%ld milliseconds\n", milliseconds_elapsed); print_statistics(); } else{ //child process int returnnum; returnnum = execvp(command, params); if(returnnum == -1){ //error occurred during execvp printf("Your command didn't work: %s\n", strerror(errno)); prev_usr_milliseconds = 0; prev_sys_milliseconds = 0; prev_stats.ru_nivcsw = 0; prev_stats.ru_nvcsw = 0; prev_stats.ru_majflt = 0; prev_stats.ru_minflt = 0; } } } }
int main(int argc, const char *argv[]) { int RUN = TRUE; char command[100] = ""; char params[100] = ""; int PIDstatus = 0; while (RUN) {/* Endlosschleife */ strcpy(command, ""); type_prompt(); /* Prompt ausgeben */ read_command(command, params); /* Eingabezeile von Tastatur lesen */ if(!strcmp(command, "quit")) { quit_shell(&RUN); } else if (!strcmp(command, "version")) { get_version(); } else if (!strcmp(command, "/")) { changedir(params); } else if (!strcmp(command, "help")) { print_help(); } else { /* PIDstatus = fork(); [> Kind erzeugen <]*/ /* if (PIDstatus < 0) {*/ /* printf("Unable to fork"); [> Fehlerbedingung <]*/ /* continue; [> Schleife wiederholen <]*/ /* }*/ /* if (PIDstatus > 0) {*/ /* waitpid (PIDstatus, &status, 0); [> Elternprozess wartet auf Kind <]*/ /* } else {*/ /* execve(command, params, 0); [> Das Kind-Programm ausführen <]*/ /* }*/ PIDstatus = fork(); if (PIDstatus < 0) { printf("Sorry, unable to fork"); } else if (PIDstatus > 0) { if (params[strlen(params)-1] != '&') { waitpid(PIDstatus,NULL,0); } } else { RUN = FALSE; // stop loop for this process if (params[strlen(params)-1] != '&') { printf("\n"); // beautify output } if (execlp(command, (char const*)params, 0) == -1) { printf("Programm nicht gefunden!\n"); } } } } return 0; }
static int eeprom_detect(void) { write_command(E1000_REG_EEPROM, 1); for (int i = 0; i < 100000 && !has_eeprom; ++i) { uint32_t val = read_command(E1000_REG_EEPROM); if (val & 0x10) has_eeprom = 1; } return 0; }
/** * shell main loop */ void shell_loop(void) { while (1) { init(); if (read_command() == -1) { break; } parse_command(); //print_command(); execute_command(); } }
/** * Main and Execute Commands */ int main(int argc, char* argv[]) { history_count = 0; char input_buffer[COMMAND_LENGTH]; char *tokens[NUM_TOKENS]; char wd[1024], prompt[1024]; strcpy(prompt, "> "); while (true) { // Get command // Use write because we need to use read()/write() to work with // signals, and they are incompatible with printf(). write(STDOUT_FILENO, prompt, strlen(prompt)); _Bool in_background = false; read_command(input_buffer, tokens, &in_background); if (tokens[0] == NULL) continue; if (strcmp(tokens[0], "exit") == 0) break; else if (strcmp(tokens[0], "cd") == 0) { if (tokens[1] == NULL) { char out[60]; strcpy(out, "shell: Expected argument for \"cd\", no action taken.\n"); write(STDOUT_FILENO, out, strlen(out)); } else if (chdir(tokens[1]) != 0) { perror("shell"); } else { getcwd(prompt, sizeof(prompt)); strcat(prompt, "> "); } } else if (strcmp(tokens[0], "pwd") == 0) { char out[30]; getcwd(wd, sizeof(wd)); strcpy(out, "shell: Working directory: "); write(STDOUT_FILENO, out, strlen(out)); write(STDOUT_FILENO, strcat(wd, "\n"), strlen(strcat(wd, "\n"))); } else if (strcmp(tokens[0], "history") == 0) { shell_print_history(); } else { shell_execute(tokens, in_background); } } return 0; }
int main(int argc, char *argv[]) { fd_set fds; int keep_going = 1; want_debug = (argc > 1) && (!strcmp(argv[1], "-debug")); if (want_debug) fprintf(stderr, "execdaemon starting.\n"); while (keep_going) { struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 100000; /* 100 ms */ FD_ZERO(&fds); FD_SET(0, &fds); switch (select(1, &fds, NULL, NULL, &timeout)) { case 1: { if (!read_command()) { keep_going = 0; } else { eval_command(); } break; } case 0: break; case -1: perror("select"); exit(1); } if (kid != 0) { int pidstatus; pid_t result = waitpid(kid, &pidstatus, WNOHANG); if (result != 0) { if (WIFEXITED(pidstatus)) { write_response("exit", num_buf(WEXITSTATUS(pidstatus))); } else if (WIFSIGNALED(pidstatus)) { write_response("signal", num_buf(WTERMSIG(pidstatus))); } else { write_response("died", ""); } kid = 0; } } } if (want_debug) fprintf(stderr, "execdaemon exiting.\n"); return 0; }
// Reads a HMDP request from a client // @param connectionfd the socket descriptor of the client // @param username the client's username // @param password the client's password // @param token the client's token // @param request_list the client's list of files to be synced // @param command the type of HMDP request being made // @return 1 if the read was successful, otherwise -1 int read_request(int connectionfd, char **username, char **password, char** token, csv_record **request_list, char **command) { char buffer[MAX_BUFFER_SIZE]; // The buffer used during recv char *request; // The buffer to hold received messages (Will be altered while reading) char *reference; // The unaltered pointer to the message memory int bytes_read = 0; // The number of bytes read from the request // Check to see if the message was completely read if (receive_all(connectionfd, buffer, &bytes_read) == -1) { syslog(LOG_ERR, "Only read %d bytes\n", bytes_read); return -1; } //end if // Keep a pointer to the memory location so we can free it later request = strdup(buffer); reference = request; *command = strdup(read_command(&request)); // Parse an 'Auth' request if (strcmp(*command, COMMAND_AUTH) == 0) { return parse_auth(&reference, &request, command, username, password); } //end if // Parse a 'List' request else if (strcmp(*command, COMMAND_LIST) == 0) { return parse_list(&reference, &request, command, token, request_list); } //end else if // Found an unrecognized command else { syslog(LOG_ERR, "Incorrect command specified"); free(*command); free(reference); *command = NULL; reference = NULL; return -1; } //end else } //end read_request
char * MPlayer::get_property ( char * p_prop ) { if ( m_window == DNULL ) return "-1"; char t_response[1024] ; char t_question[1024]; sprintf(t_question, "pausing_keep get_property %s", p_prop); sprintf(t_response, "ANS_%s=", p_prop); write_command(t_question); return (read_command(t_response)); }
/*** Read command line input and process them ***/ void start_console(void) { char command_buffer[513]; // longest command length is 512 characters uint16_t command_length; uint8_t status; int i; while(1) { for (i=0; i<513; i++) command_buffer[i]=0; // clear command buffer read_command(command_buffer, &command_length); status = process_command(command_buffer,command_length); if (status == 0XFF) return; // shutdown command } }
int main(int _argc, char **_argv) { /* clear shell variables and re-assign a minimum set */ clearenv(); setenv("PATH", ":/bin:/usr/bin", 1); setenv("PROMPT", "$ ", 1); setenv("SHELL", _argv[0], 1); signal(SIGINT, SIG_IGN); /* ignore ^C */ while(1) { printf("%s", getenv("PROMPT")); if(!read_command()) break; split_command(); if(!argc) continue; expand_args(); /* process builtin commands */ if(!strcmp(argv[0],"exit")) { break; } else if(!strcmp(argv[0],"set")) { if(argc!=3) { fprintf(stderr, "set: two arguments required\n"); continue; } setenv(argv[1], argv[2], 1); } else if(!strcmp(argv[0], "cd")) { if(argc!=2) { fprintf(stderr, "cd: one argument required\n"); continue; } if(chdir(argv[1])==-1) { perror("cd"); } } else if(!strcmp(argv[0], "pwd")) { if(argc!=1) { fprintf(stderr, "pwd: no arguments allowed\n"); continue; } printf("%s\n", getcwd(command, BUF_LEN)); } else { /* run external command */ run_program(); } free_args(); } printf("\n"); return 0; }
/** * @brief main * * @param argc argument count * @param argv[] argument vector * * @return EXIT_SUCCESS on success, otherwise EXIT_FAILURE */ int main(int argc, char * argv[]) { pthread_t run_thread; if (argc != 1) return print_help(argv[0]); pthread_mutex_init(&buffer_mutex_read, NULL); pthread_mutex_init(&buffer_mutex_exec, NULL); pthread_cond_init (&buffer_cond_read, NULL); pthread_cond_init (&buffer_cond_exec, NULL); sigint_block(); // block ^C signal_handler_init(); // print info about SIGCHILD pidlist_init(&pidlist); // init PID list of background procs pthread_create(&run_thread, NULL, (pthread_fun_t) run_command, NULL); pthread_mutex_lock(&buffer_mutex_read); while (! g_exit) { if (! read_command()) g_exit = true; pthread_cond_signal(&buffer_cond_exec); if (! g_exit) // wait only if there is something to do pthread_cond_wait(&buffer_cond_read, &buffer_mutex_read); } pthread_mutex_unlock(&buffer_mutex_read); pthread_join(run_thread, NULL); /* * kill remaining procs */ if (! pidlist_empty(&pidlist)) { write(2, MSG_SIGTERM_CHILD, strlen(MSG_SIGTERM_CHILD)); pidlist_kill_free(&pidlist); write(2, MSG_WAIT_CHILD, strlen(MSG_WAIT_CHILD)); waitpid(-1, NULL, 0); } pthread_mutex_destroy(&buffer_mutex_read); pthread_mutex_destroy(&buffer_mutex_exec); pthread_cond_destroy(&buffer_cond_read); pthread_cond_destroy(&buffer_cond_exec); sigint_unblock(); write(2, MSG_EXIT, strlen(MSG_EXIT)); return EXIT_SUCCESS; }
void run_js(void *jsargs) { js_call *call_data = (js_call *) jsargs; spidermonkey_drv_t *dd = call_data->driver_data; ErlDrvBinary *args = call_data->args; driver_free(call_data); char *data = args->orig_bytes; char *command = read_command(&data); char *call_id = read_string(&data); char *result = NULL; if (strncmp(command, "ej", 2) == 0) { char *filename = read_string(&data); char *code = read_string(&data); result = sm_eval(dd->vm, filename, code, 1); if (strstr(result, "{\"error\"") != NULL) { send_error_string_response(dd, call_id, result); } else { send_string_response(dd, call_id, result); } driver_free(filename); driver_free(code); driver_free(result); } else if (strncmp(command, "dj", 2) == 0) { char *filename = read_string(&data); char *code = read_string(&data); result = sm_eval(dd->vm, filename, code, 0); if (result == NULL) { send_ok_response(dd, call_id); } else { send_error_string_response(dd, call_id, result); driver_free(result); } driver_free(filename); driver_free(code); } else if (strncmp(command, "sd", 2) == 0) { dd->shutdown = 1; send_ok_response(dd, call_id); } else { unknown_command(dd, call_id); } driver_free(command); driver_free(call_id); driver_binary_dec_refc(args); }
int retrieve_VotingErrorCounts(unsigned int* counters){ if(DEBUG>10) std::cout<<"DEBUG[commands.cpp] retrieve_VotingErrorCounts("<<*counters<<")"<<std::endl; // *** the counters array *must* have places for at least 12 elements // fill coutners array // return value!=0 indicates failure //// testing >>> /* if(time(0)%10==0) counters[0]++; if(time(0)%10==1) counters[1]++; if(time(0)%10==2) counters[2]++; if(time(0)%10==3) counters[3]++; if(time(0)%10==4) counters[4]++; if(time(0)%10==5) counters[5]++; if(time(0)%10==3) counters[6]++; if(time(0)%10==4) counters[7]++; if(time(0)%10==5) counters[8]++; if(time(0)%10==6) counters[9]++; if(time(0)%10==7) counters[10]++; if(time(0)%10==6) counters[11]++; return 0; */ // <<< testing int commandnum=5; eth_reset(); // first, clear the buffers if(write_command(commandnum) != 0){ if(DEBUG>10) std::cout<<"DEBUG[commands.cpp] retrieve_VotingErrorCounts return -1 <== error sending command"<<std::endl; return -1; // send command } char* pkt; if(read_command(&pkt) != commandnum){ if(DEBUG>10) std::cout<<"DEBUG[commands.cpp] retrieve_VotingErrorCounts return -2 <== error reading command"<<std::endl; return -2; // get responce } if(sizeof(int)!=4){ // make sure int is 4 bytes std::cerr<<"ERROR: sizeof(int)="<<sizeof(int)<<" This code assume sizeof(int)==4!"<<std::endl; return -3; } memcpy(counters, (const void*)&pkt[2], 12*4); // fill error counts: 12x 4-byte counters // Note: this will thrash memory if the counters array does not have 12 places! // It is also possible that the bytes in the array are reversed from how they should be in the int, which will take more work to unpack if(DEBUG>10) std::cout<<"DEBUG[commands.cpp] retrieve_VotingErrorCounts return 0"<<std::endl; return 0; }
int ProcessCommandLine(FILE *in) { int rc; char commandbuffer[1024]; int flag; rc = read_command(in, commandbuffer, 1024); if (rc) { rc = handle_command(commandbuffer); } return rc; }