home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / F4STR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-19  |  1.5 KB  |  71 lines

  1.  
  2. /* (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved.
  3.  
  4.    f4str.c
  5. */
  6.  
  7. /* f4str
  8.  
  9.    Returns a pointer to static string corresponding to the field.
  10.    This string will end in a NULL character.
  11. */
  12.  
  13. #include "d4base.h"
  14. #include "p4misc.h"
  15.  
  16. #include <string.h>
  17.  
  18. extern int  v4cur_base ;
  19. extern BASE *v4base ;
  20.  
  21. static  char   buffer[258] ;
  22.  
  23. char * f4str( long field_ref)
  24. {
  25.    int width ;
  26.  
  27.    width =  f4width( field_ref ) ;
  28.    if (width < 0)  return (char *) 0 ;
  29.    if (width > 256) width = 256 ;
  30.    memcpy( buffer, f4ptr( field_ref) , (size_t) width ) ;
  31.  
  32.    buffer[width] = '\000' ;
  33.  
  34.    return( buffer) ;
  35. }
  36.  
  37. int  f4ncpy( long f_ref, char *ptr, int n )
  38. {
  39.    int  num_cpy ;
  40.  
  41.    num_cpy =  f4width(f_ref) ;
  42.    if ( n < num_cpy )  num_cpy =  n ;
  43.  
  44.    /* 'f4ptr' returns a pointer to the field within the database record buffer. */
  45.    memcpy( ptr, f4ptr(f_ref), (size_t) num_cpy ) ;
  46.  
  47.    if ( num_cpy < n )  ptr[num_cpy] =  '\000' ;
  48.  
  49.    return( num_cpy ) ;
  50. }
  51.  
  52. void  f4r_str( long f_ref, char *str )
  53. {
  54.    char *f_ptr ;
  55.    int   f_len, copy_bytes ;
  56.  
  57.    f_ptr =  f4ptr(f_ref) ;
  58.    f_len =  f4width(f_ref) ;
  59.    copy_bytes =  (int) strlen(str) ;
  60.  
  61.    if ( copy_bytes > f_len )  copy_bytes =  f_len ;
  62.  
  63.    /* Copy the data into the record buffer. */
  64.    memcpy( f_ptr, str, (size_t) copy_bytes ) ;
  65.  
  66.    /* Make the rest of the field blank. */
  67.    memset( f_ptr+copy_bytes, (int) ' ', (size_t) (f_len-copy_bytes) ) ;
  68.  
  69.    if ( v4base[v4cur_base].eof == 0 )     d4ptr()->buffer_changed =  1 ;
  70. }
  71.