FreeNOS
Public Member Functions | Private Member Functions
ListFiles Class Reference

List files on the filesystem. More...

#include <ListFiles.h>

Inheritance diagram for ListFiles:
POSIXApplication Application

Public Member Functions

 ListFiles (int argc, char **argv)
 Constructor. More...
 
virtual ~ListFiles ()
 Destructor. More...
 
virtual Result exec ()
 Execute the application. More...
 
- Public Member Functions inherited from POSIXApplication
 POSIXApplication (int argc, char **argv)
 Class constructor. More...
 
virtual ~POSIXApplication ()
 Class destructor. More...
 
- Public Member Functions inherited from Application
 Application (int argc, char **argv)
 Class constructor. More...
 
virtual ~Application ()
 Class destructor. More...
 
virtual int run ()
 Run the application. More...
 

Private Member Functions

Result printFiles (const String &path) const
 List files on the filesystem. More...
 
Result printSingleFile (const String &path, String &out) const
 List single file on the filesystem. More...
 

Additional Inherited Members

- Public Types inherited from Application
enum  Result {
  Success, NotFound, IOError, InvalidArgument,
  ShowUsage, TimedOut, OutOfMemory
}
 Result codes. More...
 
- Protected Member Functions inherited from POSIXApplication
virtual Result output (const char *string) const
 Print text to output. More...
 
int runProgram (const char *path, const char **argv)
 Runs an external program. More...
 
- Protected Member Functions inherited from Application
virtual Result initialize ()
 Initialize the application. More...
 
virtual Result output (String &string) const
 Print string to output. More...
 
ArgumentParserparser ()
 Get program arguments parser. More...
 
const ArgumentParserparser () const
 Get constant program arguments parser. More...
 
const ArgumentContainerarguments () const
 Get program arguments. More...
 
void setVersion (const String &version)
 Set program version. More...
 
- Protected Attributes inherited from Application
int m_argc
 Input argument count. More...
 
char ** m_argv
 Input argument values. More...
 

Detailed Description

List files on the filesystem.

Definition at line 31 of file ListFiles.h.

Constructor & Destructor Documentation

◆ ListFiles()

ListFiles::ListFiles ( int  argc,
char **  argv 
)

Constructor.

Parameters
argcArgument count
argvArgument values

Definition at line 30 of file ListFiles.cpp.

References Application::parser(), ArgumentParser::registerFlag(), ArgumentParser::registerPositional(), and ArgumentParser::setDescription().

◆ ~ListFiles()

ListFiles::~ListFiles ( )
virtual

Destructor.

Definition at line 40 of file ListFiles.cpp.

Member Function Documentation

◆ exec()

ListFiles::Result ListFiles::exec ( )
virtual

Execute the application.

Returns
Result code

Implements Application.

Definition at line 44 of file ListFiles.cpp.

References Application::arguments(), Vector< T >::count(), getcwd(), ArgumentContainer::getPositionals(), PATH_MAX, printFiles(), and Application::Success.

◆ printFiles()

ListFiles::Result ListFiles::printFiles ( const String path) const
private

List files on the filesystem.

Parameters
pathPath to the file(s) to list
Returns
Result code

Definition at line 76 of file ListFiles.cpp.

References Application::arguments(), closedir(), dirent::d_name, errno, ERROR, Application::IOError, String::length(), opendir(), PATH_MAX, printSingleFile(), readdir(), S_ISDIR, snprintf(), stat::st_mode, stat(), strerror(), Application::Success, and write().

Referenced by exec().

◆ printSingleFile()

ListFiles::Result ListFiles::printSingleFile ( const String path,
String out 
) const
private

List single file on the filesystem.

Parameters
pathPath to the file to list
outString to write the output to
Returns
Result code

Definition at line 132 of file ListFiles.cpp.

References Application::arguments(), basename(), BLUE, errno, ERROR, ArgumentContainer::get(), GREEN, Application::IOError, String::pad(), S_IRGRP, S_IROTH, S_IRUSR, S_ISBLK, S_ISCHR, S_ISDIR, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR, stat::st_gid, stat::st_mode, stat::st_size, stat::st_uid, stat(), strerror(), Application::Success, WHITE, YELLOW, and ZERO.

Referenced by printFiles().


The documentation for this class was generated from the following files: