/* Copyright (c) 2001 Amduus Information Works, Inc. scott_auge@yahoo.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. INPUTS/OUTPUTS: INPUT Text to be wordwrapped INPUT Size of line OUTPUT Wrapped Text */ DEF VAR RCSVersion AS CHARACTER INIT "$Header: /home/appl/opensrc/misc/RCS/wordwrap.p,v 1.1 2001/06/24 18:46:38 sauge Exp $" NO-UNDO. DEF INPUT PARAMETER lText AS CHAR NO-UNDO. DEF INPUT PARAMETER lSize AS INT NO-UNDO. DEF OUTPUT PARAMETER lWrapped AS CHAR NO-UNDO. DEF VAR i AS INT NO-UNDO. DEF VAR lTemp AS CHAR NO-UNDO. DEF VAR lSpace AS INT NO-UNDO. /* If the string is less than the size, then just send it back */ /* This is the way we get out of the recurse. */ IF LENGTH (ltext) < lSize THEN DO: ASSIGN lWrapped = lText. RETURN. END. /* Find the LAST space character within lSize characters at the */ /* at the end of lSize characters. If no spaces found, just */ /* grab "lSize" characters. */ ASSIGN lTemp = SUBSTRING (lText, 1, lSize). ASSIGN lSpace = R-INDEX (lTemp, " "). IF lSpace = 0 THEN lSpace = lSize. ASSIGN lWrapped = SUBSTRING (lText, 1, lSpace) + "
". /* Send the rest of the line to this function again and tie */ /* together the results recursively. */ ASSIGN lText = SUBSTRING (lText, lSpace + 1, LENGTH (lText) - lSpace). RUN wordwrap.p (INPUT lText, INPUT lSize, OUTPUT lTemp). ASSIGN lWrapped = lWrapped + lTemp.