PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
path_completion.h File Reference
#include "PPath.h"
+ Include dependency graph for path_completion.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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...
 

Function Documentation

◆ 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 }
Path of a directory or a file.
Definition: PPath.h:17
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
Extends the std::string.
Definition: PString.h:16
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: