void set_columns_of_solution_file(char *column_1, char *column_2, const char *path_file_name){ char *line_splited; int num_obj = 0; FILE * solution_file; char *line; line = Malloc(char, 300); solution_file = open_file(path_file_name, fREAD); //getting first line to obtain number of objectivies fgets(line,300,solution_file); line_splited = strtok (line,"\t"); while (line_splited != NULL){ num_obj = num_obj + 1; if (num_obj == 2){ strcpy(column_1, line_splited); }else if (num_obj == 3){ strcpy(column_2, line_splited); } line_splited = strtok(NULL, "\t"); } fclose(solution_file); trim(column_1); trim(column_2); remove_character(column_1, '#'); remove_character(column_2, '\n'); free(line); }
/** Loading file that contains the objectives and * final collumn has the identificator */ owner_file_t * loading_owner_file_solution_file_name_at_ending(const int *num_solutions_r, const int *numobj_r, const char *path_file_name){ FILE * solution_file; char *line; char *line_splited; int sol; owner_file_t * solutions_aux; line = Malloc(char, MAX_LINE_SOLUTION_FILE); //Alocating Solution solutions_aux = allocate_file_t(num_solutions_r, numobj_r); //Reading file and set values of objective sol = -1; solution_file = open_file(path_file_name, fREAD); //Removing first line that is collumn fgets(line,MAX_LINE_SOLUTION_FILE,solution_file); while ( fgets(line,MAX_LINE_SOLUTION_FILE,solution_file) != NULL){ sol = sol + 1; //Obtaing index collumn line_splited = strtok (line,"\t"); //Objective 0 trim(line_splited); solutions_aux[sol].obj_values[0] = str2float(line_splited); //Objective 1 line_splited = strtok (NULL,"\t"); trim(line_splited); solutions_aux[sol].obj_values[1] = str2float(line_splited); //identificator line_splited = strtok (NULL,"\t"); remove_character(line_splited, '\n'); trim(line_splited); strcpy(solutions_aux[sol].file_name, line_splited); } fclose(solution_file); free(line); return solutions_aux; }
static int _tui_input(int line, int col, const char *prompt, char *buf, int len, int echo, int clear, bool utf8) { extern int RMSG; extern int msg_num; if (clear) buf[0] = '\0'; buf[len - 1] = '\0'; int real_x = prompt ? screen_display_width(prompt, utf8) : 0; int cur, clen; cur = clen = strlen(buf); bool inited = screen_inited(), prompted = false; while (1) { if (inited || !prompted) { screen_move(line, col); clrtoeol(); if (prompt) { if (utf8) screen_printf("%s", prompt); else prints("%s", prompt); } prompted = true; } if (inited) { if (echo) prints("%s", buf); else tui_repeat_char('*', clen); screen_move(line, real_x + cur); } if (RMSG) screen_flush(); int ch = terminal_getchar(); if (RMSG && msg_num == 0) { if (ch == Ctrl('Z') || ch == KEY_UP) { buf[0] = Ctrl('Z'); clen = 1; break; } if (ch == Ctrl('A') || ch == KEY_DOWN) { buf[0] = Ctrl('A'); clen = 1; break; } } if (ch == '\n' || ch == '\r') break; if (!inited) { if (ch == '\x7f' || ch == Ctrl('H')) { int dec = remove_character(buf, &cur, clen, true); if (dec) { clen -= dec; screen_puts("\x8 \x8", 3); } } else if (isprint2(ch) && clen < len - 1) { buf[cur] = ch; buf[++cur] = '\0'; ++clen; screen_putc(echo ? ch : '*'); } continue; } if (ch == '\x7f' || ch == Ctrl('H')) { clen -= remove_character(buf, &cur, clen, true); } else if (ch == KEY_DEL) { clen -= remove_character(buf, &cur, clen, false); } else if (ch == KEY_LEFT) { if (cur > 0) --cur; } else if (ch == KEY_RIGHT) { if (cur < clen) ++cur; } else if (ch == Ctrl('E') || ch == KEY_END) { cur = clen; } else if (ch == Ctrl('A') || ch == KEY_HOME) { cur = 0; } else if (isprint2(ch) && clen < len - 1) { if (buf[cur] != '\0') memmove(buf + cur + 1, buf + cur, clen - cur); buf[cur++] = ch; buf[++clen] = '\0'; } } screen_putc('\n'); screen_flush(); return clen; }
void parse_cmd(char *cmd) { cmd = remove_leading_whitespaces(cmd); char *tok = find_next_space(cmd); // Find Command int status; debug_msg(cmd); #if USEBUILTINCLEAR if (strcmp(cmd, "clear") == 0) { clear(); } else #endif if (strcmp(cmd, "env") == 0) { env(); } else if (strcmp(cmd, "quit") == 0) { exit(EXIT_SUCCESS); } else if (strcmp(cmd, "version") == 0) { version(); } else if (strcmp(cmd, "pwd") == 0) { pwd(); } #if USEBUILTINLS else if (strcmp(cmd, "ls") == 0) { ls(); } #endif else if (strcmp(cmd, "echo") == 0) { find_next_space(tok); remove_character(tok,'\\'); echo(tok); } else if (strcmp(cmd, "cd") == 0) { find_next_space(tok); // Get Path remove_character(tok,'\\'); // Remove all '\' in target Path. debug_msg(tok); cd(tok); } else if (strcmp(cmd, "set") == 0) { // Get Name of Variable char *buffer = strtok(tok,"="); // Get new Value of Variable and set. set(buffer, strtok(NULL,"=")); } else if (strcmp(cmd, "\0") == 0) { // Do nothing. } else { // Fork application here pid_t pID = fork(); if (pID < 0) { // pID == -1: There was an error! Quit shawn!! errno_msg("Could not fork.",0); } else if (pID > 0) { // Parent Process, pID is PID of child. pID = wait(&status); // Wait for childs completion. if (WIFEXITED(status)) { // Has Child ended? last_exit_code = WEXITSTATUS(status); // Set our internal $? #if DEBUG printf("[DEBUG] Child exited with %i\n",last_exit_code); #endif } } else { // PID == 0 // Child Process. // We need to fork here. unsigned int i = 2; // Prepare a counter char *parameters[count_paramters(tok)]; // Create a list for parameters char *buffer = find_next_space(tok); // Select first parameter. remove_character(tok,'\\'); parameters[0] = cmd; // Set name of call. See execvp() Documentation parameters[1] = tok; // Set first parameter. // Save every Parameter now for our Call while (buffer != NULL) { // We need a second pointer here. char *placeholder = find_next_space(buffer); // remove all \ characters while(remove_next_special_character(buffer,'\\') == 1); // Set the Parameter to our newly delimited string parameters[i] = buffer; // Replace buffer with our placeholder buffer = placeholder; i++; // Increment i, so we set the next parameter } parameters[i-1] = NULL; // Remove an empty Parameter. Else This would be a whitespace // Run Application now. int result = execvp(cmd,parameters); if (result != 0) { errno_msg("Executing Application",1); } exit(result); } } // End of fork() Stuff. }