home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / toolkit / mm / ultimoio / ioseek.c < prev    next >
C/C++ Source or Header  |  1996-11-19  |  12KB  |  220 lines

  1. /*************************START OF SPECIFICATIONS *************************/
  2. /* SOURCE FILE NAME:  IOSEEK.C                                            */
  3. /*                                                                        */
  4. /* DESCRIPTIVE NAME: File Format IO Proc routine for MMIOM_SEEK           */
  5. /*                                                                        */
  6. /* COPYRIGHT:     IBM - International Business Machines                   */
  7. /*            Copyright (c) IBM Corporation  1991, 1992, 1993             */
  8. /*                        All Rights Reserved                             */
  9. /*                                                                        */
  10. /* STATUS: OS/2 Release 2.0                                               */
  11. /*                                                                        */
  12. /* FUNCTION: This source module contains the seek routine.                */
  13. /*                                                                        */
  14. /* NOTES:                                                                 */
  15. /*    DEPENDENCIES: none                                                  */
  16. /*    RESTRICTIONS: Runs in 32 bit protect mode (OS/2 2.0)                */
  17. /*                                                                        */
  18. /* ENTRY POINTS:                                                          */
  19. /*      IOProcSeek                                                        */
  20. /*      ioSeekFile                                                        */
  21. /*                                                                        */
  22. /************************* END OF SPECIFICATIONS **************************/
  23.  
  24.  
  25. #include        <stdio.h>
  26. #include        <string.h>
  27. #include        <stdlib.h>
  28. #include        <memory.h>
  29.  
  30. #define         INCL_DOS                        /* #define  INCL_DOSPROCESS.*/
  31. #define         INCL_ERRORS
  32. #define         INCL_WIN
  33. #define         INCL_GPI
  34. #include        <os2.h>                         /* OS/2 headers.*/
  35. #include        <pmbitmap.h>
  36.  
  37. #define         INCL_OS2MM
  38. #define         INCL_MMIO_CODEC
  39. #define         INCL_MMIO_DOSIOPROC
  40. #include        <os2me.h>                       /* Multi-Media IO extensions.*/
  41. #include        <ioi.h>
  42.  
  43.  
  44. /************************** START OF SPECIFICATIONS *************************/
  45. /*                                                                          */
  46. /* SUBROUTINE NAME:  IOProcSeek                                             */
  47. /*                                                                          */
  48. /* DESCRIPTIVE NAME: Seek a requested position.                             */
  49. /*                                                                          */
  50. /* FUNCTION: This function calculate new value of file pointer index,       */
  51. /*           clip file pointer index to reasonable value, return new        */
  52. /*           value of file pointer index.                                   */
  53. /*                                                                          */
  54. /*                                                                          */
  55. /* NOTES: None                                                              */
  56. /*                                                                          */
  57. /* ENTRY POINT: IOProcSeek                                                  */
  58. /*   LINKAGE:   CALL FAR (00:32)                                            */
  59. /*                                                                          */
  60. /* INPUT:     PMMIOINFO  pmmioinfo - pointer to MMIOINFO instance structure */
  61. /*            LONG       lSeekValue - position of file to be seeked to.     */
  62. /*            LONG       lSeekType  - position of file to be seeked from.   */
  63. /*                                                                          */
  64. /*                                                                          */
  65. /* EXIT-NORMAL:                                                             */
  66. /*              lNewPosition                                                */
  67. /*                                                                          */
  68. /* EXIT-ERROR:                                                              */
  69. /*              MMIO_ERROR                                                  */
  70. /*              Message specific error                                      */
  71. /*                                                                          */
  72. /* SIDE EFFECTS:                                                            */
  73. /*                                                                          */
  74. /*************************** END OF SPECIFICATIONS **************************/
  75. LONG IOProcSeek ( PMMIOINFO pmmioinfo,
  76.                   LONG lSeekValue,
  77.                   LONG lSeekType )
  78. {
  79.    LONG rc;
  80.    PINSTANCE  pinstance;
  81.    LONG  lNewPosition;
  82.  
  83.  
  84.    if (rc = ioGetPtrInstance(pmmioinfo,&pinstance))
  85.       return(rc);
  86.  
  87.    /***************************************************************************/
  88.    /* determine seek position.                                                */
  89.    /***************************************************************************/
  90.    switch (lSeekType) {
  91.  
  92.       /**************************************/
  93.       /* Seek offset from beginning of file.*/
  94.       /**************************************/
  95.       case SEEK_SET :
  96.          lSeekValue = lSeekValue;
  97.          break;
  98.  
  99.       /**************************************/
  100.       /* Seek offset from current.          */
  101.       /**************************************/
  102.       case SEEK_CUR :
  103.          lSeekValue += pinstance->lFileCurrentPosition;
  104.          break;
  105.  
  106.       /**************************************/
  107.       /* Seek to "end of file".             */
  108.       /**************************************/
  109.       case SEEK_END :
  110.          lSeekValue = (LONG)(pinstance->ulFileLen - (ULONG)lSeekValue);
  111.          break;
  112.  
  113.       /**************************************/
  114.       /* Invalid seek type value.           */
  115.       /**************************************/
  116.       default :
  117.          pmmioinfo->ulErrorRet = MMIOERR_INVALID_PARAMETER;
  118.          return(MMIO_ERROR);
  119.  
  120.       } /* end switch */
  121.  
  122.    /***************************************************************************/
  123.    /* Verify seek destination is not before beginning of file.                */
  124.    /***************************************************************************/
  125.    if (lSeekValue < 0L) {
  126.       pmmioinfo->ulErrorRet = MMIOERR_SEEK_BEFORE_BEGINNING;
  127.       return(MMIO_ERROR);
  128.       }
  129.  
  130.    /***************************************************************************/
  131.    /* Seek within a file                                                      */
  132.    /***************************************************************************/
  133.    if (pinstance->lCurrentTrack == MMIO_RESETTRACKS) {
  134.  
  135.       /************************************************************************/
  136.       /* Translated Seek (Seek past header if seek position = 0)              */
  137.       /*  else do:                                                            */
  138.       /* Raw Seek (Seek to absolute position without regard for headers)      */
  139.       /************************************************************************/
  140. //----if (pmmioinfo->ulTranslate & MMIO_TRANSLATEDATA) {       //TEMP BUG WORKAROUND!!!!!!!!!!!!!
  141.          if (lSeekValue == 0L) {
  142.             lNewPosition = ffSeekToDataBegin(pmmioinfo,pinstance);
  143.             }
  144.          else
  145.             lNewPosition = ioSeekFile((PLONG)&pmmioinfo->ulErrorRet,
  146.                                       pinstance->hmmioFileHandle,
  147.                                       lSeekValue);
  148. //-------}
  149. //    else
  150. //       lNewPosition = ioSeekFile(pmmioinfo,
  151. //                                 pinstance->hmmioFileHandle,
  152. //---------------------------------lSeekValue);
  153.       }
  154.  
  155.    /***************************************************************************/
  156.    /* Seek within a track                                                     */
  157.    /***************************************************************************/
  158.    else {
  159.       lNewPosition = ffSeekTrack(pmmioinfo,
  160.                                  pinstance->hmmioFileHandle,
  161.                                  lSeekValue, lSeekType ); /* File format specific */
  162.       }
  163.  
  164.    if (lNewPosition != MMIO_ERROR) {
  165.       pinstance->lFileCurrentPosition = lNewPosition;
  166.       pinstance->ulLastBufferOffset = 0L;
  167.       pinstance->pLastBuffer = 0L;
  168.       pinstance->ulDataInTempBuffer = 0L;
  169.       }
  170.  
  171.    return(lNewPosition);
  172. }
  173.  
  174.  
  175. /************************** START OF SPECIFICATIONS *************************/
  176. /*                                                                          */
  177. /* SUBROUTINE NAME:  ioSeekFile                                             */
  178. /*                                                                          */
  179. /* DESCRIPTIVE NAME: Seek within a file to absolute position.               */
  180. /*                                                                          */
  181. /* FUNCTION: This function seeks to an absolute position (raw seek)         */
  182. /*                                                                          */
  183. /*                                                                          */
  184. /* NOTES: None                                                              */
  185. /*                                                                          */
  186. /* ENTRY POINT: ioSeekFile                                                  */
  187. /*   LINKAGE:   CALL FAR (00:32)                                            */
  188. /*                                                                          */
  189. /* INPUT:     PLONG      plRc      - Pointer to error return code           */
  190. /*            HMMIO      hmmio     - mmio handle to file instance           */
  191. /*            LONG       lSeekValue - Seek position                         */
  192. /*                                                                          */
  193. /* EXIT-NORMAL:                                                             */
  194. /*              lNewPosition                                                */
  195. /*                                                                          */
  196. /* EXIT-ERROR:                                                              */
  197. /*              MMIO_ERROR                                                  */
  198. /*                                                                          */
  199. /* SIDE EFFECTS:                                                            */
  200. /*                                                                          */
  201. /*************************** END OF SPECIFICATIONS **************************/
  202. LONG ioSeekFile ( PLONG plRc,
  203.                   HMMIO hmmio,
  204.                   LONG lSeekValue )
  205.  
  206. {
  207.    LONG  lNewPosition;
  208.  
  209.    /***************************************************************************/
  210.    /* Do actual Seek within a file                                            */
  211.    /***************************************************************************/
  212.    lNewPosition = mmioSeek(hmmio,lSeekValue,SEEK_SET);
  213.    if ((lNewPosition <= MMIO_ERROR) || (lNewPosition != lSeekValue)) {
  214.       *plRc = MMIOERR_SEEK_FAILED;
  215.       return(MMIO_ERROR);
  216.       }
  217.  
  218.    return(lNewPosition);
  219. }
  220.