| 392 | /* Init a replace structure for further calls */ |
| 393 | |
| 394 | static REPLACE *init_replace(char * *from, char * *to,uint count, |
| 395 | char * word_end_chars) |
| 396 | { |
| 397 | uint i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr; |
| 398 | int used_sets,chr; |
| 399 | short default_state; |
| 400 | char used_chars[LAST_CHAR_CODE],is_word_end[256]; |
| 401 | char * pos, *to_pos, **to_array; |
| 402 | REP_SETS sets; |
| 403 | REP_SET *set,*start_states,*word_states,*new_set; |
| 404 | FOLLOWS *follow,*follow_ptr; |
| 405 | REPLACE *replace; |
| 406 | FOUND_SET *found_set; |
| 407 | REPLACE_STRING *rep_str; |
| 408 | DBUG_ENTER("init_replace"); |
| 409 | |
| 410 | /* Count number of states */ |
| 411 | for (i=result_len=max_length=0 , states=2 ; i < count ; i++) |
| 412 | { |
| 413 | len=replace_len(from[i]); |
| 414 | if (!len) |
| 415 | { |
| 416 | errno=EINVAL; |
| 417 | my_message(0,"No to-string for last from-string",MYF(ME_BELL)); |
| 418 | DBUG_RETURN(0); |
| 419 | } |
| 420 | states+=len+1; |
| 421 | result_len+=(uint) strlen(to[i])+1; |
| 422 | if (len > max_length) |
| 423 | max_length=len; |
| 424 | } |
| 425 | memset(is_word_end, 0, sizeof(is_word_end)); |
| 426 | for (i=0 ; word_end_chars[i] ; i++) |
| 427 | is_word_end[(uchar) word_end_chars[i]]=1; |
| 428 | |
| 429 | if (init_sets(&sets,states)) |
| 430 | DBUG_RETURN(0); |
| 431 | found_sets=0; |
| 432 | if (!(found_set= (FOUND_SET*) my_malloc(sizeof(FOUND_SET)*max_length*count, |
| 433 | MYF(MY_WME)))) |
| 434 | { |
| 435 | free_sets(&sets); |
| 436 | DBUG_RETURN(0); |
| 437 | } |
| 438 | (void) make_new_set(&sets); /* Set starting set */ |
| 439 | make_sets_invisible(&sets); /* Hide previus sets */ |
| 440 | used_sets=-1; |
| 441 | word_states=make_new_set(&sets); /* Start of new word */ |
| 442 | start_states=make_new_set(&sets); /* This is first state */ |
| 443 | if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME)))) |
| 444 | { |
| 445 | free_sets(&sets); |
| 446 | my_free(found_set); |
| 447 | DBUG_RETURN(0); |
| 448 | } |
| 449 | |
| 450 | /* Init follow_ptr[] */ |
| 451 | for (i=0, states=1, follow_ptr=follow+1 ; i < count ; i++) |
no test coverage detected