⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 spice中支持多层次元件模型仿真的可单独运行的插件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********Copyright 1990 Regents of the University of California.  All rights reserved.Author: 1985 Wayne A. Christopher**********//* * The main routine for cider. */#include "spice.h"#include "misc.h"#include "ifsim.h"#include "inpdefs.h"#include "iferrmsg.h"#include "cpdefs.h"#include "ftedefs.h"#include "ftedev.h"#include "ftedebug.h"#include "const.h"#include <setjmp.h>#include <sys/types.h>#ifdef HAS_GETPW#include <pwd.h>#endif#ifdef HAS_UNIX_SIGS#include <signal.h>#endif#ifndef HAS_BSDRUSAGE#ifdef HAS_FTIME#include <sys/timeb.h>#endif#endif#include "patchlev.h"#include "suffix.h"/* (Virtual) Machine architecture parameters */int ARCHme;int ARCHsize;int Patch_Level = PATCHLEVEL;char *ft_rawfile = "rawspice.raw";char *errRtn;char *errMsg;char *cp_program;bool ft_servermode = false;bool ft_intrpt = false;     /* Set by the (void) signal handlers. */bool ft_setflag = false;    /* Don't abort after an interrupt. */struct variable *(*if_getparam)( );#ifdef BATCHDISPDEVICE device[ ] = {	{"", 0, 0, 0, 0, 0, 0,		0, 0, 0, 0,		0, 0, 0, 0,		0, 0, 0, 0,		0, 0, 0, 0 }	};DISPDEVICE *dispdev = device;bool ft_nopage = false;bool ft_nomod = false;bool ft_parsedb = false;bool ft_evdb = false;bool ft_vecdb = false;bool ft_grdb = false;bool ft_gidb = false;bool ft_controldb = false;bool ft_asyncdb = false;bool ft_debug = false;bool ft_batchmode = true;bool ft_nospiceadd = true;bool ft_simdb = false;static char *usage = "Usage: %s [ - ] [ -r rawfile ] [ file ... ]\n";FILE *cp_curin = 0;FILE *cp_curout = 0;FILE *cp_curerr = 0;FILE *cp_in = 0;FILE *cp_out = 0;FILE *cp_err = 0;bool gi_endpause = true;bool ft_listprint = true;bool ft_optsprint = false;bool ft_nodesprint = false;bool ft_acctprint = false;#  ifndef SPICE2struct plot *plot_list = NULL;/* int raw_prec = -1; */int plot_num = 1;#  endif#elsebool ft_batchmode = false;jmp_buf jbuf;static char *usage = "Usage: %s [-] [-b] [-i] [-s] [-n] [-o outfile] [-r rawfile]\n\\t[-t term] [file ...]\n";struct options *exitoption;struct options *helpoption;#endifstatic started = false;IFsimulator *ft_sim = 0;#ifdef MSDOS/* XXX Can this be moved elsewhere? */int _stack = 8000;#endif#ifndef HAS_BSDRUSAGE#ifdef HAS_FTIMEextern struct timeb timebegin;		/* for use w/ ftime */#endif#endifextern IFsimulator SIMinfo;#ifdef SIMULATORbool ft_nutmeg = false;#ifndef BATCHextern struct comm spcp_coms[ ];struct comm *cp_coms = spcp_coms;#endifextern int OUTpBeginPlot(), OUTpData(), OUTwBeginPlot(), OUTwReference();extern int OUTwData(), OUTwEnd(), OUTendPlot(), OUTbeginDomain();extern int OUTendDomain(), OUTstopnow(), OUTerror(), OUTattributes();static IFfrontEnd nutmeginfo = {    IFnewUid,    IFdelUid,    OUTstopnow,    seconds,    OUTerror,    OUTpBeginPlot,    OUTpData,    OUTwBeginPlot,    OUTwReference,    OUTwData,    OUTwEnd,    OUTendPlot,    OUTbeginDomain,    OUTendDomain,    OUTattributes};#elsebool ft_nutmeg = true;extern struct comm nutcp_coms[ ];struct comm *cp_coms = nutcp_coms;static IFfrontEnd nutmeginfo;/* XXX *//* ARGSUSED */ int if_run(t, w, s, b) char *t, *w, *b; wordlist *s;        { return (0); }/* ARGSUSED */ int if_sens_run(t, w, s, b) char *t, *w, *b; wordlist *s;        { return (0); }/* ARGSUSED */ void if_dump(ckt, fp) char *ckt; FILE *fp; { }/* ARGSUSED */ char * if_inpdeck(deck, tab) struct line *deck; char **tab;        { return ((char *) 0); }/* ARGSUSED */ int if_option(ckt, name, type, value) char *name, *ckt, *value;        int type; { }/* ARGSUSED */ void if_cktfree(ckt, tab) char *ckt, *tab; { }/* ARGSUSED */ void if_setndnames(line) char *line; { }/* ARGSUSED */ char * if_errstring(code) { return ("spice error"); }/* ARGSUSED */ void if_setparam(ckt, name, param, val)         char *ckt, *name, *param;  struct variable *val; { }/* ARGSUSED */boolif_tranparams(ckt, start, stop, step) struct circ *ckt;        double *start, *stop, *step;{ return (false); }/* ARGSUSED */ struct variable *if_getstat(n, c) char *n, *c; { return (NULL);}#endifchar *hlp_filelist[] = { "spice", 0 };voidmain(ac, av)    char **av;{    char	**tv;    int		tc, i;    int		err;    long	debug_flag = false;    bool	gotone = false;    char	*p;    char	*cmd_line_term = 0, term_1stch;    int		error2;#ifdef BATCH    bool	st = false;#else#ifdef HAS_GETPW    struct passwd *pw;#endif    char	buf[BSIZE_SP];    bool	readinit = true, rflag = false, ciprefix();    bool	istty = true, iflag = false, qflag = false;    bool	gdata = true;    FILE	*fp;    FILE	*circuit_file;#endif    /* MFB tends to jump to 0 on errors.  This tends to catch it. */    if (started) {        fprintf(cp_err, "main: Internal Error: jump to zero\n");        shutdown(EXIT_BAD);    }    started = true;#ifdef PARALLEL_ARCH    PBEGIN_(ac, av);    ARCHme = NODEID_();    ARCHsize = NNODES_();    SETDBG_(&debug_flag);    fprintf( stderr, "On-line: process %d of %d total.\n", ARCHme, ARCHsize );    evlog(EVKEY_ENABLE, EVKEY_EVENT, "On-line", EVKEY_DUMP, EVKEY_DISABLE,	    EVKEY_LAST_ARG);#else    ARCHme = 0;    ARCHsize = 1;#endif /* PARALLEL_ARCH */#ifdef HAS_MAC_ARGCARGV    ac = initmac(&av);#endif    ivars( );    cp_in = stdin;    cp_out = stdout;    cp_err = stderr;    circuit_file = stdin;#ifdef BATCH    cp_curin = stdin;    cp_curout = stdout;    cp_curerr = stderr;#else#ifdef MALLOCTRACE    mallocTraceInit("malloc.out");#endif#ifdef HAS_ISATTY    istty = (bool) isatty(fileno(stdin));#endif#endif /* ~ BATCH */    init_time( );    err = SIMinit(&nutmeginfo,&ft_sim);    if(err != OK) {        ft_sperror(err,"SIMinit");        shutdown(EXIT_BAD);    }    cp_program = ft_sim->simulator;#ifdef HAS_GETPID    srandom(getpid());#else    srandom(17);#endif#ifdef PARALLEL_ARCH#ifdef NOTDEF    tv = av;    tc = ac;    /* Print Arguments. */    fprintf( stderr, "\nArgs:\n" );    while (--tc > 0) {        tv++;	fprintf( stderr, "\t%s\n", *tv );    }#endif /* NOTDEF */    /* Skip processor group file. */ /* XXX What if it's not first? */    ac--; av++;#endif /* PARALLEL_ARCH */    tv = av;    tc = ac;    /* Pass 1 -- get options. */    while (--tc > 0) {        tv++;        if (**tv == Spice_OptChar)    /* Option argument. */            switch ((*tv)[1]) {#ifndef BATCH	    case '\0':  /* No raw file. */                gdata = false;                break;	    case 'b':   /* Batch mode. */	    case 'B':                ft_batchmode = true;                break;	    case 's':   /* Server mode. */	    case 'S':                ft_servermode = true;                break;	    case 'i':   /* Interactive mode. */	    case 'I':                iflag = true;                break;	    case 'q':   /* No command completion. */	    case 'Q':                qflag = true;                break;	    case 'n':   /* Don't read .spiceinit. */	    case 'N':                readinit = false;                break;	    case 't':   /* Terminal type. */	    case 'T':                if (tc > 1) {                    tc--;                    tv++;		    cmd_line_term = *tv;		    term_1stch = **tv;                    **tv = Spice_OptChar;                } else {                    fprintf(cp_err, usage,                         cp_program);                    shutdown(EXIT_BAD);                }                break;	    case 'r':   /* The rawfile. */	    case 'R':                if (tc > 1) {                    tc--;                    tv++;		    sprintf( buf, "%s", *tv );		    cp_vset("rawfile", VT_STRING, buf);                    **tv = Spice_OptChar;                }                rflag = true;                break;#else /* if BATCH */	    case 'r':   /* The rawfile. */	    case 'R':                if (tc > 1) {                    tc--;                    tv++;		    sprintf( buf, "%s", *tv );		    ft_rawfile = copy(buf);                    **tv = Spice_OptChar;                } else {		    fprintf(cp_err, usage, cp_program);		    shutdown(EXIT_BAD);		}                break;#endif	    case 'o':   /* Output file. */	    case 'O':                if (tc > 1) {                    tc--;                    tv++;#ifdef PARALLEL_ARCH		    sprintf( buf, "%s%03d", *tv, ARCHme );#else		    sprintf( buf, "%s%", *tv );#endif /* PARALLEL_ARCH */		    if (!(freopen(buf, "w", stdout))) {                        perror(buf);                        shutdown(EXIT_BAD);                    }                    **tv = Spice_OptChar;                } else {                    fprintf(cp_err, usage, av[0]);                    shutdown(EXIT_BAD);                }                break;	    case 'c':   /* Circuit file. */	    case 'C':                if (tc > 1) {                    tc--;                    tv++;		    if (!(circuit_file = fopen(*tv, "r"))) {			perror(*tv);			shutdown(EXIT_BAD);		    }		    istty = false;                    **tv = Spice_OptChar;                } else {                    fprintf(cp_err, usage, av[0]);                    shutdown(EXIT_BAD);                }                break;#ifdef PARALLEL_ARCH	    case 'm':   /* '-master' option from "parallel". */                if (tc > 6) {		    for (i =0; i < 6; i++) {		      tc--;		      tv++;		      **tv = Spice_OptChar;		    }                } else {                    fprintf(cp_err, usage,                         cp_program);                    shutdown(EXIT_BAD);                }                break;#endif /* PARALLEL_ARCH */	    default:                fprintf(cp_err, "Error: bad option %s\n", *tv);                fprintf(cp_err, usage, cp_program);                shutdown(EXIT_BAD);            }    }#ifdef SIMULATOR    if_getparam = spif_getparam;#else    if_getparam = nutif_getparam;#endif#ifndef BATCH    if ((!iflag && !istty) || ft_servermode)        ft_batchmode = true;    if ((iflag && !istty) || qflag)        cp_nocc = true;    if (ft_servermode)        readinit = false;    if (!istty || ft_batchmode)        out_moremode = false;    /* Would like to do this later, but cpinit evals commands */    init_rlimits( );    /* Have to initialize cp now. */    ft_cpinit();    /* To catch interrupts during .spiceinit... */    if (setjmp(jbuf) == 1) {        fprintf(cp_err, "Warning: error executing .spiceinit.\n");        if (!ft_batchmode)            goto bot;    }#  ifdef HAS_UNIX_SIGS    /* Set up (void) signal handling */    if (!ft_batchmode) {        (void) signal(SIGINT, ft_sigintr);        (void) signal(SIGFPE, sigfloat);#    ifdef SIGTSTP        (void) signal(SIGTSTP, sigstop);#    endif    }    /* Set up (void) signal handling for fatal errors. */    (void) signal(SIGILL, sigill);#    ifdef SIGBUS    (void) signal(SIGBUS, sigbus);#    endif#    ifdef SIGSEGV    (void) signal(SIGSEGV, sigsegv);#    endif#    ifdef SIGSYS    (void) signal(SIGSYS, sig_sys);#    endif#  endif /* UNIX_SIGS */#  ifdef HAS_GETPW    if (readinit) {        /* Try to source either .spiceinit or ~/.spiceinit. */        if (access(".spiceinit", 0) == 0)            inp_source(".spiceinit");        else {            pw = getpwuid(getuid());            (void) strcpy(buf, pw->pw_dir);            (void) strcat(buf, "/.spiceinit");            if (access(buf, 0) == 0)                inp_source(buf);        }    }#  else /* ~ HAS_GETPW */    /* Try to source the file "spice.rc" in the current directory.  */    if (readinit) {        if ((fp = fopen("spice.rc", "r")) != NULL) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -