home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / FNMERGE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  3.8 KB  |  122 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - fnmerge.c
  3.  *
  4.  * function(s)
  5.  *        fnmerge - make new filename
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18.  
  19. #include <dir.h>
  20. #include <string.h>
  21.  
  22. /*---------------------------------------------------------------------*
  23.  
  24. Name        fnmerge - makes new file name
  25.  
  26. Usage        #include <dir.h>
  27.         void fnmerge(char *path, const char * drive, const char * dir,
  28.                  const char * name, const char * ext);
  29.  
  30. Related
  31. functions usage    int fnsplit(const char *path, char *drive, char *dir,
  32.                 char *name, char *ext);
  33.  
  34. Prototype in    dir.h
  35.  
  36. Description    fnmerge makes a file name from its components. The
  37.         new file's full path name is
  38.  
  39.             X:\DIR\SUBDIR\NAME.EXT
  40.  
  41.         where
  42.  
  43.             X is given by drive
  44.             \DIR\SUBDIR\ is given by dir
  45.             NAME.EXT is given by name and ext
  46.  
  47.         fnsplit takes a file's full path name (path) as a string
  48.         in the form
  49.  
  50.             X:\DIR\SUBDIR\NAME.EXT
  51.  
  52.         and splits path into its four components. It then stores
  53.         those components in the strings pointed to by drive, dir,
  54.         name and ext. (Each component is required but can be a
  55.         NULL, which means the corresponding component will be
  56.         parsed but not stored.)
  57.  
  58.         The maximum sizes for these strings are given by the
  59.         constants MAXDRIVE, MAXDIR, MAXPATH, MAXNAME and MAXEXT,
  60.         (defined in dir.h) and each size includes space for the
  61.         null-terminator.
  62.  
  63.             Constant    (Max.)    String
  64.  
  65.             MAXPATH        (80)    path
  66.             MAXDRIVE    (3)    drive; includes colon (:)
  67.             MAXDIR        (66)    dir; includes leading and
  68.                         trailing backslashes (\)
  69.             MAXFILE        (9)    name
  70.             MAXEXT        (5)    ext; includes leading dot (.)
  71.  
  72.         fnsplit assumes that there is enough space to store each
  73.         non-NULL component. fnmerge assumes that there is enough
  74.         space for the constructed path name. The maximum constructed
  75.         length is MAXPATH.
  76.  
  77.         When fnsplit splits path, it treats the punctuation as
  78.         follows:
  79.  
  80.         * drive keeps the colon attached (C:, A:, etc.)
  81.  
  82.         * dir keeps the leading and trailing backslashes
  83.           (\turboc\include\,\source\, etc.)
  84.  
  85.         * ext keeps the dot preceding the extension (.c, .exe, etc.)
  86.  
  87.         These two functions are invertable; if you split a given path
  88.         with fnsplit, then merge the resultant components with fnmerge,
  89.         you end up with path.
  90.  
  91. Return value    fnsplit returns an integer (composed of five flags,
  92.         defined in dir.h) indicating which of the full path name
  93.         components were present in path; these flags and the components
  94.         they represent are:
  95.  
  96.             EXTENSION    an extension
  97.             FILENAME    a filename
  98.             DIRECTORY    a directory (and possibly
  99.                     sub-directories)
  100.             DRIVE        a drive specification (see dir.h)
  101.             WILDCARDS    wildcards (* or ? cards)
  102.  
  103. *---------------------------------------------------------------------*/
  104. void _CType fnmerge(register char *pathP,const char *driveP,const char *dirP,
  105. const char *nameP,const char *extP)
  106. {
  107.     if (driveP && *driveP)
  108.     {
  109.         *pathP++ = *driveP++;
  110.         *pathP++ = ':';
  111.     }
  112.     if (dirP && *dirP)
  113.     {
  114.         pathP = stpcpy(pathP,dirP);
  115.         if (*(pathP-1) != '\\' && *(pathP-1) != '/') *pathP++ = '\\';
  116.     }
  117.     if (nameP) pathP = stpcpy(pathP,nameP);
  118.     if (extP)  pathP = stpcpy(pathP,extP);
  119.     *pathP = 0;
  120. }
  121.  
  122.