$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 *============================================================================ */ strcmpModule: do; $if not noID declare IDString (*) byte data ( '@(#)strcmp.p86 $Author: rmgillmore $ $Date:: 2025-05-04 19:35:39#$:', 0 ); $endif $set ( strcmpSource ) $include (..\lib\string.ext) strcmp: procedure ( leftPtr, rightPtr ) integer reentrant public; declare leftPtr pointer, rightPtr pointer, strcmpResults integer; declare leftString based leftPtr (*) byte, rightString based rightPtr (*) byte, leftLength word, rightLength word, compareLength word, mismatchIndex word; declare ARE_EQUIVALENT literally '0ffffh'; leftLength = strlen( leftPtr ); rightLength = strlen( rightPtr ); if ( ( leftLength = 0 ) or ( rightLength = 0 ) ) then do; if ( leftLength = rightLength ) then do; strcmpResults = 0; end; else if ( leftLength < rightLength ) then do; strcmpResults = -1; end; else do; strcmpResults = 1; end; end; else do; compareLength = leftLength; if ( compareLength > rightLength ) then do; compareLength = rightLength; end; mismatchIndex = cmpb( leftPtr, rightPtr, compareLength ); if ( ( leftLength = rightLength ) and ( mismatchIndex = ARE_EQUIVALENT ) ) then do; strcmpResults = 0; end; else do; if ( mismatchIndex < compareLength ) then do; /* * Handle the case where the strings are equivalent, but one is * shorter than the other */ if ( leftString( mismatchIndex ) = 0 ) and ( rightString( mismatchIndex ) <> 0 ) then do; strcmpResults = 1; end; else if ( rightString( mismatchIndex ) = 0 ) and ( leftString( mismatchIndex ) <> 0 ) then do; strcmpResults = -1; end; else do; if ( leftString( mismatchIndex ) < rightString( mismatchIndex ) ) then do; strcmpResults = -1; end; else do; strcmpResults = 1; end; end; end; else do; if ( leftLength < rightLength ) then do; strcmpResults = -1; end; else do; strcmpResults = 1; end; end; end; end; return ( strcmpResults ); end strcmp; end strcmpModule;