source: trunk/gsdl/lib/fileutil.cpp@ 115

Last change on this file since 115 was 114, checked in by rjmcnab, 25 years ago

Made the source more portable.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1/**********************************************************************
2 *
3 * fileutil.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: fileutil.cpp 114 1999-01-19 01:38:20Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.5 1999/01/19 01:38:14 rjmcnab
15
16 Made the source more portable.
17
18 Revision 1.4 1999/01/12 01:50:59 rjmcnab
19
20 Standard header.
21
22 Revision 1.3 1999/01/08 02:33:14 rjmcnab
23
24 Added standard header to source files.
25
26 */
27
28
29#include "fileutil.h"
30
31#if defined(GSDL_USE_OBJECTSPACE)
32# include <ospace\std\iostream>
33# include <ospace\std\fstream>
34#elif defined(GSDL_USE_IOS_H)
35# include <iostream.h>
36# include <fstream.h>
37#else
38# include <iostream>
39# include <fstream>
40#endif
41
42
43// returns the proper concatenation of the two paths
44text_t filename_cat (text_t path1, text_t path2) {
45 text_t::iterator here;
46 text_t::iterator begin;
47 text_t::iterator end;
48
49 // make sure there is just one slash, of the correct type,
50 // at the end of path1 (unless path1 is an empty string).
51 if (!path1.empty()) {
52 // remove all trailing slashes
53 here = path1.end();
54 here--;
55 begin = path1.begin();
56 while (here != begin && (*here == '/' || *here == '\\')) {
57 here--;
58 }
59 here++;
60 path1.erase(here,path1.end());
61
62 // add one final slash
63#ifdef __WIN32__
64 path1 += "\\";
65#else
66 path1 += "/";
67#endif
68 }
69
70 // remove all slashes from the start of path2
71 here = path2.begin();
72 end = path2.end();
73 while (here != end && (*here == '/' || *here == '\\')) {
74 here++;
75 }
76 path2.erase (path2.begin(), here);
77
78 // return the concatenation of the two strings
79 return path1 + path2;
80}
81
82
83// returns true if filename can be opened
84bool file_exists (const text_t &filename) {
85 char *cstr = filename.getcstr();
86 ifstream filestream (cstr);
87 delete cstr;
88
89 if (filestream) {
90 // file exists
91 filestream.close ();
92 return true;
93 }
94
95 // file does not exist
96 return false;
97}
Note: See TracBrowser for help on using the repository browser.