S_WRAP

Wrap a string

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
xcall S_WRAP(string, max_length, left_length, start, right_length, wrap)

Arguments

string

The string to wrap. (a)

max_length

The maximum length of the left wrap segment. (n)

left_length

The variable that will be loaded with the length of the left wrap segment. (n)

start

The variable that will be loaded with the start position within string of the right wrap segment. (n)

right_length

The variable that will be loaded with the length of the right wrap segment. (n)

wrap

The variable that will be loaded with one of the following values to indicate whether wrap processing occurred: (n)

0 = Wrap processing could not be performed.

1 = Wrap processing occurred.

Discussion

The S_WRAP subroutine logically divides a string into two components: a left segment that will fit on a line whose length is defined by max_length, and a right segment that contains the rest of the string. The incoming string itself is not modified, but the segment start positions and lengths returned are relative to string.

The incoming string is “split” at the rightmost space character whose position is less than or equal to max_length, creating a left and a right “wrap segment.” S_WRAP logically removes trailing white space from the left wrap segment and leading white space from the right wrap segment.

If no white space is present to the left of max_length, or if the length of the incoming string with trailing white space removed is less than max_length, wrap is zero, start and right_length are undefined, and left_length is the next character position following the space-stripped incoming string.

Examples

    .define TTCHN   ,1
record
    line        ,a80
    wpos        ,i4     ,20             ;Strings longer than 20 wrap
    llen        ,i4
    rbeg        ,i4
    rlen        ,i4
    wrap        ,i4
    start       ,i4     ,1
    len         ,i4
proc
    open(TTCHN, o, 'tt:')
    reads(TTCHN, line)
    len = %rdlen
      do
        begin
          xcall s_wrap(line(start:len), wpos, llen, rbeg, rlen, wrap)
          writes(TTCHN, line(start:llen))
          start = start + rbeg - 1
          len = rlen
        end
      until (.not.wrap)
    close TTCHN
    stop
end

Let’s assume that the following string is input:

THIS IS AN EXAMPLE TO DEMONSTRATE THE S_WRAP SUBROUTINE

Wrap processing will generate the following line segments:

THIS IS AN EXAMPLE

TO DEMONSTRATE THE

S_WRAP SUBROUTINE