Merge pull request #527 from jsquyres/topic/ompi-info-parsable-value-quoting
ompi_info: quote parsable values if they contain colons
Этот коммит содержится в:
Коммит
58c9a45d91
@ -2124,7 +2124,12 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ
|
|||||||
full_name);
|
full_name);
|
||||||
|
|
||||||
/* Output the value */
|
/* Output the value */
|
||||||
asprintf(out[0] + line++, "%svalue:%s", tmp, value_string);
|
char *colon = strchr(value_string, ':');
|
||||||
|
if (NULL != colon) {
|
||||||
|
asprintf(out[0] + line++, "%svalue:\"%s\"", tmp, value_string);
|
||||||
|
} else {
|
||||||
|
asprintf(out[0] + line++, "%svalue:%s", tmp, value_string);
|
||||||
|
}
|
||||||
|
|
||||||
/* Output the source */
|
/* Output the source */
|
||||||
asprintf(out[0] + line++, "%ssource:%s", tmp, source_string);
|
asprintf(out[0] + line++, "%ssource:%s", tmp, source_string);
|
||||||
|
@ -760,6 +760,43 @@ void opal_info_do_hostname()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *escape_quotes(const char *value)
|
||||||
|
{
|
||||||
|
const char *src;
|
||||||
|
int num_quotes = 0;
|
||||||
|
for (src = value; src != NULL && *src != '\0'; ++src) {
|
||||||
|
if ('"' == *src) {
|
||||||
|
++num_quotes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are no quotes in the string, there's nothing to do
|
||||||
|
if (0 == num_quotes) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have quotes, make a new string. Copy over the old
|
||||||
|
// string, escaping the quotes along the way. This is simple and
|
||||||
|
// clear to read; it's not particularly efficient (performance is
|
||||||
|
// definitely not important here).
|
||||||
|
char *quoted_value;
|
||||||
|
quoted_value = calloc(1, strlen(value) + num_quotes + 1);
|
||||||
|
if (NULL == quoted_value) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *dest;
|
||||||
|
for (src = value, dest = quoted_value; *src != '\0'; ++src, ++dest) {
|
||||||
|
if ('"' == *src) {
|
||||||
|
*dest++ = '\\';
|
||||||
|
}
|
||||||
|
*dest = *src;
|
||||||
|
}
|
||||||
|
|
||||||
|
return quoted_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private variables - set some reasonable screen size defaults
|
* Private variables - set some reasonable screen size defaults
|
||||||
*/
|
*/
|
||||||
@ -886,7 +923,23 @@ void opal_info_out(const char *pretty_message, const char *plain_message, const
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (NULL != plain_message && 0 < strlen(plain_message)) {
|
if (NULL != plain_message && 0 < strlen(plain_message)) {
|
||||||
printf("%s:%s\n", plain_message, value);
|
// Escape any double quotes in the value.
|
||||||
|
char *quoted_value;
|
||||||
|
quoted_value = escape_quotes(value);
|
||||||
|
if (NULL != quoted_value) {
|
||||||
|
value = quoted_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *colon = strchr(value, ':');
|
||||||
|
if (NULL != colon) {
|
||||||
|
printf("%s:\"%s\"\n", plain_message, value);
|
||||||
|
} else {
|
||||||
|
printf("%s:%s\n", plain_message, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != quoted_value) {
|
||||||
|
free(quoted_value);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("%s\n", value);
|
printf("%s\n", value);
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user