Re: #200264 and xmessage
Hilmar Preusse <hille42@web.de> writes:
> Little patch. The default message is that what we want. For any
> reason multi line messages don't work if the message is given at the
> command line with argv[1].
If you pass a string containing `\n', it's 2 characters instead
of the C escape sequence `\n'. Maybe one could pass a multi-line
argument to it ... otherwise you can replace it explicitly:
static char *
normalize_newline(const char *str)
{
int i, k;
for (i = 0, k = 0; str[i] != '\0'; i++, k++) {
/* check for non-escaped `\n' */
if (str[i] == '\\' && str[i + 1] == 'n'
&& (i == 0 || (i > 1 && str[i - 1] != '\\'))) {
str[k] = '\n';
i++;
}
else {
str[k] = str[i];
}
}
}
and then in main:
if (argc < 2) {
fprintf(stderr, "Usage: %s message\n", argv[0]);
}
if ((msg = malloc(strlen(argv[1] + 1))) == NULL) {
fprintf(stderr, "Couldn't allocate space for `%s'!\n", argv[1]);
exit(1);
}
strcpy(msg, argv[1]);
/* replace "\n" in msg (2 chars) by `\n' (one char) */
msg = normalize_newline(msg);
--
Stefan Ulrich
Reply to: