expandtilde.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 // expandtilde.cpp Expand tilde (~) in filenames.
40 
41 #include <iostream>
42 #include <fstream>
43 #include "expandtilde.hpp"
44 #include "StringUtils.hpp"
45 
46 using namespace std;
47 using namespace gnsstk;
48 
49 namespace gnsstk
50 {
51 void expand_filename(string& filename)
52 {
53 #ifndef _WIN32
54  static char *chome = getenv("HOME");
55  static string home = string(chome);
56 
57  // assume tilde occurs only once
58  string::size_type pos = filename.find_first_of("~");
59  if(pos == string::npos) return;
60  string newname;
61  if(pos > 0) newname = filename.substr(0,pos);
62  filename = filename.substr(pos+1);
63  StringUtils::stripLeading(filename,"/");
65  newname += home + string("/") + filename;
66  filename = newname;
67 #endif
68 }
69 
70 void expand_filename(vector<string>& sarray)
71 {
72  for(size_t i=0; i<sarray.size(); i++) expand_filename(sarray[i]);
73 }
74 
75 void include_path(string path, string& file)
76 {
77  if(!path.empty()) {
79  StringUtils::stripTrailing(path,"\\");
80  file = path + string("/") + file;
81  }
82 }
83 
84 void include_path(string path, vector<string>& sarray)
85 {
86  if(!path.empty()) {
88  StringUtils::stripTrailing(path,"\\");
89  for(size_t i=0; i<sarray.size(); i++)
90  sarray[i] = path + string("/") + sarray[i];
91  }
92 }
93 
94 // return false if file cannot be opened
95 bool expand_list_file(string& filename, vector<string>& values)
96 {
97  string line,word;
98  // DO NOT clear values, add to it
99 
100  // open list file
101  ifstream infile;
102  infile.open(filename.c_str());
103  if(!infile.is_open()) return false;
104 
105  // read the list file
106  while(1) {
107  getline(infile,line);
108  StringUtils::stripTrailing(line,'\r');
110  while(!line.empty()) {
112  if(word.substr(0,1) == "#") break; // skip '#...' to end of line
113  values.push_back(word);
114  }
115  if(infile.eof() || !infile.good()) break;
116  }
117 
118  infile.close();
119 
120  return true;
121 }
122 }
getenv
char * getenv()
expandtilde.hpp
gnsstk::expand_filename
void expand_filename(vector< string > &sarray)
Definition: expandtilde.cpp:70
file
page HOWTO subpage DoxygenGuide Documenting Your Code page DoxygenGuide Documenting Your Code todo Flesh out this document section doctips Tips for Documenting When defining make sure that the prototype is identical between the cpp and hpp file
Definition: DOCUMENTING.dox:9
gnsstk::StringUtils::word
std::string word(const std::string &s, const std::string::size_type wordNum=0, const char delimiter=' ')
Definition: StringUtils.hpp:1112
StringUtils.hpp
gnsstk::expand_list_file
bool expand_list_file(string &filename, vector< string > &values)
Definition: expandtilde.cpp:95
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::StringUtils::stripLeading
std::string & stripLeading(std::string &s, const std::string &aString, std::string::size_type num=std::string::npos)
Definition: StringUtils.hpp:1426
gnsstk::StringUtils::stripTrailing
std::string & stripTrailing(std::string &s, const std::string &aString, std::string::size_type num=std::string::npos)
Definition: StringUtils.hpp:1453
gnsstk::StringUtils::stripFirstWord
std::string stripFirstWord(std::string &s, const char delimiter=' ')
Definition: StringUtils.hpp:2253
example4.pos
pos
Definition: example4.py:125
gnsstk::include_path
void include_path(string path, vector< string > &sarray)
Definition: expandtilde.cpp:84
std
Definition: Angle.hpp:142


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39