dirtree fixed up nice
authorChris Koeritz <fred@gruntose.com>
Tue, 16 Oct 2018 00:05:23 +0000 (20:05 -0400)
committerChris Koeritz <fred@gruntose.com>
Tue, 16 Oct 2018 00:05:23 +0000 (20:05 -0400)
now uses the current directory as the path if no path is provided.
added a --help flag if it comes as first parameter.
improved help instructions.
zapped extra blank line that was making pattern based listings look bad.

graphiq/.settings/language.settings.xml
nucleus/.settings/language.settings.xml
nucleus/applications/utilities/dirtree.cpp

index c65707132bef1bf5100bd3a1de9635bd548ff6a5..0fb11ecebc3e46ea2531b1859a565a6e775f504f 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1260941817250426252" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1260495321477850252" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 0d6789c9ee51dd01c2b794f92408b64a00a1c6ef..c031c3c427f0a2a98a3719a4ea1d6e030689ba51 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1260941817250426252" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1260495321477850252" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 80156b38db24c375206c93119245bcb5d400dbfa..fe139dea8087fc339371ca4c7a21adf837c9f38d 100644 (file)
@@ -38,10 +38,20 @@ public:
   int execute();
   int print_instructions_and_exit() {
     LOG(a_sprintf("\
-%s: This utility requires a directory name on the command line.\n\
-The subdirectories under that directory will be shown.  If a second paramter\n\
-is provided, it is taken as a pattern that will be used to show the files in\n\
-those directories also.  Otherwise, just the tree of directories is shown.\n\
+%s: This utility shows the sub-directory structure for a chosen directory.\n\
+It expects a directory name to be provided on the command line.  If no\n\
+directory is provided, then the current directory is assumed.  The sub-\n\
+directories under the chosen directory will be displayed on the console in a\n\
+stylized textual tree.  If a second parameter is provided, it is taken as a\n\
+file pattern that causes matching files to be displayed.  Without a pattern,\n\
+just the directory tree is shown.\n\
+For example:\n\
+  dirtree\n\
+    => shows the directory structure of the current directory.\n\
+  dirtree udon\n\
+    => shows the structure of directory 'udon'\n\
+  dirtree soba \"*.txt\"\n\
+    => displays all text files and sub-directories of 'soba'\n\
 ", filename(application::_global_argv[0]).basename().raw().s()));
     return 23;
   }
@@ -58,20 +68,30 @@ astring hier_prefix(int depth, int kids)
 int dirtree::execute()
 {
   astring path;
-
  
-  if (application::_global_argc < 2) {
-    return print_instructions_and_exit();
-  }
-
-  path = application::_global_argv[1];
+//hmmm: we really need an abstraction to do some checking if they want --help;
+//      this comparison way of doing it is lame.
+astring helpword = astring("--help");
+
+  if (application::_global_argc <= 1) {
+    // plug in our default path if they gave us no parameters.
+       path = ".";
+       } else {
+               // they gave us some parameters.  but are they asking for help?
+               if (helpword == astring(application::_global_argv[1])) {
+                       return print_instructions_and_exit();
+               } else {
+                       // this seems like a serious path request.
+                       path = application::_global_argv[1];
+               }
+       }
 
   // check if we should show any of the files.
   bool show_files = false;
   astring pattern;
-  if (application::_global_argc >= 3)
+  if (application::_global_argc >= 3) {
     pattern = application::_global_argv[2];
+  }
   if (pattern.t()) {
     show_files = true;
   }
@@ -83,7 +103,7 @@ int dirtree::execute()
   if (!dir.good()) {
     continuable_error(class_name(), "tree construction",
         "the directory could not be read");
-    return 82;
+    return print_instructions_and_exit();
   }
 
   dir_tree_iterator *ted = dir.start(directory_tree::prefix);
@@ -99,8 +119,9 @@ int dirtree::execute()
     directory_tree::depth(*ted, depth);
     directory_tree::children(*ted, kids); 
     astring name_to_log = curr.basename().raw();
-    if (!depth)
+    if (!depth) {
       name_to_log = curr.raw();
+    }
     LOG(hier_prefix(depth, kids) + name_to_log);
     if (show_files) {
       astring names;
@@ -108,6 +129,10 @@ int dirtree::execute()
       if (names.length()) {
         astring split;
         string_manipulation::split_lines(names, split, depth * 2 + 2);
+        // strip eol chars off the string we got back, since we already add that in log.
+        while (parser_bits::is_eol(split[split.end()])) {
+               split.zap(split.end(), split.end());
+        }
         LOG(split);
       }
     }