OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [Utils/] [win32/] [FileName.h] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 unneback
//####COPYRIGHTBEGIN####
2
//                                                                          
3
// ----------------------------------------------------------------------------
4
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5
//
6
// This program is part of the eCos host tools.
7
//
8
// This program is free software; you can redistribute it and/or modify it 
9
// under the terms of the GNU General Public License as published by the Free 
10
// Software Foundation; either version 2 of the License, or (at your option) 
11
// any later version.
12
// 
13
// This program is distributed in the hope that it will be useful, but WITHOUT 
14
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
15
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
16
// more details.
17
// 
18
// You should have received a copy of the GNU General Public License along with
19
// this program; if not, write to the Free Software Foundation, Inc., 
20
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
//
22
// ----------------------------------------------------------------------------
23
//                                                                          
24
//####COPYRIGHTEND####
25
//===========================================================================
26
//#####DESCRIPTIONBEGIN####
27
//
28
// Author(s):   sdf
29
// Contact(s):  sdf
30
// Date:                1998/09/11
31
// Version:             0.01
32
// Purpose:             Class to encapsulate filename operations (i.e. broadly on a file which probably do not involve opening
33
//              it).  Importantly, the + and += operators performs filename segment addition, making sure that only one '\\'
34
//                              comes between each piece.
35
// Description: Interface of a the filename class
36
// Requires:    
37
// Provides:    
38
// See also:    
39
// Known bugs:  
40
// Usage:       
41
//
42
//####DESCRIPTIONEND####
43
//
44
//===========================================================================
45
 
46
#ifndef _FILENAME_H
47
#define _FILENAME_H
48
#include <afxtempl.h>
49
class CFileName;
50
typedef CArray<CFileName,CFileName&> CFileNameArray;
51
class CFileName : public CString {
52
public:
53
        void ReplaceExtension (LPCTSTR pszNewExt);
54
 
55
  // previous directory is returned:
56
  static CFileName SetCurrentDirectory (LPCTSTR pszDir);
57
  const CString Root() const;
58
  const CString Extension() const;
59
  static CFileName GetTempPath();
60
  bool IsAbsolute() const;
61
 
62
  static const TCHAR cSep;        // The path separator ('\' on windows)
63
 
64
  // Standard ctors
65
  CFileName():CString(){}
66
  CFileName(const CFileName& stringSrc):CString(stringSrc){Normalize();}
67
  CFileName(const CString& stringSrc):CString(stringSrc){Normalize();}
68
  CFileName(TCHAR ch, int nRepeat = 1):CString(ch,nRepeat){Normalize();}
69
  CFileName(LPCSTR lpsz):CString(lpsz){Normalize();}
70
  CFileName(LPCWSTR lpsz):CString(lpsz){Normalize();}
71
  CFileName(LPCSTR lpch, int nLength):CString(lpch,nLength){Normalize();}
72
  CFileName(LPCWSTR lpch, int nLength):CString(lpch,nLength){Normalize();}
73
  CFileName(const unsigned char* psz):CString(psz){Normalize();}
74
 
75
  // Construct from path fragments
76
  CFileName(LPCTSTR,LPCTSTR);
77
  CFileName(LPCTSTR,LPCTSTR,LPCTSTR);
78
  CFileName(LPCTSTR,LPCTSTR,LPCTSTR,LPCTSTR);
79
  CFileName(LPCTSTR,LPCTSTR,LPCTSTR,LPCTSTR,LPCTSTR);
80
 
81
  // catenation operators: exactly one separator is placed between L and R
82
  const CFileName& operator+=(const CFileName& string);
83
  const CFileName& operator+=(TCHAR ch);
84
#ifdef _UNICODE
85
  const CFileName& operator+=(char ch);
86
#endif
87
  const CFileName& operator+=(LPCTSTR lpsz);
88
  friend CFileName AFXAPI operator+(const CFileName& string1,const CFileName& string2);
89
  friend CFileName AFXAPI operator+(const CFileName& string, TCHAR ch);
90
  friend CFileName AFXAPI operator+(TCHAR ch, const CFileName& string);
91
#ifdef _UNICODE
92
  friend CFileName AFXAPI operator+(const CFileName& string, char ch);
93
  friend CFileName AFXAPI operator+(char ch, const CFileName& string);
94
#endif
95
  friend CFileName AFXAPI operator+(const CFileName& string, LPCTSTR lpsz);
96
  friend CFileName AFXAPI operator+(LPCTSTR lpsz, const CFileName& string);
97
 
98
  // Textual append - no separator functionality
99
  const CFileName& Append (TCHAR ch);
100
  const CFileName& Append (LPCTSTR psz);
101
 
102
  // Utility functions
103
  const CFileName FullName() const;   // full path name
104
  const CFileName NoSpaceName() const;// sans spaces
105
  const CFileName ShortName() const;    // the type with ~s in it
106
  const CFileName Tail() const;       // file name sans directory part
107
  const CFileName Head() const;       // directory part
108
  const CFileName CygPath() const;    // path mangled for CygWin
109
 
110
  static CFileName GetCurrentDirectory();
111
  const CFileName& ExpandEnvironmentStrings();
112
  static CFileName ExpandEnvironmentStrings(LPCTSTR psz);
113
 
114
  // Form path name relative to given parameter (if NULL, current directory)
115
  const CFileName& MakeRelative(LPCTSTR pszRelativeTo=0);
116
  static CFileName Relative(LPCTSTR psz,LPCTSTR pszRelativeTo=0);
117
 
118
  bool SameFile (const CFileName &strOther) const;
119
  bool SetFileAttributes (DWORD dwFileAttributes) const;
120
 
121
  DWORD Attributes() const { return ::GetFileAttributes(*this); }
122
 
123
  bool Exists     () const {return 0xFFFFFFFF!=Attributes();}
124
  bool IsDir      () const {    DWORD a=Attributes(); return 0xFFFFFFFF!=a && (0!=(a&FILE_ATTRIBUTE_DIRECTORY));}
125
  bool IsFile     () const {    DWORD a=Attributes(); return 0xFFFFFFFF!=a && (0==(a&FILE_ATTRIBUTE_DIRECTORY));}
126
  bool IsReadOnly () const {    DWORD a=Attributes(); return 0xFFFFFFFF!=a && (0!=(a&FILE_ATTRIBUTE_READONLY ));}
127
  FILETIME LastModificationTime() const;
128
 
129
  bool RecursivelyDelete();
130
 
131
  bool CreateDirectory (bool bParentsToo=true,bool bFailIfAlreadyExists=false) const;
132
 
133
  static int FindFiles (LPCTSTR pszDir,CFileNameArray &ar,LPCTSTR pszPattern=_T("*.*"),bool bRecurse=true,DWORD dwExclude=FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN);
134
 
135
protected:
136
  // Helpers for Relative():
137
  LPCTSTR *Chop ();
138
  static CFileName Drive(LPCTSTR psz);
139
 
140
  // Remove trailing '/' (helper for ctors)
141
  void Normalize();
142
 
143
  // Implementating catenation functionality:
144
  void ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData);
145
  void ConcatCopy(int nSrc1Len, LPCTSTR lpszSrc1Data,int nSrc2Len, LPCTSTR lpszSrc2Data);
146
};
147
 
148
class CSaveExcursion {
149
  const CFileName m_strPrevDir;
150
public:
151
  CSaveExcursion(LPCTSTR pszDir) : m_strPrevDir(CFileName::SetCurrentDirectory(pszDir)) {}
152
  ~CSaveExcursion() { ::SetCurrentDirectory(m_strPrevDir); }
153
  bool Ok() const { return !m_strPrevDir.IsEmpty(); }
154
};
155
 
156
#endif  

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.