use PR_CatStrings for strcat and padstr. ironicly, this should work better for now, and definitely will by the time I'm done.

This commit is contained in:
Bill Currie 2007-04-08 00:00:35 +00:00 committed by Jeff Teunissen
parent eaa79afe64
commit e27b2a9e54
2 changed files with 15 additions and 25 deletions

View file

@ -399,7 +399,7 @@ pr_settempstring (progs_t *pr, char *s)
return string_index (pr, sr); return string_index (pr, sr);
} }
string_t VISIBLE string_t
PR_CatStrings (progs_t *pr, const char *a, const char *b) PR_CatStrings (progs_t *pr, const char *a, const char *b)
{ {
int lena; int lena;

View file

@ -74,21 +74,10 @@ PF_getuid (progs_t *pr)
static void static void
PF_strcat (progs_t *pr) PF_strcat (progs_t *pr)
{ {
const char *st1; const char *st1 = P_GSTRING (pr, 0);
const char *st2; const char *st2 = P_GSTRING (pr, 1);
int len;
char *result;
st1 = P_GSTRING (pr, 0); R_STRING (pr) = PR_CatStrings (pr, st1, st2);
st2 = P_GSTRING (pr, 1);
len = strlen (st1) + strlen (st2);
result = alloca (len + 1);
strcpy (result, st1);
strcat (result, st2);
RETURN_STRING (pr, result);
} }
/* /*
@ -100,8 +89,8 @@ static void
PF_padstr (progs_t *pr) PF_padstr (progs_t *pr)
{ {
const char *st; const char *st;
unsigned int i, padlen, givenlen; size_t i, padlen, givenlen;
char *result; char *padding;
st = P_GSTRING (pr, 0); st = P_GSTRING (pr, 0);
padlen = (unsigned int) P_FLOAT (pr, 1); padlen = (unsigned int) P_FLOAT (pr, 1);
@ -113,14 +102,14 @@ PF_padstr (progs_t *pr)
return; return;
} }
// ok, lets pad it! // ok, lets pad it!
result = alloca (padlen + 1); padlen -= givenlen;
strcpy (result, st); padding = alloca (padlen + 1);
for (i = givenlen; i < padlen; i++) for (i = 0; i < padlen; i++)
result[i] = ' '; padding[i] = ' ';
result[i] = '\0'; padding[i] = '\0';
RETURN_STRING (pr, result); R_STRING (pr) = PR_CatStrings (pr, st, padding);
} }
/* /*
@ -144,10 +133,11 @@ PF_colstr (progs_t *pr)
{ {
const char *srcstr; const char *srcstr;
unsigned char *result; unsigned char *result;
unsigned int action, len, i; unsigned action;
size_t len, i;
srcstr = P_GSTRING (pr, 0); srcstr = P_GSTRING (pr, 0);
action = (unsigned int) P_FLOAT (pr, 1); action = (unsigned) P_FLOAT (pr, 1);
len = strlen (srcstr); len = strlen (srcstr);
// Check for errors, if any, return given string // Check for errors, if any, return given string