-
Notifications
You must be signed in to change notification settings - Fork 5
/
copies.c
51 lines (43 loc) · 1017 Bytes
/
copies.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
/*
* $Id: copies.c,v 1.4 2008/07/15 07:40:54 bnv Exp $
* $Log: copies.c,v $
* Revision 1.4 2008/07/15 07:40:54 bnv
* #include changed from <> to ""
*
* Revision 1.3 2002/06/11 12:37:15 bnv
* Added: CDECL
*
* Revision 1.2 2001/06/25 18:49:48 bnv
* Header changed to Id
*
* Revision 1.1 1998/07/02 17:17:00 bnv
* Initial revision
*
*/
#include "lstring.h"
/* ------------------ Lcopies -------------------- */
void __CDECL
Lcopies(const PLstr to, const PLstr from, long n) {
Lstr tmp, tmp2;
long l;
LZEROSTR(*to);
if (n < 0 || !LLEN(*from)) return;
L2STR(to);
Lfx(to, (size_t) (LLEN(*from) * n));
LINITSTR(tmp);
LINITSTR(tmp2);
l = 1;
while (l < n) l <<= 1;
l >>= 1;
Lfx(&tmp, (size_t) l);
Lfx(&tmp2, (size_t) l);
Lstrcpy(&tmp, from);
while (n != 0) {
if (n & 1) Lstrcat(to, &tmp);
Lstrcpy(&tmp2, &tmp);
Lstrcat(&tmp, &tmp2);
n >>= 1;
}
LFREESTR(tmp);
LFREESTR(tmp2);
} /* Lcopies */