Add the %c format, and some warning messages.
This commit is contained in:
parent
4d3611c5f1
commit
6535b48c1c
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT) && !defined(macintosh)
|
#if !defined(WINNT) && !defined(macintosh)
|
||||||
#ident "$Id: sys_display.c,v 1.31 2001/11/02 05:56:47 steve Exp $"
|
#ident "$Id: sys_display.c,v 1.32 2002/01/11 04:48:01 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
@ -70,6 +70,7 @@ static int format_str(vpiHandle scope, unsigned int mcd,
|
||||||
s_vpi_value value;
|
s_vpi_value value;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
char*cp = fmt;
|
char*cp = fmt;
|
||||||
|
char format_char = ' ';
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
assert(fmt);
|
assert(fmt);
|
||||||
|
|
@ -88,7 +89,7 @@ static int format_str(vpiHandle scope, unsigned int mcd,
|
||||||
|
|
||||||
} else if (*cp == '%') {
|
} else if (*cp == '%') {
|
||||||
int fsize = -1, ffsize = -1;
|
int fsize = -1, ffsize = -1;
|
||||||
int do_num = 0;
|
int do_arg = 0;
|
||||||
|
|
||||||
cp += 1;
|
cp += 1;
|
||||||
if (isdigit(*cp))
|
if (isdigit(*cp))
|
||||||
|
|
@ -100,61 +101,95 @@ static int format_str(vpiHandle scope, unsigned int mcd,
|
||||||
switch (*cp) {
|
switch (*cp) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'B':
|
case 'B':
|
||||||
do_num = 1;
|
format_char = 'b';
|
||||||
|
do_arg = 1;
|
||||||
value.format = vpiBinStrVal;
|
value.format = vpiBinStrVal;
|
||||||
cp += 1;
|
cp += 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'D':
|
case 'D':
|
||||||
do_num = 1;
|
format_char = 'd';
|
||||||
|
do_arg = 1;
|
||||||
value.format = vpiDecStrVal;
|
value.format = vpiDecStrVal;
|
||||||
cp += 1;
|
cp += 1;
|
||||||
break;
|
break;
|
||||||
#if 0
|
|
||||||
case 'f':
|
|
||||||
do_num = 1;
|
|
||||||
value.format = vpiDecStrVal;
|
|
||||||
cp += 1;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case 'h':
|
case 'h':
|
||||||
case 'H':
|
case 'H':
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'X':
|
case 'X':
|
||||||
do_num = 1;
|
format_char = 'h';
|
||||||
|
do_arg = 1;
|
||||||
value.format = vpiHexStrVal;
|
value.format = vpiHexStrVal;
|
||||||
cp += 1;
|
cp += 1;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
|
||||||
assert(scope);
|
case 'c':
|
||||||
vpi_mcd_printf(mcd, "%s", vpi_get_str(vpiFullName, scope));
|
case 'C':
|
||||||
cp += 1;
|
format_char = 'c';
|
||||||
break;
|
do_arg = 1;
|
||||||
case 'o':
|
|
||||||
case 'O':
|
|
||||||
do_num = 1;
|
|
||||||
value.format = vpiOctStrVal;
|
|
||||||
cp += 1;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
case 'S':
|
|
||||||
do_num = 1;
|
|
||||||
value.format = vpiStringVal;
|
value.format = vpiStringVal;
|
||||||
cp += 1;
|
cp += 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'm':
|
||||||
|
case 'M':
|
||||||
|
assert(scope);
|
||||||
|
vpi_mcd_printf(mcd, "%s",
|
||||||
|
vpi_get_str(vpiFullName, scope));
|
||||||
|
cp += 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'o':
|
||||||
|
case 'O':
|
||||||
|
format_char = 'o';
|
||||||
|
do_arg = 1;
|
||||||
|
value.format = vpiOctStrVal;
|
||||||
|
cp += 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
case 'S':
|
||||||
|
format_char = 's';
|
||||||
|
do_arg = 1;
|
||||||
|
value.format = vpiStringVal;
|
||||||
|
cp += 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
case 'T':
|
case 'T':
|
||||||
do_num = 1;
|
format_char = 't';
|
||||||
|
do_arg = 1;
|
||||||
value.format = vpiDecStrVal;
|
value.format = vpiDecStrVal;
|
||||||
cp += 1;
|
cp += 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '%':
|
case '%':
|
||||||
|
if (fsize != -1 && ffsize != -1) {
|
||||||
|
vpi_printf("\nERROR: Illegal format \"%s\"\n", fmt);
|
||||||
|
fsize = -1;
|
||||||
|
ffsize = -1;
|
||||||
|
}
|
||||||
vpi_mcd_printf(mcd, "%%");
|
vpi_mcd_printf(mcd, "%%");
|
||||||
cp += 1;
|
cp += 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'v':
|
||||||
|
case 'V':
|
||||||
|
case 'e':
|
||||||
|
case 'f':
|
||||||
|
case 'g':
|
||||||
|
vpi_printf("\nERROR: Unsupported format \"%s\"\n", fmt);
|
||||||
|
vpi_mcd_printf(mcd, "%c", *cp);
|
||||||
|
cp += 1;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
vpi_printf("\nERROR: Illegal format \"%s\"\n", fmt);
|
||||||
vpi_mcd_printf(mcd, "%c", *cp);
|
vpi_mcd_printf(mcd, "%c", *cp);
|
||||||
cp += 1;
|
cp += 1;
|
||||||
break;
|
break;
|
||||||
|
|
@ -163,17 +198,26 @@ static int format_str(vpiHandle scope, unsigned int mcd,
|
||||||
/* If we encountered a numeric format string, then
|
/* If we encountered a numeric format string, then
|
||||||
grab the number value from the next parameter
|
grab the number value from the next parameter
|
||||||
and display it in the requested format. */
|
and display it in the requested format. */
|
||||||
if (do_num) {
|
if (do_arg) {
|
||||||
if (idx >= argc) {
|
if (idx >= argc) {
|
||||||
vpi_printf("\ntoo few arguments for format %s\n",
|
vpi_printf("\ntoo few arguments for format %s\n",
|
||||||
fmt);
|
fmt);
|
||||||
} else {
|
} else {
|
||||||
vpi_get_value(argv[idx++], &value);
|
vpi_get_value(argv[idx++], &value);
|
||||||
if (fsize>0)
|
|
||||||
vpi_mcd_printf(mcd, "%*s",
|
switch(format_char){
|
||||||
fsize, value.value.str);
|
case 'c':
|
||||||
else
|
vpi_mcd_printf(mcd, "%c", value.value.str[strlen(value.value.str)-1]);
|
||||||
vpi_mcd_printf(mcd, "%s", value.value.str);
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (fsize > 0)
|
||||||
|
vpi_mcd_printf(mcd, "%*s", fsize,
|
||||||
|
value.value.str);
|
||||||
|
else
|
||||||
|
vpi_mcd_printf(mcd, "%s",
|
||||||
|
value.value.str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -758,6 +802,9 @@ void sys_display_register()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: sys_display.c,v $
|
* $Log: sys_display.c,v $
|
||||||
|
* Revision 1.32 2002/01/11 04:48:01 steve
|
||||||
|
* Add the %c format, and some warning messages.
|
||||||
|
*
|
||||||
* Revision 1.31 2001/11/02 05:56:47 steve
|
* Revision 1.31 2001/11/02 05:56:47 steve
|
||||||
* initialize scope for %m in $fdisplay.
|
* initialize scope for %m in $fdisplay.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue