driver: New function output_driver_parse_option().
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 26 Nov 2018 00:58:02 +0000 (16:58 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 25 Dec 2018 20:55:09 +0000 (12:55 -0800)
This moves this function out of terminal-opts.c so that other code can use
it too.

src/output/driver.c
src/output/driver.h
src/ui/terminal/terminal-opts.c

index 653aa8d9c30031e86d271ce6d7734738aad9024e..f2d581cfe4558d5e1171b937f7f7ad72eb12bbeb 100644 (file)
@@ -38,6 +38,7 @@
 #include "output/output-item.h"
 #include "output/text-item.h"
 
+#include "gl/error.h"
 #include "gl/xalloc.h"
 #include "gl/xmemdup0.h"
 
@@ -403,3 +404,25 @@ output_driver_create (struct string_map *options)
 
   return driver;
 }
+
+void
+output_driver_parse_option (const char *option, struct string_map *options)
+{
+  const char *equals = strchr (option, '=');
+  if (equals == NULL)
+    {
+      error (0, 0, _("%s: output option missing `='"), option);
+      return;
+    }
+
+  char *key = xmemdup0 (option, equals - option);
+  if (string_map_contains (options, key))
+    {
+      error (0, 0, _("%s: output option specified more than once"), key);
+      free (key);
+      return;
+    }
+
+  char *value = xmemdup0 (equals + 1, strlen (equals + 1));
+  string_map_insert_nocopy (options, key, value);
+}
index bc2b52183f2328f66c62dc80768cf2e9454d21bd..53dfde8b84128dec3c732eb0acab33678b48ef61 100644 (file)
@@ -31,6 +31,8 @@ void output_engine_pop (void);
 void output_submit (struct output_item *);
 void output_flush (void);
 
+void output_driver_parse_option (const char *option,
+                                 struct string_map *options);
 struct output_driver *output_driver_create (struct string_map *options);
 bool output_driver_is_registered (const struct output_driver *);
 
index 4464296498de8674ecdeb208714691efcc443252..cd58f81e94d8a123b7ee8c0511e528dc0fc75ba4 100644 (file)
@@ -112,31 +112,6 @@ register_output_driver (struct terminal_opts *to)
     }
 }
 
-static void
-parse_output_option (struct terminal_opts *to, const char *option)
-{
-  const char *equals;
-  char *key, *value;
-
-  equals = strchr (option, '=');
-  if (equals == NULL)
-    {
-      error (0, 0, _("%s: output option missing `='"), option);
-      return;
-    }
-
-  key = xmemdup0 (option, equals - option);
-  if (string_map_contains (&to->options, key))
-    {
-      error (0, 0, _("%s: output option specified more than once"), key);
-      free (key);
-      return;
-    }
-
-  value = xmemdup0 (equals + 1, strlen (equals + 1));
-  string_map_insert_nocopy (&to->options, key, value);
-}
-
 static char *
 get_supported_formats (void)
 {
@@ -235,7 +210,7 @@ terminal_option_callback (int id, void *to_)
       break;
 
     case OPT_OUTPUT_OPTION:
-      parse_output_option (to, optarg);
+      output_driver_parse_option (optarg, &to->options);
       break;
 
     case OPT_NO_OUTPUT: