Convert a single % at the end of a format string to %%.

If there is a single % at the end of a format string then automatically
convert this to %% so that we get a single % in the output.
This commit is contained in:
Cary R 2011-04-19 15:31:45 -07:00 committed by Stephen Williams
parent 4006bb2336
commit 54ed0832db
1 changed files with 4 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999-2010 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2011 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -172,7 +172,7 @@ static char * format_as_string(int ljust, int plus, int ld_zero, int width,
size += sprintf(&buf[size], "%d", width);
if (prec != -1)
size += sprintf(&buf[size], ".%d", prec);
buf[size++] = fmt;
if (fmt) buf[size++] = fmt;
/* The same goes here ">"! */
buf[size++] = '>';
buf[size] = '\0';
@ -277,6 +277,7 @@ static unsigned int get_format_char(char **rtn, int ljust, int plus,
switch (fmt) {
case '%':
case '\0':
if (ljust != 0 || plus != 0 || ld_zero != 0 || width != -1 ||
prec != -1) {
vpi_printf("WARNING: %s:%d: invalid format %s%s.\n",
@ -845,7 +846,7 @@ static unsigned int get_format(char **rtn, char *fmt,
memcpy(*rtn+size-1, result, cnt);
free(result);
size += cnt;
cp += 1;
if (*cp) cp += 1;
}
}
*(*rtn+size-1) = '\0';