home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / U4HUGE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  4.7 KB  |  218 lines

  1.  
  2. /* (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved. */
  3.  
  4. #include "p4misc.h"
  5. #include "d4all.h"
  6. #include "u4error.h"
  7.  
  8. #include <string.h>
  9. #ifndef UNIX
  10. #include <io.h>
  11. #endif
  12.  
  13. void  u4huge_set( char H_PTR ptr, int val, long len )
  14. {
  15.    long  i ;
  16.  
  17.    for ( i=0; i< len; i++)
  18.       ptr[i] = (char) val ;
  19. }
  20.  
  21. void  u4huge_cpy( void H_PTR dest, void H_PTR sou, long bytes )
  22. {
  23.    for ( ;; )
  24.    {
  25.       if ( bytes <= 0xFFFF )
  26.       {
  27.      memcpy( (char *) dest, (char *) sou, (unsigned) bytes ) ;
  28.          return ;
  29.       }
  30.  
  31.       memcpy( (char *) dest, (char *) sou, (size_t) 0xFFFF ) ;
  32.       dest   =  (char H_PTR) dest +  0xFFFF ;
  33.       sou    =  (char H_PTR) sou  +  0xFFFF ;
  34.       bytes -=  0xFFFF ;
  35.    }
  36. }
  37.  
  38. int  u4huge_cmp( unsigned char H_PTR a, unsigned char H_PTR b, unsigned len )
  39. {
  40.    #ifdef LANGUAGE
  41.       int i ;
  42.  
  43.       for (i=0; i<len; i++)
  44.       {
  45.          if ( v4map[a[i]] != v4map[b[i]] )
  46.          {
  47.             if ( v4map[a[i]] < v4map[b[i]] )  return -1 ;
  48.             return 1 ;
  49.          }
  50.       }
  51.       return 0 ;
  52.    #else
  53.       return( memcmp( (char *) a, (char *) b, (size_t) len ) ) ;
  54.    #endif
  55. }
  56.  
  57. #ifdef OS2
  58.  
  59. void H_PTR u4huge_norm( void H_PTR ptr )
  60. {
  61.    return( ptr ) ;
  62. }
  63.  
  64. /* u4huge_read returns the number of bytes read. 
  65.    CLH Memory Models only. */
  66.  
  67. long  u4huge_read( int hand, char H_PTR ptr, long len_ptr )  
  68. {
  69.    long          tot, left_seg ;
  70.    unsigned int  u_rc ;
  71.  
  72.    tot = 0L ;
  73.  
  74.    for(;;)
  75.    {
  76.       left_seg =  0x10000L - *((unsigned *)&(ptr)) ;
  77.       if ( (long) left_seg > len_ptr )  left_seg =  len_ptr ;
  78.       if ( left_seg == 0L )   return( tot ) ;
  79.       if ( left_seg > 0xFFFEL )  left_seg =  0xFC00L ;
  80.  
  81.       u_rc =  read(hand, ptr, (unsigned) left_seg ) ;
  82.       if ( u_rc == 0xFFFF )
  83.       {
  84.          u4error( E_READ, (char *) 0 ) ;
  85.      return -1L ;
  86.       }
  87.  
  88.       tot +=  u_rc ;
  89.       if ( (long) u_rc < left_seg )  return( tot ) ;
  90.  
  91.       ptr     +=  u_rc ;
  92.       len_ptr -=  u_rc ;
  93.    }
  94. }
  95.  
  96. /* CLH Memory Models only. */
  97. int  u4huge_write( int hand, char H_PTR ptr, long len_ptr ) 
  98. {
  99.    unsigned int  u_rc ;
  100.    long          left_seg ;
  101.  
  102.    for(;;)
  103.    {
  104.       left_seg = 0x10000L - (long) *((unsigned *)&(ptr)) ;
  105.       if ( (long) left_seg > len_ptr )  left_seg =  (unsigned) len_ptr ;
  106.       if ( left_seg == 0 )  return 0 ;
  107.  
  108.       if ( left_seg > 0xFFFE )  left_seg =  0xFC00 ;
  109.  
  110.       u_rc =  write(hand, ptr, (unsigned) left_seg ) ;
  111.       if ( u_rc != (unsigned) left_seg )
  112.       {
  113.          u4error( E_READ, (char *) 0 ) ;
  114.      return -1 ;
  115.       }
  116.  
  117.       ptr     +=  u_rc ;
  118.       len_ptr -=  u_rc ;
  119.    }
  120. }
  121.  
  122. #else
  123.  
  124. /* Normalize the pointer so that the offset is as small as possible. */
  125.  
  126. void H_PTR u4huge_norm( void H_PTR ptr )
  127. {
  128.    #ifdef IS_386
  129.       return( ptr )  ;
  130.    #else
  131.       #ifdef NO_HUGE
  132.      return( ptr ) ;
  133.       #else
  134.      static   union
  135.      {
  136.         void H_PTR far_ptr ;
  137.         unsigned  off_seg[2] ; /* off_seg[0] is offset, off_seg[1] is segment */
  138.      }  memory_ptr ;
  139.  
  140.      memory_ptr.far_ptr =  ptr ;
  141.      memory_ptr.off_seg[1] +=  memory_ptr.off_seg[0] >> 4 ;
  142.      memory_ptr.off_seg[0] &=  0xF ;
  143.  
  144.      return( memory_ptr.far_ptr ) ;
  145.       #endif
  146.    #endif
  147. }
  148.  
  149. /* DOS  u4huge_read and u4huge_write.
  150.    CLH Memory Models only. */
  151.  
  152. long  u4huge_read( int hand, char H_PTR ptr, long len_ptr )  
  153. {
  154.    long          tot ;
  155.    unsigned int  u_rc ;
  156.  
  157.    tot = 0L ;
  158.  
  159.    while ( len_ptr > 0xFFF0L )
  160.    {
  161.       ptr =  (char H_PTR) u4huge_norm( ptr ) ;
  162.       u_rc =  read(hand, (char *) ptr, 0xFFF0) ;
  163.       tot  += u_rc ;
  164.  
  165.       if ( u_rc != 0xFFF0 )
  166.       {
  167.      if ( u_rc == 0xFFFF )
  168.      {
  169.           u4error( E_READ, (char *) 0 ) ;
  170.         return -1 ;
  171.      }
  172.      tot +=  (long) u_rc ;
  173.      return( tot ) ;
  174.       }
  175.  
  176.       ptr      = (char *) ptr + 0xFFF0L ;
  177.       len_ptr -= 0xFFF0L ;
  178.    }
  179.  
  180.    ptr =  (char H_PTR) u4huge_norm( ptr ) ;
  181.    u_rc = read(hand, (char *) ptr, (unsigned int) len_ptr) ;
  182.    if ( u_rc == 0xFFFF )
  183.    {
  184.       u4error( E_READ, (char *) 0 ) ;
  185.       return -1L ;
  186.    }
  187.  
  188.    return( tot+u_rc ) ;
  189. }
  190.  
  191. /* CLH Memory Models only. */
  192. int  u4huge_write( int hand, char H_PTR ptr, long len_ptr )  
  193. {
  194.    while ( len_ptr > 0xFFF0L)
  195.    {
  196.       ptr =  (char H_PTR) u4huge_norm( ptr ) ;
  197.       if ( (unsigned int) write( hand, (char *) ptr, 0xFFF0) != 0xFFF0)
  198.       {
  199.      u4error( E_WRITE, (char *) 0 ) ;
  200.      return -1 ;
  201.       }
  202.  
  203.       ptr      = (char *) ptr + 0xFFF0L ;
  204.       len_ptr -= 0xFFF0L ;
  205.    }
  206.  
  207.    ptr =  (char H_PTR) u4huge_norm( ptr ) ;
  208.    if ( (unsigned int) write(hand, (char *) ptr, (unsigned int) len_ptr) !=
  209.                                         (unsigned int) len_ptr)
  210.    {
  211.       u4error( E_WRITE, (char *) 0 ) ;
  212.       return -1 ;
  213.    }
  214.  
  215.    return 0 ;
  216. }
  217. #endif
  218.