1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include <cosv/ploc.hxx>
31 // NOT FULLY DECLARED SERVICES
33 #include <cosv/bstream.hxx>
34 #include <cosv/csv_ostream.hxx>
43 class UnixRootDir
: public Root
49 ostream
& o_rPath
) const;
51 bostream
& o_rPath
) const;
52 virtual DYN Root
* CreateCopy() const;
57 class WorkingDir
: public Root
61 const char * i_sDelimiter
= Delimiter() );
64 ostream
& o_rPath
) const;
66 bostream
& o_rPath
) const;
67 virtual DYN Root
* CreateCopy() const;
74 class WinRootDir
: public Root
80 ostream
& o_rPath
) const;
82 bostream
& o_rPath
) const;
83 virtual DYN Root
* CreateCopy() const;
88 class WinDrive
: public Root
94 ostream
& o_rPath
) const;
96 bostream
& o_rPath
) const;
97 virtual DYN Root
* CreateCopy() const;
104 class WinDriveRootDir
: public Root
108 const char * i_sPath
);
113 ostream
& o_rPath
) const;
115 bostream
& o_rPath
) const;
116 virtual DYN Root
* CreateCopy() const;
118 OwnDelimiter() const;
123 class UNCRoot
: public Root
127 const char * i_sPath
);
129 const String
& i_sComputer
,
130 const String
& i_sEntryPt
);
133 ostream
& o_rPath
) const;
135 bostream
& o_rPath
) const;
136 virtual DYN Root
* CreateCopy() const;
138 OwnDelimiter() const;
144 class InvalidRoot
: public Root
148 ostream
& o_rPath
) const;
150 bostream
& o_rPath
) const;
151 virtual DYN Root
* CreateCopy() const;
153 OwnDelimiter() const;
158 Create_WindowsRoot( const char * & o_sPathAfterRoot
,
159 const char * i_sPath
)
161 if (i_sPath
[0] == '\\')
163 if (i_sPath
[1] == '\\')
165 o_sPathAfterRoot
= strchr(i_sPath
+2,'\\');
166 if (o_sPathAfterRoot
!= 0)
168 o_sPathAfterRoot
= strchr(o_sPathAfterRoot
+1,'\\');
169 if (o_sPathAfterRoot
!= 0)
171 return new UNCRoot(i_sPath
);
173 return new InvalidRoot
; // Incomplete UNC root.
177 o_sPathAfterRoot
= i_sPath
+1;
178 return new WinRootDir
;
181 else if (i_sPath
[1] == ':')
183 if ( i_sPath
[2] == '\\')
185 o_sPathAfterRoot
= i_sPath
+ 3;
186 return new WinDriveRootDir(i_sPath
);
190 o_sPathAfterRoot
= i_sPath
+ 2;
191 return new WinDrive(*i_sPath
);
196 o_sPathAfterRoot
= i_sPath
;
197 return new WorkingDir("\\");
202 Create_UnixRoot( const char * & o_sPathAfterRoot
,
203 const char * i_sPath
)
207 o_sPathAfterRoot
= i_sPath
+ 1;
208 return new UnixRootDir
;
212 o_sPathAfterRoot
= i_sPath
;
213 return new WorkingDir("/");
218 //********************** Root ****************************//
226 Root::Create_( const char * & o_sPathAfterRoot
,
227 const char * i_sPath
,
228 const char * i_sDelimiter
)
230 if (i_sPath
[0] == '.')
232 switch ( i_sPath
[1] )
234 case '\0': o_sPathAfterRoot
= i_sPath
+ 1;
236 case '\\': o_sPathAfterRoot
= i_sPath
+ 2;
238 case '/': o_sPathAfterRoot
= i_sPath
+ 2;
240 case '.': o_sPathAfterRoot
= i_sPath
;
243 o_sPathAfterRoot
= 0;
244 return new InvalidRoot
;
245 } // end switch (i_sPath[1])
247 return new WorkingDir
;
248 } // end if (i_sPath[0] == '.')
250 switch (*i_sDelimiter
)
252 case '\\': return Create_WindowsRoot(o_sPathAfterRoot
, i_sPath
);
253 case '/': return Create_UnixRoot(o_sPathAfterRoot
, i_sPath
);
256 o_sPathAfterRoot
= 0;
257 return new InvalidRoot
;
262 //********************** UnixRootDir ****************************//
265 UnixRootDir::UnixRootDir()
270 UnixRootDir::Get( ostream
& o_rPath
) const
276 UnixRootDir::Get( bostream
& o_rPath
) const
278 o_rPath
.write( "/", 1 );
282 UnixRootDir::CreateCopy() const
284 return new UnixRootDir
;
288 UnixRootDir::OwnDelimiter() const
294 //********************** WorkingDir ****************************//
296 WorkingDir::WorkingDir( const char * i_sDelimiter
)
297 : sOwnDelimiter(i_sDelimiter
)
302 WorkingDir::Get( ostream
& o_rPath
) const
304 o_rPath
<< '.' << sOwnDelimiter
;
308 WorkingDir::Get( bostream
& o_rPath
) const
310 o_rPath
.write( ".", 1 );
311 o_rPath
.write( sOwnDelimiter
);
315 WorkingDir::CreateCopy() const
317 return new WorkingDir(sOwnDelimiter
);
321 WorkingDir::OwnDelimiter() const
323 return sOwnDelimiter
;
327 //********************** WinRootDir ****************************//
329 WinRootDir::WinRootDir()
334 WinRootDir::Get( ostream
& o_rPath
) const
340 WinRootDir::Get( bostream
& o_rPath
) const
342 o_rPath
.write( "\\", 1 );
346 WinRootDir::CreateCopy() const
348 return new WinRootDir
;
352 WinRootDir::OwnDelimiter() const
358 //********************** WinDrive ****************************//
360 WinDrive::WinDrive( char i_cDrive
)
361 : cDrive(static_cast< char >(toupper(i_cDrive
)))
366 WinDrive::Get( ostream
& o_rPath
) const
368 o_rPath
<< cDrive
<< ':';
372 WinDrive::Get( bostream
& o_rPath
) const
374 static char buf_
[3] = " :";
376 o_rPath
.write( &buf_
[0], 2 );
380 WinDrive::CreateCopy() const
382 return new WinDrive(cDrive
);
386 WinDrive::OwnDelimiter() const
392 //********************** WinDriveRootDir ****************************//
394 WinDriveRootDir::WinDriveRootDir( const char * i_sPath
)
395 : cDrive(static_cast< char >(toupper(*i_sPath
)))
397 if ( 'A' > cDrive OR
'Z' < cDrive
)
401 WinDriveRootDir::WinDriveRootDir( char i_cDrive
)
407 WinDriveRootDir::Get( ostream
& o_rPath
) const
409 o_rPath
<< cDrive
<< ":\\";
413 WinDriveRootDir::Get( bostream
& o_rPath
) const
415 static char buf_
[4] = " :\\";
417 o_rPath
.write( &buf_
[0], 3 );
421 WinDriveRootDir::CreateCopy() const
423 return new WinDriveRootDir(cDrive
);
427 WinDriveRootDir::OwnDelimiter() const
433 //********************** UNCRoot ****************************//
435 UNCRoot::UNCRoot( const char * i_sPath
)
439 const char * pRestPath
= i_sPath
+ 2;
440 const char * pDirEnd
= strchr(pRestPath
, '\\');
441 csv_assert(pDirEnd
!= 0);
443 sComputer
= String(pRestPath
, pDirEnd
- pRestPath
);
444 pRestPath
= pDirEnd
+1;
445 pDirEnd
= strchr(pRestPath
, '\\');
449 sEntryPt
= String(pRestPath
, pDirEnd
- pRestPath
);
453 sEntryPt
= pRestPath
;
457 UNCRoot::UNCRoot( const String
& i_sComputer
,
458 const String
& i_sEntryPt
)
459 : sComputer(i_sComputer
),
465 UNCRoot::Get( ostream
& o_rPath
) const
467 o_rPath
<< "\\\\" << sComputer
<< '\\' << sEntryPt
<< "\\";
471 UNCRoot::Get( bostream
& o_rPath
) const
473 o_rPath
.write( "\\\\", 2 );
474 o_rPath
.write( sComputer
);
475 o_rPath
.write( "\\", 1 );
476 o_rPath
.write( sEntryPt
);
477 o_rPath
.write( "\\", 1 );
481 UNCRoot::CreateCopy() const
483 return new UNCRoot(sComputer
,sEntryPt
);
487 UNCRoot::OwnDelimiter() const
494 //********************** InvalidRoot ****************************//
497 InvalidRoot::Get( ostream
& ) const
502 InvalidRoot::Get( bostream
& ) const
507 InvalidRoot::CreateCopy() const
509 return new InvalidRoot
;
513 InvalidRoot::OwnDelimiter() const