char *check_line_cmd(char *str) { int i; i = 0; while (str[i] == ' ' && str[i]) ++i; if (!str[i]) return (NULL); i = 0; if (check_line(str) == 2 || check_redir(str) == 1) { ft_putendl("msh: Parse error"); return (NULL); } while (check_line(str) == 1 || str[ft_strlen(str) - 1] == '\\') { ft_putstr("parse> "); str = ft_strjoin(str, take_cmd(1)); } if (check_line(str) == 2 || check_redir(str) == 1) { ft_putendl("msh: Parse error"); return (NULL); } return (str); }
int find_full_path(t_info *info) { char *path; int i; char *line; char *tp; i = 0; path = my_getenv(info, "PATH"); if (path == NULL) return (error_int("Variable PATH doesn't exist", 1)); tp = strtok(path, ":"); check_line(tp, info); while ((tp = strtok(NULL, ":"))) { if (check_line(tp, info) == RETURN_SUCCESS) { free(path); return (RETURN_SUCCESS); } memset(tp, '\0', strlen(tp)); } free(tp); free(path); return (RETURN_ERROR); }
void network_generator::choose_dir(pair <int, int> &path_head, int layer, vector < vector <double> > *heat_map){ vector <double> score(4); if(path_head.first+1 <= 100 && liquid_network[layer][path_head.second][path_head.first+1] != 7 && liquid_network[layer][path_head.second][path_head.first+1] != 4){ score[0] += (*heat_map)[path_head.second][path_head.first+1]; if(check_line(path_head, 0, layer)){ score[0] -= 1000; } } if(path_head.second-1 >= 0 && liquid_network[layer][path_head.second-1][path_head.first] != 7 && liquid_network[layer][path_head.second-1][path_head.first] != 4){ score[1] += (*heat_map)[path_head.second-1][path_head.first]; if(check_line(path_head, 1, layer)){ score[1] -= 1000; } } if(path_head.first-1 >= 0 && liquid_network[layer][path_head.second][path_head.first-1] != 7 && liquid_network[layer][path_head.second][path_head.first-1] != 4){ score[2] += (*heat_map)[path_head.second][path_head.first-1]; if(check_line(path_head, 2, layer)){ score[2] -= 1000; } } if(path_head.second+1 <= 100 && liquid_network[layer][path_head.second+1][path_head.first] != 7 && liquid_network[layer][path_head.second+1][path_head.first] != 4){ score[3] += (*heat_map)[path_head.second+1][path_head.first]; if(check_line(path_head, 3, layer)){ score[3] -= 1000; } } double max_score = 0.0; int next_location = -1; for( int i=0;i<4;i++ ){ //cout << i << " " << score[i] << endl; if(max_score < score[i]){ max_score = score[i]; next_location = i; } } if(next_location == 0){ path_head.first ++; } else if(next_location == 1){ path_head.second --; } else if(next_location == 2){ path_head.first --; } else if(next_location == 3){ path_head.second ++; } if(next_location == -1){ cout << "error" << endl; getchar(); } }
int check_map(char **map, int* size_column) { int size_line; t_check test; int i; test.testk = 0; test.testo = 0; test.testi = 0; i = -1; *size_column = 0; size_line = strlen(map[0]); while (map[++i] != NULL) { (*size_column)++; if (size_line != strlen(map[i])) exitError("[ERROR] : Map syntax error : the map have to be a rectangle\n"); check_line(map[i], &test, i); } if (test.testk == 0) exitError("[ERROR] : Map syntax error : a key are necessary (k)\n"); if (test.testo == 0) exitError("[ERROR] : Map syntax error : an exit are necessary (o)\n"); if (test.testi == 0) exitError("[ERROR] : Map syntax error : an enter are necessary (i)\n"); return (size_line); }
int parsing(t_env *data) { char *line; int ret; line = NULL; while (!(data->ants)) get_ants(data, line); while ((ret = get_next_line(0, &line))) { if (!check_line(&line, data)) { if (!can_start(data)) parsing_error(data, line); ft_strdel(&line); ft_putchar('\n'); return (solve(data)); } ft_putendl(line); ft_strdel(&line); } if (ret == -1) ft_error("read"); ft_putchar('\n'); if (!can_start(data)) parsing_error(data, line); return (solve(data)); }
int calcndrop (void) { int col, lin, drops = 1, dtotal = 0; while (drops) { drops = 0; for (lin = 0; lin < DEF_H; lin++) for (col = 0; col < DEF_W; col++) if (field[col][lin] != COL_NONE) { drops += check_line (col, lin); drops += check_col (col, lin); drops += check_diagdown (col, lin); drops += check_diagup (col, lin); } if (drops) { fprintf (stderr, "Found %i places with matches\n", drops); killblocks (COL_BG); //sleep (1); dtotal += drop (); } memset (killfield, false, sizeof(killfield)); } return dtotal; }
void overlayData (nvMapGL *map, OPTIONS *options, MISC *misc) { // Show the filter masked points if any are present. if (misc->filter_mask) { QColor mask = options->marker_color; mask.setAlpha (64); for (NV_INT32 i = 0 ; i < misc->abe_share->point_cloud_count ; i++) { // If we are displaying and editing only a single line, only get those points that // are in that line. if (!misc->num_lines || check_line (misc, misc->data[i].line)) { if (!check_bounds (options, misc, i, NVTrue, misc->slice)) { if (misc->data[i].fmask) { NV_INT32 pix_x, pix_y; map->get2DCoords (misc->data[i].x, misc->data[i].y, -misc->data[i].z, &pix_x, &pix_y); map->drawLine (pix_x - 3, pix_y - 3, pix_x + 3, pix_y - 3, mask, 2, Qt::SolidLine, NVFalse); map->drawLine (pix_x + 3, pix_y - 3, pix_x + 3, pix_y + 3, mask, 2, Qt::SolidLine, NVFalse); map->drawLine (pix_x + 3, pix_y + 3, pix_x - 3, pix_y + 3, mask, 2, Qt::SolidLine, NVFalse); map->drawLine (pix_x - 3, pix_y + 3, pix_x - 3, pix_y - 3, mask, 2, Qt::SolidLine, NVFalse); } } } } map->drawLine (0, 0, 0, 0, options->background_color, 0, Qt::SolidLine, NVTrue); } }
void move_down(void) //블록 밑으로 이동하는 함수 { int i, j; if (crush_on&&check_crush(bx, by + 1, b_rotation) == true) crush_on = 0; //밑이 비어있으면 crush flag 끔 if (crush_on&&check_crush(bx, by + 1, b_rotation) == false) //밑이 비어있지않고 crush flag가 켜저있으면 { for (i = 0; i<height_y; i++) //현재 조작중인 블럭을 굳힘 { for (j = 0; j<width_x; j++) { if (game_scr[i][j] == moving_block) game_scr[i][j] = fixed_block; } } crush_on = 0; //flag를 끔 check_line(); //라인체크를 함 new_block_on = 1; //새로운 블럭생성 flag를 켬 return; //함수 종료 } if (check_crush(bx, by + 1, b_rotation) == true) move_block(DOWN); //밑이 비어있으면 밑으로 한칸 이동 if (check_crush(bx, by + 1, b_rotation) == false) crush_on++; //밑으로 이동이 안되면 crush flag를 켬 }
ATF_TC_BODY(exec_array, tc) { atf_fs_path_t process_helpers; atf_check_result_t result; get_process_helpers_path(tc, false, &process_helpers); const char *argv[4]; argv[0] = atf_fs_path_cstring(&process_helpers); argv[1] = "echo"; argv[2] = "test-message"; argv[3] = NULL; RE(atf_check_exec_array(argv, &result)); ATF_CHECK(atf_check_result_exited(&result)); ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_SUCCESS); { const char *path = atf_check_result_stdout(&result); int fd = open(path, O_RDONLY); ATF_CHECK(fd != -1); check_line(fd, "test-message"); close(fd); } atf_check_result_fini(&result); atf_fs_path_fini(&process_helpers); }
char *add_to_vertex(char *line, t_vertex **list, int i) { t_vertex *elem; if (check_line(line) == -1) { if (*list != NULL) free_list_v(*list); write(1, "Error list point\n", 17); free(line); return (NULL); } if ((elem = malloc(sizeof (t_vertex))) == NULL) { write(1, "Error malloc\n", 12); exit(-1); } elem->number = i; elem->x = take_next_val(line); elem->z = take_next_val(line); elem->y = take_next_val(line); elem->preview = NULL; elem->next = *list; if (elem->next != NULL) elem->next->preview = elem; *list = elem; return ("ok"); }
int check_file(int **lines, int **ia_goal, int fd) { int i; int nb; char **line; if (!(line = (char**)malloc(sizeof(char*)))) error("ERROR MALLOC\n"); i = 0; while (get_next_line(fd, line) == 1) { *lines = ft_realloc_int(*lines, sizeof(int) * i, sizeof(int) * (i + 1)); *ia_goal = ft_realloc_int(*ia_goal, sizeof(int) * i, sizeof(int) * (i + 1)); nb = check_line(line, fd); if (nb == -1) break ; (*lines)[i] = nb; (*ia_goal)[i] = 1; if (i != 0 && ((((*ia_goal)[i - 1] == 1) && ((*lines)[i - 1] - 1) % 4 == 0) || (((*ia_goal)[i - 1] == 0) && ((*lines)[i - 1] - 1) % 4 != 0))) (*ia_goal)[i] = 0; i++; } return (i); }
int convert_file(char *filename) { t_function *file; char *line; int ret; int fd; int test; g_begin = 0; g_lines_tot = 0; file = NULL; fd = open(filename, O_RDONLY); if (fd <= -1) return (cant_read_file(filename)); while ((ret = get_next_line(fd, &line)) == 1) { if (!(is_valid_line(line, g_lines_tot + 1))) return (0); test = check_line(line); add_command(test, &file, line); g_lines_tot++; } if (ret == -1) return (error_while_reading(filename)); check_file(&file); convert_to_bytecode(file, filename); return (0); }
void timer(void) { int i, j; static int count=0; count++; if (count >= DTICS_MAX * TICS_MIN) { count = 0; } if (gamestatus == GAME) { if (fmod(count, DTICS_BOX_FALLS) == DTICS_FMOD_MOVE) { move_all_boxes(); //check_line(); } if (fmod(count, DTICS_BOX_FALLS) == DTICS_FMOD_FALL) { //move_all_boxes(); check_line(); } if (fmod(count, DTICS_BOX_NEW) == DTICS_FMOD_NEW) { new_box(); man.ay = 0; } } return; }
struct variable * create_var(char *text, struct list *vars) { APP_DEBUG_FNAME; if (check_line(text) != LINE_VARIABLE) { ERR("create_var()"); myabort(); } size_t n; struct variable *var; var = malloc(sizeof (struct variable)); n = run_r(CONF_REGEX_VARIABLE, text); trim(text); var->name = alloc_string(text); strcpy(var->name, text); text += n; trim(text); var->substitution = alloc_string(text); strcpy(var->substitution, text); substitute(var->substitution, vars, var->substitution); DEBUG("variable '%s' = '%s' created", var->name, var->substitution); return (var); }
int check_all(int x, int y, int value, char **map) { if (check_col(x, value, map) == 1 && check_line(y, value, map) == 1 && check_square(x, y, value, map) == 1) return (1); return (0); }
int check_error(t_alum *list, int nb) { if (nb > list->nb_matches || nb <= 0) return (error_allum1("\nLa ligne n'est pas correct\n")); if (check_line(list, nb) == -1) return (error_allum1("\nLa ligne est vide\n")); else if (nb < 0) return (error_allum1("\nMettez un nombre superieur a zero\n")); return (nb); }
int main(int argc, char ** argv){ linenum=0; if(argc!=3){ printf("Usage: %s (sickle|ssd|spp|retina) .vcf\n", argv[0]); printf("\t sickle = Sickle Cell Anemia\n"); printf("\t ssd = Severe Skeletal Dysplasia\n"); printf("\t spp = Spastic Paraplegia\n"); printf("\t retina = Retinitis Pigmentosa\n"); exit(2); } if(strcmp("sickle", argv[1])==0) disease_check=sickle_check; if(strcmp("ssd", argv[1])==0) disease_check=ssd_check; if(strcmp("spp", argv[1])==0) disease_check=spp_check; if(strcmp("retina", argv[1])==0) disease_check=retina_check; FILE * varfile = fopen(argv[2], "r"); if(!varfile){ fprintf(stderr, "Couldnt open file: %s\n", argv[2]); exit(1); } char line[4096]; line[1]='#';//prime //Skip all the lines starting with '#' while (fgets(line, sizeof(line)-1, varfile) != NULL && line[1]=='#'); printf("%s",line); //Header char *sp=line, *st=NULL; //prime Strtok size_t idx=0, format_loc=0, family_num=0; /* Scan this line and find the family names and locations */ while((st = strtok_r(NULL, " \t", &sp)) != NULL ){ if(strcmp(st, "FORMAT")==0)format_loc=idx; idx++; } idx--; family_num=idx-format_loc; fprintf(stderr,"%u Family members, loc: %u\n", family_num, format_loc); /* Start Checking Variations */ /* each line could be done in parrallel */ while (fgets(line, sizeof(line)-1, varfile) != NULL){ //No Sex Chromosomes if(line[0]=='X' || line[0]=='Y') break; check_line(line); linenum++; } fflush(stdout); }
int verif(char **src) { char *zero; if ((zero = malloc(sizeof(char) * 20)) == NULL) return (error_basic(3)); zero = fill_zero(zero); if ((check_line(src, zero, 1, 1) == -1) || (check_col(src, zero, 1, 2) == -1)) return (-1); free(zero); return (0); }
/* main()-25 statements */ int main(int argc, char *argv[]) { char str[STR_SIZE],query[STR_SIZE],c; int bytes=0,count_l=1; ranker_t ranked_lines[MAX_LINES_OUT]; initialize_ranked(ranked_lines); /* Checking if no command line query is given as input */ if(argc<2) { printf("Sorry !! But the query is cannot be empty !!"); exit(EXIT_FAILURE); } strcpy(query,argv[1]); check_query(query); /* Printing the query for S0 */ printf("S0: query = %s",query); printf("\n---"); /*Taking each line as input */ while((c=getchar())!=EOF) { /* Checking for end of each line */ if(c=='\n') { str[bytes]='\0'; /* Checking if each line is valid */ check_line(str); /* Manipulations to give the S1,S2,S3 AND S4*/ manip(str,query,count_l,ranked_lines); strcpy(str,""); bytes=0; count_l++; } else { str[bytes]=c; /* Putting characters into the string */ bytes++; } } printf("---------------------------------------------"); print_rankedlines(ranked_lines); /* All done !! Thank You. */ return 0; }
struct command * create_cmd(char *text, struct list *vars) { APP_DEBUG_FNAME; if (check_line(text) != LINE_COMMAND) { ERR("create_cmd()"); myabort(); } struct command *cmd; struct command_config c; size_t n; #define asterisk (strcmp(text, "*") == 0) ? -1 : strtol(text, NULL, 10) n = run_r(CONF_REGEX_COMMAND_MIN, text); c.min = asterisk; text += n; n = run_r(CONF_REGEX_COMMAND_HOUR, text); c.hour = asterisk; text += n; n = run_r(CONF_REGEX_COMMAND_DOM, text); c.dom = asterisk; text += n; n = run_r(CONF_REGEX_COMMAND_MON, text); c.month = asterisk; text += n; n = run_r(CONF_REGEX_COMMAND_DOW, text); c.dow = asterisk; text += n; if (strlen(text) <= 0) { ERR("command_length <= 0"); myabort(); } c.cmd = alloc_string(text); strcpy(c.cmd, text); cmd = transform(&c); substitute(cmd->cmd, vars, cmd->cmd); DEBUG("command '%s: %s' created", time_to_string(cmd->seconds), cmd->cmd); return (cmd); }
void tick(int * reached_bottom){ static int filled_lines[4]; static int counter = 0; if(*reached_bottom){ //new piece reached the bottom or gravity activated and things need to be rechecked *reached_bottom = 0; if(counter == 0){//only if call is not coming from gravity stuff write_to_world(¤t_tetromino, &world); } counter = 0; //check for lines right here & gravity for(int i = WORLD_HEIGHT-1; i >= world.top_line; i--){ if(check_line(i)){ fill_line(i); filled_lines[counter] = i; counter++; } } world.points += 100*counter*counter; if(counter == 0){ fill_tetromino(¤t_tetromino,rand()%7); if(check_collision(¤t_tetromino, &world)){ //GAME OVER init_game(); } }else{ current_tetromino.visible = 0;//dont display it while removing lines } }else if(counter != 0){ //lines to remove, gravity to activate //remove from top to bottom for(int i = counter-1; i >= 0; i--){ remove_line(filled_lines[i]); } set_tick_time(); *reached_bottom = 1; }else{ //just a normal turn, m8 *reached_bottom = go_down(¤t_tetromino, &world);//in the next tick: block is placed } }
void ft_read(char *path) { int fd; int rd; int line; char buf[BUF_SIZE]; char **map; fd = open(path, O_RDONLY); while ((rd = read(fd, buf, BUF_SIZE))) { buf[rd] = '\0'; map = check_line(map, buf, line++, rd); } }
static size_t get_len(const char *file) { int fd; size_t len; char *line; len = 1; fd = open(file, O_RDONLY); while (get_next_line(fd, &line)) { check_line(line); len++; } close(fd); return (len); }
int main(int argc, char **argv) { struct sigaction sa; t_data *data; data = get_data(); sa.sa_sigaction = signal_usr1; sa.sa_flags = SA_SIGINFO; sigaction(SIGUSR1, &sa, NULL); if (argc >= 2) data->server_pid = ft_atoi(argv[1]); if (argc == 3) send_message(argv[2]); else if (argc == 2) check_line(); return (0); }
//read the map in the agent file void read_agent_map(MapData *m) { m->mapForAgents = malloc(m->height * sizeof(char *)); for (int r = 0; r < m->height; ++r) { m->mapForAgents[r] = calloc(m->width + 2, sizeof(char)); if(fgets(m->mapForAgents[r], m->width+2, stdin) == NULL || m->mapForAgents[r][m->width] != '\n') { agent_error(4); } check_line(m, r); } }
static int check_diez(char *str) { int nb_diez; int ret; int i; nb_diez = 0; ret = 1; i = 0; while (i < 4 && ret != -1) { ret = check_line(&str); nb_diez += ret; i++; } if (nb_diez != 4) return (0); return (1); }
int check_args(t_lemin *lemin) { char *line; lemin->started = 0; lemin->ended = 0; if (get_nbr_ants(lemin) == 1) return (2); while ((line = get_next_line(0)) != NULL) { if (check_line(lemin, line)) { free(line); return (start_end_needed(lemin)); } free(line); } return (0); }
int check_winner(t_grid *grid, int c) { int i; int j; i = 0; while (grid->map[i] != NULL) { j = 0; while (grid->map[i][j]) { if (!check_line(grid, i, j - 1)) if (grid->map[i][j] == c && read_line(i, j, c, grid) == 1) return (c); ++j; } ++i; } return (0); }
ATF_TC_BODY (exec_list, tc) { atf_fs_path_t process_helpers; atf_list_t argv; atf_process_status_t status; RE (atf_list_init (&argv)); get_process_helpers_path (tc, true, &process_helpers); atf_list_append (&argv, strdup (atf_fs_path_cstring (&process_helpers)), true); atf_list_append (&argv, strdup ("echo"), true); atf_list_append (&argv, strdup ("test-message"), true); { atf_fs_path_t outpath; atf_process_stream_t outsb; RE (atf_fs_path_init_fmt (&outpath, "stdout")); RE (atf_process_stream_init_redirect_path (&outsb, &outpath)); RE (atf_process_exec_list (&status, &process_helpers, &argv, &outsb, NULL)); atf_process_stream_fini (&outsb); atf_fs_path_fini (&outpath); } atf_list_fini (&argv); ATF_CHECK (atf_process_status_exited (&status)); ATF_CHECK_EQ (atf_process_status_exitstatus (&status), EXIT_SUCCESS); { int fd = open ("stdout", O_RDONLY); ATF_CHECK (fd != -1); check_line (fd, "test-message"); close (fd); } atf_process_status_fini (&status); atf_fs_path_fini (&process_helpers); }
static int write_replacements(genhomedircon_settings_t * s, FILE * out, const semanage_list_t * tpl, const replacement_pair_t *repl) { Ustr *line = USTR_NULL; for (; tpl; tpl = tpl->next) { line = replace_all(tpl->data, repl); if (!line) goto fail; if (check_line(s, line) == STATUS_SUCCESS) { if (!ustr_io_putfileline(&line, out)) goto fail; } ustr_sc_free(&line); } return STATUS_SUCCESS; fail: ustr_sc_free(&line); return STATUS_ERR; }