PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
path_completion.cpp File Reference
#include <dirent.h>
#include "path_completion.h"
+ Include dependency graph for path_completion.cpp:

Go to the source code of this file.

Functions

PPath completePathDir (const PPath &pathDir)
 Complete the path directory. More...
 
PPath path_completion_all (const PPath &basePath)
 Return all path/files which match the basePath. More...
 
PPath path_completion_dirOnly (const PPath &basePath)
 Return all directories only which match the basePath. More...
 
PPath prefixPathDir (const PPath &pathDir)
 Complete the path directory with a prefix. More...
 

Function Documentation

◆ completePathDir()

PPath completePathDir ( const PPath pathDir)

Complete the path directory.

Parameters
pathDir: path of the directory
Returns
completed directory

Definition at line 15 of file path_completion.cpp.

15  {
16  if(pathDir == ""){return PString(".");}
17  else if(pathDir[0] == '/'){return pathDir;}
18  else if(pathDir.isSameBegining("./")){return pathDir;}
19  else{return PPath(PString("./") + pathDir);}
20 }
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16
bool isSameBegining(const PString &beginStr) const
Say if the current PString has the same begining of beginStr.
Definition: PString.cpp:306

References PString::isSameBegining().

Referenced by path_completion_all().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ path_completion_all()

PPath path_completion_all ( const PPath basePath)

Return all path/files which match the basePath.

Parameters
basePath: incomming path
Returns
all path/files which match the basePath

Definition at line 37 of file path_completion.cpp.

37  {
38 // std::cerr << "path_completion_all : basePath = '"<<basePath<<"'" << std::endl;
39  if(basePath == ""){return PString("./");}
40  if(basePath.isFileExist()){return PString("");}
41 
42  PPath listMatchingPath("");
43  if(basePath.isDirectoryExist()){
44  PPath completedPathDir(completePathDir(basePath));
45  PPath prefixPath(prefixPathDir(basePath));
46  DIR * dp = opendir(completedPathDir.c_str());
47  dirent * dptr = readdir(dp);
48  while(NULL != dptr){
49  PPath pathName(dptr->d_name);
50  if(pathName != "." && pathName != ".."){
51  listMatchingPath += prefixPath + pathName + PString("\n");
52  }
53  dptr = readdir(dp);
54  }
55  closedir(dp);
56  }else{
57  PPath baseDir(basePath.getParentDirectory()), startNewPath(basePath.getFileName());
58  PPath completedPathDir(completePathDir(baseDir));
59  PPath prefixPath(prefixPathDir(baseDir));
60  DIR * dp = opendir(completedPathDir.c_str());
61 
62  dirent * dptr = readdir(dp);
63  while(NULL != dptr){
64  PPath pathName(dptr->d_name);
65  if(pathName != "." && pathName != ".."){
66  if(pathName.isSameBegining(startNewPath)){
67  listMatchingPath += prefixPath + pathName + PString("\n");
68  }
69  }
70  dptr = readdir(dp);
71  }
72 
73  closedir(dp);
74  }
75 // std::cerr << "path_completion_all : listMatchingPath = '"<<listMatchingPath<<"'" << std::endl;
76  return listMatchingPath;
77 }
PPath getParentDirectory() const
Get path of parent directory of current path.
Definition: PPath.cpp:207
bool isDirectoryExist() const
Say if the current directory path does exist.
Definition: PPath.cpp:151
bool isFileExist() const
Say if the current file path does exist.
Definition: PPath.cpp:139
PPath getFileName() const
Get the name of the file, from last char to /.
Definition: PPath.cpp:172
PPath prefixPathDir(const PPath &pathDir)
Complete the path directory with a prefix.
PPath completePathDir(const PPath &pathDir)
Complete the path directory.

References completePathDir(), PPath::getFileName(), PPath::getParentDirectory(), PPath::isDirectoryExist(), PPath::isFileExist(), PString::isSameBegining(), and prefixPathDir().

Referenced by OptionValue::bashCompletionValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ path_completion_dirOnly()

PPath path_completion_dirOnly ( const PPath basePath)

Return all directories only which match the basePath.

Parameters
basePath: incomming path
Returns
all directories which match the basePath

Definition at line 83 of file path_completion.cpp.

83  {
84  if(basePath == ""){return PString("./");}
85  PPath listMatchingPath("");
86  if(basePath.isDirectoryExist()){
87  DIR * dp = opendir(basePath.c_str());
88  dirent * dptr = readdir(dp);
89  while(NULL != dptr){
90  if(dptr->d_type == DT_DIR){ //We search for directory only
91  PPath pathName(dptr->d_name);
92  if(pathName != "." && pathName != ".."){
93  listMatchingPath += basePath / pathName + PString("\n");
94  }
95  }
96  dptr = readdir(dp);
97  }
98  }else{
99  PPath baseDir(basePath.getParentDirectory()), startNewPath(basePath.getFileName());
100  DIR * dp = opendir(baseDir.c_str());
101 
102  dirent * dptr = readdir(dp);
103  while(NULL != dptr){
104  if(dptr->d_type == DT_DIR){ //We search for directory only
105  PPath pathName(dptr->d_name);
106  if(pathName != "." && pathName != ".."){
107  if(pathName.isSameBegining(startNewPath)){
108  listMatchingPath += baseDir / pathName + PString("\n");
109  }
110  }
111  }
112  dptr = readdir(dp);
113  }
114 
115  closedir(dp);
116  }
117  return listMatchingPath;
118 }

References PPath::getFileName(), PPath::getParentDirectory(), PPath::isDirectoryExist(), and PString::isSameBegining().

Referenced by OptionValue::bashCompletionValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prefixPathDir()

PPath prefixPathDir ( const PPath pathDir)

Complete the path directory with a prefix.

Parameters
pathDir: path of the directory
Returns
completed directory

Definition at line 26 of file path_completion.cpp.

26  {
27  if(pathDir == ""){return pathDir;}
28  else if(pathDir[pathDir.size() - 1lu] == '/'){return pathDir;}
29  else if(pathDir[pathDir.size() - 1lu] != '/'){return PPath(pathDir + PString("/"));}
30  else{return pathDir;}
31 }

Referenced by path_completion_all().

+ Here is the caller graph for this function: