MacOS portability improvements.
Added a class to encapsulate Mac vs. Unix path separator differences.
This commit is contained in:
parent
f8dde93e05
commit
5bddbd0ca9
@ -3,6 +3,7 @@
|
|||||||
noinst_LIBRARIES = libMisc.a
|
noinst_LIBRARIES = libMisc.a
|
||||||
|
|
||||||
libMisc_a_SOURCES = \
|
libMisc_a_SOURCES = \
|
||||||
|
fgpath.cxx fgpath.hxx \
|
||||||
fgstream.cxx fgstream.hxx \
|
fgstream.cxx fgstream.hxx \
|
||||||
stopwatch.hxx \
|
stopwatch.hxx \
|
||||||
strutils.cxx strutils.hxx \
|
strutils.cxx strutils.hxx \
|
||||||
|
75
Lib/Misc/fgpath.cxx
Normal file
75
Lib/Misc/fgpath.cxx
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
//
|
||||||
|
// fgpath.cxx -- routines to abstract out path separator differences
|
||||||
|
// between MacOS and the rest of the world
|
||||||
|
//
|
||||||
|
// Written by Curtis L. Olson, started April 1999.
|
||||||
|
//
|
||||||
|
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
|
||||||
|
#include "fgpath.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
// If Unix, replace all ":" with "/". If MacOS, replace all "/" with
|
||||||
|
// ":" it should go without saying that neither of these characters
|
||||||
|
// should be used in file or directory names.
|
||||||
|
|
||||||
|
static string fix_path( const string path ) {
|
||||||
|
string result = path;
|
||||||
|
|
||||||
|
for ( int i = 0; i < (int)path.size(); ++i ) {
|
||||||
|
if ( result[i] == FG_BAD_PATH_SEP ) {
|
||||||
|
result[i] = FG_PATH_SEP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// default constructor
|
||||||
|
FGPath::FGPath() {
|
||||||
|
path = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// create a path based on "path"
|
||||||
|
FGPath::FGPath( const string p ) {
|
||||||
|
path = fix_path( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
FGPath::~FGPath() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// append to the existing path
|
||||||
|
void FGPath::append( const string p ) {
|
||||||
|
string part = fix_path( p );
|
||||||
|
|
||||||
|
if ( path.size() == 0 ) {
|
||||||
|
path = part;
|
||||||
|
} else {
|
||||||
|
if ( part[0] != FG_PATH_SEP ) {
|
||||||
|
path += FG_PATH_SEP;
|
||||||
|
}
|
||||||
|
path += part;
|
||||||
|
}
|
||||||
|
}
|
74
Lib/Misc/fgpath.hxx
Normal file
74
Lib/Misc/fgpath.hxx
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
//
|
||||||
|
// fgpath.hxx -- routines to abstract out path separator differences
|
||||||
|
// between MacOS and the rest of the world
|
||||||
|
//
|
||||||
|
// Written by Curtis L. Olson, started April 1999.
|
||||||
|
//
|
||||||
|
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _FGPATH_HXX
|
||||||
|
#define _FGPATH_HXX
|
||||||
|
|
||||||
|
|
||||||
|
#include <Include/compiler.h>
|
||||||
|
|
||||||
|
#include STL_STRING
|
||||||
|
|
||||||
|
FG_USING_STD(string);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MACOS
|
||||||
|
# define FG_PATH_SEP ':'
|
||||||
|
# define FG_BAD_PATH_SEP '/'
|
||||||
|
#else
|
||||||
|
# define FG_PATH_SEP '/'
|
||||||
|
# define FG_BAD_PATH_SEP ':'
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
class FGPath {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
string path;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// default constructor
|
||||||
|
FGPath();
|
||||||
|
|
||||||
|
// create a path based on "path"
|
||||||
|
FGPath( const string p );
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
~FGPath();
|
||||||
|
|
||||||
|
// append to the existing path
|
||||||
|
void append( const string p );
|
||||||
|
|
||||||
|
// get the path string
|
||||||
|
inline string get_path() const { return path; }
|
||||||
|
inline const char *get_path_c_str() { return path.c_str(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _FGPATH_HXX
|
||||||
|
|
||||||
|
|
@ -98,18 +98,22 @@ skipeol( istream& in )
|
|||||||
while ( in.get(c) && (c != '\n' && c != '\r') )
|
while ( in.get(c) && (c != '\n' && c != '\r') )
|
||||||
;
|
;
|
||||||
|
|
||||||
// \r\n ?
|
#ifdef __MWERKS // -dw- need to strip line ending!
|
||||||
|
in >> skipws;
|
||||||
|
#endif
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
istream&
|
istream&
|
||||||
skipws( istream& in )
|
skipws( istream& in ) {
|
||||||
{
|
|
||||||
char c;
|
char c;
|
||||||
while ( in.get(c) )
|
while ( in.get(c) ) {
|
||||||
{
|
#ifdef __MWERKS__ // -dw- for unix file compatibility
|
||||||
if ( ! isspace( c ) )
|
if ( ! (isspace( c ) ) || c != '\0' || c!='\n' || c != '\r' ) {
|
||||||
{
|
#else
|
||||||
|
if ( ! isspace( c ) ) {
|
||||||
|
#endif
|
||||||
// put pack the non-space character
|
// put pack the non-space character
|
||||||
in.putback(c);
|
in.putback(c);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user