output: Add null sentinel automatically to parse_enum() arguments.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 8 Feb 2023 19:27:05 +0000 (11:27 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 8 Feb 2023 19:27:58 +0000 (11:27 -0800)
src/output/ascii.c
src/output/driver.c
src/output/options.c
src/output/options.h

index 692f7f4d421bbfae5f64bc44bfb5c12e015a21a7..d581675fe37d99bf7f63cfb6d2332b9c0b5b1b3e 100644 (file)
@@ -386,8 +386,7 @@ ascii_create (struct file_handle *fh, enum settings_output_devices device_type,
                              ? "unicode" : "ascii");
   enum { BOX_ASCII, BOX_UNICODE } box = parse_enum (opt (o, "box", default_box),
                                                     "ascii", BOX_ASCII,
-                                                    "unicode", BOX_UNICODE,
-                                                    NULL_SENTINEL);
+                                                    "unicode", BOX_UNICODE);
 
   static const struct render_ops ascii_render_ops = {
     .draw_line = ascii_draw_line,
index ba2d54f9f5060f055a96be78ba517ef3d7913cb7..6df9057a7da36cd975ec70ea2e970ea3af9b7d24 100644 (file)
@@ -563,7 +563,6 @@ output_driver_create (struct string_map *options)
   if (file_name == NULL)
     file_name = xstrdup (f->default_file_name);
 
-  /* XXX should use parse_enum(). */
   enum settings_output_devices default_type = default_device_type (file_name);
   const char *default_type_string = (default_type == SETTINGS_DEVICE_TERMINAL
                                 ? "terminal" : "listing");
index c05ea746c04d199e6f936d60ef5107af9fffdb5a..227b132aa0d34932abeaba0b85250a7784b21688 100644 (file)
@@ -107,10 +107,10 @@ parse_boolean (struct driver_option o)
    O has no user-specified value, then O's default value is treated the same
    way.  If the default value still does not match, parse_enum() returns 0.
 
-   Example: parse_enum (o, "a", 1, "b", 2, NULL_SENTINEL) returns 1 if O's
-   value if "a", 2 if O's value is "b". */
+   Example: parse_enum (o, "a", 1, "b", 2) returns 1 if O's value if "a", 2 if
+   O's value is "b". */
 int
-parse_enum (struct driver_option o, ...)
+(parse_enum) (struct driver_option o, ...)
 {
   va_list args;
   va_start (args, o);
index 2c0fc5c13f674e8cc1885805185d0b901d1f1379..e8e675f8bc2b928dbad740625a02ada3a9cd3d73 100644 (file)
@@ -49,7 +49,10 @@ struct driver_option driver_option_get (struct driver_options *,
 
 void parse_paper_size (struct driver_option, int *h, int *v);
 bool parse_boolean (struct driver_option);
+
 int parse_enum (struct driver_option, ...) SENTINEL(0);
+#define parse_enum(...) parse_enum(__VA_ARGS__, NULL_SENTINEL)
+
 int parse_int (struct driver_option, int min_value, int max_value);
 int parse_dimension (struct driver_option);
 char *parse_string (struct driver_option);