void get_next_file_block( char *datafile, unsigned char *block, int *length ) { static FILE *fp; static int first = 1; if( first ) { fp = fopen( datafile, "r" ); first = 0; } fread( block, 5, sizeof( char ), fp ); while( ! match_end( block ) ) { memmove( block, block + 1, 4 ); fread( &block[4], 1, sizeof( char ), fp ); } *length = 5; fread( &block[++(*length) - 1], 1, sizeof( char ), fp ); while( ! match_end( block + *length - 4 - 1 ) ) { fread( &block[++(*length) - 1], 1, sizeof( char ), fp ); } fseek( fp, -5, SEEK_CUR ); *length -= 4; }
t_jobs *get_jobs(t_get *words, t_jobs *prev, char **bad_sintax) { t_jobs *link; if (!words) return (prev); if ((link = xmalloc(sizeof(*link))) == NULL) return (word_nullify(words)); link->tmp = words; if (!(link->type = match_end(&words, bad_sintax))) return (word_nullify(words)); if (words) if (words->prev) words->prev->next = NULL; if (words) if (words->next) words->next->prev = NULL; if (prev) prev->next = link; link->next = NULL; if (!words) return (link); if (get_jobs(words->next, link, bad_sintax) == NULL) return (nullify(link)); rm_words(words); return (link); }
static here_search_result_ctx *here_execute_search_program_step( const char *buffer, const char *buffer_end, here_search_program_ctx *step) { here_search_result_ctx *search_result = NULL; switch (step->ctype) { case HERE_CTYPE_CMATCH: search_result = match_char(buffer, buffer_end, step); break; case HERE_CTYPE_END: search_result = match_end(buffer, buffer_end, step); break; case HERE_CTYPE_DOT: search_result = match_dot(buffer, buffer_end, step); break; case HERE_CTYPE_LIST: search_result = match_list(buffer, buffer_end, step); break; case HERE_CTYPE_OPTION: search_result = match_opt(buffer, buffer_end, step); break; default: //bypass duh! break; } return search_result; }
static here_search_result_ctx *match_dot(const char *buffer, const char *buffer_end, here_search_program_ctx *search_program) { here_search_result_ctx *search_result = NULL; int matches = 0; const char *b = buffer, *rb; int occur_nr = 0; here_search_program_ctx *next_step, *sp; switch (search_program->ccomp) { case HERE_CTYPE_STAR: search_result = match_end(b, buffer_end, search_program); if (!here_matches(search_result)) { if (search_program->next != NULL) { del_here_search_result_ctx(search_result); search_result = NULL; rb = buffer; while (rb != (buffer_end + 1) && !here_matches(search_result)) { next_step = search_program->next; b = rb; while (next_step != NULL) { del_here_search_result_ctx(search_result); search_result = here_execute_search_program_step(b, buffer_end, next_step); if (!here_matches(search_result)) { break; } else { if (next_step->ctype == HERE_CTYPE_DOT && next_step->ccomp == HERE_CTYPE_STAR) { break; } } next_step = next_step->next; b++; } rb++; } } } else { del_here_search_result_ctx(search_result); new_here_search_result_ctx(search_result); } matches = 1; if (here_matches(search_result)) { search_result->end_at = rb; } else { if (search_result == NULL) { new_here_search_result_ctx(search_result); } search_result->end_at = buffer + 1; } break; case HERE_CTYPE_QUESTION: search_result = match_end(b, buffer_end, search_program); if (!here_matches(search_result)) { next_step = search_program->next; if (next_step != NULL) { del_here_search_result_ctx(search_result); search_result = here_execute_search_program_step(b, buffer_end, next_step); } search_result->end_at = (here_matches(search_result)) ? b + 1 : b + 2 ; matches = 1; } break; case HERE_CTYPE_PLUS: search_result = match_end(b, buffer_end, search_program); if (!here_matches(search_result)) { next_step = search_program->next; if (next_step != NULL) { del_here_search_result_ctx(search_result); b++; search_result = here_execute_search_program_step(b, buffer_end, next_step); while (b != buffer_end && !here_matches(search_result)) { b++; del_here_search_result_ctx(search_result); search_result = here_execute_search_program_step(b, buffer_end, next_step); } } search_result->end_at = b - 1; matches = 1; } else { matches = 0; } break; case HERE_CTYPE_RANGE: search_result = match_end(b, buffer_end, search_program); if (!here_matches(search_result)) { occur_nr = 1; b++; next_step = search_program->next; if (next_step != NULL) { del_here_search_result_ctx(search_result); search_result = here_execute_search_program_step(b, buffer_end, next_step); while (b != buffer_end && !here_matches(search_result)) { b++; occur_nr++; del_here_search_result_ctx(search_result); search_result = here_execute_search_program_step(b, buffer_end, next_step); } } if (occur_nr > 0) { search_result->occur_nr = occur_nr; if (search_program->max == -1) { matches = (occur_nr == search_program->min); } else if (search_program->min > -1 && search_program->max > 0) { matches = (occur_nr >= search_program->min && occur_nr <= search_program->max); } else if (search_program->max == 0) { matches = (occur_nr >= search_program->min); } if (matches) { search_result->end_at = b; } } } break; case HERE_CTYPE_NONE: search_result = match_end(b, buffer_end, search_program); if ((matches = (!here_matches(search_result)))) { search_result->start_at = buffer; search_result->end_at = buffer; search_result->next_step = search_program->next; } break; default: //bypass break; } if (matches) { search_result->next_step = search_program->next; search_result->start_at = buffer; if (search_program->ccomp != HERE_CTYPE_NONE && search_program->ccomp != HERE_CTYPE_PLUS) { search_result->end_at = (search_result->end_at != NULL) ? search_result->end_at - 1 : 0 ; } } else { search_result->start_at = NULL; search_result->end_at = NULL; search_result->next_step = NULL; } return search_result; }