From 86958c4f5e1be3364955e57078fb156968f3e5ae Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sat, 30 Oct 2010 16:59:22 +0100 Subject: Make replacestr more generic, to allow for variable length replacements --- blasms.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'blasms.c') diff --git a/blasms.c b/blasms.c index 639b902..e4380dc 100644 --- a/blasms.c +++ b/blasms.c @@ -28,8 +28,8 @@ void remtrailn(char* line) { } } -/* Replace source[i] with str */ -void replacestr(char* source, int i, char* str) { +/* Replace n characters in source with str at i */ +void replacestr(char* source, int i, int n, char* str) { /* Temporary string for building */ char strtmp[1000]; @@ -37,7 +37,7 @@ void replacestr(char* source, int i, char* str) { strxfrm(source, strtmp, i); source[i] = '\0'; strcat(source, str); - strcat(source, strtmp + i + 2); + strcat(source, strtmp + i + n); } /* Converts a string to lowercase */ @@ -262,23 +262,23 @@ int main(int argc, char *argv[]) { switch (systemcmd[i+1]) { case 'N': setname(telnum); - replacestr(systemcmd, i, telnum); + replacestr(systemcmd, i, 2, telnum); break; case 'n': - replacestr(systemcmd, i, telnum); + replacestr(systemcmd, i, 2, telnum); break; case 'd': - replacestr(systemcmd, i, argv[2]); + replacestr(systemcmd, i, 2, argv[2]); break; case 's': - replacestr(systemcmd, i, sms + offset + 1); + replacestr(systemcmd, i, 2, sms + offset + 1); break; case 'P': if (!match) { settelnum(telnum, sms, &offset); match = 1; } - replacestr(systemcmd, i, telnum); + replacestr(systemcmd, i, 2, telnum); break; } } -- cgit v1.2.3