LEX 'SPSTRING' * Add leading or trailing spaces to a string ID #EC * J.Elhay, 2/4/88. MSG 0 * O/P string set to nominated length POLL 0 ENTRY SPSTRL * for leading spaces CHAR #F * a function ENTRY SPSTRT * for trailing spaces CHAR #F * a function KEY 'SPSTRL$' * syntax: B$=SPSTRL$(A$,n), adds leading spaces; TOKEN 137 * and LEN(B$)=n; error if n<=LEN(A$) [eIVARG] KEY 'SPSTRT$' * syntax: B$=SPSTRT$(A$,n), adds trailing spaces; TOKEN 138 * and LEN(B$)=n; error as above ENDTXT * useful for formatting in columns. ARGERR EQU #0BF19 * invalid argument error exit RNDAHX EQU #136CB * pop,test,round,convert to hex integer REV$ EQU #1B38E * reverse a string on the stack XXHEAD EQU #1A44E * undo ADHEAD ADHEAD EQU #181B7 * add header to string on stack EXPR EQU #0F23C * general purpose function exit SPACE EQU #20 * ASCII for ' ' is 32 NIBHEX 8422 * a string and a number, both mandatory SPSTRT ST=0 1 * clear ST1 for trailing spaces case GOTO COMMON * jump to common code ERR GOVLNG ARGERR NIBHEX 8422 * as above SPSTRL ST=1 1 * set ST1 for leading spaces COMMON GOSBVL RNDAHX * get the number (final length of string) GONC ERR * no negatives A=A+A A * bytes to nibs by doubling R3=A * save in R3 D1=D1+ 16 * move past number - point to string header ?ST=0 1 * trailing spaces? GOYES LEAD * don't reverse, add to end ST=1 1 * reset ST1 GOSBVL REV$ * reverse for leading spaces LEAD GOSBVL XXHEAD * strip off header, set R1,D1,D as required C=R3 * recover number of nibs, new length ?A>=C A * is it <= actual length? GOYES ERR * don't want it C=C-A A * deduct actual length, get 2*Nú of spaces to add B=C A * put into B(A) as loop counter BSRB * actual number of spaces to add B=B-1 A * 1 less for loop count LC(2) SPACE * load space ASCII code into C(B) LOOP D1=D1- 2 * make room on stack for 1 byte (1 character) DAT1=C B * write a space to end of string B=B-1 A * decrement loop counter GONC LOOP * loop back while B(A)>=00000 ST=1 0 * set ST0 for ADHEAD to return GOSBVL ADHEAD * add the header now ?ST=0 1 * did we want trailing spaces? GOYES OUT * we can leave GOSBVL REV$ * otherwise the string needs to be reversed back OUT GOVLNG EXPR * and THEN we can leave