fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / rexx / lstring / substr.c
blobb4e4c7fadb615ba81d4e220c219d16f3f058d0b4
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:38 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.1 1998/07/02 17:18:00 bnv
8 * Initial Version
12 #include <string.h>
13 #include <lstring.h>
15 /* --------------------------- Lsubstr -------------------------------- */
16 /* to - Output Lstr *
17 * from - Input Lstr *
18 * start - an integer, can take values from [1,from length] *
19 * if start<1 then start = 1 *
20 * length - negative value means rest of string (default) *
21 * [1 - nnn] cuts string and pad's it if necessary. *
22 * pad - pad character *
23 * -------------------------------------------------------------------- */
24 void
25 Lsubstr(const PLstr to, const PLstr from,
26 long start, long length, const char pad )
28 size_t l;
30 L2STR(from);
32 start--;
33 if (start<0) start = 0;
35 if (length<=0) {
36 if (length==0 || start>=LLEN(*from)) {
37 LZEROSTR(*to);
38 return;
40 length = LLEN(*from) - start;
43 Lfx(to,(size_t)length);
45 if (start<LLEN(*from)) {
46 if (length+start>LLEN(*from)) {
47 l = LLEN(*from) - (size_t)start;
48 MEMMOVE( LSTR(*to), LSTR(*from)+start, l);
49 MEMSET( LSTR(*to)+l, pad, (size_t)length-l);
50 } else
51 MEMMOVE( LSTR(*to), LSTR(*from)+start, (size_t)length);
52 } else
53 MEMSET(LSTR(*to),pad,(size_t)length);
55 LTYPE(*to) = LSTRING_TY;
56 LLEN(*to) = (size_t)length;
57 } /* Lstrsub */