*===================================================================== * This copybook contains the definition of the generic @sort() * procedure which can be invoked from either the qsort() or the * bsearch() API's by specifying the @sort@@ procedure pointer as the * last parameter to either API. * * Prior to calling either qsort() or bsearch(), you must initialize * the @sort_control structure as follows: * * @sort.start: This field must be set to the start position within * each array element where sorting/searching should * start. * * @sort.length: This field should be set to the length of the string * (starting at the position specified by @sort_start) * which should be used to sort/search the array. * * @sort.count: This field should be initialized to zero (0) before * each invocation of qsort(0 or bsearch(). On return * from qsort() or bsearch() it holds a count of how * many times @sort() was executed for the invocation * of qsort() or bsearch(). * It also ensures that error checking for the other * parameters within the @sort_control structure will be * performed on the first invocation of @sort() within * the call to qsort() or bsearch(). * * @sort.order: This field defines the order in which the array * should be sorted/searched. It can take the following * values: * * 1 - The array will be sorted in ascending sequence * -1 - The array will be sorted in descending sequence * * @sort.error: This field will be returned set either to zero (0) if * the sort/search completed successfully or to a value * other than zero if an error occurred. * * @sort.igncas: This field determines whether the comparison * processing in @sort(0 should ignore the case of the * strings being compared. It can take the following * values: * * 0 - Preserve case of comparison strings * 1 - Ignore case of comparison strings * *===================================================================== * /DEFINE @SORT_P * /IF NOT DEFINED(BSEARCH_P) D/COPY QRPGLECPY,BSEARCH_P /ENDIF * D @sort PR 10I 0 Extproc('@sort') D Elem1@ * Value D Elem2@ * Value * D @sort@@ S * Procptr D Inz(%paddr('@sort')) D @search@@ S * Procptr D Inz(%paddr('@sort')) * D inz_@sort PR 10I 0 Extproc('inz_@sort') D Start 10I 0 Value D Length 10I 0 Value * /IF DEFINED(@SORT) D @sort_control DS Export('@sort_control') /ELSE D @sort_control DS Import('@sort_control') /ENDIF D Qualified D start 10I 0 D length 10I 0 D count 10I 0 D order 10I 0 D error 10I 0 D igncas 10I 0 * * Error codes (returned in @sort_control.error) * D ESORTORDER C 1 D ESORTSTART C 2 D ESORTLENGTH C 3 D ESORTIGNCAS C 4 D ESORTERROR C 5 *