The world's most popular open source database
#include <my_global.h>#include <m_ctype.h>#include <my_sys.h>#include <m_string.h>#include <errno.h>Include dependency graph for replace.c:

Go to the source code of this file.
Classes | |
| struct | st_pointer_array |
| struct | st_replace |
| struct | st_replace_found |
| struct | st_rep_set |
| struct | st_rep_sets |
| struct | st_found_set |
| struct | st_follow |
Defines | |
| #define | DONT_USE_RAID |
| #define | PC_MALLOC 256 |
| #define | PS_MALLOC 512 |
| #define | SPACE_CHAR 256 |
| #define | START_OF_LINE 257 |
| #define | END_OF_LINE 258 |
| #define | LAST_CHAR_CODE 259 |
| #define | WORD_BIT (8*sizeof(uint)) |
| #define | SET_MALLOC_HUNC 64 |
Typedefs | |
| typedef st_pointer_array | POINTER_ARRAY |
| typedef st_replace | REPLACE |
| typedef st_replace_found | REPLACE_STRING |
| typedef st_rep_set | REP_SET |
| typedef st_rep_sets | REP_SETS |
| typedef st_found_set | FOUND_SET |
| typedef st_follow | FOLLOWS |
Functions | |
| static int | static_get_options (int *argc, char ***argv) |
| static int | get_replace_strings (int *argc, char ***argv, POINTER_ARRAY *from_array, POINTER_ARRAY *to_array) |
| static int | insert_pointer_name (POINTER_ARRAY *pa, my_string name) |
| static void | free_pointer_array (POINTER_ARRAY *pa) |
| static int | convert_pipe (REPLACE *, FILE *, FILE *) |
| static int | convert_file (REPLACE *, my_string) |
| static REPLACE * | init_replace (my_string *from, my_string *to, uint count, my_string word_end_chars) |
| static uint | replace_strings (REPLACE *rep, my_string *start, uint *max_length, my_string from) |
| static int | initialize_buffer (void) |
| static void | reset_buffer (void) |
| static void | free_buffer (void) |
| int | main (int argc, char *argv[]) |
| static int | static_get_options (int *argc, argv) |
| static int | get_replace_strings (int *argc, argv, POINTER_ARRAY *from_array, POINTER_ARRAY *to_array) |
| static int | insert_pointer_name (reg1 POINTER_ARRAY *pa, my_string name) |
| static void | free_pointer_array (reg1 POINTER_ARRAY *pa) |
| static int | init_sets (REP_SETS *sets, uint states) |
| static REP_SET * | make_new_set (REP_SETS *sets) |
| static void | make_sets_invisible (REP_SETS *sets) |
| static void | free_last_set (REP_SETS *sets) |
| static void | free_sets (REP_SETS *sets) |
| static void | internal_set_bit (REP_SET *set, uint bit) |
| static void | internal_clear_bit (REP_SET *set, uint bit) |
| static void | or_bits (REP_SET *to, REP_SET *from) |
| static void | copy_bits (REP_SET *to, REP_SET *from) |
| static int | cmp_bits (REP_SET *set1, REP_SET *set2) |
| static int | get_next_bit (REP_SET *set, uint lastpos) |
| static short | find_set (REP_SETS *sets, REP_SET *find) |
| static short | find_found (FOUND_SET *found_set, uint table_offset, int found_offset) |
| static uint | start_at_word (my_string pos) |
| static uint | end_of_word (my_string pos) |
| static uint | replace_len (my_string pos) |
| static int | fill_buffer_retaining (File fd, int n) |
Variables | |
| static int | silent = 0 |
| static int | verbose = 0 |
| static int | updated = 0 |
| static uint | found_sets = 0 |
| static char * | buffer |
| static int | bufbytes |
| static int | bufread |
| static int | my_eof |
| static uint | bufalloc |
| static char * | out_buff |
| static uint | out_length |
| typedef struct st_found_set FOUND_SET |
| typedef struct st_pointer_array POINTER_ARRAY |
| typedef struct st_rep_set REP_SET |
| typedef struct st_rep_sets REP_SETS |
| typedef struct st_replace REPLACE |
| typedef struct st_replace_found REPLACE_STRING |
Definition at line 778 of file replace.c.
References bcmp, st_rep_set::bits, and st_rep_set::size_of_bits.
00779 { 00780 return bcmp((byte*) set1->bits,(byte*) set2->bits, 00781 sizeof(uint) * set1->size_of_bits); 00782 }
Definition at line 1051 of file replace.c.
References convert_pipe(), create_temp_file(), DBUG_ENTER, DBUG_RETURN, dirname_part(), error, FN_REFLEN, my_delete(), my_disable_symlinks, my_fclose(), my_fdopen(), my_fopen(), MY_LINK_WARNING, my_readlink(), my_redel(), MY_WME, MYF, silent, updated, and verbose.
Referenced by main().
01052 { 01053 int error; 01054 FILE *in,*out; 01055 char dir_buff[FN_REFLEN], tempname[FN_REFLEN]; 01056 char link_name[FN_REFLEN], *org_name = name; 01057 File temp_file; 01058 DBUG_ENTER("convert_file"); 01059 01060 /* check if name is a symlink */ 01061 #ifdef HAVE_READLINK 01062 org_name= (!my_disable_symlinks && 01063 !my_readlink(link_name, name, MYF(0))) ? link_name : name; 01064 #endif 01065 if (!(in= my_fopen(org_name,O_RDONLY,MYF(MY_WME)))) 01066 DBUG_RETURN(1); 01067 dirname_part(dir_buff,org_name); 01068 if ((temp_file= create_temp_file(tempname, dir_buff, "PR", O_WRONLY, 01069 MYF(MY_WME))) < 0) 01070 { 01071 my_fclose(in,MYF(0)); 01072 DBUG_RETURN(1); 01073 } 01074 if (!(out= my_fdopen(temp_file, tempname, O_WRONLY, MYF(MY_WME)))) 01075 { 01076 my_fclose(in,MYF(0)); 01077 DBUG_RETURN(1); 01078 } 01079 01080 error=convert_pipe(rep,in,out); 01081 my_fclose(in,MYF(0)); my_fclose(out,MYF(0)); 01082 01083 if (updated && ! error) 01084 my_redel(org_name,tempname,MYF(MY_WME | MY_LINK_WARNING)); 01085 else 01086 my_delete(tempname,MYF(MY_WME)); 01087 if (!silent && ! error) 01088 { 01089 if (updated) 01090 printf("%s converted\n",name); 01091 else if (verbose) 01092 printf("%s left unchanged\n",name); 01093 } 01094 DBUG_RETURN(error); 01095 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int convert_pipe | ( | REPLACE * | , | |
| FILE * | , | |||
| FILE * | ||||
| ) | [static] |
Definition at line 1009 of file replace.c.
References DBUG_ENTER, DBUG_RETURN, error, fill_buffer_retaining(), my_fwrite(), MY_NABP, MY_WME, MYF, replace_strings(), reset_buffer(), and updated.
Referenced by convert_file(), and main().
01012 { 01013 int retain,error; 01014 uint length; 01015 char save_char,*end_of_line,*start_of_line; 01016 DBUG_ENTER("convert_pipe"); 01017 01018 updated=retain=0; 01019 reset_buffer(); 01020 01021 while ((error=fill_buffer_retaining(fileno(in),retain)) > 0) 01022 { 01023 end_of_line=buffer ; 01024 buffer[bufbytes]=0; /* Sentinel */ 01025 for (;;) 01026 { 01027 start_of_line=end_of_line; 01028 while (end_of_line[0] != '\n' && end_of_line[0]) 01029 end_of_line++; 01030 if (end_of_line == buffer+bufbytes) 01031 { 01032 retain= (int) (end_of_line - start_of_line); 01033 break; /* No end of line, read more */ 01034 } 01035 save_char=end_of_line[0]; 01036 end_of_line[0]=0; 01037 end_of_line++; 01038 if ((length=replace_strings(rep,&out_buff,&out_length,start_of_line)) == 01039 (uint) -1) 01040 return 1; 01041 if (!my_eof) 01042 out_buff[length++]=save_char; /* Don't write added newline */ 01043 if (my_fwrite(out,out_buff,length,MYF(MY_WME | MY_NABP))) 01044 DBUG_RETURN(1); 01045 } 01046 } 01047 DBUG_RETURN(error); 01048 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int fill_buffer_retaining | ( | File | fd, | |
| int | n | |||
| ) | [static] |
Definition at line 965 of file replace.c.
References bmove(), my_read, my_realloc(), MY_WME, and MYF.
Referenced by convert_pipe().
00968 { 00969 int i; 00970 00971 /* See if we need to grow the buffer. */ 00972 if ((int) bufalloc - n <= bufread) 00973 { 00974 while ((int) bufalloc - n <= bufread) 00975 { 00976 bufalloc *= 2; 00977 bufread *= 2; 00978 } 00979 buffer = my_realloc(buffer, bufalloc+1, MYF(MY_WME)); 00980 if (! buffer) 00981 return(-1); 00982 } 00983 00984 /* Shift stuff down. */ 00985 bmove(buffer,buffer+bufbytes-n,(uint) n); 00986 bufbytes = n; 00987 00988 if (my_eof) 00989 return 0; 00990 00991 /* Read in new stuff. */ 00992 if ((i=(int) my_read(fd, buffer + bufbytes, (uint) bufread,MYF(MY_WME))) < 0) 00993 return -1; 00994 00995 /* Kludge to pretend every nonempty file ends with a newline. */ 00996 if (i == 0 && bufbytes > 0 && buffer[bufbytes - 1] != '\n') 00997 { 00998 my_eof = i = 1; 00999 buffer[bufbytes] = '\n'; 01000 } 01001 01002 bufbytes += i; 01003 return i; 01004 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 835 of file replace.c.
References st_found_set::found_offset, found_sets, and st_found_set::table_offset.
00837 { 00838 int i; 00839 for (i=0 ; (uint) i < found_sets ; i++) 00840 if (found_set[i].table_offset == table_offset && 00841 found_set[i].found_offset == found_offset) 00842 return (short) (-i-2); 00843 found_set[i].table_offset=table_offset; 00844 found_set[i].found_offset=found_offset; 00845 found_sets++; 00846 return (short) (-i-2); /* return new postion */ 00847 }
Definition at line 812 of file replace.c.
References cmp_bits(), st_rep_sets::count, find(), free_last_set(), and st_rep_sets::set.
00813 { 00814 uint i; 00815 for (i=0 ; i < sets->count-1 ; i++) 00816 { 00817 if (!cmp_bits(sets->set+i,find)) 00818 { 00819 free_last_set(sets); 00820 return (short) i; 00821 } 00822 } 00823 return (short) i; /* return new postion */ 00824 }
Here is the call graph for this function:

| static void free_buffer | ( | void | ) | [static] |
Definition at line 952 of file replace.c.
References my_free, MY_WME, and MYF.
Referenced by Lgman::execDUMP_STATE_ORD(), main(), and Lgman::process_log_buffer_waiters().
Here is the caller graph for this function:

| static void free_last_set | ( | REP_SETS * | sets | ) | [static] |
| static void free_pointer_array | ( | reg1 POINTER_ARRAY * | pa | ) | [static] |
| static void free_pointer_array | ( | POINTER_ARRAY * | pa | ) | [static] |
| static void free_sets | ( | REP_SETS * | sets | ) | [static] |
Definition at line 744 of file replace.c.
References st_rep_sets::bit_buffer, my_free, MYF, and st_rep_sets::set_buffer.
00745 { 00746 my_free((gptr)sets->set_buffer,MYF(0)); 00747 my_free((gptr)sets->bit_buffer,MYF(0)); 00748 return; 00749 }
Definition at line 787 of file replace.c.
References st_rep_set::bits, pos(), st_rep_set::size_of_bits, start(), and WORD_BIT.
00788 { 00789 uint pos,*start,*end,bits; 00790 00791 start=set->bits+ ((lastpos+1) / WORD_BIT); 00792 end=set->bits + set->size_of_bits; 00793 bits=start[0] & ~((1 << ((lastpos+1) % WORD_BIT)) -1); 00794 00795 while (! bits && ++start < end) 00796 bits=start[0]; 00797 if (!bits) 00798 return 0; 00799 pos=(uint) (start-set->bits)*WORD_BIT; 00800 while (! (bits & 1)) 00801 { 00802 bits>>=1; 00803 pos++; 00804 } 00805 return pos; 00806 }
Here is the call graph for this function:

| static int get_replace_strings | ( | int * | argc, | |
| argv | , | |||
| POINTER_ARRAY * | from_array, | |||
| POINTER_ARRAY* | to_array | |||
| ) | [static] |
Definition at line 218 of file replace.c.
References bzero, insert_pointer_name(), ME_BELL, my_message(), MYF, pos(), and strcmp().
00222 { 00223 char *pos; 00224 00225 bzero((char*) from_array,sizeof(from_array[0])); 00226 bzero((char*) to_array,sizeof(to_array[0])); 00227 while (*argc > 0 && (*(pos = *(*argv)) != '-' || pos[1] != '-' || pos[2])) 00228 { 00229 insert_pointer_name(from_array,pos); 00230 (*argc)--; 00231 (*argv)++; 00232 if (!*argc || !strcmp(**argv,"--")) 00233 { 00234 my_message(0,"No to-string for last from-string",MYF(ME_BELL)); 00235 return 1; 00236 } 00237 insert_pointer_name(to_array,**argv); 00238 (*argc)--; 00239 (*argv)++; 00240 } 00241 if (*argc) 00242 { /* Skip "--" argument */ 00243 (*argc)--; 00244 (*argv)++; 00245 } 00246 return 0; 00247 }
Here is the call graph for this function:

| static int get_replace_strings | ( | int * | argc, | |
| char *** | argv, | |||
| POINTER_ARRAY * | from_array, | |||
| POINTER_ARRAY * | to_array | |||
| ) | [static] |
| static REPLACE* init_replace | ( | my_string * | from, | |
| my_string * | to, | |||
| uint | count, | |||
| my_string | word_end_chars | |||
| ) | [static] |
Definition at line 675 of file replace.c.
References bzero, my_free, my_malloc(), MY_WME, MYF, and SET_MALLOC_HUNC.
00676 { 00677 bzero((char*) sets,sizeof(*sets)); 00678 sets->size_of_bits=((states+7)/8); 00679 if (!(sets->set_buffer=(REP_SET*) my_malloc(sizeof(REP_SET)*SET_MALLOC_HUNC, 00680 MYF(MY_WME)))) 00681 return 1; 00682 if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits* 00683 SET_MALLOC_HUNC,MYF(MY_WME)))) 00684 { 00685 my_free((gptr) sets->set,MYF(0)); 00686 return 1; 00687 } 00688 return 0; 00689 }
Here is the call graph for this function:

| static int initialize_buffer | ( | void | ) | [static] |
Definition at line 934 of file replace.c.
References my_malloc(), MY_WME, and MYF.
Referenced by main().
00935 { 00936 bufread = 8192; 00937 bufalloc = bufread + bufread / 2; 00938 if (!(buffer = my_malloc(bufalloc+1,MYF(MY_WME)))) 00939 return 1; 00940 bufbytes=my_eof=0; 00941 out_length=bufread; 00942 if (!(out_buff=my_malloc(out_length,MYF(MY_WME)))) 00943 return(1); 00944 return 0; 00945 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int insert_pointer_name | ( | reg1 POINTER_ARRAY * | pa, | |
| my_string | name | |||
| ) | [static] |
Definition at line 249 of file replace.c.
References ADD_TO_PTR, DBUG_ENTER, DBUG_RETURN, MALLOC_OVERHEAD, memcpy, my_free, my_malloc(), my_realloc(), MY_WME, MYF, PC_MALLOC, PS_MALLOC, PTR_BYTE_DIFF, and strlen().
00250 { 00251 uint i,length,old_count; 00252 byte *new_pos; 00253 const char **new_array; 00254 DBUG_ENTER("insert_pointer_name"); 00255 00256 if (! pa->typelib.count) 00257 { 00258 if (!(pa->typelib.type_names=(const char **) 00259 my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/ 00260 (sizeof(my_string)+sizeof(*pa->flag))* 00261 (sizeof(my_string)+sizeof(*pa->flag))),MYF(MY_WME)))) 00262 DBUG_RETURN(-1); 00263 if (!(pa->str= (byte*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD), 00264 MYF(MY_WME)))) 00265 { 00266 my_free((gptr) pa->typelib.type_names,MYF(0)); 00267 DBUG_RETURN (-1); 00268 } 00269 pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(byte*)+ 00270 sizeof(*pa->flag)); 00271 pa->flag= (int7*) (pa->typelib.type_names+pa->max_count); 00272 pa->length=0; 00273 pa->max_length=PS_MALLOC-MALLOC_OVERHEAD; 00274 pa->array_allocs=1; 00275 } 00276 length=(uint) strlen(name)+1; 00277 if (pa->length+length >= pa->max_length) 00278 { 00279 pa->max_length=(pa->length+length+MALLOC_OVERHEAD+PS_MALLOC-1)/PS_MALLOC; 00280 pa->max_length=pa->max_length*PS_MALLOC-MALLOC_OVERHEAD; 00281 if (!(new_pos= (byte*) my_realloc((gptr) pa->str, 00282 (uint) pa->max_length, 00283 MYF(MY_WME)))) 00284 DBUG_RETURN(1); 00285 if (new_pos != pa->str) 00286 { 00287 my_ptrdiff_t diff=PTR_BYTE_DIFF(new_pos,pa->str); 00288 for (i=0 ; i < pa->typelib.count ; i++) 00289 pa->typelib.type_names[i]= ADD_TO_PTR(pa->typelib.type_names[i],diff, 00290 char*); 00291 pa->str=new_pos; 00292 } 00293 } 00294 if (pa->typelib.count >= pa->max_count-1) 00295 { 00296 int len; 00297 pa->array_allocs++; 00298 len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD); 00299 if (!(new_array=(const char **) my_realloc((gptr) pa->typelib.type_names, 00300 (uint) len/ 00301 (sizeof(byte*)+sizeof(*pa->flag))* 00302 (sizeof(byte*)+sizeof(*pa->flag)), 00303 MYF(MY_WME)))) 00304 DBUG_RETURN(1); 00305 pa->typelib.type_names=new_array; 00306 old_count=pa->max_count; 00307 pa->max_count=len/(sizeof(byte*) + sizeof(*pa->flag)); 00308 pa->flag= (int7*) (pa->typelib.type_names+pa->max_count); 00309 memcpy((byte*) pa->flag,(my_string) (pa->typelib.type_names+old_count), 00310 old_count*sizeof(*pa->flag)); 00311 } 00312 pa->flag[pa->typelib.count]=0; /* Reset flag */ 00313 pa->typelib.type_names[pa->typelib.count++]= pa->str+pa->length; 00314 pa->typelib.type_names[pa->typelib.count]= NullS; /* Put end-mark */ 00315 VOID(strmov(pa->str+pa->length,name)); 00316 pa->length+=length; 00317 DBUG_RETURN(0); 00318 } /* insert_pointer_name */
Here is the call graph for this function:


