/* * Copyright (c) 2000 Stephen G. Tell * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU * General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) #ident "$Id: vpi_mcd.c,v 1.1 2000/05/07 18:20:08 steve Exp $" #endif # include "vpi_priv.h" # include # include # include # include # include struct mcd_entry { FILE *fp; char *filename; }; static struct mcd_entry mcd_table[32]; /* Initialize mcd portion of vpi. Must be called before * any vpi_mcd routines can be used. */ void vpi_mcd_init() { mcd_table[0].fp = stdout; mcd_table[0].filename = ""; mcd_table[1].fp = stderr; mcd_table[1].filename = ""; mcd_table[2].fp = stdout; /* TODO: initialize this to log file */ mcd_table[2].filename = ""; } /* * close one or more channels. we silently refuse to close the preopened ones. */ unsigned int vpi_mcd_close(unsigned int mcd) { int i; int rc; rc = 0; for(i = 3; i < 31; i++) { if( ((mcd>>i) & 1) && mcd_table[i].filename) { if(fclose(mcd_table[i].fp) != 0) rc |= 1<>i) & 1) return mcd_table[i].filename; } return NULL; } unsigned int vpi_mcd_open(char *name) { int i; for(i = 0; i < 31; i++) { if(mcd_table[i].filename == NULL) goto got_entry; } return 0; /* too many open mcd's */ got_entry: mcd_table[i].fp = fopen(name, "w"); if(mcd_table[i].fp == NULL) return 0; mcd_table[i].filename = strdup(name); return 1<>i) & 1) { if(mcd_table[i].fp) len = vfprintf(mcd_table[i].fp, fmt, ap); else rc = EOF; } } va_end(ap); if(rc) return rc; else return len; }