Tuning output, display information also from stat operation.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 16 Oct 2013 19:02:42 +0000 (21:02 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 16 Oct 2013 19:02:42 +0000 (21:02 +0200)
run.cpp

diff --git a/run.cpp b/run.cpp
index 11a53a0..cfda31a 100644 (file)
--- a/run.cpp
+++ b/run.cpp
@@ -8,6 +8,20 @@
 
 #define DMLITE_DEFAULT_CONF "/etc/dmlite.conf"
 
+
+
+static void outheader() {
+       printf("%6s     %5s     %5s     %5s     %s\n", "Mode", "UID", "GID", "Size", "Name");
+}
+
+
+
+static void outstat(dmlite::ExtendedStat& xStat) {
+       printf("%06o    %5d     %5d     %5zu    %s\n", xStat.stat.st_mode, xStat.stat.st_uid, xStat.stat.st_gid, xStat.stat.st_size, xStat.name.c_str());
+}
+
+
+
 int main(int argc, char *argv[]) {
        dmlite::PluginManager manager;
        std::string conf = DMLITE_DEFAULT_CONF;
@@ -77,6 +91,8 @@ int main(int argc, char *argv[]) {
                        operation = "stat the file";
 
                        xstat = catalog->extendedStat(path);
+                       outheader();
+                       outstat(xstat);
                        std::cout << "Success!" << std::endl;
 
                        break;
@@ -88,12 +104,14 @@ int main(int argc, char *argv[]) {
 
                        operation = "list the directory";
 
+                       path = "/";
+                       if (argc >= 4) path = argv[3];
                        dir = catalog->openDir(path);
 
-                       std::cout << "Content of the directory " << path << std::endl;
-                       printf("        %6s     %5s     %5s     %5s     %s\n", "Mode", "UID", "GID", "Size", "Name");
+                       std::cout << "Content of the directory " << path << ":" << std::endl;
+                       outheader();
                        while ((xstat = catalog->readDirx(dir)) != NULL) {
-                               printf("        %06o    %5d     %5d     %5zu    %s\n", xstat->stat.st_mode, xstat->stat.st_uid, xstat->stat.st_gid, xstat->stat.st_size, xstat->name.c_str());
+                               outstat(*xstat);
                                //std::cout << '\t' << xstat->name << std::endl;
                        }