This commit is contained in:
Anton Kochkov 2014-04-25 04:48:31 +04:00
parent 9864220150
commit 06057c3945

View File

@ -1210,24 +1210,31 @@ R_API int r_print_format_length (const char *fmt) {
R_API char *r_str_prefix_all (char *s, const char *pfx) {
int newlines = 1;
int len = strlen (s);
int plen = strlen (pfx);
int len = 0;
int plen = 0;
char *o, *p, *os = s;
for (p=s;*p;p++) if (*p=='\n') newlines++;
o = malloc (len + (plen*newlines)+1);
if (!s) return NULL;
memcpy (o, pfx, plen);
for (p=o+plen;*s;s++) {
*p++ = *s;
if (*s=='\n' && s[1]) {
memcpy (p, pfx, plen);
p += plen;
if (s) {
len = strlen (s);
if (pfx) {
plen = strlen (pfx);
}
for (p=s;*p;p++) if (*p=='\n') newlines++;
o = malloc (len + (plen*newlines)+1);
memcpy (o, pfx, plen);
for (p=o+plen;*s;s++) {
*p++ = *s;
if (*s=='\n' && s[1]) {
memcpy (p, pfx, plen);
p += plen;
}
}
*p = 0;
free (os);
return o;
} else {
return NULL;
}
*p = 0;
free (os);
return o;
}
#define HASCH(x) strchr (input_value,x)