home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-1.ZIP / SOURCE.ZIP / U4NAME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-09  |  2.2 KB  |  106 lines

  1.  
  2. /* (c)Copyright Sequiter Software Inc., 1987, 1988, 1989.  All rights reserved. */
  3.  
  4. #include "d4base.h"
  5.  
  6. #include <string.h>
  7.  
  8.  
  9. /*  u4name_full.c  
  10.  
  11.     If a file name does not have an extension, a default is added.
  12. */
  13.  
  14. void  u4name_full( result_name,  in_name,  default_extension )
  15. char    *result_name, *in_name, *default_extension ;
  16. {
  17.    int   len, i ;
  18.    char *ptr ;
  19.  
  20.    strcpy( result_name, in_name ) ;
  21.  
  22.    len =  strlen( result_name ) ;
  23.    if ( len > 64 )  len =  64 ;
  24.    while ( len >= 0  &&  (result_name[len-1] == '\0' || result_name[len-1] == ' ') )  len-- ;
  25.    result_name[len] =  '\0' ;
  26.  
  27.    strupr( result_name ) ;
  28.  
  29.    for ( i=len-1, ptr= result_name+len-1; i >= 0;  i--,ptr-- )
  30.    {
  31.       if ( *ptr == '\\' || *ptr == '\/' || *ptr == '.' )  break ;
  32.    }
  33.    if ( i < 0  ||  *ptr != '.' )
  34.    {
  35.       /* Add Extension */
  36.       if ( *default_extension == '.' )
  37.      strcat( result_name + len, default_extension ) ;
  38.       else
  39.       {
  40.      result_name[len++] = '.' ;
  41.      strcat( result_name + len, default_extension ) ;
  42.       }
  43.    }
  44. }
  45.  
  46.  
  47. /* u4name_char.c 
  48.  
  49.    Returns TRUE iff it is a valid dBase field or function name character
  50. */
  51.  
  52. u4name_char( ch)
  53. 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( result_name, in_name, give_dir, give_ext )
  69. char  *result_name, *in_name ;
  70. int    give_dir, give_ext ;
  71. {
  72.    char *start_ptr ;
  73.    int   len, i ;
  74.  
  75.    start_ptr =  in_name ;
  76.    len =  strlen(in_name) ;
  77.  
  78.    if ( ! give_dir )
  79.    {
  80.       start_ptr =  in_name+ len ;
  81.  
  82.       while ( --start_ptr >= in_name )
  83.      if ( *start_ptr == ':' || *start_ptr == '\\' || *start_ptr == '\/' )
  84.         break ;
  85.  
  86.       start_ptr++ ;
  87.  
  88.       len =  strlen(start_ptr) ;
  89.    }
  90.  
  91.    if ( ! give_ext )
  92.    {
  93.       if ( ! give_dir && len > 8 )  len = 8 ;
  94.  
  95.       for ( i=len; i >= 0; i-- )
  96.      if ( start_ptr[i] == '.' )
  97.      {
  98.         len =  i ;
  99.         break ;
  100.      }
  101.    }
  102.  
  103.    memmove( result_name, start_ptr, (size_t) len ) ;
  104.    result_name[len] =  '\0' ;
  105. }
  106.