|
|
1.1 ! root 1: #include "../h/rt.h" ! 2: ! 3: /* ! 4: * right(s1,n,s2) - pad s1 on left with s2 to length n. ! 5: */ ! 6: ! 7: Xright(nargs, arg3, arg2, arg1, arg0) ! 8: int nargs; ! 9: struct descrip arg3, arg2, arg1, arg0; ! 10: { ! 11: register char *s, *st; ! 12: int cnt, slen; ! 13: char *sbuf, *s3, sbuf1[MAXSTRING], sbuf2[MAXSTRING]; ! 14: extern char *alcstr(); ! 15: ! 16: /* ! 17: * s1 must be a string. n must be a non-negative integer and defaults ! 18: * to 1. s2 must be a string and defaults to a blank. ! 19: */ ! 20: if (cvstr(&arg1, sbuf1) == NULL) ! 21: runerr(103, &arg1); ! 22: defshort(&arg2, 1); ! 23: if ((cnt = INTVAL(arg2)) < 0) ! 24: runerr(205, &arg2); ! 25: defstr(&arg3, sbuf2, &blank); ! 26: ! 27: sneed(cnt); ! 28: ! 29: if (STRLEN(arg3) == 0) { ! 30: /* ! 31: * The padding string is null, make it a blank. ! 32: */ ! 33: slen = 1; ! 34: s3 = " "; ! 35: } ! 36: else { ! 37: slen = STRLEN(arg3); ! 38: s3 = STRLOC(arg3); ! 39: } ! 40: ! 41: /* ! 42: * Get n bytes of string space. Start at the left end of the new ! 43: * string and copy s2 into the new string as many times as it fits. ! 44: */ ! 45: sbuf = alcstr(NULL, cnt); ! 46: s = sbuf; ! 47: while (s < sbuf + cnt) { ! 48: st = s3; ! 49: while (st < s3 + slen && s < sbuf + cnt) ! 50: *s++ = *st++; ! 51: } ! 52: ! 53: /* ! 54: * Copy s1 into the new string, starting at the right end and copying ! 55: * s2 from right to left. If *s1 > n, only copy n bytes. ! 56: */ ! 57: s = sbuf + cnt; ! 58: slen = STRLEN(arg1); ! 59: st = STRLOC(arg1) + slen; ! 60: if (slen > cnt) ! 61: slen = cnt; ! 62: while (slen-- > 0) ! 63: *--s = *--st; ! 64: ! 65: /* ! 66: * Return the new string. ! 67: */ ! 68: STRLEN(arg0) = cnt; ! 69: STRLOC(arg0) = sbuf; ! 70: } ! 71: ! 72: Procblock(right,3)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.