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

  1.  
  2. /* (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved. */
  3.  
  4. #include "d4all.h"
  5. #include "p4misc.h"
  6.  
  7. #include <string.h>
  8.  
  9.  
  10. /*  u4name_full.c  
  11.  
  12.     If a file name does not have an extension, a default is added.
  13. */
  14.  
  15. void  u4name_full( char *result_name,  char *in_name,  char *default_extension )
  16. {
  17.    int   len, i ;
  18.    char *ptr ;
  19.  
  20.    strcpy( result_name, in_name ) ;
  21.  
  22.    len =  (int) strlen( result_name ) ;
  23.    if ( len > 64 )  len =  64 ;
  24.    while ( len >= 0  &&  (result_name[len-1] == '\000' || result_name[len-1] == ' ') )  len-- ;
  25.    result_name[len] =  '\000' ;
  26.    result_name[len+1] = '\000' ;  /* For the 'strcat' after '.' has been added. */
  27.  
  28.    u4upper( result_name ) ;
  29.  
  30.    for ( i=len-1, ptr= result_name+len-1; i >= 0;  i--,ptr-- )
  31.    {
  32.       if ( *ptr == '\\' || *ptr == '\/' || *ptr == '.' )  break ;
  33.    }
  34.    if ( i < 0  ||  *ptr != '.' )
  35.    {
  36.       /* Add Extension */
  37.       if ( *default_extension == '.' )
  38.      strcat( result_name + len, default_extension ) ;
  39.       else
  40.       {
  41.      result_name[len++] = '.' ;
  42.      strcat( result_name + len, default_extension ) ;
  43.       }
  44.    }
  45. }
  46.  
  47.  
  48. /* u4name_char.c 
  49.  
  50.    Returns TRUE iff it is a valid dBase field or function name character
  51. */
  52.  
  53. u4name_char( char ch)
  54. {
  55.    return ( ch>='a' && ch<='z'  ||
  56.         ch>='A' && ch<='Z'  ||
  57.         ch>='0' && ch<='9'  ||
  58.         ch=='\\'  ||  ch=='.'  || ch=='_'  ||  ch==':' ) ;
  59. }
  60.  
  61.  
  62. /* u4name_part
  63.  
  64.    Copies up to 8 characters of the file name.  No directory
  65.    or file extension information is included.
  66. */
  67.  
  68. void  u4name_part( char *result_name, char *in_name, int give_dir, int give_ext)
  69. {
  70.    char *start_ptr ;
  71.    int   len, i ;
  72.  
  73.    start_ptr =  in_name ;
  74.    len =  (int) strlen(in_name) ;
  75.  
  76.    if ( ! give_dir )
  77.    {
  78.       start_ptr =  in_name+ len ;
  79.  
  80.       while ( --start_ptr >= in_name )
  81.      if ( *start_ptr == ':' || *start_ptr == '\\' || *start_ptr == '\/' )
  82.         break ;
  83.  
  84.       start_ptr++ ;
  85.  
  86.       len =  (int) strlen(start_ptr) ;
  87.    }
  88.  
  89.    if ( ! give_ext )
  90.    {
  91.       if ( ! give_dir && len > 8 )  len = 8 ;
  92.  
  93.       for ( i=len; i >= 0; i-- )
  94.      if ( start_ptr[i] == '.' )
  95.      {
  96.         len =  i ;
  97.         break ;
  98.      }
  99.    }
  100.  
  101.    /* Trim any extra blanks. */
  102.    while ( start_ptr[len-1] == ' ' && len > 0 ) len-- ;
  103.    memmove( result_name, start_ptr, (size_t) len ) ;
  104.    result_name[len] =  '\000' ;
  105. }
  106.  
  107.  
  108. int  u4ptr_equal( void *p1, void *p2 )
  109. {
  110.    return( p1 == p2 ) ;
  111. }
  112.