#include <base/Application.h>
#include <base/string/FormatOutputStream.h>
#include <base/filesystem/FolderInfo.h>
#include <base/filesystem/FileInfo.h>
#include <base/filesystem/FileSystem.h>
#include <base/TypeInfo.h>
#include <base/string/StringOutputStream.h>
#include <base/collection/HashTable.h>
#include <base/string/ANSIEscapeSequence.h>
using namespace com::azure::dev::base;
private:
static const unsigned int MAJOR_VERSION = 1;
static const unsigned int MINOR_VERSION = 1;
static const unsigned int MAXIMUM_TRUSTEE_LENGTH = 10;
enum Command {
COMMAND_HELP,
COMMAND_VERSION,
COMMAND_LIST
};
int currentYear = 0;
bool limitTrustees = false;
bool colorize = false;
Command command = COMMAND_HELP;
public:
ListApplication()
{
thisYearFormat = MESSAGE("%b %#d %H:%M");
otherYearFormat = MESSAGE("%b %#d %Y");
limitTrustees = false;
command = COMMAND_LIST;
path = MESSAGE(".");
}
{
(date.
getYear() == currentYear) ? thisYearFormat : otherYearFormat
);
}
void parseArguments()
{
bool pathSpecified = false;
while (enu.hasNext()) {
if (argument == "--help") {
command = COMMAND_HELP;
return;
} else if (argument == "--color") {
colorize = true;
} else if (argument == "--nocolor") {
colorize = false;
} else if (argument == "--limit") {
limitTrustees = true;
} else if (argument == "--nolimit") {
limitTrustees = false;
} else if (argument == "--version") {
command = COMMAND_VERSION;
return;
} else {
if (pathSpecified) {
ferr << "Error: " << "Invalid argument" << ENDL;
setExitCode(EXIT_CODE_ERROR);
return;
}
path = argument;
pathSpecified = true;
}
}
}
void version()
{
fout << getFormalName() << " version "
<< MAJOR_VERSION << '.' << MINOR_VERSION << EOL
<< "The Base Framework (Test Suite)" << EOL
<< ENDL;
}
void help()
{
version();
fout << "Usage: " << getFormalName() << " [options] [path]" << EOL
<< EOL
<< "--help This message." << EOL
<< "--version Dump the version." << EOL
<< EOL
<< "--color Enable colorization of output." << EOL
<< "--nocolor Disable colorization of output." << EOL
<< "--limit Limit trustee fields to fixed size." << EOL
<< "--nolimit Disable fixed trustee fields." << EOL
<< ENDL;
}
void list()
{
ferr << "Error: " << "Not a folder." << ENDL;
setExitCode(EXIT_CODE_ERROR);
return;
}
while (enu.hasNext()) {
const String entry = enu.next();
try {
bool link = false;
bool linkTarget = false;
bool deadLink = false;
try {
link = true;
if (!target) {
target = "<UNKNOWN>";
}
linkTarget = true;
}
if (link && !linkTarget) {
target = MESSAGE("<UNKNOWN>");
}
ferr << entry << ": " << e << ENDL;
}
{
unsigned int mode = info.
getMode();
char flags[10];
flags[0] = (link) ? 'l' : '-';
} else {
}
} else {
}
} else {
}
ownerName = owners[owner];
} else {
try {
const String name = sos << owner;
ownerName = name;
}
owners.
add(owner, ownerName);
}
groupName = groups[group];
} else {
try {
const String name = sos << group;
groupName = name;
}
groups.
add(group, groupName);
}
fout << Sequence<char>(flags, sizeof(flags)) << ' '
<< setWidth(4);
} else {
fout << ' ';
}
if (limitTrustees) {
if (ownerName.
getLength() > MAXIMUM_TRUSTEE_LENGTH) {
ownerName.
getLength() - MAXIMUM_TRUSTEE_LENGTH
);
}
if (groupName.
getLength() > MAXIMUM_TRUSTEE_LENGTH) {
groupName.
getLength() - MAXIMUM_TRUSTEE_LENGTH
);
}
}
fout << ' '
<< setWidth(MAXIMUM_TRUSTEE_LENGTH) << ownerName << ' '
<< setWidth(MAXIMUM_TRUSTEE_LENGTH) << groupName << ' '
<< setWidth(8) << info.
getSize() <<
' '
if (link) {
if (colorize) {
fout << setForeground(COLOR_LINK) << entry << normal();
} else {
fout << entry;
}
fout << " -> ";
if (deadLink && colorize) {
fout << setForeground(COLOR_DEAD_LINK) << target << normal();
fout << setForeground(COLOR_EXECUTABLE) << target << normal();
} else {
fout << target;
}
} else {
fout << setForeground(COLOR_EXECUTABLE) << entry << normal();
} else {
fout << entry;
}
}
fout << EOL;
unsigned int mode = info.
getMode();
char flags[10];
flags[0] = (link) ? 'l' : 'd';
} else {
}
} else {
}
} else {
}
ownerName = owners[owner];
} else {
try {
const String name = sos << owner;
ownerName = name;
}
owners.
add(owner, ownerName);
}
groupName = groups[group];
} else {
try {
const String name = sos << group;
groupName = name;
}
groups.
add(group, groupName);
}
fout << Sequence<char>(flags, sizeof(flags)) << ' '
<< setWidth(4);
} else {
fout << ' ';
}
if (limitTrustees) {
if (ownerName.
getLength() > MAXIMUM_TRUSTEE_LENGTH) {
ownerName.
getLength() - MAXIMUM_TRUSTEE_LENGTH
);
}
if (groupName.
getLength() > MAXIMUM_TRUSTEE_LENGTH) {
groupName.
getLength() - MAXIMUM_TRUSTEE_LENGTH
);
}
}
fout << ' '
<< setWidth(MAXIMUM_TRUSTEE_LENGTH) << ownerName << ' '
<< setWidth(MAXIMUM_TRUSTEE_LENGTH) << groupName << ' '
<< setWidth(8) << ' ' << ' '
if (link) {
if (colorize) {
fout << setForeground(COLOR_LINK) << entry << normal();
} else {
fout << entry;
}
fout << " -> ";
if (deadLink && colorize) {
fout << setForeground(COLOR_DEAD_LINK) << target << normal();
} else if (colorize) {
fout << setForeground(COLOR_FOLDER) << target << normal();
} else {
fout << target;
}
} else {
if (colorize) {
fout << setForeground(COLOR_FOLDER) << entry << normal();
} else {
fout << entry;
}
}
fout << EOL;
} else {
char flags[10];
fill(flags, getArraySize(flags), '-');
flags[0] = (link) ? 'l' : '-';
fout << Sequence<char>(flags, sizeof(flags)) << ' '
<< setWidth(4) << ' ' << ' '
<< setWidth(MAXIMUM_TRUSTEE_LENGTH) << ' ' << ' '
<< setWidth(MAXIMUM_TRUSTEE_LENGTH) << ' ' << ' '
<< setWidth(8) << ' ' << ' '
<< setWidth(12) << ' ' << ' ';
if (link) {
if (colorize) {
fout << setForeground(COLOR_LINK) << entry << normal();
} else {
fout << entry;
}
fout << " -> ";
if (deadLink && colorize) {
fout << setForeground(COLOR_DEAD_LINK) << target << normal();
} else {
fout << target;
}
} else {
fout << entry;
}
fout << EOL;
}
}
fout << FLUSH;
ferr << entry << ": " << e << ENDL;
}
}
}
void main() {
parseArguments();
switch (command) {
case COMMAND_HELP:
help();
break;
case COMMAND_VERSION:
version();
break;
case COMMAND_LIST:
list();
break;
}
}
~ListApplication()
{
}
};
APPLICATION_STUB(ListApplication);