home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / smrtsort / sample2.c < prev    next >
Text File  |  1995-07-18  |  3KB  |  71 lines

  1. /*********************************************************/
  2. /*                                                        */ 
  3. /*  Licensed Material -- Property of IBM                  */    
  4. /*  5765-349                                              */
  5. /*  (c) Copyright IBM Corporation 1995                    */
  6. /*  All rights reserved                                   */
  7. /*                                                        */
  8. /**********************************************************/
  9.  
  10. /**********************************************************/
  11. /*                                                        */
  12. /* SMARTsort -- sample2.c                                 */
  13. /*                                                        */
  14. /* This program sorts a single file of department         */
  15. /* members where all of the input data to sort is         */
  16. /* passed from an input exit.                             */
  17. /*                                                        */
  18. /**********************************************************/
  19.  
  20. #pragma linkage (SMARTsort,system)
  21.  
  22. #define INCL_DOSFILEMGR
  23. #include <os2.h>
  24. #include "smrtsort.h"
  25.  
  26. #define READ_LENGTH     10
  27.  
  28. int getdata(SMARTSORT_BUFFER *to_SMARTsort, SMARTSORT_BUFFER *from_SMARTsort);
  29. int (*inputexit)(SMARTSORT_BUFFER *to_SMARTsort, SMARTSORT_BUFFER *from_SMARTsort) = getdata;
  30.  
  31. HFILE  hf;
  32. ULONG  ulAction;
  33. APIRET rc;
  34. ULONG bytesread = READ_LENGTH;
  35.  
  36.  
  37. void main(void)
  38. {
  39.  char *filename=".\\data\\dept.L92";
  40.  char *sortcommand="-s sort -o .\\output\\dept.L92 -k 2b,2";
  41.  int rc;
  42.  
  43.  /* Open file from where data will be read */
  44.  rc=DosOpen(filename,&hf,&ulAction,0,FILE_NORMAL,FILE_OPEN,
  45.             OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,(PEAOP2) NULL);
  46.   
  47.  rc=SMARTsort(sortcommand,NULL,NULL,inputexit,NULL,NULL,NULL);
  48.  
  49.  /* Close file used by input exit */
  50.  DosClose(hf);
  51.  
  52. }
  53.  
  54. int getdata(SMARTSORT_BUFFER *to_SMARTsort, SMARTSORT_BUFFER *from_SMARTsort) 
  55. {
  56.  /* End input exit processing if previous call to this routine encountered EOF */
  57.  if ( bytesread<READ_LENGTH ) return(UE_END);
  58.  
  59.  /* Read bytes from a file into the buffer supplied by SMARTsort */
  60.  DosRead(hf,(BYTE *) to_SMARTsort->buffer, READ_LENGTH, &bytesread);
  61.  
  62.  /* Set to_SMARTsort structure according to results of read */
  63.  if ( bytesread<1 ) {
  64.    to_SMARTsort->buffer_size=to_SMARTsort->nbytes_used=0;
  65.  } else {
  66.    to_SMARTsort->buffer_size=to_SMARTsort->nbytes_used=bytesread;
  67.  }
  68.    
  69.  return(UE_OK);  
  70. }
  71.