$include (..\lib\compStch.ext) /* *============================================================================ * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE * * Permission to use for any purpose, modify, copy, and make enhancements * and derivative works of the software is granted if attribution is given to * R.M. Gillmore, dba the ACME Software Deli, as the author * * While the ACME Software Deli does not work for money, there is nonetheless * a significant amount of work involved. The ACME Software Deli maintains the * rights to all code written, though it may be used and distributed as long as * the following conditions are maintained. * * 1. The copyright statement at the top of each code block is maintained in * your distribution. * 2. You do not identify yourself as the ACME Software Deli * 3. Any changes made to the software are sent to the ACME Software Deli *============================================================================ */ strSplitModule: do; $if not noID declare IDString (*) byte data ( '@(#)strSplit.p86 $Author: rmgillmore $ $Date:: 2025-05-04 19:35:39#$:', 0 ); $endif $include (..\lib\comnDefs.ext) $set (strSplitSource) $include (..\lib\string.ext) $include (..\lib\ptrMath.ext) /*============================================================================ * Function: strSplit() * * Description: * Predictably breaks a string into pieces (at white spaces) * * Input: * initialAllowance - the number of white space characters to the left * maxLineLength - this is the number of characters allowed on a line * stringToDivide - the actual string to be broken at white spaces to * create the desired affect * * Output: * an array of pointers to the strings (maybe only one, but there may * be more than one, also) *============================================================================ */ strSplit: procedure ( initialAllowance, maxLineLength, stringToDivide ) pointer public; declare initialAllowance integer, maxLineLength integer, stringToDivide pointer; /* the address of the character array */ declare returnArray stringArray_t, segmentArray (10) pointer, segArrayIndex word; declare printableCharPerLine word, stringBeginning pointer, string based stringBeginning (*) char, overallStringLength word, lengthRemaining word, done boolean; segArrayIndex = 0; /* * derive the number of printable characters that may exist on each line */ printableCharPerLine = unsign( ( maxLineLength - 1 ) - ( initialAllowance - 1 ) ); /* * point to the beginning of the string. this pointer will move to * the next string segment as we divide */ stringBeginning = stringToDivide; /* * we need to know the length of the input string */ overallStringLength = strlen( stringToDivide ); /* * when length remaining is less than the window length, we are done * dividing the input string */ lengthRemaining = overallStringLength; /* * loop termination switch */ done = false; do while ( not done ); /* * store the address of the string in the array */ segmentArray( segArrayIndex ) = stringBeginning; segArrayIndex = segArrayIndex + 1; /* * if the remainder of the string is shorter than what an output * line can handle, we are done */ if ( lengthRemaining <= printableCharPerLine ) then do; done = true; end; else do; /* * there will be further dividing. find the end of the next * string segment */ declare stringEnding pointer, endingChar based stringEnding char, tempStringLen word; stringEnding = @string( printableCharPerLine ); /* * if the character at the end of the string is a NUL, we're done */ if ( endingChar = NUL ) then do; done = true; end; else do; /* * the last character was not a NUL, so search backward for * a white space */ do while ( endingChar <> SPACE ) and ( endingChar <> TAB ); stringEnding = decPtr( stringEnding, size( endingChar ), 1 ); end; /* * we found the white space, so divide the string here */ endingChar = NUL; /* * calculate the length of this segment */ tempStringLen = strlen( stringBeginning ); /* * subtract the length of this string from the total */ lengthRemaining = lengthRemaining - tempStringLen; /* * store the address of the next segment */ stringBeginning = incPtr( stringEnding, size( endingChar ), 1 ); end; /* string end not NUL */ end; /* not at the end of the string */ end; /* not done */ returnArray.numberSegments = signed( segArrayIndex ); returnArray.stringSegments = @segmentArray; return ( @returnArray ); end strSplit; end strSplitModule;