home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 5.ddi / CLIBSRC2.ZIP / FNSPLIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.8 KB  |  95 lines

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