1#ifndef ROSE_FileUtility_H
2#define ROSE_FileUtility_H
4#include "commandline_processing.h"
6#include <Rose/StringUtility.h>
13namespace StringUtility {
46 : str(str), filename(filename), line(line) {}
48 ROSE_UTIL_API std::string toString()
const;
64ROSE_UTIL_API
void writeFile(
const std::string& outputString,
const std::string& fileNameString,
65 const std::string& directoryName);
73ROSE_UTIL_API std::string
readFile(
const std::string& fileName);
89ROSE_UTIL_API
void homeDir(std::string& dir);
143ROSE_UTIL_API std::list<std::string>
findfile(std::string patternString, std::string pathString)
144 SAWYER_DEPRECATED(
"use Rose::FileSystem functions instead");
150enum FileNameLocation {
151 FILENAME_LOCATION_UNKNOWN,
152 FILENAME_LOCATION_USER,
153 FILENAME_LOCATION_LIBRARY,
154 FILENAME_LOCATION_NOT_EXIST
157static const std::string FILENAME_LIBRARY_UNKNOWN =
"Unknown";
158static const std::string FILENAME_LIBRARY_USER =
"User";
159static const std::string FILENAME_LIBRARY_C =
"C";
160static const std::string FILENAME_LIBRARY_STDCXX =
"C++";
161static const std::string FILENAME_LIBRARY_STL =
"STL";
162static const std::string FILENAME_LIBRARY_LINUX =
"Linux";
163static const std::string FILENAME_LIBRARY_GCC =
"GCC";
164static const std::string FILENAME_LIBRARY_BOOST =
"Boost";
165static const std::string FILENAME_LIBRARY_ROSE =
"Rose";
168typedef std::string FileNameLibrary;
173 FileNameLocation location;
176 FileNameLibrary library;
181 : location(loc), library(lib), distance(dist) {}
184 : location(FILENAME_LOCATION_UNKNOWN), library(
"Unknown"), distance(0) {}
187 FileNameLocation getLocation()
const {
192 FileNameLibrary getLibrary()
const {
205 int getDistanceFromSourceDirectory()
const {
209 bool isUserCode()
const {
210 return location == FILENAME_LOCATION_USER;
213 bool isLibraryCode()
const {
214 return location == FILENAME_LOCATION_LIBRARY;
218 std::string getLibraryName()
const {
242 const std::map<std::string, std::string>& libPathCollection);
249 const std::map<std::string, std::string>& libPathCollection,
281bool popen_wrapper(
const std::string &command, std::vector<std::string> &result);
304 a.insert(a.end(), b.begin(), b.end());
331 if (!f.empty() && f.back().filename ==
"") {
340 f << std::string(str);
351ROSE_UTIL_API std::string
copyEdit(
const std::string& inputString,
const std::string & oldToken,
const std::string & newToken);
353 const std::string& newToken);
ROSE_UTIL_API const std::string stripDotsFromHeaderFileName(const std::string &name)
Remove leading dots.
ROSE_UTIL_API std::string fileNameSuffix(const std::string &fileName)
Get the file name suffix (extension) without the leading dot.
ROSE_UTIL_API std::string stripFileSuffixFromFileName(const std::string &fileNameWithSuffix)
Get the file name without the ".suffix".
ROSE_UTIL_API int directoryDistance(const std::string &left, const std::string &right)
Edit distance between two directory names.
ROSE_UTIL_API std::string getPathFromFileName(const std::string &fileNameWithPath)
Returns all but the last component of a path in a filesystem.
std::ostream & operator<<(std::ostream &os, const StringWithLineNumber &s)
Prints a StringWithLineNumber.
ROSE_UTIL_API std::string copyEdit(const std::string &inputString, const std::string &oldToken, const std::string &newToken)
Replace all occurrences of a string with another string.
ROSE_UTIL_API void homeDir(std::string &dir)
Name of the home directory.
ROSE_UTIL_API std::string readFile(const std::string &fileName)
Reads entire text file.
ROSE_UTIL_API std::list< std::string > findfile(std::string patternString, std::string pathString) __attribute__((deprecated))
Find file names non-recursively.
FileWithLineNumbers operator+(const FileWithLineNumbers &a, const FileWithLineNumbers &b)
Concatenate vectors of strings with source location.
ROSE_UTIL_API void writeFile(const std::string &outputString, const std::string &fileNameString, const std::string &directoryName)
Create a file.
ROSE_UTIL_API std::vector< std::string > readWordsInFile(std::string filename)
Reads words from a file.
ROSE_UTIL_API std::string toString(const FileWithLineNumbers &strings, const std::string &filename="<unknown>", int line=1)
Generate C preprocessor #line directives.
ROSE_UTIL_API OSType getOSType()
Obtain operating system type information.
bool popen_wrapper(const std::string &command, std::vector< std::string > &result)
Simple wrapper for Unix popen command.
ROSE_UTIL_API std::string stripPathFromFileName(const std::string &fileNameWithPath)
Returns the last component of a path in a filesystem.
FileWithLineNumbers & operator+=(FileWithLineNumbers &a, const FileWithLineNumbers &b)
Append strings with source location information to vector of such.
std::vector< StringWithLineNumber > FileWithLineNumbers
A vector of strings with line numbers and file names.
ROSE_UTIL_API FileWithLineNumbers readFileWithPos(const std::string &fileName)
Reads an entire text file.
ROSE_UTIL_API FileNameClassification classifyFileName(const std::string &fileName, const std::string &appPath)
Determine whether a file is source code or system library.
ROSE_UTIL_API std::string getAbsolutePathFromRelativePath(const std::string &relativePath, bool printErrorIfAny=false)
Get the absolute path from the relative path.
String with source location information.