X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Foptions.c;h=e0259f0936246e9f5f49a184de9239176eaf57e6;hb=c75794cffb05769b71a346af8513a3e8dde55f94;hp=918f718c0fb79df7a06d2bb19416581b09e42624;hpb=dfd1972f7bcb550a4fc3b05dbe7e71d12334b0a7;p=pspp diff --git a/src/output/options.c b/src/output/options.c index 918f718c0f..e0259f0936 100644 --- a/src/output/options.c +++ b/src/output/options.c @@ -110,7 +110,7 @@ do_parse_boolean (const char *driver_name, const char *key, return false; else { - error (0, 0, _("%s: \"%s\" is \"%s\" but a Boolean value is required"), + error (0, 0, _("%s: `%s' is `%s' but a Boolean value is required"), driver_name, value, key); return -1; } @@ -145,7 +145,7 @@ 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, (char *) NULL) returns 1 if O's + Example: parse_enum (o, "a", 1, "b", 2, NULL) returns 1 if O's value if "a", 2 if O's value is "b". Destroys O. */ @@ -185,7 +185,7 @@ parse_enum (struct driver_option *o, ...) ds_put_format (&choices, "`%s'", s); } - error (0, 0, _("%s: \"%s\" is \"%s\" but one of the following " + error (0, 0, _("%s: `%s' is `%s' but one of the following " "is required: %s"), o->driver_name, o->name, o->value, ds_cstr (&choices)); ds_destroy (&choices); @@ -229,22 +229,22 @@ parse_int (struct driver_option *o, int min_value, int max_value) else if (max_value == INT_MAX) { if (min_value == 0) - error (0, 0, _("%s: \"%s\" is \"%s\" but a nonnegative integer " + error (0, 0, _("%s: `%s' is `%s' but a nonnegative integer " "is required"), o->driver_name, o->name, o->value); else if (min_value == 1) - error (0, 0, _("%s: \"%s\" is \"%s\" but a positive integer is " + error (0, 0, _("%s: `%s' is `%s' but a positive integer is " "required"), o->driver_name, o->name, o->value); else if (min_value == INT_MIN) - error (0, 0, _("%s: \"%s\" is \"%s\" but an integer is required"), + error (0, 0, _("%s: `%s' is `%s' but an integer is required"), o->driver_name, o->name, o->value); else - error (0, 0, _("%s: \"%s\" is \"%s\" but an integer greater " + error (0, 0, _("%s: `%s' is `%s' but an integer greater " "than %d is required"), o->driver_name, o->name, o->value, min_value - 1); } else - error (0, 0, _("%s: \"%s\" is \"%s\" but an integer between %d and " + error (0, 0, _("%s: `%s' is `%s' but an integer between %d and " "%d is required"), o->driver_name, o->name, o->value, min_value, max_value); } @@ -282,30 +282,57 @@ parse_string (struct driver_option *o) return retval; } -/* Parses O's value as a string and returns it as a malloc'd string that the - caller is responsible for freeing. +static char * +default_chart_file_name (const char *file_name) +{ + if (strcmp (file_name, "-")) + { + const char *extension = strrchr (file_name, '.'); + int stem_length = extension ? extension - file_name : strlen (file_name); + return xasprintf ("%.*s-#.png", stem_length, file_name); + } + else + return NULL; +} + +/* Parses and returns a chart file name, or NULL if no charts should be output. + If a nonnull string is returned, it will contain at least one '#' character, + which the client will presumably replace by a number as part of writing + charts to separate files. + + If O->value is "none", then this function returns NULL. - The string must contain at least one '#' character, which the client will - presumably replace by a number as part of writing charts to separate files. + If O->value is non-NULL but not "none", returns a copy of that string (if it + contains '#'). + + If O->value is NULL, then O's default_value should be the name of the main + output file. Returns NULL if default_value is "-", and otherwise returns a + copy of string string with its extension stripped off and "-#.png" appended. Destroys O. */ char * parse_chart_file_name (struct driver_option *o) { - char *value; + char *chart_file_name; - if (o->value != NULL && strchr (o->value, '#') != NULL) - value = xstrdup (o->value); - else + if (o->value != NULL) { - value = xstrdup (o->default_value); - if (o->value != NULL) - error (0, 0, _("%s: \"%s\" is \"%s\" but a file name that contains " - "\"#\" is required."), - o->name, o->value, o->driver_name); + if (!strcmp (o->value, "none")) + chart_file_name = NULL; + else if (strchr (o->value, '#') != NULL) + chart_file_name = xstrdup (o->value); + else + { + error (0, 0, _("%s: `%s' is `%s' but a file name that contains " + "`#' is required."), + o->name, o->value, o->driver_name); + chart_file_name = default_chart_file_name (o->default_value); + } } + else + chart_file_name = default_chart_file_name (o->default_value); driver_option_destroy (o); - return value; + return chart_file_name; }