X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/89efe8ae36c375d8d876117cc49b1748ffdab136..c801085faffe5e42117edfab7b8507fc45abc696:/tools/tesh2/src/str_replace.c diff --git a/tools/tesh2/src/str_replace.c b/tools/tesh2/src/str_replace.c deleted file mode 100644 index f4c275ab7c..0000000000 --- a/tools/tesh2/src/str_replace.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include - -#include - -int -str_replace(char** str, const char* what, const char* with) -{ - int pos, i; - char* begin; - char* buf; - - if(!(begin = strstr(*str, what))) - { - errno = ESRCH; - return -1; - } - - pos = begin - *str; - - i = 0; - - /*while(begin[i] != ' ' && begin[i] != '\n' && begin[i] != '\r' && begin[i] != '\0') - i++; - - pos += i; - */ - - pos += strlen(what); - - if(begin == *str) - { - if(!(buf = (char*) calloc(strlen(with) + ((pos < strlen(*str)) ? strlen(*str + pos) : 0) + 1, sizeof(char)))) - return -1; - - strcpy(buf, with); - - if(pos < strlen(*str)) - strcpy(buf + strlen(with), *str + pos); - } - else - { - if(!(buf = (char*) calloc((begin - *str) + strlen(with) + ((pos < strlen(*str)) ? strlen(*str + pos) : 0) + 1, sizeof(char)))) - return -1; - - strncpy(buf, *str, (begin - *str)); - strcpy(buf + (begin - *str) , with); - - - if(pos < strlen(*str)) - strcpy(buf + (begin - *str) + strlen(with), *str + pos); - } - - free(*str);; - *str = buf; - - return 0; - -} - -int -str_replace_all(char** str, const char* what, const char* with) -{ - int rv; - - while(!(rv = str_replace(str, what, with))); - - return (errno == ESRCH) ? 0 : -1; -} - -