int words_are_valid(char *line, int line_number) { log_int("starting words validation for line: ", line_number); if (names_are_valid(line, line_number) == 0) { log_simple("words validation ended unsuccesfully"); return (0); } if (email_is_valid(get_word_number(line, 3), line_number) == 0) { log_simple("words validation ended unsuccesfully"); return (0); } if (grade_is_valid(get_word_number(line, 4), line_number) == 0) { log_simple("words validation ended unsuccesfully"); return (0); } if (county_is_valid(get_word_number(line, 5), line_number) == 0) { log_simple("words validation ended unsuccesfully"); return (0); } return (1); log_simple("words validation ended succesfully"); }
int set_range(uint32 *bitmap, int start, int end, int bit) { int i; int start_num = get_word_number(start); int start_offset = start / WORD_LEN; int end_num = get_word_number(end); int end_offset = end / WORD_LEN; if(start_offset) { start_num++; } if(end_offset) { end_num--; } // Set bits in whole words for(i = start_num; i <= end_num; i++) { if(!bit) { bitmap[i] = 0; } else { bitmap[i] = ~((uint32)0); } } // Set bits in start and end word if(start_offset) { set_word_bits(bitmap + start_num - 1, start_offset, WORD_LEN, bit); } if(end_offset) { set_word_bits(bitmap + end_num - 1, end_offset, WORD_LEN, bit) } }
uint32 *init_bitmap(uint32 len) { uint32 *bitmap = (uint32*) malloc(sizeof(uint32) * get_word_number(len)); if(!bitmap) { _debug("Cannot initiate bitmap\n"); return NULL; } return bitmap; }
int is_from_county(char *line, char *county) { log_string("verifying if student is from county: ", county); if (ft_strequ(county, ft_strupcase(get_word_number(line, 5))) == 1) { log_string("student is not from the county: ", county); return (1); } log_string("student is not from the county: ", county); return (0); }
int set_bit(uint32 *bitmap, uint32 idx, int bit) { int word_num = get_word_number(idx); int bit_offset = idx % WORD_LEN; uint32 setter = 1 << bit_offset; if(!bit) { // Set to 0 setter = ~setter; bitmap[word_num] = bitmap[word_num] & setter; } else { // Set to 1 bitmap[word_num] = bitmap[word_num] | setter; } return 0; }
/* This part is a little tricky, I design this function with initial "_", * because I don't want to use malloc while doing the frame management. * So this function return 0 as illegal address. * * But normally, a bitmap should be legal to return 0 */ int _get_and_flip_lowest_zero(uint32 *bitmap, int N) { int word_num = get_word_number(N); int offset = N % WORD_LEN; int i, idx; for(i = 0; i < word_num; i++) { idx = get_and_flip_lowest_zero_in_word(bitmap + i); if(idx >= 0) { return (uint32)idx + word_num * WORD_LEN; } } idx = get_and_flip_lowest_zero_in_word(bitmap + word_num); if(idx >= 0 && idx <= offset) { return (uint32)idx + word_num * WORD_LEN; } else { return 0; // Noted that, 0 is illegal here } }