void create_nick_command(EGetSet getset, char* new_nick, int len) { char nick_data[MAX_NICK_LENGTH+2]; nick_data[0] = getset; if(len > 0) memcpy(nick_data + 1, new_nick, len); create_command(ECommandCodes_Nick, nick_data, len + 1); }
END_TEST START_TEST(create_command_test) { char *argv[] = {(char *)"ls", (char *)"-ltr", (char *)"/home/dbeer", (char *)"|", (char *)"grep", (char *)"bob", NULL}; std::string cmd; create_command(cmd, argv); fail_unless(cmd == "ls -ltr /home/dbeer | grep bob", cmd.c_str()); }
bool TCS34725::initialize() { bool ret = true; for (uint8_t i = 0; i < 4; i++) { switch (i) { // RGBC timing is 256 - contents x 2.4mS = case 0 : ret = I2Cdev::writeByte(DEVICE_ADDRESS, create_command(ATIME_ADDR), ATIME_VALUE); break; // Can be used to change the wait time case 1 : { ret = I2Cdev::writeByte( DEVICE_ADDRESS, create_command(CONFIG_ADDR), 2 ); // sets WLONG to 1 if ( ret ) { ret = I2Cdev::writeByte(DEVICE_ADDRESS, create_command(WTIME_ADDR), WAIT_TIME_VALUE); } //ret = I2Cdev::writeByte(DEVICE_ADDRESS, WTIME_ADDR, WAIT_TIME_VALUE); } break; // RGBC gain control case 2 : ret = I2Cdev::writeByte(DEVICE_ADDRESS, create_command(CONTROL_ADDR), CONTROL_VALUE); break; // enable ADs and oscillator for sensor case 3 : ret = I2Cdev::writeByte(DEVICE_ADDRESS, create_command(ENABLE_ADDR), ENABLE_VALUE); break; } if (!ret) { return false; m_open = false; } } m_open = true; return true; }
bool TCS34725::isConnected() { uint8_t r_register = 0; if ( !I2Cdev::readByte(DEVICE_ADDRESS, create_command(ID_ADDR), &r_register, 0) ) return false; if ( r_register == 0x44 ) { return true; } return false; }
bool TCS34725::read() { uint8_t buf[8] = {0}; if ( ! I2Cdev::readBytes(DEVICE_ADDRESS, create_command(COLOR_ADDR), 8, buf, 0) ) return false; m_clear = (uint16_t)(buf[1]<<8) + (uint16_t)buf[0]; m_red = (uint16_t)(buf[3]<<8) + (uint16_t)buf[2]; m_green = (uint16_t)(buf[5]<<8) + (uint16_t)buf[4]; m_blue = (uint16_t)(buf[7]<<8) + (uint16_t)buf[6]; return true; }
void draw_dashed_line(renderer::Command_queue& queue, glm::vec2 p1, glm::vec2 p2, float dash_len, Rgba color) { auto cmd = create_command() .require_not(Gl_option::depth_test) .require_not(Gl_option::depth_write) .object(*unit_line) .shader(*dashed_line_shader); cmd.uniforms().emplace("p1", p1); cmd.uniforms().emplace("p2", p2); cmd.uniforms().emplace("dash_len", 1.f/dash_len); cmd.uniforms().emplace("color", color); queue.push_back(cmd); }
void password_input_handler_impl(char *raw_data) { if (nullptr == raw_data) { cstate.set_execution_state(EX_FINISH); clear_input_handler(); return; } cterm_ptr<char> raw_data_ptr(raw_data); std::string password(raw_data_ptr.get()); // extract and remove login from client_state parameters state_params_t &state_params = cstate.get_params(); std::string login = state_params.at(login_key); state_params.erase(login_key); // form login command std::string login_command = create_command(login, password); // execute login command execution_state ex_state = process_request(login_command, cstate); cstate.set_execution_state(ex_state); }
/* This is separate due to it being required from inside the tests. */ void setup_objects (void) { init_objects_command(1); cmd = create_command("my_command", "/bin/true"); ck_assert(cmd != NULL); register_command(cmd); init_objects_host(1); hst = create_host(TARGET_HOST_NAME); ck_assert(hst != NULL); hst->check_command_ptr = cmd; hst->retain_status_information = TRUE; register_host(hst); init_objects_service(1); svc = create_service(hst, TARGET_SERVICE_NAME); ck_assert(svc != NULL); svc->check_command_ptr = cmd; svc->retain_status_information = TRUE; register_service(svc); }
char *get_command(char *database,char *speech) { FILE *file; char buf[1024]; char *ret = NULL; // The command to return. if(! file_exists(database)) { printf("The database \"%s\" doesn't exist!\n",database); exit(2); } file = fopen(database,"r"); int i; if(LINE_IN_DATABASE != 0) { for(i = 0;i < LINE_IN_DATABASE;++i) { if(!(fgets(buf,1024,file))) { return ret; } } } while( fgets(buf,1024,file)) { ++LINE_IN_DATABASE; if(is_match(speech,buf)) { // Yes the speech matches, now to get variables in it. STORE_VARIABLES = 1; store_special_variables(speech,buf); is_match(speech,buf); // Will now store variables in in a LL fgets(buf,1024,file); ++LINE_IN_DATABASE; ret = create_command(buf); break; } } fclose(file); return ret; }
char AD_to_server (int sockfd,char* tIP, short unsigned int port) { //connecting active data socket to server char temp1[4]={0}; char * ptr=strstr(tIP, "."); strncpy(temp1,tIP, ptr-tIP); strcpy(tIP,ptr+1); char temp2[4]={0}; ptr=strstr(tIP, "."); strncpy(temp2,tIP, ptr-tIP); strcpy(tIP,ptr+1); char temp3[4]={0}; ptr=strstr(tIP, "."); strncpy(temp3,tIP, ptr-tIP); strcpy(tIP,ptr+1); char temp4[4]={0}; strcpy(temp4,tIP); short unsigned int first_half=0x00FF; short unsigned int second_half=0xFF00; second_half=(second_half & port)>>8; first_half=first_half & port; char port_message[64]={0}; sprintf(port_message,"%s, %s, %s, %s, %d, %d",temp1,temp2,temp3,temp4,second_half,first_half); char std_message[36]={0}; char status=create_command ("PORT", port_message, std_message); status= send(sockfd , std_message , strlen(std_message), 0); //send_command(sockfd,std_message,strlen(std_message)); if (status!=-1) { status=recv_response(sockfd); } return status; }
int guts(int accept_fd, int listen_fd) { char buffer[RECV_WINDOW] = ""; // recv buffer int msgbuflen = MSG_SIZE; char status_msg[MSG_SIZE]; char *msg; // Incoming message. char *send_msg; // Outgoing message. char *tmp_msg; void *msg_cursor; struct response_struct response; int msglen = 0; // length of the assembled message that we receive. int recvlen = 0; // how many bytes recv call returns. int responselen = 0; int offset; int retval; char* token_vector[MAX_ARGS] = {'\0'}; int token_count = 0; // Re-register the sigterm handler to our cleanup function. signal(SIGTERM, sigterm_handler_child); close(listen_fd); // Close this resource from our parent. We don't need it any more. while (1) { msglen = 0; msgbuflen = MSG_SIZE; msg = malloc(sizeof(char) * msgbuflen); msg_cursor = (void*)msg; bzero(msg, msgbuflen); // Wait for some data while (((recvlen = recv(accept_fd, (void*)buffer, RECV_WINDOW, MSG_PEEK)) == -1) && (errno == EAGAIN)); if (recvlen == 0) { fprintf(stderr, "Client closed the connection.\n"); close(accept_fd); cleanup_and_exit(0); }; // Receive data from our buffered stream until we would block. while ((recvlen = recv(accept_fd, (void*)buffer, RECV_WINDOW, 0)) != -1) { if (recvlen == 0) { fprintf(stderr, "Client closed the connection.\n"); close(accept_fd); cleanup_and_exit(0); }; if (recvlen == -1) { fprintf(stderr, "Got error %d from recv.\n", errno); close(accept_fd); cleanup_and_exit(-1); }; // Extend our message buffer if need be. if ((msglen += recvlen) > (msgbuflen)) { msgbuflen += msgbuflen; offset = msg_cursor - (void*)msg; tmp_msg = malloc(sizeof(char) * msgbuflen); bzero(tmp_msg, msgbuflen); memcpy(tmp_msg, msg, offset); msg_cursor = tmp_msg + offset; free(msg); msg = tmp_msg; fprintf(stderr, "msgbuflen expanded to %d\n", msgbuflen); } memcpy(msg_cursor, (void*)buffer, recvlen); msg_cursor += recvlen; if (memchr((void*)buffer, '\n', recvlen)) break; // Got a terminator character. Go process our message. } tmp_msg = msg; strsep(&tmp_msg, "\r\n"); token_count = tokenize_command(msg, token_vector); switch (extract_command(token_vector, token_count)) { case 0: // quit cleanup_and_exit(); break; case 1: // create response = create_command(token_vector, token_count); break; case 2: // read response = read_command(token_vector, token_count); break; case 3: // delete response = delete_command(token_vector, token_count); break; case 4: // subkeys response = keys_command(token_vector, token_count); break; default: if ((response.msg = malloc(sizeof(char) * MSG_SIZE)) == NULL) { perror(NULL); cleanup_and_exit; } bzero(response.msg, MSG_SIZE); sprintf(response.msg, "Unknown command."); response.status = 1; } responselen = prepare_send_msg(response, &send_msg); if((send(accept_fd, (void*)send_msg, responselen, 0) == -1)) perror("Send failed"); free(msg); free(response.msg); free(send_msg); }; return(0); }
EErrorCodes create_nick_command() { return create_command(ECommandCodes_Nick, (unsigned char*)State.nick, strlen(State.nick)); }
/*********************** Main **********************/ int main(int argc, char *argv[]) { setup_home(); int g = 0; int x = 0; int V = 0; int c = 0; int l = 0; int e = 0; int d = 0; int u = 0; int h = 0; int G = 0; int T = 0; int C = 0; int M = 0; int N = 0; char * group; char * label; char * content; int opt ; while((opt= getopt(argc,argv, "V(verbose)g:x(execute)c(create)l(list)e(echo):d(drop):u(edit):h(help)G(group):T(template):C(command)::M(macro)::N(note)::"))!= -1) { switch(opt) { case 'g': g=1; group = optarg; break; case 'V': V = 1; break; case 'x': x = 1; break; case 'c': c = 1; break; case 'l': l = 1; break; case 'e': e = 1; label = argv[optind]; break; case 'd': d = 1; label = argv[optind]; break; case 'u': u = 1; label = argv[optind]; break; case 'h': h = 1; break; case 'G': G = 1; label = argv[optind]; break; case 'T': T = 1; label = argv[optind]; break; case 'C': C = 1; label = argv[optind]; content = argv[optind+1]; break; case 'N': N = 1; label = argv[optind]; content = argv[optind+1]; break; default: puts("test"); break; } } if(g == 1) { if(c == 1) { if(G ==1) { create_group(label); //break; } else if(N == 1) { create_note(group, label, content); //break; } else if(C == 1) { create_command(label,group,content); //break; } else if(T == 1) { create_template_from_current(group,label); //break; } else { puts("Invalid Command"); return -1; } } if(e == 1) { if(N == 1) { echo_note(group,label); } else if( C == 1) { echo_command(label, group); } else if (T == 1) { echo_template(label, group); } } else if(l == 1) { if(N == 1) { list_notes(group); //break; } else if(C == 1) { list_commands(group); //break; } else if(T == 1) { list_templates(group); } else { puts("Invalid Command"); return -1; } } else if(x == 1) { if(C == 1) { execute_command(group,label); //break; } else if(T == 1) { execute_template(group,label); } else { puts("Invalid Command"); return -1; } } } else if(c == 1) { if(G == 1) { create_group(label); //break; } else { puts("Invalid Command"); return -1; } } else if(e == 1) { if(G == 1) { echo_group(label); } } return 0; }
// Reads the input file and creates a process. void read_commands(char *commands, struct process process_table[]) { FILE * filePointer; // File pointer filePointer = fopen(commands, "r"); // Opens the filename pointed to by commands using the given mode. char line[128]; // Variable that holds each line that is read char command[10]; // Command int time; // Time or start time of command // Run while fscanf successfully reads in 2 variables and store the first part as // a string and the second as an int while(fscanf(filePointer, "%s %d", command, &time) == 2) { int cmd_name; // Parsing the commands if (strcmp(command,"NEW")==0) { // Create process process_table[process_ctr] = create_new_process(); cmd_name = NEW; // Increment process id pid_ctr++; // Increment process counter process_ctr++; } else if(strcmp(command,"CPU")==0) { // Access CPU cmd_name = CPU; } else if(strcmp(command,"INP")==0) { // Access INP cmd_name = INP; } else if(strcmp(command,"SSD")==0) { // Access SSD cmd_name = SSD; } // Access the process table and get the created process. Access the commands array of that // process at position of the command index. Create a command in that position. process_table[process_ctr-1].commands[process_table[process_ctr-1].command_index] = create_command(cmd_name, time); // Increment the command index process_table[process_ctr-1].command_index++; process_table[process_ctr-1].total_commands++; } // Close the file fclose(filePointer); }
/************************** * command* create_parse_tree_recursive( * struct tokenized_node*, * * Input: * tokenized_command - Token node to start at * * Given a tokenized command, create a parse tree out of it. */ command* create_parse_tree_recursive(struct tokenized_node* tokenized_command) { // Used so we don't have to special-case first node in the tree command fake_start_node; fake_start_node.piped_to = NULL; command* current_command = &fake_start_node; bool in_command = false; commanditem fake_start_item; fake_start_item.next = NULL; commanditem* current_command_item = &fake_start_item; struct tokenized_node* token_iterator = tokenized_command; for (iterator(token_iterator, tokenized_command)) { if (!in_command) { current_command->piped_to = create_command(); current_command = current_command->piped_to; in_command = true; } if (is_pipe(token_iterator)) { in_command = false; current_command->contents = fake_start_item.next; current_command_item = &fake_start_item; continue; } if (is_backtick(token_iterator)) { perror("You're f****d.\n"); exit(1); } // Input redirect if ('<' == *(token_iterator->contents)) { token_iterator = token_iterator->next; current_command->input = malloc(sizeof(char) * (strlen(token_iterator->contents) + 1)); strcpy(current_command->input, token_iterator->contents); continue; } // Output redirect if ('>' == *(token_iterator->contents)) { token_iterator = token_iterator->next; if (token_iterator && '>' == *(token_iterator->contents)) { current_command->output_append = true; token_iterator = token_iterator->next; } current_command->output = malloc(sizeof(char) * (strlen(token_iterator->contents) + 1)); strcpy(current_command->output, token_iterator->contents); continue; } // Background if ('&' == *(token_iterator->contents)) { in_command = false; current_command->background = true; current_command->contents = fake_start_item.next; current_command_item = &fake_start_item; continue; } commanditem* newitem = create_commanditem(ARGUMENT); newitem->contents = malloc(sizeof(char) * (strlen(token_iterator->contents) + 1)); strcpy(newitem->contents, token_iterator->contents); current_command_item->next = newitem; current_command_item = current_command_item->next; } // Make sure last command has contents. current_command->contents = fake_start_item.next; return fake_start_node.piped_to; }