/*! \fn static void printBlock(uint8_t num) * \brief Print text 'Block' followed by blocknumber * * \param uint8_t num - number to be printed next to 'Block #' string */ static void printBlock(uint8_t num) { char str[4]; printTextP(PSTR("\nBlock #")); char_to_string(num, str); printText(str); }
bool is_allowed_groupcode (const string& groupcode) { size_t L = groupcode.size(); if (L == 1) { const string GC = char_to_string(groupcode.at(0)); return is_allowed_basic_groupcode_str (GC); } else if (L == 3) { const string GC1 = char_to_string(groupcode.at(0)); const string GC2 = char_to_string(groupcode.at(1)); const string GC3 = char_to_string(groupcode.at(2)); if ( is_allowed_basic_groupcode_str (GC1) && is_allowed_basic_groupcode_str (GC2) && is_allowed_basic_groupcode_str (GC3)) return true; return false; } else return false; }
int main(int argc, char *argv[]) { printf("command argument: %s\n", argv[1]); // io_tools //gpchar(); // data_type printf("------------ data_type example ------------\n"); print_sizeof (); // pointer printf("\n------------ pointer example --------------\n"); address(); // string printf("\n------------ string example ---------------\n"); char_to_string(); // struct printf("\n------------ struct example ---------------\n"); structure(); // union printf("\n------------ union example ----------------\n"); union_test(); // bit_field printf("\n------------ bit_field example -----------\n"); bit_field_test(); // file_io printf("\n------------ file_io example -------------\n"); file_io_test(); // recursion printf("\n------------ recusion example -------------\n"); recursion_test(); // variable_args printf("\n------------ valist example -------------\n"); varargs_test(); // memory printf("\n------------ memory example -------------\n"); memory_mgmt_test(); return 0; }
char *ope_str(char *str, int start, int *i) { char *result; if (str[*i] == '$') result = isdollars(i, str); else if (str[*i] == '~') result = istild(i, str, start); else if (str[*i] == '`') result = isbackquote(i, str); else if (str[*i] == '(') result = isbraquet(i, str); else result = char_to_string(str[start]); return (result); }
char *change_cmd(int i, char *result, char letter) { char *c; show_autocomplete(NULL, 0); spe_argument_completion(NULL, NULL, 1); spe_autocomp(NULL, 0, 1); c = char_to_string(letter); if (!result) return (c); if (i == ft_strlen(result)) result = i_equal_len(c, result); else if (i == 0) result = i_equal_zero(c, result); else result = insert_a_char(result, c, i); return (result); }
/****************************************************************************** * dot_delim_string() * * Parameters * --------- * - a string * * Returns * ------- * - a new string * * Notes * ----- * Takes a whitespace delimited string and make it dot delimited * there is NO leading or trailing dot ******************************************************************************/ char *dot_delim_string(char *s1) { int num_words, j; char *ret_str; if (s1 == NULL ) print_error("NULL string passed to dot_delim_string"); num_words = num_words_in_string(s1); ret_str = get_word_from_string(s1,1); if (num_words > 1){ for (j=2;j<=num_words;j++){ // note memorey leak, should use a temp string // so can free old ret_str bf reassigning..... ret_str = concat_2(char_to_string('.'),get_word_from_string(s1,j) ); } } return(ret_str); }
t_nfa* analyze_grammar(lex_stack* input) { std::list<t_nfa*> nfa_stack = std::list<t_nfa*>(); CC_DEBUG_OUT("==== SEMANTIC ANALYSIS BEGINS HERE ====") std::list<lex_parcel>::const_iterator iterator; for (iterator = input->begin(); iterator != input->end(); ++iterator) { lex_parcel lp = *iterator; switch (lp._type) { case TOKEN_LITERAL: { nfa_stack.push_front(thompsons_construction::get_a(char_to_string(lp._val))); CC_DEBUG_OUT(lp._val); break; } case TOKEN_CONNECT: { CC_DEBUG_OUT("-"); t_nfa* after = nfa_stack.front(); nfa_stack.pop_front(); t_nfa* before = nfa_stack.front(); nfa_stack.pop_front(); nfa_stack.push_front(thompsons_construction::get_M_and_N(before, after)); break; } case TOKEN_PIPE: { CC_DEBUG_OUT("|"); t_nfa* after = nfa_stack.front(); nfa_stack.pop_front(); t_nfa* before = nfa_stack.front(); nfa_stack.pop_front(); nfa_stack.push_front(thompsons_construction::get_M_or_N(before, after)); break; } case TOKEN_QUESTION_MARK: { CC_DEBUG_OUT("?"); t_nfa* item = nfa_stack.front(); nfa_stack.pop_front(); nfa_stack.push_front(thompsons_construction::get_M_question(item)); break; } case TOKEN_ASTERISK: { CC_DEBUG_OUT("*"); t_nfa* item = nfa_stack.front(); nfa_stack.pop_front(); nfa_stack.push_front(thompsons_construction::get_M_star(item)); break; } case TOKEN_PLUS: { CC_DEBUG_OUT("+"); t_nfa* item = nfa_stack.front(); nfa_stack.pop_front(); nfa_stack.push_front(thompsons_construction::get_M_plus(item)); break; } default: { break; } } } CC_DEBUG_OUT("==== SEMANTIC ANALYSIS ENDS HERE ====") t_nfa* nfa = nfa_stack.front(); nfa->_end->set_accept(); return nfa_stack.front(); }
std::string quote(const std::string& s, char quotes) { return char_to_string(quotes) + s + char_to_string(quotes) ; }
char *make_man_path(char *path, char *man, char *cmd) { return (ft_strjoin(path, ft_strjoin("/", ft_strjoin(man, ft_strjoin(cmd, ft_strjoin(".", char_to_string(man[3]))))))); }
void handleRequests() { //receive message from client int sockfd, newsockfd, portno, clilen; char buffer[BUFSIZ]; struct sockaddr_in serv_addr, cli_addr; int n; sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); bzero((char *) &serv_addr, sizeof(serv_addr)); portno = 50060; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); int optval = 1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); //can accomodate up to 5 requests at the same time clilen = sizeof(cli_addr); while(1) //receive messages from neighbors and process { newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen); if (newsockfd < 0) error("ERROR on accept"); bzero(buffer, BUFSIZ); n = read(newsockfd,buffer,BUFSIZ); if (n < 0) error("ERROR reading from socket"); //get the IP of the client char *client_ip = inet_ntoa(cli_addr.sin_addr); string client_ip_str = char_to_string(client_ip); ros::spinOnce(); //to get the most recent position of the robot //check whether the received message is an "ok_to_move" command or a /position message /*ros::Message *rosmsg = new ros::Message(); rosmsg->deserialize((uint8_t *)buffer); string strmsg = rosmsg->__s_getDataType();*/ if(strcmp(buffer, "ok_to_move") == 0) { cout << "received ok_to_move msg" << endl; ok_to_move = true; } else{ //deserialize received position message boost::shared_ptr<position_tracker::Position> newpos(new position_tracker::Position()); newpos->deserialize((uint8_t *)buffer); cout << "received position = (" << newpos->x << "," << newpos->y << "," << newpos->theta << ") "; printf("from %s\n", client_ip); //associate received position message with the corresponding neighbor/sender (just keep the last message received by the neighbor with client_ip) cout << "wn.count = " << wn.count << endl; cout << "wn.neighbors.size = " << wn.neighbors.size() << endl; if(wn.count != 0) { nn_pos.erase(client_ip_str); cout << "CURRENT nn_pos.size() = " << nn_pos.size() << endl; nn_pos.insert(pair<string, boost::shared_ptr<position_tracker::Position> >(client_ip_str, newpos)); } if(ok_to_move) { //get the current positions of your neighbors and determine your new position so that you are in the middle of them list< boost::shared_ptr<position_tracker::Position> > nn_pos_list; vector<batman_mesh_info::WifiNN>::iterator it; for(it = wn.neighbors.begin(); it != wn.neighbors.end(); ++it) { /*char *tmp_ip = new char[strlen((*it).ip.c_str())]; strcpy(tmp_ip, (*it).ip.c_str()); cout << "(*it).ip = " << (*it).ip << endl; printf("tmp_ip = %s\n", tmp_ip);*/ mapType::iterator iter1; for(iter1 = nn_pos.begin(); iter1 != nn_pos.end(); ++iter1) { cout << "iter1->first = " << iter1->first << endl; cout << "iter1->second->x = " << iter1->second->x << endl; } mapType::iterator iter = nn_pos.find((*it).ip); if(iter != nn_pos.end()) { nn_pos_list.push_back(iter->second); cout << "inserting neighbors..." << endl; } //delete []tmp_ip; } cout << "nn_pos.size() = " << nn_pos.size() << endl; std::cout << "nn_pos_list.size() = " << nn_pos_list.size() << std::endl; reach_middle_point(nn_pos_list); //ok_to_move = false; //in case I need an ok_to_move message to make me move again } } close(newsockfd); } close(sockfd); }