[beast: 2/9] BSE: move file crawling test from bseinfo to "bsetool crawl"



commit 13f7e4249883a45b7221d15e0ba9ddf0b2b8597c
Author: Tim Janik <timj gnu org>
Date:   Thu Sep 17 17:33:45 2015 +0200

    BSE: move file crawling test from bseinfo to "bsetool crawl"

 bse/bseinfo.cc |   13 -------------
 bse/bsetool.cc |   43 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 15 deletions(-)
---
diff --git a/bse/bseinfo.cc b/bse/bseinfo.cc
index 4f775ae..ce62101 100644
--- a/bse/bseinfo.cc
+++ b/bse/bseinfo.cc
@@ -87,18 +87,5 @@ main (int   argc,
        g_free (name);
       }
 
-  if (argc == 2)
-    {
-      SfiRing *ring;
-      g_print ("search path: \"%s\"\n", argv[1]);
-      // plist = bse_search_path_list_files (argv[1], NULL);
-      ring = sfi_file_crawler_list_files (argv[1], NULL, GFileTest (0));
-      while (ring)
-        {
-          char *name = (char*) sfi_ring_pop_head (&ring);
-          g_print ("%s\n", name);
-        }
-    }
-
   return 0;
 }
diff --git a/bse/bsetool.cc b/bse/bsetool.cc
index cc349aa..70429a7 100644
--- a/bse/bsetool.cc
+++ b/bse/bsetool.cc
@@ -116,6 +116,27 @@ ArgParser::parse_args (const uint argc, char *const argv[])
   return ""; // success
 }
 
+// == crawl ==
+static ArgDescription crawl_options[] = {
+  { "<glob>",   "",     "Glob pattern to list matching files", "" },
+};
+
+static String
+crawl (const ArgParser &ap)
+{
+  const String glob = ap["glob"];
+  // plist = bse_search_path_list_files (argv[1], NULL);
+  SfiRing *ring = sfi_file_crawler_list_files (glob.c_str(), NULL, GFileTest (0));
+  while (ring)
+    {
+      const char *name = (const char*) sfi_ring_pop_head (&ring);
+      printout ("%s\n", name);
+    }
+  sfi_ring_free_deep (ring, g_free);
+  return "";
+}
+
+
 // == render2wav ==
 static ArgDescription render2wav_options[] = {
   { "-s, --seconds", "<seconds>", "Number of seconds to record", "0" },
@@ -181,9 +202,10 @@ static ArgDescription bsetool_options[] = {
 };
 
 int
-main (int argc, char *argv[])
+main (int argc_int, char *argv[])
 {
-  bse_init_inprocess (&argc, argv, "bsetool"); // Bse::cstrings_to_vector (NULL)
+  bse_init_inprocess (&argc_int, argv, "bsetool"); // Bse::cstrings_to_vector (NULL)
+  const unsigned int argc = argc_int;
   // now that the BSE thread runs, drop scheduling priorities if we have any
   setpriority (PRIO_PROCESS, getpid(), 0);
   // pre-command option argument parsing
@@ -240,6 +262,23 @@ main (int argc, char *argv[])
         }
       return 0; // success
     }
+  else if (option_argc < argc && argv[option_argc] == String ("crawl"))
+    {
+      ArgParser ap (crawl_options);
+      String error = ap.parse_args (argc - option_argc - 1, argv + option_argc + 1);
+      if (!error.empty())
+        {
+          printerr ("%s: crawl: %s\n", argv[0], error);
+          return 127;
+        }
+      error = crawl (ap);
+      if (!error.empty())
+        {
+          printerr ("crawl: %s\n", error);
+          return 127;
+        }
+      return 0; // success
+    }
   else
     {
       printerr ("%s: %s\n", argv[0], "missing command");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]