From 5bddbd0ca9c20b066563b84d468e3c6ae9e8ff8e Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 27 Apr 1999 15:56:22 +0000 Subject: [PATCH] MacOS portability improvements. Added a class to encapsulate Mac vs. Unix path separator differences. --- Lib/Misc/Makefile.am | 1 + Lib/Misc/fgpath.cxx | 75 +++++++++++++++++++++++++++++++++++++++++++ Lib/Misc/fgpath.hxx | 74 ++++++++++++++++++++++++++++++++++++++++++ Lib/Misc/fgstream.cxx | 18 +++++++---- 4 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 Lib/Misc/fgpath.cxx create mode 100644 Lib/Misc/fgpath.hxx diff --git a/Lib/Misc/Makefile.am b/Lib/Misc/Makefile.am index e35acf4f..8cab48b3 100644 --- a/Lib/Misc/Makefile.am +++ b/Lib/Misc/Makefile.am @@ -3,6 +3,7 @@ noinst_LIBRARIES = libMisc.a libMisc_a_SOURCES = \ + fgpath.cxx fgpath.hxx \ fgstream.cxx fgstream.hxx \ stopwatch.hxx \ strutils.cxx strutils.hxx \ diff --git a/Lib/Misc/fgpath.cxx b/Lib/Misc/fgpath.cxx new file mode 100644 index 00000000..73212818 --- /dev/null +++ b/Lib/Misc/fgpath.cxx @@ -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; + } +} diff --git a/Lib/Misc/fgpath.hxx b/Lib/Misc/fgpath.hxx new file mode 100644 index 00000000..801b4513 --- /dev/null +++ b/Lib/Misc/fgpath.hxx @@ -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 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 + + diff --git a/Lib/Misc/fgstream.cxx b/Lib/Misc/fgstream.cxx index f45d45e3..830154c2 100644 --- a/Lib/Misc/fgstream.cxx +++ b/Lib/Misc/fgstream.cxx @@ -98,18 +98,22 @@ skipeol( istream& in ) while ( in.get(c) && (c != '\n' && c != '\r') ) ; - // \r\n ? + #ifdef __MWERKS // -dw- need to strip line ending! + in >> skipws; + #endif + return in; } istream& -skipws( istream& in ) -{ +skipws( istream& in ) { char c; - while ( in.get(c) ) - { - if ( ! isspace( c ) ) - { + while ( in.get(c) ) { + #ifdef __MWERKS__ // -dw- for unix file compatibility + if ( ! (isspace( c ) ) || c != '\0' || c!='\n' || c != '\r' ) { + #else + if ( ! isspace( c ) ) { + #endif // put pack the non-space character in.putback(c); break; -- 2.39.5