home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cslio205.zip / INCLUDE / CSFILE.H < prev    next >
C/C++ Source or Header  |  1997-01-21  |  6KB  |  286 lines

  1. /***********************************************************************
  2.  
  3.                        CSA Library, Free Evaluation Version 2.0.5 
  4.                                        Release: January 22th 1997 
  5.  
  6.        A wrapper class to hide file name uglyness.
  7.  
  8.                                            Copyright(c) 1994-1997 
  9.                                                           ComBits 
  10.                                                   The Netherlands 
  11. ***********************************************************************/
  12.  
  13. #ifndef __CSFILE_H
  14. #define __CSFILE_H
  15.  
  16. #include "stdio.h"
  17. #include "csstr.h"
  18.  
  19.  
  20. #ifdef _CP_030
  21.    // Unix
  22.    #include "sys/stat.h"
  23.    #include "dirent.h"
  24. #endif
  25.  
  26. #ifdef _CP_004
  27.    #include "sys\types.h"
  28.    #include "sys\stat.h"
  29.    #include "direct.h"
  30.    #include "dos.h"
  31. #endif
  32.  
  33.  
  34.  
  35. #ifdef _CP_030
  36. // Unix
  37.   #define DIRSLASH '/'
  38. #else
  39. // Dos, OS2
  40.   #define DIRSLASH '\\'
  41. #endif
  42.  
  43.  
  44. ////////////////// Bit masks for pFnsplit /////////////////////////////
  45.  
  46.  
  47. #define CS_WILDCARDS 0x01
  48. #define CS_EXTENSION 0x02
  49. #define CS_FILENAME  0x04
  50. #define CS_DIRECTORY 0x08
  51. #define CS_DRIVE     0x10
  52.  
  53.  
  54. /////////////////////// Portability stuff //////////////////////////////
  55.  
  56. #ifdef _CP_001
  57. #include "dir.h"
  58. #include "dos.h"
  59. #endif
  60.  
  61. #if (defined(_CP_002a) || defined(_CP_002c))
  62. #include "direct.h"
  63. #include "dos.h"
  64. #endif
  65.  
  66. #ifdef _CP_002b
  67. #include "direct.h"
  68. #include "io.h"
  69. #endif
  70.  
  71.  
  72. #ifdef _CP_003
  73. #include "limits.h"
  74. #include "unistd.h"
  75. #endif
  76.  
  77.  
  78. #ifdef _CP_030
  79. /////////////////////// UNIX ///////////////////////////////////////////
  80.  
  81. #ifdef NAME_MAX
  82. #define MAXFILE NAME_MAX
  83. #else
  84. #define MAXFILE  256
  85. #endif
  86.  
  87. #ifdef PATH_MAX
  88. #define MAXPATH PATH_MAX
  89. #else
  90. #define MAXPATH  1024
  91. #endif
  92.  
  93. #ifndef MAXEXT
  94. #define MAXEXT MAXFILE
  95. #endif
  96.  
  97. #define MAXDIR  (MAXPATH-MAXFILE-1)
  98.  
  99. #endif
  100.  
  101.  
  102.  
  103. #if (defined( _CP_010) || defined(_CP_021))
  104. ///////////////////// DOS & Win16 ///////////////////////////////////
  105.  
  106. #ifndef MAXPATH
  107. #define MAXPATH   80
  108. #endif
  109. #ifndef MAXDIR
  110. #define MAXDIR    66
  111. #endif
  112. #ifndef MAXFILE
  113. #define MAXFILE   9
  114. #endif
  115.  
  116. #endif
  117.  
  118.  
  119.  
  120.  
  121.  
  122. #ifdef _CP_022
  123. /////////////////////// Win32 /////////////////////////////////////////
  124.  
  125. #ifndef MAXFILE
  126. #ifdef  NAME_MAX
  127. #define MAXFILE NAME_MAX
  128. #else
  129. #define MAXFILE  256
  130. #endif
  131. #endif
  132.  
  133. #ifndef MAXPATH
  134. #ifdef PATH_MAX
  135. #define MAXPATH PATH_MAX
  136. #else
  137. #define MAXPATH MAXFILE
  138. #endif
  139. #endif
  140.  
  141. #ifndef MAXEXT
  142. #define MAXEXT  MAXFILE
  143. #endif
  144.  
  145. #ifndef MAXDIR
  146. #define MAXDIR  MAXPATH
  147. #endif
  148.  
  149. #endif
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. #ifdef _CP_040
  158. /////////////////////// OS2 ///////////////////////////////////////////
  159.  
  160. #ifndef MAXFILE
  161. #ifdef NAME_MAX
  162. #define MAXFILE NAME_MAX
  163. #else
  164. #define MAXFILE  256
  165. #endif
  166. #endif
  167.  
  168. #ifndef MAXPATH
  169. #ifdef PATH_MAX
  170. #define MAXPATH PATH_MAX
  171. #else
  172. #define MAXPATH  MAXFILE
  173. #endif
  174. #endif
  175.  
  176. #ifndef MAXEXT
  177. #define MAXEXT MAXFILE
  178. #endif
  179.  
  180. #ifndef MAXDIR
  181. #define MAXDIR  MAXPATH
  182. #endif
  183.  
  184. #endif
  185.  
  186.  
  187.  
  188. //////////////////// Extension & Drive /////////////////////////////
  189.  
  190. #ifndef MAXEXT
  191. #define MAXEXT    5
  192. #endif
  193.  
  194. #ifndef MAXDRIVE
  195. #define MAXDRIVE  3
  196. #endif
  197.  
  198.  
  199. ////////////////////////////////////////////////////////////////////////
  200. //////////////////////// Class FILE_NAME ///////////////////////////////
  201. ////////////////////////////////////////////////////////////////////////
  202.  
  203. class FILE_NAME
  204. {
  205.  
  206. private:
  207.   csSTR fn;      // user input UNCHANGED
  208.   csSTR direc;   // default path  ( including DRIVE, if any)
  209.   csSTR exten;
  210.  
  211. protected:
  212.   void combine(void);
  213.  
  214. ////////////////////////////////////////////////////////////////////////
  215. ////////////////////// PUBLIC FUNCTIONS ////////////////////////////////
  216. ////////////////////////////////////////////////////////////////////////
  217.  
  218.  
  219. public:
  220.  
  221.   void set_dir(csCHAR *s);
  222.   csCHAR *ori_dir(void)       { return ((csCHAR *)direc); }
  223.   void set_name_only(csCHAR *s)  { fn=s;  }
  224.   void set_name(csCHAR *s);
  225.   int  exist(void)            { return file_exist(name_dpfe()); }
  226.   int  file_delete(void)      { return remove(name_dpfe()); }
  227.   csCHAR *name(void)          { return ((csCHAR *)fn); }
  228.  
  229.  
  230. ///////////////////////////////////////////////////////////////////////
  231. // Everything after the last dot in the file name is considered
  232. // to be the extension.
  233. //
  234. // The extension keeps the leading dot attached.
  235. // The Path keeps the leading and trailing slash.
  236. // The drive designator keeps the trailing colon.
  237.  
  238. /* Example:  c:\subdir\dir\filename.ext
  239.            drive    :  c:
  240.            path     :  \subdir\dir\
  241.            filename :  filename
  242.            ext      :  .ext
  243.  
  244. */
  245.   void set_ext(csCHAR *s);
  246.   void set_dir_cur(void);     // Current directory on the current drive.
  247.   void del_ext(void);
  248.   csCHAR *extension(void)     { return exten; }
  249.  
  250.   void force_ext(csCHAR *s);
  251.  
  252.   csCHAR *name_dpfe(csCHAR *n);
  253.   csCHAR *name_dp(csCHAR *n);
  254.   csCHAR *name_dpf(csCHAR *n);
  255.   csCHAR *name_pfe(csCHAR *n);
  256.   csCHAR *name_pf(csCHAR *n);
  257.   csCHAR *name_fe(csCHAR *n);
  258.   csCHAR *name_f(csCHAR *n);
  259.   csCHAR *name_e(csCHAR *n);
  260.   csCHAR *name_p(csCHAR *n);
  261.   csCHAR *name_d(csCHAR *n);
  262.  
  263.   csCHAR *name_dpfe(void);
  264.   csCHAR *name_dp(void);
  265.   csCHAR *name_dpf(void);
  266.   csCHAR *name_pfe(void);
  267.   csCHAR *name_pf(void);
  268.   csCHAR *name_fe(void);
  269.   csCHAR *name_f(void);
  270.   csCHAR *name_e(void);
  271.   csCHAR *name_p(void);
  272.   csCHAR *name_d(void);
  273.  
  274.  
  275.   int operator==(FILE_NAME& fn);
  276.  
  277.   FILE_NAME(void);
  278.   virtual ~FILE_NAME(void) {}
  279.  
  280.  
  281.  
  282. };
  283.  
  284.  
  285. #endif
  286.