/*
DYLSORT.C
*/

#include <plib.h>
#include <sort.g>

GLREF_D VOID *DatCommandPtr;

GLDEF_D P_RECT _DefScreenRect;

LOCAL_D INT array[] = {10,1,5,7,9,3,6,8,4,2};

#pragma save,ENTER_CALL

LOCAL_C INT RunSort(HANDLE dyl)
    {
    VOID *sort;

    sort=f_newlibh(dyl,C_ISORT);
    p_send4(sort,O_SORT,&array[0],10);
    p_send2(sort,O_DESTROY);
    return(0);
    }

#pragma restore

GLDEF_C INT main(VOID)
    {
    INT err,i;
    HANDLE dyl;
    VOID *dcb;

    p_openlib(&dcb,DatCommandPtr);
    err=p_loadfilelib(dcb,0,&dyl,TRUE);
    if (!err)
        {
        _DefScreenRect.tl.x=0;
        _DefScreenRect.tl.y=0;
        _DefScreenRect.br.x=40;
        _DefScreenRect.br.y=8;

        p_printf("Sorting...");
        err=p_enter2(RunSort,dyl);
        p_unloadlib(dyl);
        for (i=0;i<10;i+=2)
            p_printf("%4d %4d",array[i],array[i+1]);
        p_getch();
        }
    return(err);
    }
