Add vpi_fopen and vpi_get_file.
This commit is contained in:
parent
3770dda0b8
commit
e3e4e648d7
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#ifdef HAVE_CVS_IDENT
|
||||
#ident "$Id: sys_display.c,v 1.60 2003/05/15 16:51:08 steve Exp $"
|
||||
#ident "$Id: sys_display.c,v 1.61 2003/05/23 04:04:02 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "config.h"
|
||||
|
|
@ -26,9 +26,31 @@
|
|||
# include <assert.h>
|
||||
# include <string.h>
|
||||
# include <ctype.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <math.h>
|
||||
|
||||
#define IS_MCD(mcd) !((mcd)>>31&1)
|
||||
|
||||
/* Printf wrapper to handle both MCD/FD */
|
||||
static PLI_INT32 my_mcd_printf(PLI_UINT32 mcd, const char *fmt, ...)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
if (IS_MCD(mcd)) {
|
||||
r = vpi_mcd_vprintf(mcd, fmt, ap);
|
||||
} else {
|
||||
FILE *fp = vpi_get_file(mcd);
|
||||
if (fp) r = vfprintf(fp, fmt, ap);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
return r;
|
||||
}
|
||||
|
||||
struct timeformat_info_s {
|
||||
int units;
|
||||
unsigned prec;
|
||||
|
|
@ -276,7 +298,7 @@ static void format_time(unsigned mcd, int fsize,
|
|||
}
|
||||
|
||||
|
||||
vpi_mcd_printf(mcd, "%s", bp);
|
||||
my_mcd_printf(mcd, "%s", bp);
|
||||
}
|
||||
|
||||
static void format_time_real(unsigned mcd, int fsize,
|
||||
|
|
@ -291,7 +313,7 @@ static void format_time_real(unsigned mcd, int fsize,
|
|||
|
||||
/* The timeformat_info.prec is the number of digits after the
|
||||
decimal point, no matter what the units. */
|
||||
vpi_mcd_printf(mcd, "%0.*f%s", timeformat_info.prec, value,
|
||||
my_mcd_printf(mcd, "%0.*f%s", timeformat_info.prec, value,
|
||||
timeformat_info.suff);
|
||||
}
|
||||
|
||||
|
|
@ -300,7 +322,7 @@ static void format_strength(unsigned int mcd, s_vpi_value*value)
|
|||
{
|
||||
char str[4];
|
||||
vpip_format_strength(str, value);
|
||||
vpi_mcd_printf(mcd, "%s", str);
|
||||
my_mcd_printf(mcd, "%s", str);
|
||||
}
|
||||
|
||||
static void format_error_msg(const char*msg, int leading_zero,
|
||||
|
|
@ -356,7 +378,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
ffsize = -1;
|
||||
}
|
||||
|
||||
vpi_mcd_printf(mcd, "%%");
|
||||
my_mcd_printf(mcd, "%%");
|
||||
|
||||
use_count = 0;
|
||||
break;
|
||||
|
|
@ -372,7 +394,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
case 'Z':
|
||||
format_error_msg("Unsupported format", leading_zero,
|
||||
fsize, ffsize, fmt);
|
||||
vpi_mcd_printf(mcd, "%c", fmt);
|
||||
my_mcd_printf(mcd, "%c", fmt);
|
||||
|
||||
use_count = 0;
|
||||
break;
|
||||
|
|
@ -380,7 +402,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
default:
|
||||
format_error_msg("Illegal format", leading_zero,
|
||||
fsize, ffsize, fmt);
|
||||
vpi_mcd_printf(mcd, "%c", fmt);
|
||||
my_mcd_printf(mcd, "%c", fmt);
|
||||
break;
|
||||
|
||||
/* Print numeric value in binary/hex/octal format. */
|
||||
|
|
@ -437,7 +459,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
value_str += i;
|
||||
}
|
||||
|
||||
vpi_mcd_printf(mcd, "%*s", fsize, value_str);
|
||||
my_mcd_printf(mcd, "%*s", fsize, value_str);
|
||||
}
|
||||
|
||||
use_count = 1;
|
||||
|
|
@ -467,7 +489,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
return 1;
|
||||
}
|
||||
|
||||
vpi_mcd_printf(mcd, "%c", value.value.str[strlen(value.value.str)-1]);
|
||||
my_mcd_printf(mcd, "%c", value.value.str[strlen(value.value.str)-1]);
|
||||
|
||||
use_count = 1;
|
||||
break;
|
||||
|
|
@ -506,7 +528,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
: vpi_get_dec_size(argv[idx]);
|
||||
}
|
||||
|
||||
vpi_mcd_printf(mcd, "%*s", fsize, value.value.str);
|
||||
my_mcd_printf(mcd, "%*s", fsize, value.value.str);
|
||||
|
||||
use_count = 1;
|
||||
break;
|
||||
|
|
@ -528,7 +550,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
return 1;
|
||||
}
|
||||
|
||||
vpi_mcd_printf(mcd, "%*.*f", fsize, ffsize, value.value.real);
|
||||
my_mcd_printf(mcd, "%*.*f", fsize, ffsize, value.value.real);
|
||||
|
||||
use_count = 1;
|
||||
break;
|
||||
|
|
@ -544,7 +566,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
if (fsize == -1)
|
||||
fsize = 0;
|
||||
assert(scope);
|
||||
vpi_mcd_printf(mcd, "%*s",
|
||||
my_mcd_printf(mcd, "%*s",
|
||||
fsize,
|
||||
vpi_get_str(vpiFullName, scope));
|
||||
break;
|
||||
|
|
@ -568,7 +590,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
}
|
||||
|
||||
if (fsize==-1){
|
||||
vpi_mcd_printf(mcd, "%s", value.value.str);
|
||||
my_mcd_printf(mcd, "%s", value.value.str);
|
||||
|
||||
} else {
|
||||
char* value_str = value.value.str;
|
||||
|
|
@ -592,7 +614,7 @@ static int format_str_char(vpiHandle scope, unsigned int mcd,
|
|||
|
||||
}
|
||||
|
||||
vpi_mcd_printf(mcd, "%*s", fsize, value_str);
|
||||
my_mcd_printf(mcd, "%*s", fsize, value_str);
|
||||
}
|
||||
|
||||
use_count = 1;
|
||||
|
|
@ -686,7 +708,7 @@ static int format_str(vpiHandle scope, unsigned int mcd,
|
|||
cnt = sizeof buf - 1;
|
||||
strncpy(buf, cp, cnt);
|
||||
buf[cnt] = 0;
|
||||
vpi_mcd_printf(mcd, "%s", buf);
|
||||
my_mcd_printf(mcd, "%s", buf);
|
||||
cp += cnt;
|
||||
|
||||
} else if (*cp == '%') {
|
||||
|
|
@ -718,19 +740,19 @@ static int format_str(vpiHandle scope, unsigned int mcd,
|
|||
case 0:
|
||||
break;
|
||||
case 'n':
|
||||
vpi_mcd_printf(mcd, "\n");
|
||||
my_mcd_printf(mcd, "\n");
|
||||
cp += 1;
|
||||
break;
|
||||
case 't':
|
||||
vpi_mcd_printf(mcd, "\t");
|
||||
my_mcd_printf(mcd, "\t");
|
||||
cp += 1;
|
||||
break;
|
||||
case '\\':
|
||||
vpi_mcd_printf(mcd, "\\");
|
||||
my_mcd_printf(mcd, "\\");
|
||||
cp += 1;
|
||||
break;
|
||||
case '"':
|
||||
vpi_mcd_printf(mcd, "\"");
|
||||
my_mcd_printf(mcd, "\"");
|
||||
cp += 1;
|
||||
break;
|
||||
|
||||
|
|
@ -746,19 +768,19 @@ static int format_str(vpiHandle scope, unsigned int mcd,
|
|||
&& isdigit(cp[1])
|
||||
&& isdigit(cp[2])) {
|
||||
/* handle octal escapes (e.g. "\015" is CR)*/
|
||||
vpi_mcd_printf(mcd, "%c",
|
||||
my_mcd_printf(mcd, "%c",
|
||||
(cp[2] - '0') +
|
||||
8 * ((cp[1] - '0') +
|
||||
8 * (cp[0] - '0')));
|
||||
cp += 3;
|
||||
} else {
|
||||
vpi_mcd_printf(mcd, "%c", *cp);
|
||||
my_mcd_printf(mcd, "%c", *cp);
|
||||
cp += 1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
vpi_mcd_printf(mcd, "%c", *cp);
|
||||
my_mcd_printf(mcd, "%c", *cp);
|
||||
cp += 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -779,7 +801,7 @@ static void do_display(unsigned int mcd, struct strobe_cb_info*info)
|
|||
switch (vpi_get(vpiType, item)) {
|
||||
|
||||
case 0:
|
||||
vpi_mcd_printf(mcd, " ");
|
||||
my_mcd_printf(mcd, " ");
|
||||
break;
|
||||
|
||||
case vpiConstant:
|
||||
|
|
@ -793,7 +815,7 @@ static void do_display(unsigned int mcd, struct strobe_cb_info*info)
|
|||
} else {
|
||||
value.format = vpiBinStrVal;
|
||||
vpi_get_value(item, &value);
|
||||
vpi_mcd_printf(mcd, "%s", value.value.str);
|
||||
my_mcd_printf(mcd, "%s", value.value.str);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -807,11 +829,11 @@ static void do_display(unsigned int mcd, struct strobe_cb_info*info)
|
|||
switch(info->default_format){
|
||||
case vpiDecStrVal:
|
||||
size = vpi_get_dec_size(item);
|
||||
vpi_mcd_printf(mcd, "%*s", size, value.value.str);
|
||||
my_mcd_printf(mcd, "%*s", size, value.value.str);
|
||||
break;
|
||||
|
||||
default:
|
||||
vpi_mcd_printf(mcd, "%s", value.value.str);
|
||||
my_mcd_printf(mcd, "%s", value.value.str);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -820,13 +842,13 @@ static void do_display(unsigned int mcd, struct strobe_cb_info*info)
|
|||
case vpiTimeVar:
|
||||
value.format = vpiTimeVal;
|
||||
vpi_get_value(item, &value);
|
||||
vpi_mcd_printf(mcd, "%20u", value.value.time->low);
|
||||
my_mcd_printf(mcd, "%20u", value.value.time->low);
|
||||
break;
|
||||
|
||||
case vpiRealVar:
|
||||
value.format = vpiRealVal;
|
||||
vpi_get_value(item, &value);
|
||||
vpi_mcd_printf(mcd, "%f", value.value.real);
|
||||
my_mcd_printf(mcd, "%f", value.value.real);
|
||||
break;
|
||||
|
||||
case vpiSysFuncCall: {
|
||||
|
|
@ -836,7 +858,7 @@ static void do_display(unsigned int mcd, struct strobe_cb_info*info)
|
|||
if (strcmp(tmp,"$time") == 0) {
|
||||
value.format = vpiTimeVal;
|
||||
vpi_get_value(item, &value);
|
||||
vpi_mcd_printf(mcd, "%20u", value.value.time->low);
|
||||
my_mcd_printf(mcd, "%20u", value.value.time->low);
|
||||
} else if (strcmp(tmp,"$realtime") == 0) {
|
||||
int time_units = vpi_get(vpiTimeUnit, scope);
|
||||
int time_prec = vpi_get(vpiTimePrecision, 0);
|
||||
|
|
@ -846,16 +868,16 @@ static void do_display(unsigned int mcd, struct strobe_cb_info*info)
|
|||
|
||||
value.format = vpiRealVal;
|
||||
vpi_get_value(item, &value);
|
||||
vpi_mcd_printf(mcd, "%0.*f", use_prec,
|
||||
my_mcd_printf(mcd, "%0.*f", use_prec,
|
||||
value.value.real);
|
||||
} else {
|
||||
vpi_mcd_printf(mcd, "<%s>", tmp);
|
||||
my_mcd_printf(mcd, "<%s>", tmp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
vpi_mcd_printf(mcd, "?");
|
||||
my_mcd_printf(mcd, "?");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -902,7 +924,7 @@ static int sys_display_calltf(char *name)
|
|||
do_display(1, info);
|
||||
|
||||
if (strncmp(name,"$display",8) == 0)
|
||||
vpi_mcd_printf(1, "\n");
|
||||
my_mcd_printf(1, "\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1099,8 +1121,8 @@ static int sys_monitoroff_calltf(char*name)
|
|||
*/
|
||||
static int sys_fopen_calltf(char *name)
|
||||
{
|
||||
s_vpi_value val, value, modevalue;
|
||||
unsigned char *mode_string;
|
||||
s_vpi_value value;
|
||||
unsigned char *mode_string = 0;
|
||||
|
||||
vpiHandle call_handle = vpi_handle(vpiSysTfCall, 0);
|
||||
vpiHandle argv = vpi_iterate(vpiArgument, call_handle);
|
||||
|
|
@ -1128,10 +1150,8 @@ static int sys_fopen_calltf(char *name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (mode == 0) {
|
||||
mode_string = "w";
|
||||
} else {
|
||||
if (is_constant(mode)) {
|
||||
if (mode) {
|
||||
if (! is_constant(mode)) {
|
||||
vpi_printf("ERROR: %s parameter must be a constant\n", name);
|
||||
vpi_free_object(argv);
|
||||
return 0;
|
||||
|
|
@ -1142,18 +1162,22 @@ static int sys_fopen_calltf(char *name)
|
|||
vpi_free_object(argv);
|
||||
return 0;
|
||||
}
|
||||
modevalue.format = vpiStringVal;
|
||||
vpi_get_value(mode, &modevalue);
|
||||
mode_string = modevalue.value.str;
|
||||
value.format = vpiStringVal;
|
||||
vpi_get_value(mode, &value);
|
||||
mode_string = strdup(value.value.str);
|
||||
}
|
||||
|
||||
value.format = vpiStringVal;
|
||||
vpi_get_value(item, &value);
|
||||
|
||||
val.format = vpiIntVal;
|
||||
val.value.integer = vpi_mcd_open_x( value.value.str, mode_string );
|
||||
value.format = vpiIntVal;
|
||||
if (mode) {
|
||||
value.value.integer = vpi_fopen(value.value.str, mode_string);
|
||||
free(mode_string);
|
||||
} else
|
||||
value.value.integer = vpi_mcd_open(value.value.str);
|
||||
|
||||
vpi_put_value(call_handle, &val, 0, vpiNoDelay);
|
||||
vpi_put_value(call_handle, &value, 0, vpiNoDelay);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1224,7 +1248,7 @@ static int sys_fdisplay_calltf(char *name)
|
|||
free(info.items);
|
||||
|
||||
if (strncmp(name,"$fdisplay",9) == 0)
|
||||
vpi_mcd_printf(mcd, "\n");
|
||||
my_mcd_printf(mcd, "\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1278,6 +1302,7 @@ static int sys_fputc_calltf(char *name)
|
|||
vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
|
||||
vpiHandle argv = vpi_iterate(vpiArgument, sys);
|
||||
vpiHandle item = vpi_scan(argv);
|
||||
FILE *fp;
|
||||
|
||||
if (item == 0) {
|
||||
vpi_printf("%s: mcd parameter missing.\n", name);
|
||||
|
|
@ -1301,13 +1326,18 @@ static int sys_fputc_calltf(char *name)
|
|||
vpi_get_value(item, &value);
|
||||
mcd = value.value.integer;
|
||||
|
||||
if (IS_MCD(mcd)) return EOF;
|
||||
|
||||
item = vpi_scan(argv);
|
||||
|
||||
xvalue.format = vpiIntVal;
|
||||
vpi_get_value(item, &xvalue);
|
||||
x = xvalue.value.integer;
|
||||
|
||||
return vpi_mcd_fputc( mcd, x );
|
||||
fp = vpi_get_file(mcd);
|
||||
if (!fp) return EOF;
|
||||
|
||||
return fputc(x, fp);
|
||||
}
|
||||
|
||||
static int sys_fgetc_calltf(char *name)
|
||||
|
|
@ -1318,6 +1348,7 @@ static int sys_fgetc_calltf(char *name)
|
|||
vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
|
||||
vpiHandle argv = vpi_iterate(vpiArgument, sys);
|
||||
vpiHandle item = vpi_scan(argv);
|
||||
FILE *fp;
|
||||
|
||||
if (item == 0) {
|
||||
vpi_printf("%s: mcd parameter missing.\n", name);
|
||||
|
|
@ -1342,7 +1373,12 @@ static int sys_fgetc_calltf(char *name)
|
|||
mcd = value.value.integer;
|
||||
|
||||
rval.format = vpiIntVal;
|
||||
rval.value.integer = vpi_mcd_fgetc( mcd );
|
||||
|
||||
fp = vpi_get_file(mcd);
|
||||
if (!fp || IS_MCD(mcd))
|
||||
rval.value.integer = EOF;
|
||||
else
|
||||
rval.value.integer = fgetc(fp);
|
||||
|
||||
vpi_put_value(sys, &rval, 0, vpiNoDelay);
|
||||
|
||||
|
|
@ -1666,6 +1702,9 @@ void sys_display_register()
|
|||
|
||||
/*
|
||||
* $Log: sys_display.c,v $
|
||||
* Revision 1.61 2003/05/23 04:04:02 steve
|
||||
* Add vpi_fopen and vpi_get_file.
|
||||
*
|
||||
* Revision 1.60 2003/05/15 16:51:08 steve
|
||||
* Arrange for mcd id=00_00_00_01 to go to stdout
|
||||
* as well as a user specified log file, set log
|
||||
|
|
|
|||
12
vpi_user.h
12
vpi_user.h
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#ifdef HAVE_CVS_IDENT
|
||||
#ident "$Id: vpi_user.h,v 1.25 2003/05/15 16:51:08 steve Exp $"
|
||||
#ident "$Id: vpi_user.h,v 1.26 2003/05/23 04:04:02 steve Exp $"
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
EXTERN_C_START
|
||||
|
||||
# include <stdarg.h>
|
||||
# include <stdio.h>
|
||||
# include "_pli_types.h"
|
||||
|
||||
typedef struct __vpiHandle *vpiHandle;
|
||||
|
|
@ -232,9 +233,9 @@ extern PLI_INT32 vpi_mcd_vprintf(PLI_UINT32 mcd, const char*fmt, va_list ap);
|
|||
extern PLI_INT32 vpi_flush(void);
|
||||
extern PLI_INT32 vpi_mcd_flush(PLI_UINT32 mcd);
|
||||
|
||||
extern PLI_UINT32 vpi_mcd_open_x(char *name, char *mode);
|
||||
extern PLI_INT32 vpi_mcd_fputc(PLI_UINT32 mcd, unsigned char x);
|
||||
extern PLI_INT32 vpi_mcd_fgetc(PLI_UINT32 mcd);
|
||||
/* proposed extensions */
|
||||
extern PLI_INT32 vpi_fopen(const char*name, const char*mode);
|
||||
extern FILE *vpi_get_file(PLI_INT32 fd);
|
||||
|
||||
/*
|
||||
* support for VPI callback functions.
|
||||
|
|
@ -395,6 +396,9 @@ EXTERN_C_END
|
|||
|
||||
/*
|
||||
* $Log: vpi_user.h,v $
|
||||
* Revision 1.26 2003/05/23 04:04:02 steve
|
||||
* Add vpi_fopen and vpi_get_file.
|
||||
*
|
||||
* Revision 1.25 2003/05/15 16:51:08 steve
|
||||
* Arrange for mcd id=00_00_00_01 to go to stdout
|
||||
* as well as a user specified log file, set log
|
||||
|
|
|
|||
162
vvp/vpi_mcd.cc
162
vvp/vpi_mcd.cc
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#ifdef HAVE_CVS_IDENT
|
||||
#ident "$Id: vpi_mcd.cc,v 1.9 2003/05/15 16:51:09 steve Exp $"
|
||||
#ident "$Id: vpi_mcd.cc,v 1.10 2003/05/23 04:04:02 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "vpi_priv.h"
|
||||
|
|
@ -33,12 +33,21 @@
|
|||
* standard output file, which may be replicated to a logfile
|
||||
* depending on flags to the command line.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MCD/FD manipulation macros
|
||||
*/
|
||||
#define IS_MCD(mcd) !((mcd)>>31&1)
|
||||
#define FD_IDX(fd) ((fd)&~(1U<<31))
|
||||
#define FD_MAX 32
|
||||
|
||||
struct mcd_entry {
|
||||
FILE *fp;
|
||||
char *filename;
|
||||
};
|
||||
static struct mcd_entry mcd_table[31];
|
||||
static struct mcd_entry fd_table[FD_MAX];
|
||||
|
||||
static struct mcd_entry mcd_table[32];
|
||||
static FILE* logfile;
|
||||
|
||||
/* Initialize mcd portion of vpi. Must be called before
|
||||
|
|
@ -47,7 +56,14 @@ static FILE* logfile;
|
|||
void vpi_mcd_init(FILE *log)
|
||||
{
|
||||
mcd_table[0].fp = stdout;
|
||||
mcd_table[0].filename = "<stdout>";
|
||||
mcd_table[0].filename = "stdout";
|
||||
|
||||
fd_table[0].fp = stdin;
|
||||
fd_table[0].filename = "stdin";
|
||||
fd_table[1].fp = stdout;
|
||||
fd_table[1].filename = "stdout";
|
||||
fd_table[2].fp = stderr;
|
||||
fd_table[2].filename = "stderr";
|
||||
|
||||
logfile = log;
|
||||
}
|
||||
|
|
@ -55,38 +71,52 @@ void vpi_mcd_init(FILE *log)
|
|||
/*
|
||||
* close one or more channels. we silently refuse to close the preopened ones.
|
||||
*/
|
||||
extern "C" PLI_UINT32 vpi_mcd_close(unsigned int mcd)
|
||||
extern "C" PLI_UINT32 vpi_mcd_close(PLI_UINT32 mcd)
|
||||
{
|
||||
int i;
|
||||
int rc;
|
||||
rc = 0;
|
||||
for(i = 1; i < 31; i++) {
|
||||
if( ((mcd>>i) & 1) && mcd_table[i].filename) {
|
||||
if(fclose(mcd_table[i].fp) != 0)
|
||||
int rc = 0;
|
||||
|
||||
if (IS_MCD(mcd)) {
|
||||
for(int i = 1; i < 31; i++) {
|
||||
if(((mcd>>i) & 1) && mcd_table[i].fp) {
|
||||
if(fclose(mcd_table[i].fp)) rc |= 1<<i;
|
||||
free(mcd_table[i].filename);
|
||||
mcd_table[i].fp = NULL;
|
||||
mcd_table[i].filename = NULL;
|
||||
} else {
|
||||
rc |= 1<<i;
|
||||
free(mcd_table[i].filename);
|
||||
mcd_table[i].fp = NULL;
|
||||
mcd_table[i].filename = NULL;
|
||||
} else {
|
||||
rc |= 1<<i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unsigned idx = FD_IDX(mcd);
|
||||
if (idx > 2 && idx < FD_MAX && fd_table[idx].fp) {
|
||||
rc = fclose(fd_table[idx].fp);
|
||||
free(fd_table[idx].filename);
|
||||
fd_table[idx].fp = NULL;
|
||||
fd_table[idx].filename = NULL;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
extern "C" char *vpi_mcd_name(unsigned int mcd)
|
||||
extern "C" char *vpi_mcd_name(PLI_UINT32 mcd)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < 31; i++) {
|
||||
if( (mcd>>i) & 1)
|
||||
return mcd_table[i].filename;
|
||||
if (IS_MCD(mcd)) {
|
||||
for(int i = 0; i < 31; i++) {
|
||||
if((mcd>>i) & 1)
|
||||
return mcd_table[i].filename;
|
||||
}
|
||||
} else {
|
||||
unsigned idx = FD_IDX(mcd);
|
||||
if (idx < FD_MAX)
|
||||
return fd_table[idx].filename;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C" PLI_UINT32 vpi_mcd_open_x(char *name, char *mode)
|
||||
extern "C" PLI_UINT32 vpi_mcd_open(char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 31; i++) {
|
||||
if(mcd_table[i].filename == NULL)
|
||||
goto got_entry;
|
||||
|
|
@ -94,45 +124,35 @@ extern "C" PLI_UINT32 vpi_mcd_open_x(char *name, char *mode)
|
|||
return 0; /* too many open mcd's */
|
||||
|
||||
got_entry:
|
||||
mcd_table[i].fp = fopen(name, mode);
|
||||
mcd_table[i].fp = fopen(name, "w");
|
||||
if(mcd_table[i].fp == NULL)
|
||||
return 0;
|
||||
mcd_table[i].filename = strdup(name);
|
||||
return 1<<i;
|
||||
}
|
||||
|
||||
extern "C" PLI_UINT32 vpi_mcd_open(char *name)
|
||||
{
|
||||
return vpi_mcd_open_x(name,"w");
|
||||
}
|
||||
|
||||
extern "C" PLI_INT32
|
||||
vpi_mcd_vprintf(unsigned int mcd, const char*fmt, va_list ap)
|
||||
vpi_mcd_vprintf(PLI_UINT32 mcd, const char*fmt, va_list ap)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
int rc;
|
||||
int rc = 0;
|
||||
|
||||
rc = len = 0;
|
||||
for(i = 0; i < 31; i++) {
|
||||
if( (mcd>>i) & 1) {
|
||||
if (!IS_MCD(mcd)) return 0;
|
||||
|
||||
for(int i = 0; i < 31; i++) {
|
||||
if((mcd>>i) & 1) {
|
||||
if(mcd_table[i].fp) {
|
||||
// echo to logfile
|
||||
if (i == 0 && logfile)
|
||||
vfprintf(logfile, fmt, ap);
|
||||
len = vfprintf(mcd_table[i].fp, fmt, ap);
|
||||
rc = vfprintf(mcd_table[i].fp, fmt, ap);
|
||||
} else
|
||||
rc = EOF;
|
||||
}
|
||||
}
|
||||
|
||||
if(rc)
|
||||
return rc;
|
||||
else
|
||||
return len;
|
||||
return rc;
|
||||
}
|
||||
|
||||
extern "C" PLI_INT32 vpi_mcd_printf(unsigned int mcd, const char *fmt, ...)
|
||||
extern "C" PLI_INT32 vpi_mcd_printf(PLI_UINT32 mcd, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
|
@ -141,42 +161,60 @@ extern "C" PLI_INT32 vpi_mcd_printf(unsigned int mcd, const char *fmt, ...)
|
|||
return r;
|
||||
}
|
||||
|
||||
extern "C" PLI_INT32 vpi_mcd_flush(unsigned int mcd)
|
||||
extern "C" PLI_INT32 vpi_mcd_flush(PLI_UINT32 mcd)
|
||||
{
|
||||
int i, rc = 0;
|
||||
for(i = 0; i < 31; i++) {
|
||||
if( (mcd>>i) & 1)
|
||||
if (fflush(mcd_table[i].fp)) rc |= 1<<i;
|
||||
int rc = 0;
|
||||
|
||||
if (IS_MCD(mcd)) {
|
||||
for(int i = 0; i < 31; i++) {
|
||||
if((mcd>>i) & 1) {
|
||||
if (i == 0 && logfile) fflush(logfile);
|
||||
if (fflush(mcd_table[i].fp)) rc |= 1<<i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unsigned idx = FD_IDX(mcd);
|
||||
if (idx < FD_MAX) rc = fflush(fd_table[idx].fp);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int vpi_mcd_fputc(unsigned int mcd, unsigned char x)
|
||||
/*
|
||||
* MCD/FD Extensions
|
||||
*/
|
||||
extern "C" PLI_INT32 vpi_fopen(const char*name, const char*mode)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 31; i++) {
|
||||
if( (mcd>>i) & 1) {
|
||||
return fputc(x, mcd_table[i].fp);
|
||||
}
|
||||
unsigned i;
|
||||
for(i = 0; i < FD_MAX; i++) {
|
||||
if(fd_table[i].filename == NULL)
|
||||
goto got_entry;
|
||||
}
|
||||
return 0;
|
||||
return 0; /* too many open fd's */
|
||||
|
||||
got_entry:
|
||||
fd_table[i].fp = fopen(name, mode);
|
||||
if(fd_table[i].fp == NULL)
|
||||
return 0;
|
||||
fd_table[i].filename = strdup(name);
|
||||
return ((1U<<31)|i);
|
||||
}
|
||||
|
||||
int vpi_mcd_fgetc(unsigned int mcd)
|
||||
extern "C" FILE *vpi_get_file(PLI_INT32 fd)
|
||||
{
|
||||
int i;
|
||||
// Only deal with FD's
|
||||
if (IS_MCD(fd)) return NULL;
|
||||
|
||||
for(i = 0; i < 31; i++) {
|
||||
if( (mcd>>i) & 1) {
|
||||
return fgetc(mcd_table[i].fp);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
// Only know about FD_MAX indicies
|
||||
if (FD_IDX(fd) >= FD_MAX) return NULL;
|
||||
|
||||
return fd_table[FD_IDX(fd)].fp;
|
||||
}
|
||||
|
||||
/*
|
||||
* $Log: vpi_mcd.cc,v $
|
||||
* Revision 1.10 2003/05/23 04:04:02 steve
|
||||
* Add vpi_fopen and vpi_get_file.
|
||||
*
|
||||
* Revision 1.9 2003/05/15 16:51:09 steve
|
||||
* Arrange for mcd id=00_00_00_01 to go to stdout
|
||||
* as well as a user specified log file, set log
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ EXPORTS
|
|||
|
||||
vpi_chk_error
|
||||
vpi_control
|
||||
vpi_flush
|
||||
vpi_fopen
|
||||
vpi_free_object
|
||||
vpi_get
|
||||
vpi_get_file
|
||||
vpi_get_str
|
||||
vpi_get_time
|
||||
vpi_get_userdata
|
||||
|
|
@ -18,7 +21,6 @@ vpi_mcd_fgetc
|
|||
vpi_mcd_fputc
|
||||
vpi_mcd_name
|
||||
vpi_mcd_open
|
||||
vpi_mcd_open_x
|
||||
vpi_mcd_printf
|
||||
vpi_printf
|
||||
vpi_put_userdata
|
||||
|
|
|
|||
Loading…
Reference in New Issue