1: #include "../h/rt.h"
2:
3: /*
4: * repl(s,n) - concatenate n copies of string s.
5: */
6: Xrepl(nargs, arg2, arg1, arg0)
7: int nargs;
8: struct descrip arg2, arg1, arg0;
9: {
10: register int cnt;
11: register char *sloc;
12: long l1;
13: char sbuf[MAXSTRING];
14: extern char *alcstr();
15:
16: /*
17: * Make sure that s is a string.
18: */
19: if (cvstr(&arg1, sbuf) == NULL)
20: runerr(103, &arg1);
21: /*
22: * Make sure that n is a (non-long) integer.
23: */
24: switch (cvint(&arg2, &l1)) {
25: case T_INTEGER:
26: if ((cnt = (int)l1) >= 0)
27: break;
28: #ifdef LONGS
29: case T_LONGINT:
30: #endif LONGS
31: runerr(205, &arg2);
32: default:
33: runerr(101, &arg2);
34: }
35:
36: /*
37: * Be sure that resulting string won't be too long. (This is bogus
38: * on the VAX as MAXSHORT is 32k.)
39: */
40: if ((l1 * STRLEN(arg1)) > MAXSHORT)
41: runerr(302, NULL);
42: /*
43: * Return a empty string if n == 0.
44: */
45: if (cnt == 0) {
46: arg0.type = D_NULL;
47: INTVAL(arg0) = 1;
48: }
49: else {
50: /*
51: * Ensure enough space for the replicated string and allocate a copy
52: * of s. Then allocate and copy s n-1 times.
53: */
54: sneed(cnt * STRLEN(arg1));
55: sloc = alcstr(STRLOC(arg1), STRLEN(arg1));
56: cnt--;
57: while (cnt--)
58: alcstr(STRLOC(arg1), STRLEN(arg1));
59: /*
60: * Make arg0 a descriptor for the replicated string.
61: */
62: STRLEN(arg0) = (int)l1 * STRLEN(arg1);
63: STRLOC(arg0) = sloc;
64: }
65: }
66:
67: Procblock(repl,2)
Defined functions
Xrepl
defined in line
6;
never used