int main() { printf("%d\n", string_to_int("123")); printf("%d\n", string_to_int("-123")); return 0; }
static int assemble_constant(assembly_state_t *state, instruction_t *instr, uint32_t addr, uint32_t *offset) { /* PRE: Given state is initialised. Instruction is valid SDTR instruction. offset points to sufficient space to store uint32_t. */ /* POST: Loads the assembled constant into relevant bits in number pointed to by offset. Returns 0 if successful, 1 otherwise. */ assert (state != NULL && instr != NULL && offset != NULL); uint32_t expression = string_to_int(instr->ops[1]); /* If the expression is <= 0xff we use a mov function instead: */ if (expression <= 0xff) { /* Change the format of the operand from =0x... to #... Will now be in decimal. */ sprintf(instr->ops[1], "#%d", string_to_int(instr->ops[1])); strcpy(instr->mnemonic, "mov"); instr->no_of_ops = 2; return EXIT_FAILURE; } else { /* We allocate 4 bytes at end of program for the expression: */ add_to_data_aloc_table(state->data_aloc_table, addr, expression); *offset |= 0x000f0000; } return EXIT_SUCCESS; }
static void finish_recovery_recv_file_name(struct aeEventLoop *eventLoop, int sockfd, void *clientData, int mask) { storage_client_t *pClient; pClient = clientData; pClient->file.proc = finish_recv_recovery_file; pClient->file.start_offlen = string_to_int(pClient->file.file_name + 15,4); pClient->file.file_size = string_to_int(pClient->file.file_name + 19,4); memcpy(pClient->file.real_file_name,pClient->file.file_name,24); logDebug("finish_recovery_recv_file_name %s",pClient->file.file_name); /*get all_trunk_name*/ memcpy(pClient->file.file_name,pClient->file.file_name+8,5); pClient->file.file_name[5] = '\0'; logDebug("finish_recovery_recv_trunk_name %d,%d,%s",pClient->file.file_size,pClient->file.start_offlen,pClient->file.file_name); if((pClient->file.fd = open(pClient->file.file_name,O_WRONLY|O_CREAT,0664)) == -1) { logError( "file: "__FILE__",line :%d, "\ "finish_recovery_recv_file_name open file failed,"\ "errno: %d,error info: %s",\ __LINE__,errno,strerror(errno)); *(char *)NULL = 0; // exit(1); } lseek(pClient->file.fd,pClient->file.start_offlen,SEEK_SET); nb_sock_recv_file(eventLoop,sockfd,pClient,AE_READABLE); return ; }
void cBonusBox::Load_From_XML(XmlAttributes& attributes) { cBaseBox::Load_From_XML(attributes); // item Set_Bonus_Type(static_cast<SpriteType>(string_to_int(attributes["item"]))); // force best possible item Set_Force_Best_Item(string_to_int(attributes["force_best_item"])); // gold color if (box_type == TYPE_GOLDPIECE) Set_Goldcolor(Get_Color_Id(attributes.fetch("gold_color", Get_Color_Name(m_gold_color)))); }
int main(int argc, char *argv[]) { char number_array[MAX_LENGTH_ARRAY]; // Array che verrà passato alla funzione int_to_string unsigned int result; // Il risultato è dove verrà salvato il risultato di string_to_int if (argc == 2) { // Se gli argomenti passati sono due if (( strcmp(argv[1], "-unit") == 0)) { // ed il secondo è '-unit' debug = 1; unit_test() == 0 ? printf("[+] Unit test Riuscito\n") : printf("[!] Unit test Fallito\n"); // Avvia gli unit test } else { printf("[!] Argomento sconosciuto\n"); // se il secondo argomento non è '-unit' usage(); // richiama la funzione 'usage' return 1; } } else if ( argc != 4) { // se gli argomenti passati non sono due e non sono neanche 4 usage(); // richiama la funzione 'usage' } else { char* numero_da_convertire = argv[1]; char* base_di_partenza = argv[2]; char* base_di_arrivo = argv[3]; int partenza = string_to_int(base_di_partenza, 10); // Base di partenza convertita in int per passarla alle funzioni int arrivo = string_to_int(base_di_arrivo, 10); // Base di arrivo convertita in int per passarla alle funzioni if (controllo_numero_base(numero_da_convertire, partenza, arrivo) == 1) { if(controllo_input(numero_da_convertire) == 1) { if (arrivo == 10) { // Se la base di arrivo è 10 usiamo string_to_int result = string_to_int(numero_da_convertire, partenza); printf("%i\n", result); // Stampiamo a schermo il risultato } else { // Se abbiamo un numero in base 10 da convertire a un'altra base usiamo int_to_string int convertire = string_to_int(numero_da_convertire, partenza); // Il numero da convertire deve essere un int per into_to_string int_to_string(convertire, number_array, arrivo); // Non stampiamo il risultato perché viene stampato dalla funzione stessa } } else { printf("La stringa inserita contiene dei caratteri non ammessi\n\n"); return 1; } } else if (controllo_numero_base(numero_da_convertire, partenza, arrivo) == -1) { printf("Il numero inserito non può far parte della base %d\n\n", partenza); return 1; } else { printf("Il numero inserito non può essere convertito nella base %d\n", arrivo); } } return 0; // Terminiamo il programma }
//executa alguns comandos como cd e pwd... int execute_int_commands(StringList arguments){ String command = get_string(arguments, 0); if(equals(command, "cd")){ if(chdir(get_string(arguments, 1))){ printf("Error: no such directory\n"); return 0; } }else if(equals(command, "pwd")){ printf("%s\n", get_current_dir_name()); }else if(equals(command, "jobs")){ print_job_list(job_list); }else if(equals(command,"fg")){ Job aux; int pid = string_to_int(get_string(arguments, 1)); kill(pid, SIGCONT); aux = get_by_pid(job_list, pid); if (aux == NULL) { //busca por jid aux = get_by_jid(job_list, pid); if (aux == NULL) { printf("Error: job not found\n"); return 0; } } aux->status = RUNNING; background = 0; wait(NULL); }else if(equals(command,"bg")){ Job aux; int pid = string_to_int(get_string(arguments, 1)); kill(pid ,SIGCONT); aux = get_by_pid(job_list, pid); if (aux == NULL) { //busca por jid aux = get_by_jid(job_list, pid); if (aux == NULL) { printf("Error: job not found\n"); return 0; } } aux->status = RUNNING; background = 1; }else{ return 0; } return 1; }
bin2hex_input_t bin2hex_parse_command_line( char const* const* cmdline ) { bin2hex_input_t input = {0}; int arg, asize; error_context_push( "parsing command line", "" ); for( arg = 1, asize = array_size( cmdline ); arg < asize; ++arg ) { if( string_equal( cmdline[arg], "--columns" ) ) { if( arg < ( asize - 1 ) ) input.columns = string_to_int( cmdline[++arg] ); } else if( string_equal( cmdline[arg], "--" ) ) break; //Stop parsing cmdline options else if( ( string_length( cmdline[arg] ) > 2 ) && string_equal_substr( cmdline[arg], "--", 2 ) ) continue; //Cmdline argument not parsed here else { array_push( input.input_files, string_clone( cmdline[arg] ) ); array_push( input.output_files, string_format( "%s.hex", cmdline[arg] ) ); } } error_context_pop(); return input; }
void IterDialog::OnApply(wxCommandEvent& event) { // Redraw fractal. text = textCtrl->GetValue(); number = string_to_int(text); target->ChangeIterations(number); }
int command_line_params::get_value_as_int(const wchar_t* pKey, uint index, int def, int l, int h, uint value_index) const { param_map_const_iterator it = get_param(pKey, index); if ((it == end()) || (value_index >= it->second.m_values.size())) return def; int val; const wchar_t* p = it->second.m_values[value_index].get_ptr(); if (!string_to_int(p, val)) { crnlib::console::warning(L"Invalid value specified for parameter \"%s\", using default value of %i", pKey, def); return def; } if (val < l) { crnlib::console::warning(L"Value %i for parameter \"%s\" is out of range, clamping to %i", val, pKey, l); val = l; } else if (val > h) { crnlib::console::warning(L"Value %i for parameter \"%s\" is out of range, clamping to %i", val, pKey, h); val = h; } return val; }
int get_mp3_info (char *file_name, tihm_t *tihm) { struct mp3_file mp3; if (mp3_open (file_name, &mp3) < 0) { mp3_close (&mp3); /* Make sure everything is cleaned up */ return -1; } if (mp3_scan (&mp3) < 0) { mp3_close (&mp3); return -1; } mp3_close (&mp3); tihm->bitrate = mp3.bitrate; tihm->vbr = mp3.vbr; tihm->samplerate = mp3.samplerate; tihm->time = mp3.duration; tihm->size = mp3.file_size; tihm->mod_date = mp3.mod_date; tihm->creation_date = mp3.mod_date; tihm->type = string_to_int ("MP3 "); tihm->is_video = 0; return 0; }
int main() { int_to_string(-50, A); printf("digit %d is string %s\n", -50, A); printf("string 12345 is digit %d\n",string_to_int("-12345")); return 0; }
void insertar_nodo(ListaNodo **ptrCabecera, ArbolNodo **ptrarbol, char **palabras, size_t largo_array, int contador){ int n_callback; if(*ptrarbol==NULL){ ListaNodo *ptrAuxLista=NULL; ArbolNodo *ptrAuxArbol=NULL; ptrAuxArbol = malloc(sizeof(ArbolNodo)); ptrAuxLista = malloc(sizeof(ListaNodo)); ptrAuxArbol->children=NULL; ptrAuxArbol->word="ROOT"; ptrAuxLista->data=ptrAuxArbol; ptrAuxLista->siguiente=NULL; *ptrarbol=ptrAuxArbol; *ptrCabecera=ptrAuxLista; } else{ ArbolNodo *ptrAuxArbol=*ptrarbol; ListaNodo *ptrAuxLista=*ptrCabecera; if(ptrAuxArbol->children==NULL && contador<largo_array){ n_callback=string_to_int(palabras[0]); //ListaNodo *ptrAuxLista=*ptrCabecera; ptrAuxLista = malloc(sizeof(ListaNodo)); ptrAuxArbol = malloc(sizeof(ArbolNodo)); ptrAuxArbol->word=malloc(sizeof(char) * (strlen(palabras[contador]) + 1)); //completar con callbacks strcpy(ptrAuxArbol->word,palabras[contador]);//revisar cuando llamamos recursivamente ptrAuxArbol->children=NULL; //*ptrArbol=ptrAuxArbol; ptrAuxLista->data = ptrAuxArbol; ptrAuxLista->siguiente = NULL; (*ptrarbol)->children=ptrAuxLista; //puts("ahora es cuando!"); insertar_nodo(&ptrAuxArbol->children, &ptrAuxLista->data,palabras,largo_array,contador+1); } } }
void Box::load_movies_seen() { vector<Movie> Seen; string s; float c; int t; ifstream file; file.open("info//Seen Movies.txt"); if (!file.fail()) { while (!file.eof()) { getline(file, s); int i = 1; string name, aux; do { name.push_back(s.at(i)); i++; } while (s.at(i) != '\"'); i+=2; do { aux.push_back(s.at(i)); i++; } while (s.at(i) != ' '); c = string_to_float(aux); t = string_to_int(s.substr(i + 1, s.length())); Movie temp(name, c, t); Seen.push_back(temp); } file.close(); } seenMovies = Seen; }
static uint32_t assemble_expression(instruction_t *instr) { /* PRE: Take a valid and legal pointer to an instruction. The address is exactly [Rn, <#expression>] or "[Rn], <#expression>". */ /* POST: Returns the the value of the expression. */ assert (instr != NULL); /* We will save the start and end of the string matched in match */ regmatch_t match[1]; regex_t regex; /* We execute the regex on the instr->instr_str in order to know where the * expression starts and finishes. The regex execution will save in match * the index of start and end of the string matched. RE_HASH_EXP is a * regex to check if a string contains an expression (i.e. #expression) */ check_and_compile_regex(®ex, RE_HASH_EXP, REG_EXTENDED); regexec(®ex, instr->instr_str, 1, match, 0); uint8_t start = (uint8_t) match->rm_so; uint8_t end = (uint8_t) match->rm_eo; /* We cut the full_instruction keeping only the expression */ char *exp = cut_string(instr->instr_str, start, end); regfree(®ex); /* We free the regex used */ return string_to_int(exp); }
void read_value (Logical newline, char *string, int *value, int lower_bound) { char response[MAXWORD]; Logical error; Logical reading = TRUE; int nmr_items; while (reading) { printf ("%s", string); nmr_items = scanf ("%s", response); verify_read (nmr_items, 1); /* read past any comments */ while (response[0] == COMMENT) { read_line (); nmr_items = scanf ("%s", response); verify_read (nmr_items, 1); } if (!isatty (0)) printf ("%s ", response); if (!isatty (0) && newline) printf ("\n"); *value = string_to_int (response, &error); if (error) printf ("Error in input -- must be integer only\n"); else if ((reading = (*value < lower_bound))) printf ("Error: supplied value must be at least %d\n", lower_bound); } }
int get_int (const char * section, const char * name) { int value = 0; char * string = get_string (section, name); string_to_int (string, & value); g_free (string); return value; }
void cBackground::Load_From_Attributes(XmlAttributes& attributes) { Set_Type(static_cast<BackgroundType>(string_to_int(attributes["type"]))); if (m_type == BG_GR_HOR || m_type == BG_GR_VER) { int r, g, b; r = string_to_int(attributes["bg_color_1_red"]); g = string_to_int(attributes["bg_color_1_green"]); b = string_to_int(attributes["bg_color_1_blue"]); Set_Color_1(Color(static_cast<Uint8>(r), static_cast<Uint8>(g), static_cast<Uint8>(b))); r = string_to_int(attributes["bg_color_2_red"]); g = string_to_int(attributes["bg_color_2_green"]); b = string_to_int(attributes["bg_color_2_blue"]); Set_Color_2(Color(static_cast<Uint8>(r), static_cast<Uint8>(g), static_cast<Uint8>(b))); } else if (m_type == BG_IMG_BOTTOM || m_type == BG_IMG_TOP || m_type == BG_IMG_ALL) { Set_Start_Pos(string_to_float(attributes["posx"]), string_to_float(attributes["posy"])); Set_Pos_Z(string_to_float(attributes["posz"])); Set_Image(utf8_to_path(attributes["image"])); Set_Scroll_Speed(string_to_float(attributes["speedx"]), string_to_float(attributes["speedy"])); Set_Const_Velocity_X(string_to_float(attributes["const_velx"])); Set_Const_Velocity_Y(string_to_float(attributes["const_vely"])); } }
bool cFlyon::Editor_Max_Distance_Text_Changed(const CEGUI::EventArgs& event) { const CEGUI::WindowEventArgs& windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>(event); std::string str_text = static_cast<CEGUI::Editbox*>(windowEventArgs.window)->getText().c_str(); Set_Max_Distance(static_cast<float>(string_to_int(str_text))); return 1; }
bool cLayer_Line_Point_Start :: Editor_Origin_Text_Changed( const CEGUI::EventArgs &event ) { const CEGUI::WindowEventArgs &windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>( event ); std::string str_text = static_cast<CEGUI::Editbox *>( windowEventArgs.window )->getText().c_str(); m_origin = string_to_int( str_text ); return 1; }
int string_to_int_test(char *string, int base, int result) { if (string_to_int(string, base) != result) // se il test non da i risultati esatti { printf("Test fallito, %s in base %d dovrebbe diventare %d in base 10, invece risulta %d\n", string, base, result, string_to_int(string, base)); return -1; // scrive un messaggio di errore ed esce dal ciclo } return 0; }
void cFlyon::Load_From_Savegame(cSave_Level_Object* save_object) { cEnemy::Load_From_Savegame(save_object); // move_back if (save_object->exists("move_back")) { m_move_back = string_to_int(save_object->Get_Value("move_back")) > 0; } }
bool is_RECORD_CORRECT (const vector<string>& SETrecord, const vector<vector<vector<string> > >& DEF, size_t j, size_t k) { string actual_key = SETrecord.at(0); string list_key = DEF.at(j).at(0).at(0); if (actual_key != list_key) return false; string actual_value = capslock (SETrecord.at(1)); string list_value = capslock (DEF.at(j).at(k).at(0)); if (actual_key == "LINEWIDTH:" || actual_key == "STRESSANGLE:" || actual_key == "WELLINTERVAL_LENGTH:") { bool conv_has_failed = true; double min_value = string_to_double (DEF.at(j).at(k).at(1), conv_has_failed); double max_value = string_to_double (DEF.at(j).at(k).at(2), conv_has_failed); string_to_int (actual_value, conv_has_failed); if (actual_key == "LINEWIDTH:" && conv_has_failed) return false; if (actual_key == "STRESSANGLE:" && conv_has_failed) return false; if (actual_key == "WELLINTERVAL_LENGTH:" && conv_has_failed) return false; double value = string_to_double (actual_value, conv_has_failed); if (is_in_range(min_value, max_value, value) && !conv_has_failed) return true; else return false; } else if (actual_key == "CLUSTERNUMBER:") { if (actual_value == "A" || actual_value == "N") { if (actual_value == list_value) return true; else return false; } else { bool conv_has_failed = true; double min_value = string_to_double (DEF.at(j).at(k).at(1), conv_has_failed); double max_value = string_to_double (DEF.at(j).at(k).at(2), conv_has_failed); double value = string_to_double (actual_value, conv_has_failed); if (is_in_range(min_value, max_value, value) && !conv_has_failed) return true; else return false; } } else { if (actual_value == list_value) return true; else return false; } }
cDialog :: cDialog( double nposx, double nposy, string nidentifier, string ntext, DialogType dialogtype, Uint8 nmax_length /* = 20 */, unsigned int nmin_width ) : cSprite( NULL, nposx, nposy ) { stext = NULL; if( is_valid_number( ntext.c_str() ) ) { text_number = string_to_int( ntext ); } else { text_number = 0; } identifier.reserve( nidentifier.length() ); identifier = nidentifier; text = ntext; type = dialogtype; boarder_in = 2; boarder_out = 2; text_area = 1; min_width = nmin_width; if( type != DIALOG_ONLY_NUMBERS ) { if( nmax_length < ntext.length() ) { max_length = ntext.length(); } else { max_length = nmax_length; } text.reserve( max_length ); } else { if( nmax_length < text_number ) { max_length = text_number; } else { max_length = nmax_length; } text.reserve( 20 ); } SetColors( colorDarkBlue, colorBlue, colorWhite, colorBlack ); Update_Boarders(); Update_Text(); }
bool cRandom_Sound::Editor_Delay_Max_Text_Changed(const CEGUI::EventArgs& event) { const CEGUI::WindowEventArgs& windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>(event); std::string str_text = static_cast<CEGUI::Editbox*>(windowEventArgs.window)->getText().c_str(); Set_Delay_Max(string_to_int(str_text)); return 1; }
Status set_debug_level(const char *value) { int ivalue; if (ERROR == string_to_int(value, &ivalue)) return ERROR; else _s_debug_level = ivalue; return OK; }
static int glsl_dim_from_token(const string_const_t token) { string_const_t dim; size_t ofs = string_find(STRING_ARGS(token), '[', 0); if (ofs == STRING_NPOS) return 1; ++ofs; dim = string_substr(STRING_ARGS(token), ofs, string_find(STRING_ARGS(token), ']', ofs) - ofs); return string_to_int(STRING_ARGS(dim)); }
void AssociateArray::load_data(const std::string & data, int method) { unsigned int pos = 0; while (pos < data.size()) { if (data[pos] == '\x00') // probably EOF, NULL-byte due to encryption padding break; int start = pos; while (data[pos] != ' ') pos++; int len = string_to_int(data.substr(start, pos-start)); pos++; // read key start = pos; while (data[pos] != '\x00') pos++; std::string key = data.substr(start, pos-start); decode_method(key, method); pos++; len -= key.size(); // read string start = pos; while (data[pos] != '\x00') pos++; std::string string = data.substr(start, pos-start); decode_method(string, method); pos++; len -= string.size(); // read value std::string value = data.substr(pos, len); decode_method(value, method); pos += len; AssociateArrayItem & item = (*map)[key]; item.value = string_to_int(value); item.string = string; } }
int Usermanage::add_user(User user){ int found = this->find_user("name", user.get("name")); if(found == -1){ if(this->is_same_name(user.get("name"))) return FAILED_NAME; this->users.push_back(user); this->active_user_amount++; return NEW_USER; } else{ if(this->users[found].is_online()) return IS_ONLINE; //if((user.get("name") != this->users[found].get("name")) && this->is_same_name(user.get("name"))) return FAILED_NAME; this->users[found].online(string_to_int(user.get("fd")), string_to_int(user.get("port")), user.get("ip")); this->active_user_amount++; return OLD_USER; } return FAILED; }
static int parse_threshold_key(section_config_t *section, char *value) { if(!strcasecmp(value, "unlimited")) { section->config.threshold = -1; } else { section->config.threshold = string_to_int(value); } return OMPI_SUCCESS; }
//handler para tratar CTRL + C static void ctrlc_hand(int signo, siginfo_t *info, void *data) { if (background == 1) { return; } else { Job job = vector_end(job_list); if (job) kill(string_to_int(job->pid), SIGINT); } }