forked from adesutherland/CMS-370-BREXX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changest.c
57 lines (51 loc) · 1.32 KB
/
changest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* $Id: changest.c,v 1.6 2008/07/15 07:40:54 bnv Exp $
* $Log: changest.c,v $
* Revision 1.6 2008/07/15 07:40:54 bnv
* #include changed from <> to ""
*
* Revision 1.5 2002/06/11 12:37:15 bnv
* Added: CDECL
*
* Revision 1.4 2001/06/25 18:49:48 bnv
* Header changed to Id
*
* Revision 1.3 2000/09/28 15:52:19 bnv
* Corrected a bug if the input string had repeated targets.
*
* Revision 1.2 2000/02/07 11:21:35 bnv
* Corrected: The case where the old string has length equal to ZERO.
*
* Revision 1.1 1998/07/02 17:17:00 bnv
* Initial revision
*
*/
#include "lstring.h"
/* ----------------- Lchagestr ------------------- */
void __CDECL
Lchangestr(const PLstr to, const PLstr oldstr,
const PLstr str, const PLstr newstr) {
size_t pos, foundpos;
Lstr tmp;
if (LLEN(*oldstr) == 0) {
Lstrcpy(to, str);
return;
}
Lfx(to, LLEN(*str));
LZEROSTR(*to);
LINITSTR(tmp);
pos = 1;
for (;;) {
foundpos = Lindex(str, oldstr, pos);
if (foundpos == 0) break;
if (foundpos != pos) {
_Lsubstr(&tmp, str, pos, foundpos - pos);
Lstrcat(to, &tmp);
}
Lstrcat(to, newstr);
pos = foundpos + LLEN(*oldstr);
}
_Lsubstr(&tmp, str, pos, 0);
Lstrcat(to, &tmp);
LFREESTR(tmp);
} /* Lchagestr */