home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / ADPro251-3.DMS / ADPro251-3.adf / FREDScripts.lha / FREDFunctions / WordWrap < prev   
Encoding:
Text File  |  1994-01-31  |  1.4 KB  |  62 lines

  1. /*
  2. ** WordWrap
  3. **
  4. ** $VER: WordWrap 1.1.0 (5.11.93)
  5. **
  6. ** This ARexx script contains a function which performs word wrapping on
  7. ** a given text string.
  8. **
  9. ** INPUTS
  10. **    NumRows -- maximum number of rows of text.
  11. **    NumCols -- maximum number of columns of text.
  12. **    RawText -- unformatted text string.
  13. **
  14. ** RETURNS
  15. **    FormattedText -- formatted text string.  Use the 'Result'
  16. **        variable to retrieve this string.
  17. **
  18. ** NOTE: This function does not properly handle embedded NEWLINE control
  19. ** characters.
  20. **
  21. ** This script should work with current versions of ARexx.
  22. **
  23. ** Copyright © 1992-1993 ASDG, Incorporated
  24. ** All Rights Reserved
  25. */
  26.  
  27. OPTIONS RESULTS
  28.  
  29. NL = '0A'X
  30.  
  31.  
  32. PARSE ARG NumRows NumCols RawText
  33.  
  34. CharPos = 1
  35. RawTextLen = LENGTH( RawText )
  36. Rows = 1
  37. FormattedText = ""
  38. DO WHILE ((CharPos <= RawTextLen) & (Rows <= NumRows))
  39.     RawRowText = SUBSTR( RawText, CharPos, NumCols )
  40.  
  41.     LastSpacePos = LASTPOS( ' ', RawRowText )
  42.     IF (LastSpacePos ~= 0) THEN
  43.         RawRowText = LEFT( RawRowText, LastSpacePos-1 )
  44.  
  45.     FormattedText = FormattedText || NL || STRIP( STRIP( RawRowText, "B", " "), "B", " " )
  46.  
  47.     CharPos = CharPos + LENGTH( RawRowText )
  48.     Rows = Rows + 1
  49. END
  50.  
  51. RETURN FormattedText
  52.  
  53. /*
  54. ** strict format (no word wrap):
  55. **
  56. ** RawTextLen = LENGTH( RawText )
  57. ** FormattedText = ""
  58. ** DO Row = 0 TO (NumRows-1) UNTIL ((Row*NumCols+NumCols) > RawTextLen)
  59. **     FormattedText = FormattedText || NL || SUBSTR( RawText, (Row*NumCols+1), NumCols )
  60. ** END
  61. */
  62.