- Adapted indenation to new agreed upon system
This commit is contained in:
@@ -89,54 +89,57 @@
|
||||
** strncpy to be sure result is always
|
||||
** null terminated.
|
||||
*/
|
||||
char *StrJoin (
|
||||
char *StrJoin(
|
||||
/* =======
|
||||
*/ char *result,
|
||||
int result_size,
|
||||
char *str_a,
|
||||
char *str_b) {
|
||||
*/ char *result,
|
||||
int result_size, char *str_a, char *str_b)
|
||||
{
|
||||
|
||||
int i, size, size_a, size_b;
|
||||
int i, size, size_a, size_b;
|
||||
|
||||
size = result_size - 1;
|
||||
size = result_size - 1;
|
||||
|
||||
if (size < 0) return result;
|
||||
|
||||
if (result == str_a) { /* Are the result and str_a the same? */
|
||||
size_a = strlen (str_a); /* Yes */
|
||||
if (size_a > size) { /* Check sizes anyway. */
|
||||
result[size] = NIL; /* Truncate str_a. No room for str_b! */
|
||||
}else {
|
||||
size = size - strlen (result); /* And append str_b */
|
||||
if (size > 0) {
|
||||
strncat (result, str_b, size);
|
||||
}
|
||||
}
|
||||
}else if (result == str_b) { /* Are the result and str_b the same? */
|
||||
size_a = strlen (str_a); /* Yes, this is a bit complicated! */
|
||||
size_b = strlen (str_b);
|
||||
if (size_a >= size) { /* If str_a completely fills result, .. */
|
||||
result[0] = NIL; /* .. then just copy in str_a */
|
||||
strncat (result, str_a, size);
|
||||
}else {
|
||||
/*
|
||||
** Otherwise, str_b must first be moved to
|
||||
** make room for str_a and then str_a must
|
||||
** be put at the front of the result.
|
||||
*/
|
||||
if ((size_a + size_b) > size) size_b = size - size_a;
|
||||
result[size_a+size_b] = NIL;
|
||||
for (i = (size_b-1); i >= 0; i--) {
|
||||
result[size_a+i] = str_b[i];
|
||||
}
|
||||
memcpy (result, str_a, size_a);
|
||||
}
|
||||
}else { /* Result is neither str_a nor str_b so .. */
|
||||
result[0] = NIL; /* .. str_a needs to be copied */
|
||||
strncat (result, str_a, size);
|
||||
size = size - strlen (result); /* And str_a appended */
|
||||
if (size > 0) strncat (result, str_b, size);
|
||||
}
|
||||
if (size < 0)
|
||||
return result;
|
||||
|
||||
if (result == str_a) { /* Are the result and str_a the same? */
|
||||
size_a = strlen(str_a); /* Yes */
|
||||
if (size_a > size) { /* Check sizes anyway. */
|
||||
result[size] = NIL; /* Truncate str_a. No room for str_b! */
|
||||
} else {
|
||||
size = size - strlen(result); /* And append str_b */
|
||||
if (size > 0) {
|
||||
strncat(result, str_b, size);
|
||||
}
|
||||
}
|
||||
} else if (result == str_b) { /* Are the result and str_b the same? */
|
||||
size_a = strlen(str_a); /* Yes, this is a bit complicated! */
|
||||
size_b = strlen(str_b);
|
||||
if (size_a >= size) { /* If str_a completely fills result, .. */
|
||||
result[0] = NIL; /* .. then just copy in str_a */
|
||||
strncat(result, str_a, size);
|
||||
} else {
|
||||
/*
|
||||
** Otherwise, str_b must first be moved to
|
||||
** make room for str_a and then str_a must
|
||||
** be put at the front of the result.
|
||||
*/
|
||||
if ((size_a + size_b) > size)
|
||||
size_b = size - size_a;
|
||||
result[size_a + size_b] = NIL;
|
||||
for (i = (size_b - 1); i >= 0; i--) {
|
||||
result[size_a + i] = str_b[i];
|
||||
}
|
||||
memcpy(result, str_a, size_a);
|
||||
}
|
||||
} else { /* Result is neither str_a nor str_b so .. */
|
||||
result[0] = NIL; /* .. str_a needs to be copied */
|
||||
strncat(result, str_a, size);
|
||||
size = size - strlen(result); /* And str_a appended */
|
||||
if (size > 0)
|
||||
strncat(result, str_b, size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------- End of STRJOIN.C =======*/
|
||||
|
||||
Reference in New Issue
Block a user