all [...] blocks would be replacved by the string picked for the firs
toccurence.
Update the code so we use different strings for each for "extra
randomness".
rndc[0] = str[random()%num + 1];
rndc[1] = '\0';
- all_string_sub(line, str, rndc);
+ single_string_sub(line, str, rndc);
goto again;
void *shm_setup(int size);
void all_string_sub(char *s,const char *pattern,const char *insert);
+void single_string_sub(char *s,const char *pattern,const char *insert);
BOOL next_token(char **ptr,char *buff,char *sep);
struct timeval timeval_current(void);
double timeval_elapsed(struct timeval *tv);
}
}
+void single_string_sub(char *s,const char *pattern,const char *insert)
+{
+ char *p;
+ size_t ls,lp,li;
+
+ if (!insert || !pattern || !s) return;
+
+ ls = strlen(s);
+ lp = strlen(pattern);
+ li = strlen(insert);
+
+ if (!*pattern) return;
+
+ p = strstr(s,pattern);
+ memmove(p+li,p+lp,ls + 1 - (((int)(p-s)) + lp));
+ memcpy(p, insert, li);
+ s = p + li;
+ ls += (li-lp);
+}
/****************************************************************************
Get the next token from a string, return False if none found