home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Secrets (4th Edition) / Windows95Secrets4thEdition.iso / tools / installr / freeman / fpath.h_ / fpath
Encoding:
Text File  |  1995-06-14  |  4.6 KB  |  258 lines

  1. #define __FPATH_H
  2.  
  3.  
  4. #ifndef __IO_H
  5. #include "io.h"
  6. #endif
  7. #ifndef __DOS_H
  8. #include "dos.h"
  9. #endif
  10. #ifndef __STRING_H
  11. #include "string.h"
  12. #endif
  13. #ifndef __DSTRING_H
  14. #include "dstring.h"
  15. #endif
  16.  
  17.  
  18. #undef enable             /* we don't need the macro enable & disable in dos.h */
  19.  
  20. #undef disable
  21.  
  22.  
  23. #ifdef _MSC_VER                                                   /* microsoft */
  24. #undef  isborland
  25. #else                                                               /* borland */
  26. #define isborland
  27. #endif
  28.  
  29.  
  30. #ifdef isborland
  31.  
  32. typedef  find_t ffbuf; 
  33.  
  34. enum
  35. {
  36.    ffarch   = FA_ARCH,
  37.    ffdirec  = FA_DIREC,
  38.    ffhidden = FA_HIDDEN,
  39.    ffsystem = FA_SYSTEM,
  40.    ffrdonly = FA_RDONLY,
  41.    ffnormal = FA_NORMAL
  42. };
  43.  
  44. #else
  45.  
  46. typedef _find_t ffbuf;
  47.  
  48. enum
  49. {
  50.    ffarch   = _A_ARCH,
  51.    ffdirec  = _A_SUBDIR,
  52.    ffhidden = _A_HIDDEN,
  53.    ffsystem = _A_SYSTEM,
  54.    ffrdonly = _A_RDONLY,
  55.    ffnormal = _A_NORMAL
  56. };
  57.                              /* MS didn't define ftime. we copy borland's io.h */
  58. struct ftime
  59. {          
  60.    unsigned    ft_tsec  : 5;   /* Two second interval */
  61.    unsigned    ft_min   : 6;   /* Minutes */
  62.    unsigned    ft_hour  : 5;   /* Hours */
  63.    unsigned    ft_day   : 5;   /* Days */
  64.    unsigned    ft_month : 4;   /* Months */
  65.    unsigned    ft_year  : 7;   /* Year */
  66. };
  67.  
  68. #endif
  69.  
  70. typedef unsigned int UINT;
  71.  
  72.  
  73. class varpath;
  74.  
  75.  
  76. class abspath                                                 /* abstract path */
  77. {
  78.    public: 
  79.  
  80.    enum
  81.    {
  82.       maxpath = 128, maxdrive = 4, maxdir = 128, maxfile = 15, maxext = 5
  83.    };
  84.  
  85.    virtual char *getbuf() = 0;
  86.  
  87.    operator char*()
  88.    {
  89.       return getbuf();
  90.    }
  91.    char operator[](int i)
  92.    {
  93.       return getbuf()[i];
  94.    }
  95.    int del();
  96.    int chdir();
  97.    int mkdir();
  98.    int rmdir();
  99.    int chkdll();
  100.    int chsize(long l);
  101.    int access(int amode);
  102.    int rename(abspath &x);
  103.    int chkroot();
  104.    int chkexist();
  105.    int chkcanwrite();
  106.    int chkdiroccupied();
  107.    int multimkdir();
  108.    int getdad(varpath *dad);
  109.    int getd(varpath *d);
  110.    int getf(varpath *f);
  111.    int tostd(varpath *path);
  112.    int gettime(ftime *ft);
  113.    int settime(ftime &ft);
  114.    int chksame(abspath &x);
  115.    int comparetime(abspath &y);
  116.    int setfileattr(UINT flags);
  117.    int getfileattr(UINT *flags);
  118.    int findfirst(int flags, ffbuf *b);
  119.    int findnext(ffbuf *b);
  120.    void get(char path[]);
  121.    void getf(char f[]);
  122.    long getsize();
  123.    long locatestr(char s[]);
  124.  
  125.    #ifdef isborland
  126.    static struct  find_t fs;
  127.    #else
  128.    static struct _find_t fs;
  129.    #endif
  130.  
  131.    static int gethftime(int h, ftime *ft);
  132.    static int sethftime(int h, ftime &ft);
  133. };
  134.  
  135. class conpath;
  136.  
  137. class varpath:public abspath                                  /* variable path */
  138. {
  139.    public:
  140.  
  141.    virtual int set(char b[]) = 0;
  142.  
  143.    int tostd()
  144.    {
  145.       return abspath::tostd(this);
  146.    }
  147.    int setcwd();
  148.    int gethome();
  149.    int setroot(int drv);
  150.    int setdirwin();
  151.    int setdirsys();
  152.    int setbackup(abspath &path);
  153.    int merge(char d[], char f[]);
  154.    int merge(abspath &d, abspath &f);
  155.    int rplfile(char f[]);
  156.    int rplfile(abspath &f);
  157.    int setext(char newext[]);
  158.    int setlastc(char c);
  159.    int tmpindir(abspath &d, char prefix[]);
  160.    int tmpinsamedir(abspath &path, char prefix[]);
  161. };
  162.  
  163. class dynpath:public varpath                 /* variable path with dynamic buf */
  164. {
  165.    dstring s;
  166.  
  167.    public:
  168.  
  169.    dynpath()
  170.    {
  171.  
  172.    }
  173.    dynpath(char b[])
  174.    {
  175.       set(b);
  176.    }
  177.    int set(char b[])
  178.    {
  179.       return s.set(b);
  180.    }
  181.    int set(int n)
  182.    {
  183.       return s.set(n);
  184.    }
  185.    int getlen()
  186.    {
  187.       return s.getlen();
  188.    } 
  189.    char *getbuf()
  190.    {
  191.       return s;
  192.    }
  193. };
  194.  
  195. class borpath:public varpath                /* variable path with borrowed buf */
  196. {
  197.    char *s;                                 /* the buffer must be large enough */
  198.  
  199.    public:
  200.  
  201.    borpath(char sx[])
  202.    {
  203.       s = sx;
  204.    }
  205.    int set(char b[])
  206.    {
  207.       strcpy(s, b);
  208.  
  209.       return 1;
  210.    } 
  211.    char *getbuf()
  212.    {
  213.       return s;
  214.    }
  215. };
  216.  
  217. class stcpath:public varpath                  /* variable path with static buf */
  218. {
  219.    char s[maxpath];
  220.  
  221.    public:
  222.  
  223.    stcpath()
  224.    {
  225.       s[0] = '\0';
  226.    }
  227.    stcpath(char b[])
  228.    {
  229.       set(b);
  230.    }
  231.    int set(char b[])
  232.    {
  233.       strcpy(s, b);
  234.  
  235.       return 1;
  236.    } 
  237.    char *getbuf()
  238.    {
  239.       return s;
  240.    }
  241. };
  242.  
  243. class conpath:public abspath                     /* constant (invariable) path */
  244. {
  245.    char *s;
  246.  
  247.    public:
  248.  
  249.    conpath(char b[])
  250.    {
  251.       s = b;
  252.    }
  253.    char *getbuf()
  254.    {
  255.       return s;
  256.    }
  257. };
  258.