Program Ssubstr;
{$nomain}

{ 
  Version   3.2
  File:[22,310]Ssubstr.PAS
  Author: Jim Bostwick  29-Nov-83

  Last Edit: 23-JUN-1988 22:31:15 

  History:
	 23-JUN-1988 21:59:30  - JMB PA3UTL upgrade.


}
{$nolist}
{[a+,b+,l-,k+,r+] Pasmat }
%INCLUDE 'PAS$EXT:slen.ext';
{$list}

Procedure SSubstr(var t: packed array [tlow..thigh: integer] of char;
                    s: packed array [slow..shigh: integer] of char;
                    start, span: integer);external;

  {*USER*
       -- String Package Module --
   The substring of string "s" defined by "start" and "span" is assigned
   to the target string "t".
  }

procedure SSubstr;

  var
    i, sl: integer;


  begin {substring}
      sl := slen(s);  {get length of source string }
      if span < 0 then  { wants left-string function }
        begin
        span := - span;
        start := start - span
        end;
      if start < 1 then  { adjust to BOS }
        begin
        span := span + start - 1;
        start := 1
        end;
      { make it fit in target }
      if start + span - 1 > sl then span := sl - start + 1;
      if span < 0 then span  := 0;
      if span > 0 then  { copy substring to target }
        for i := 1 to span do t[i] := s[start + i - 1];
      if tlow = 0 then t[0] := chr(span)
        else for i := span + 1 to thigh do t[i] := chr(0)
  end {substring} ;
