📄 bspice.c
字号:
/* RCS Info: $Revision: 1.4 $ on $Date: 92/02/05 17:21:27 $ * $Source: //pepper/atesse_spice/spice3/FTE/RCS/bspice.c,v $ * Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group * * The main routine for spice 3 in batch mode (small binary version). */#include "prefix.h"#include "CPdefs.h"#include "FTEdefs.h"#include "FTEparse.h"#include "FTEdata.h"#include "FTEinp.h"#include "FTEdebug.h"#include "IFsim.h"#include "INPdefs.h"#ifndef CMS#include "IFerrmsgs.h"#else /* CMS */#include "IFerrmsg.h"#endif /* CMS */#ifdef UNIX#include <pwd.h>#endif#ifdef IBMPC /* really should be ndef BSD, clear up later */#include <sys/types.h>#include <sys/timeb.h>#endif/* gtri - add - 12/12/90 - wbk - include ipc stuff */#include "IPCtiein.h"/* gtri - end - 12/12/90 */#include "suffix.h"char *errRtn;char *errMsg;/* This is left false in the spice front end. */bool ft_nutmeg = false;char *cp_program;#ifdef UNIXchar *ft_rawfile = "rawspice";#elsechar *ft_rawfile = "rawspice.raw";#endifbool ft_debug = false;bool ft_servermode = false;bool ft_nospiceadd = true;bool ft_listprint = true;bool ft_optsprint = false;bool ft_nodesprint = false;bool ft_acctprint = false;bool ft_nopage = false;bool ft_simdb = false;static char *usage = "Usage: %s [ - ] [ -r rawfile ] [ file ... ]\n";static started = false;IFsimulator *ft_sim;FILE *cp_in, *cp_curin;FILE *cp_out, *cp_curout;FILE *cp_err, *cp_curerr;struct plot *plot_list = NULL;int raw_prec = -1;bool gi_endpause = true;int plot_num = 1;extern int OUTpBeginPlot(), OUTpData(), OUTwBeginPlot(), OUTwReference();extern int OUTwData(), OUTwEnd(), OUTendPlot(), OUTbeginDomain();extern int OUTendDomain(), OUTstopnow(), OUTerror(), OUTattributes();static IFfrontEnd nutmeginfo = { IFnewUid, OUTstopnow, seconds, OUTerror, OUTpBeginPlot, OUTpData, OUTwBeginPlot, OUTwReference, OUTwData, OUTwEnd, OUTendPlot, OUTbeginDomain, OUTendDomain, OUTattributes};/* The main routine for batch spice. */#ifndef OPTCHAR#define OPTCHAR '-'#endif#ifdef IBMPCint _stack = 8000;struct timeb timebegin; /* for use w/ ftime */#endifvoidmain(ac, av) char **av;{ char **tv; bool gotone = false; bool st = false; int tc, i; int err;/* gtri - add - 12/13/90 - wbk - ipc processing data */ char ipc_path[IPC_MAX_PATH_LEN+1]; /* Pathname to use for mailbox */ char ipc_log_file[IPC_MAX_PATH_LEN+1]; /* Pathname to use for logfile */ int ipc_len; /* Length of returned string */ Ipc_Status_t ipc_status; /* Status from IPC calls *//* gtri - end - 12/13/90 */ /* MFB tends to jump to 0 on errors... This will catch it. */ if (started) { fprintf(cp_err, "Internal Error: jump to zero\n"); fatal(); } started = true; cp_curin = cp_in = stdin; cp_curout = cp_out = stdout; cp_curerr = cp_err = stderr; err = SIMinit(&nutmeginfo,&ft_sim); if(err != OK) { ft_sperror(err,"SIMinit"); exit(1); } cp_program = ft_sim->simulator;#ifdef UNIX srandom(getpid());#else srandom(17); /* Yeah... */#endif/* gtri - add - 12/13/90 - wbk - ipc processing */ /* Check to see if we are using IPC */ if(strcmp(av[1],"-ipc") == 0) { /* Mark that IPC is enabled */ g_ipc.enabled = IPC_TRUE; /* Make sure there are at least two args to the -ipc switch */ if(ac < 4) { printf("\nERROR - Too few arguments to -ipc switch\n"); printf("\nUsage - atesse_xspice -ipc <mode> <ipc channel>\n"); exit(1); } /* Get the args and store them */ if(strcmp(av[2],"INTERACTIVE") == 0) g_ipc.mode = IPC_MODE_INTERACTIVE; else if(strcmp(av[2],"BATCH") == 0) g_ipc.mode = IPC_MODE_BATCH; else { printf("\nERROR - Bad mode type as first argument\n"); printf("\nMust be INTERACTIVE or BATCH\n"); exit(1); } if(strlen(av[3]) > IPC_MAX_PATH_LEN) { printf("\nERROR - IPC pathname exceeds %d characters\n",IPC_MAX_PATH_LEN); exit(1); } else strcpy(ipc_path, av[3]); /* Create the IPC transport server */ ipc_status = ipc_initialize_server(ipc_path, g_ipc.mode, IPC_PROTOCOL_V1); if(ipc_status != IPC_STATUS_OK) { printf("\nERROR - Problems initializing IPC server\n"); exit(1); } /* Reopen the stdout and stderr streams so we can ship stuff written */ /* by prinf(), etc. over the mailbox */ if ( ! freopen(IPC_STDERR_FILE_NAME, "w+", stderr)) { printf("\nERROR - Problems reopening stderr for w+\n"); exit(1); } if ( ! freopen(IPC_STDOUT_FILE_NAME, "w+", stdout)) { printf("\nERROR - Problems reopening stdout for w+\n"); exit(1); } /* Call inp_spsource() to read and process the deck */ /* If errors occur, they will be flagged in g_ipc.syntax_error */ inp_spsource(NULL, false, NULL); /* Call ft_dotsaves() to collect the .save cards if any */ ft_dotsaves(); /* Call ft_dorun() to run the analysis. */ ft_dorun("/usr/tmp/rawspice.tmp"); /* Call ft_cktcoms() to print a listing and accounting information */ /* Argument "false" says to print full accounting information */ ft_cktcoms(false); /* Send across everything written to stdout and stderr */ ipc_send_std_files(); /* Send the final status to the client */ ipc_send_end(); /* Close the IPC channel */ ipc_terminate_server(); exit(0); } /* gtri - end - 12/13/90 */ tv = av; tc = ac; /* Pass 1 -- get options. */ while (--tc > 0) { tv++; if (**tv == OPTCHAR) /* Option argument. */ switch ((*tv)[1]) { case 'r': /* The rawfile. */ case 'R': if (tc > 1) { tc--; tv++; ft_rawfile = copy(*tv); **tv = OPTCHAR; /* Hide... */ } else { fprintf(cp_err, usage, cp_program); exit(EXIT_BAD); } break; case 'o': /* Output file. */ case 'O': if (tc > 1) { tc--; tv++; if (!(freopen(*tv, "w", stdout))) { perror(*tv); exit(EXIT_BAD); } **tv = OPTCHAR; /* Hide... */ } else { fprintf(cp_err, usage, av[0]); exit(EXIT_BAD); } break; default: fprintf(cp_err, usage, cp_program); exit(EXIT_BAD); } } /* Pass 2 -- get the filenames. If we are spice, then this means * build a circuit for this file. If this is in server mode, don't * process any of these args. */#ifdef IBMPC ftime(&timebegin); /* time we started */#endif#ifdef CMScp_interactive = false;#endif#ifndef CMS if (!ft_servermode) { FILE *file = NULL, *tp = NULL; char *tempfile = NULL, buf[BSIZE], *mktemp(); for (tv = av + 1, i = 0; *tv; tv++) if (**tv != OPTCHAR) i++; if (i == 1) { for (tv = av + 1, i = 0; *tv; tv++) if (**tv != OPTCHAR) break; file = fopen(*tv, "r"); } else if (i) { tempfile = mktemp("/tmp/spXXXXXX"); if (!(file = fopen(tempfile, "w+"))) { perror(tempfile); exit(EXIT_BAD); } for (tv = av + 1, i = 0; *tv; tv++) if (**tv != OPTCHAR) { if (!(tp = fopen(*tv, "r"))) { perror(tempfile); exit(EXIT_BAD); } while ((i = fread(buf, 1, BSIZE, tp)) > 0) (void) fwrite(buf, i, 1, file); (void) fclose(tp); } (void) fseek(file, (long) 0, 0); } if (file) { inp_spsource(file, false, tempfile ? (char *) NULL : *tv); gotone = true; if (tempfile) (void) unlink(tempfile); } }#endif if (!gotone) inp_spsource(stdin, false, (char *) NULL); ft_nospiceadd = false; /* If we get back here in batch mode then something is * wrong, so exit. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -