%%HP: T(3)A(D)F(.);
\<<
@ HP49G Version S.Lui 9/25/01
@ Stan Lui 5/17/98
@ getstr - This utility returns two strings s0, and s1, from an input string s.
@            s0 will contain a substring of s, starting from the beginning of s,
@            which will fit under a specified delta width of a display window.
@            The delta width of the display is also an input.  s1 will contain
@            the remaining portion of the string s.  s1 can contains the NULL
@            string.  s0 is determined by the delta width and the position of a
@            delimiter - the space character. 
@      input: x0 - the left x coordinate of the display window
@               x1 - the right x coordinate of the display window
@               ef - flag : 1 - reserve space for "..." or 6 pixels
@               s   - the input string
@      output: s0  s1  

"" "" "" 0 0 0 RCLF \-> x0 x1 ef s    s0 ss0 ss   dx p nc fs \<<
  x1 x0 - 1 + 'dx' STO
  WHILE s s SIZE DUP SUB " " == REPEAT
     s 1 s SIZE 1 - SUB 's' STO
  END
  WHILE s 1 1 SUB " " == REPEAT
     s 2 s SIZE SUB 's' STO
  END
  IF s " " POS 0 == THEN
    s SIZE 1 + 'nc' STO 1 CF
    WHILE s 1 'nc' DECR SUB 1 \->GROB SIZE DROP B\->R 
    IF ef THEN 6 + END dx > REPEAT 1 SF END
    IF 1 FS? THEN s 1 nc SUB " " + s nc 1 + s SIZE SUB + 's' STO END
  END
 
  IF s 1 \->GROB SIZE DROP B\->R IF ef THEN 6 + END  dx  > THEN
      1 CF 2 CF  s " " + 's' STO
      WHILE 1 FC? REPEAT
         s " " POS 'p' STO
         s0 'ss0' STO s 'ss' STO   
         IF 2 FC? THEN 2 SF ELSE s0 " " + 's0' STO END 
         s0 s 1 p 1 - SUB + 's0' STO
         IF p s SIZE \=/ THEN
           s p 1 + s SIZE SUB 's' STO
         ELSE
           "" 's' STO
         END
         IF s0 1 \->GROB SIZE DROP B\->R IF ef THEN 6 + END dx > THEN
            ss0 's0' STO ss 's' STO 1 SF
         ELSE
            IF s "" == THEN 1 SF END
         END
         WHILE s 1 1 SUB " " == REPEAT
            s 2 s SIZE SUB 's' STO
         END
      END
  ELSE
      s 's0' STO "" 's' STO
  END
  fs STOF s0 s  
\>>
\>>

