#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:

| static int insert_pointer_name | ( | POINTER_ARRAY * | pa, | |
| my_string | name | |||
| ) | [static] |
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 103 of file replace.c.
References convert_file(), convert_pipe(), error, exit, free_buffer(), free_pointer_array(), from, get_replace_strings(), init_replace(), initialize_buffer(), my_charset_latin1, MY_CHECK_ERROR, my_end(), MY_GIVE_INFO, MY_INIT, my_isspace, pos(), replace, static_get_options(), to, and verbose.
00104 { 00105 int i,error; 00106 char word_end_chars[256],*pos; 00107 POINTER_ARRAY from,to; 00108 REPLACE *replace; 00109 MY_INIT(argv[0]); 00110 00111 if (static_get_options(&argc,&argv)) 00112 exit(1); 00113 if (get_replace_strings(&argc,&argv,&from,&to)) 00114 exit(1); 00115 00116 for (i=1,pos=word_end_chars ; i < 256 ; i++) 00117 if (my_isspace(&my_charset_latin1,i)) 00118 *pos++= (char) i; 00119 *pos=0; 00120 if (!(replace=init_replace((char**) from.typelib.type_names, 00121 (char**) to.typelib.type_names, 00122 (uint) from.typelib.count,word_end_chars))) 00123 exit(1); 00124 free_pointer_array(&from); 00125 free_pointer_array(&to); 00126 if (initialize_buffer()) 00127 return 1; 00128 00129 error=0; 00130 if (argc == 0) 00131 error=convert_pipe(replace,stdin,stdout); 00132 else 00133 { 00134 while (argc--) 00135 { 00136 error=convert_file(replace,*(argv++)); 00137 } 00138 } 00139 free_buffer(); 00140 my_end(verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR); 00141 exit(error ? 2 : 0); 00142 return 0; /* No compiler warning */ 00143 } /* main */
Here is the call graph for this function:

Definition at line 700 of file replace.c.
References st_rep_sets::bit_buffer, st_rep_set::bits, bzero, st_rep_sets::count, st_rep_sets::extra, st_rep_set::found_len, st_rep_set::found_offset, st_rep_sets::invisible, LAST_CHAR_CODE, make_new_set(), my_realloc(), MY_WME, MYF, st_rep_set::next, st_rep_sets::set, st_rep_sets::set_buffer, SET_MALLOC_HUNC, st_rep_set::size_of_bits, st_rep_sets::size_of_bits, and st_rep_set::table_offset.
00701 { 00702 uint i,count,*bit_buffer; 00703 REP_SET *set; 00704 if (sets->extra) 00705 { 00706 sets->extra--; 00707 set=sets->set+ sets->count++; 00708 bzero((char*) set->bits,sizeof(uint)*sets->size_of_bits); 00709 bzero((char*) &set->next[0],sizeof(set->next[0])*LAST_CHAR_CODE); 00710 set->found_offset=0; 00711 set->found_len=0; 00712 set->table_offset= (uint) ~0; 00713 set->size_of_bits=sets->size_of_bits; 00714 return set; 00715 } 00716 count=sets->count+sets->invisible+SET_MALLOC_HUNC; 00717 if (!(set=(REP_SET*) my_realloc((gptr) sets->set_buffer, 00718 sizeof(REP_SET)*count, 00719 MYF(MY_WME)))) 00720 return 0; 00721 sets->set_buffer=set; 00722 sets->set=set+sets->invisible; 00723 if (!(bit_buffer=(uint*) my_realloc((gptr) sets->bit_buffer, 00724 (sizeof(uint)*sets->size_of_bits)*count, 00725 MYF(MY_WME)))) 00726 return 0; 00727 sets->bit_buffer=bit_buffer; 00728 for (i=0 ; i < count ; i++) 00729 { 00730 sets->set_buffer[i].bits=bit_buffer; 00731 bit_buffer+=sets->size_of_bits; 00732 } 00733 sets->extra=SET_MALLOC_HUNC; 00734 return make_new_set(sets); 00735 }
Here is the call graph for this function:

| static void make_sets_invisible | ( | REP_SETS * | sets | ) | [static] |
Definition at line 693 of file replace.c.
References st_rep_sets::count, st_rep_sets::invisible, and st_rep_sets::set.
00694 { 00695 sets->invisible=sets->count; 00696 sets->set+=sets->count; 00697 sets->count=0; 00698 }
| static uint replace_strings | ( | REPLACE * | rep, | |
| my_string * | start, | |||
| uint * | max_length, | |||
| my_string | from | |||
| ) | [static] |
Definition at line 881 of file replace.c.
References my_realloc(), MY_WME, MYF, st_replace::next, pos(), reg1, reg2, to, and updated.
Referenced by convert_pipe().
00883 { 00884 reg1 REPLACE *rep_pos; 00885 reg2 REPLACE_STRING *rep_str; 00886 my_string to,end,pos,new; 00887 00888 end=(to= *start) + *max_length-1; 00889 rep_pos=rep+1; 00890 for(;;) 00891 { 00892 while (!rep_pos->found) 00893 { 00894 rep_pos= rep_pos->next[(uchar) *from]; 00895 if (to == end) 00896 { 00897 (*max_length)+=8192; 00898 if (!(new=my_realloc(*start,*max_length,MYF(MY_WME)))) 00899 return (uint) -1; 00900 to=new+(to - *start); 00901 end=(*start=new)+ *max_length-1; 00902 } 00903 *to++= *from++; 00904 } 00905 if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string) 00906 return (uint) (to - *start)-1; 00907 updated=1; /* Some my_string is replaced */ 00908 to-=rep_str->to_offset; 00909 for (pos=rep_str->replace_string; *pos ; pos++) 00910 { 00911 if (to == end) 00912 { 00913 (*max_length)*=2; 00914 if (!(new=my_realloc(*start,*max_length,MYF(MY_WME)))) 00915 return (uint) -1; 00916 to=new+(to - *start); 00917 end=(*start=new)+ *max_length-1; 00918 } 00919 *to++= *pos; 00920 } 00921 if (!*(from-=rep_str->from_offset) && rep_pos->found != 2) 00922 return (uint) (to - *start); 00923 rep_pos=rep; 00924 } 00925 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void reset_buffer | ( | void | ) | [static] |
Definition at line 947 of file replace.c.
Referenced by convert_pipe().
Here is the caller graph for this function:

| static int static_get_options | ( | int * | argc, | |
| argv | ||||
| ) | [static] |
Definition at line 149 of file replace.c.
References DBUG_PUSH, exit, MACHINE_TYPE, ME_BELL, my_message(), my_progname, MYF, pos(), silent, SYSTEM_TYPE, verbose, and version().
00152 { 00153 int help,version; 00154 char *pos; 00155 00156 silent=verbose=help=0; 00157 00158 while (--*argc > 0 && *(pos = *(++*argv)) == '-' && pos[1] != '-') { 00159 while (*++pos) 00160 { 00161 version=0; 00162 switch((*pos)) { 00163 case 's': 00164 silent=1; 00165 break; 00166 case 'v': 00167 verbose=1; 00168 break; 00169 case '#': 00170 DBUG_PUSH (++pos); 00171 pos= (char*) " "; /* Skip rest of arguments */ 00172 break; 00173 case 'V': 00174 version=1; 00175 case 'I': 00176 case '?': 00177 help=1; /* Help text written */ 00178 printf("%s Ver 1.4 for %s at %s\n",my_progname,SYSTEM_TYPE, 00179 MACHINE_TYPE); 00180 if (version) 00181 break; 00182 puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); 00183 puts("This program replaces strings in files or from stdin to stdout.\n" 00184 "It accepts a list of from-string/to-string pairs and replaces\n" 00185 "each occurrence of a from-string with the corresponding to-string.\n" 00186 "The first occurrence of a found string is matched. If there is\n" 00187 "more than one possibility for the string to replace, longer\n" 00188 "matches are preferred before shorter matches.\n\n" 00189 "A from-string can contain these special characters:\n" 00190 " \\^ Match start of line.\n" 00191 " \\$ Match end of line.\n" 00192 " \\b Match space-character, start of line or end of line.\n" 00193 " For a end \\b the next replace starts locking at the end\n" 00194 " space-character. A \\b alone in a string matches only a\n" 00195 " space-character.\n"); 00196 printf("Usage: %s [-?svIV] from to from to ... -- [files]\n", my_progname); 00197 puts("or"); 00198 printf("Usage: %s [-?svIV] from to from to ... < fromfile > tofile\n", my_progname); 00199 puts(""); 00200 puts("Options: -? or -I \"Info\" -s \"silent\" -v \"verbose\""); 00201 break; 00202 default: 00203 fprintf(stderr,"illegal option: -%c\n",*pos); 00204 break; 00205 } 00206 } 00207 } 00208 if (*argc == 0) 00209 { 00210 if (!help) 00211 my_message(0,"No replace options given",MYF(ME_BELL)); 00212 exit(0); /* Don't use as pipe */ 00213 } 00214 return(0); 00215 } /* static_get_options */
Here is the call graph for this function:

| static int static_get_options | ( | int * | argc, | |
| char *** | argv | |||
| ) | [static] |
int bufbytes [static] |
char* buffer [static] |
Definition at line 927 of file replace.c.
Referenced by _mi_cmp_dynamic_record(), _rl_init_terminal_io(), _rl_read_file(), _rl_read_init_file(), add_int_to_prompt(), add_line(), Dbdict::alterIndex_toCreateTrigger(), append_definer(), append_stmt_result(), az_open(), bind_fetch(), Dbdict::buildIndex_toCreateConstr(), yaSSL::buildOutput(), com_clear(), com_connect(), com_edit(), com_ego(), com_go(), com_help(), com_print(), com_server_help(), create_defaults_file(), delete_chars(), TaoCrypt::PBKDF2_HMAC< T >::DeriveKey(), yaSSL::DoProcessReply(), fetch_float_with_conversion(), fetch_long_with_conversion(), fetch_string_with_conversion(), fill_buffer(), ft_init_stopwords(), Field_blob::get_key_image(), MgmApiSession::getConfig_common(), yaSSL::hashHandShake(), history_do_write(), history_truncate_file(), init_line_buffer(), init_line_buffer_from_string(), insert_dynamic(), insert_some_chars(), int10_to_str(), int2str(), intern_read_line(), localRandom48(), localRandom48Init(), main(), make_schemata_old_format(), make_table_names_old_format(), my_dir(), my_dirend(), my_long10_to_str_8bit(), my_longlong10_to_str_8bit(), my_process_stmt_result(), mysql_ha_read(), mysqld_show_create(), mysqld_show_create_db(), yaSSL::yassl_int_cpp_local1::SumBuffer::operator()(), Item_char_typecast::print(), Item_func_format::print(), Item_func_benchmark::print(), Item_float::print(), Item_param::print(), print_conclusions_csv(), print_table_data(), PrintServerData(), yaSSL::ProcessOldClientHello(), putLong(), read_and_execute(), read_history_range(), handler::read_multi_range_first(), readFromFile(), remove_cntrl(), Item::send(), TaoCrypt::BasicDES::SetKey(), sp_head::show_create_function(), sp_head::show_create_procedure(), sp_head::show_routine_code(), Protocol_simple::store(), subst_spvars(), table_check_intact(), test_bind_date_conv(), test_buffers(), test_bug17667(), test_bug3117(), test_bug6049(), test_bug6058(), test_bug6096(), test_mem_overun(), Item_func_find_in_set::val_int(), wf_comp(), wf_end(), and writeToFile().
uint found_sets = 0 [static] |
char* out_buff [static] |
uint out_length [static] |
Definition at line 932 of file replace.c.
Referenced by _tr_tally(), batch_readline(), my_b_vprintf(), test_bug3796(), and test_ps_null_param().
int updated = 0 [static] |
Definition at line 99 of file replace.c.
Referenced by convert_file(), convert_pipe(), mysql_update(), and replace_strings().
1.4.7

