home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-28 | 56.4 KB | 1,999 lines |
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!haven.umd.edu!darwin.sura.net!ukma!cs.widener.edu!dsinc!ub!galileo.cc.rochester.edu!ee.rochester.edu!rbc!al
- From: al@rbc.uucp (Al Davis)
- Newsgroups: alt.sources
- Subject: ACS circuit simulator part 16/20
- Message-ID: <1993Jan27.040952.11870@rbc.uucp>
- Date: 27 Jan 93 04:09:52 GMT
- Sender: al@rbc.uucp (Al Davis)
- Organization: Huh?
- Lines: 1988
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # src/help.c
- # src/inorder.c
- # src/insert.c
- # src/ipow.c
- # src/isfloat.c
- # src/isterm.c
- # src/itos.c
- # src/line.c
- # src/list.c
- # src/main.c
- # src/match.c
- # src/modify.c
- # src/network.c
- # src/nodes.c
- # src/nodeset.c
- # src/options.c
- # src/outset.c
- # src/outtext.c
- # This archive created: Tue Jan 26 22:51:06 1993
- export PATH; PATH=/bin:$PATH
- if test -f 'src/help.c'
- then
- echo shar: will not over-write existing file "'src/help.c'"
- else
- cat << \SHAR_EOF > 'src/help.c'
- /* help 10/08/91
- * Copyright 1983-1992 Albert Davis
- * Accesses a help file to provide on-line documentation.
- * Will follow the executables path to find it.
- */
- #include "ecah.h"
- #include "error.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_help(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern const char e_int[];
- /*--------------------------------------------------------------------------*/
- void cmd_help(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- static FILE *hfn;
- char buffer[BUFLEN];
- char *name;
-
- if (hfn)
- (void)fclose(hfn);
- name = findfile(HELPFILE, HELPPATH, R_OK);
- if (!name)
- error(bERROR, "Help not available\n");
- hfn = fopen(name, "r");
- if (!hfn)
- error(bERROR, e_int, "help");
- if (cmd[*cnt])
- do {
- if (!fgets(buffer, BUFLEN, hfn)) {
- error(bWARNING, "No help on %s\n", &cmd[*cnt]);
- break;
- }
- } while (buffer[0]!=':' || !pmatch(cmd,cnt,&buffer[1]));
-
- for (;;) {
- if (!fgets(buffer,BUFLEN,hfn))
- break;
- if (buffer[0]==':')
- break;
- mputs(buffer,io.mstderr);
- }
- (void)fclose(hfn);
- hfn = (FILE*)NULL;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/inorder.c'
- then
- echo shar: will not over-write existing file "'src/inorder.c'"
- else
- cat << \SHAR_EOF > 'src/inorder.c'
- /* inorder 03/02/84-2
- * Copyright 1983-1992 Albert Davis
- * 3 way test
- * returns true if the middle argument is between the outer 2
- * else false
- * uses "double" args
- */
-
- int inorder(arg1,arg2,arg3)
- double arg1,arg2,arg3;
- {
- return ( (arg1<=arg2 && arg2<=arg3) || (arg1>=arg2 && arg2>=arg3) );
- }
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/insert.c'
- then
- echo shar: will not over-write existing file "'src/insert.c'"
- else
- cat << \SHAR_EOF > 'src/insert.c'
- /* insert 12/29/92
- * Copyright 1983-1992 Albert Davis
- * insert command
- * insert new nodes
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "mode.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_insert(const char*, int*);
- /*--------------------------------------------------------------------------*/
- extern const struct status stats;
- /*--------------------------------------------------------------------------*/
- void cmd_insert(cmd,cnt)
- const char *cmd; /* pointer to command buffer */
- int *cnt; /* pointer to position counter */
- {
- int nod; /* first node number to insert */
- int ncnt; /* how many nodes to insert */
- branch_t *brh; /* branch pointer, for loop */
- branch_t *stop; /* stop loop */
-
- dealloc(YES);
- nod = ctoi(cmd,cnt); /* get args.. */
- if (nod <= 0)
- error(bERROR, "insert which node?\n");
- if (nod > stats.total_nodes)
- error(bERROR, "%u nodes\n", stats.total_nodes);
-
- ncnt = ctoi(cmd,cnt);
- if (ncnt <= 0)
- ncnt = 1;
-
- stop = brh = firstbranch_dev();
- do {
- int ii;
- for (ii = 0; brh->n[ii].e != INVALIDNODE; ii++){
- if (brh->n[ii].e >= nod) /* move them up */
- brh->n[ii].e += ncnt;
- }
- } while (brh = nextbranch_dev(brh), brh != stop);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/ipow.c'
- then
- echo shar: will not over-write existing file "'src/ipow.c'"
- else
- cat << \SHAR_EOF > 'src/ipow.c'
- /* ipow 04/02/92
- * Copyright 1983-1992 Albert Davis
- * like pow() (std function) but y rounded to integer
- * done by repeated multiplication
- * returns zero if x
- */ /* z = pow(x,y) */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- double ipow(double,int);
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- double ipow(x,y)
- double x;
- int y;
- {
- struct exception z;
-
- if (y < 0){
- if (x != 0.){
- x = 1/x;
- y = -y;
- }else{
- errno = EDOM;
- z.type = DOMAIN;
- z.name = "ipow";
- z.arg1 = x;
- z.arg2 = (double)y;
- z.retval = HUGE;
- if (!matherr(&z)){
- fputs("ipow: DOMAIN error\n",stderr);
- errno = EDOM;
- }
- return z.retval;
- }
- }
-
- for ( z.retval=1.; y>0; y-- )
- z.retval *= x;
-
- return z.retval;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/isfloat.c'
- then
- echo shar: will not over-write existing file "'src/isfloat.c'"
- else
- cat << \SHAR_EOF > 'src/isfloat.c'
- /* isfloat 03/13/84-3 04/10/90
- * Copyright 1983-1992 Albert Davis
- * return 1 if any character that a floating number string can start with
- */
- #include "ecah.h"
- #include "declare.h"
-
- int isfloat(chr)
- int chr;
- {
- return ( isdigit(chr) || chr=='.' || chr=='-' || chr=='+' );
- }
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/isterm.c'
- then
- echo shar: will not over-write existing file "'src/isterm.c'"
- else
- cat << \SHAR_EOF > 'src/isterm.c'
- /* isterm 12/06/90
- * Copyright 1983-1992 Albert Davis
- * return 1 if terminator (space, comma, =, or null)
- * else 0
- */
- #include "ecah.h"
- #include "declare.h"
-
- int isterm(chr)
- int chr;
- {
- return (chr=='\0' || isspace(chr) || strchr(",=()[]",chr));
- }
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/itos.c'
- then
- echo shar: will not over-write existing file "'src/itos.c'"
- else
- cat << \SHAR_EOF > 'src/itos.c'
- /* itos 04/02/92
- * Copyright 1983-1992 Albert Davis
- * Integer to string (signed).
- * num = number to convert.
- * str = string to put it in. Must be big enough, or else!!
- * Must have length at least len+1.
- * len = number of significant digits.
- * If minus, left justify, else right.
- * fmt = format : 0 = normal : sign if minus.
- * FMTSIGN = always sign.
- */
- #include "ecah.h"
- #include "formats.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- char *itos(int,char*,int,int);
- /*--------------------------------------------------------------------------*/
- char *itos( num, str, len, fmt )
- int num, len, fmt;
- char *str;
- {
- int ii;
- char sign;
-
- if (num < 0){
- sign = '-';
- num = -num;
- }else if (fmt & FMTSIGN){
- sign = '+';
- }else{
- sign = ' ';
- }
-
- (void)utos( (unsigned)num, &str[1], len );
- for ( ii=1; str[ii]==' '; ++ii )
- ;
- str[ii-1] = sign;
- return str;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/line.c'
- then
- echo shar: will not over-write existing file "'src/line.c'"
- else
- cat << \SHAR_EOF > 'src/line.c'
- /* line 04/02/92
- * from C-Ware, and modified to be user installable?
- */
- #include "ecah.h"
- #include "pixelh.h"
- #include "declare.h"
- /*LINTLIBRARY*/
- /*--------------------------------------------------------------------------*/
- void initgraph(struct graph *);
- void stext(int,int,const char*,int);
- void setpixel(int,int,int);
- void box(int,int,int,int,int);
- void line(int,int,int,int,int);
- static void badpixel(int,int,int);
- static void badbox(int,int,int,int,int);
- static void badline(int,int,int,int,int);
- /*--------------------------------------------------------------------------*/
- #define sign(x) ((x < 0) ? 1 : 0)
-
- static void (*d_setpix)(int,int,int); /* setpixel function */
- static void (*d_line)(int,int,int,int,int); /* line function */
- static void (*d_box)(int,int,int,int,int); /* box function */
- static void (*d_text)(int,int,const char*,int); /* text function */
- /*--------------------------------------------------------------------------*/
- void initgraph(d)
- struct graph *d;
- {
- if (d->spx || d->lin)
- {
- if (d->spx)
- d_setpix = d->spx;
- else
- d_setpix = badpixel;
-
- if (d->lin)
- d_line = d->lin;
- else
- d_line = badline;
-
- if (d->box)
- d_box = d->box;
- else
- d_box = badbox;
-
- d_text = (d->txt) ;
- }
- }
- /*--------------------------------------------------------------------------*/
- void stext(x,y,str,color)
- int x,y,color;
- const char *str;
- {
- (*d_text)(x,y,str,color);
- }
- /*--------------------------------------------------------------------------*/
- void setpixel(x,y,color)
- int x,y,color;
- {
- (*d_setpix)(x,y,color);
- }
- /*--------------------------------------------------------------------------*/
- void box( x1, y1, x2, y2, color )
- int x1, y1, x2, y2, color;
- {
- (*d_box)(x1,y1,x2,y2,color);
- }
- /*--------------------------------------------------------------------------*/
- void line( x1, y1, x2, y2, color )
- int x1, y1, x2, y2, color;
- {
- (*d_line)(x1,y1,x2,y2,color);
- }
- /*--------------------------------------------------------------------------*/
-
- static void badpixel(x,y,color)
- int x, y, color;
- {
- line(x,y,x,y,color);
- }
- /*--------------------------------------------------------------------------*/
- static void badbox( x1, y1, x2, y2, color )
- int x1, y1, x2, y2, color;
- {
- line(x1,y1,x2,y1,color);
- line(x2,y1,x2,y2,color);
- line(x2,y2,x1,y2,color);
- line(x1,y2,x1,y1,color);
- }
- /*--------------------------------------------------------------------------*/
- static void badline( x1, y1, x2, y2, color )
- int x1, y1, x2, y2, color;
- {
- int x, y, dx, dy, adx, ady, d, d1, d2, step;
-
- dx = x2 - x1;
- adx = abs(dx);
- dy = y2 - y1;
- ady = abs(dy);
-
- if (adx == 0) /* Vertical line */
- {
- y = min(y1, y2);
- ady++;
- while (ady--)
- (*d_setpix)(x1, y++, color);
- return;
- }
-
- if (ady == 0) /* Horizontal line */
- {
- x = min(x1, x2);
- adx++;
- while (adx--)
- (*d_setpix)(x++, y1, color);
- return;
- }
-
- if (adx < ady)
- {
- d = (adx << 1) - ady;
- d1 = adx << 1;
- d2 = (adx - ady) << 1;
- (y1 < y2) ? (x = x1, y = y1) : (x = x2, y = y2);
- step = ((sign(dx) == sign(dy)) ? 1 : -1);
- (*d_setpix)(x, y, color);
- while (ady--)
- {
- y++;
- if (d < 0)
- d += d1;
- else
- {
- x += step;
- d += d2;
- }
- (*d_setpix)(x, y, color);
- }
- }
- else
- {
- d = (ady << 1) - adx;
- d1 = ady << 1;
- d2 = (ady - adx) << 1;
- (x1 < x2) ? (x = x1, y = y1) : (x = x2, y = y2);
- step = ((sign(dx) == sign(dy)) ? 1 : -1);
- (*d_setpix)(x, y,color);
- while (adx--)
- {
- x++;
- if (d < 0)
- d += d1;
- else
- {
- y += step;
- d += d2;
- }
- (*d_setpix)(x, y, color);
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/list.c'
- then
- echo shar: will not over-write existing file "'src/list.c'"
- else
- cat << \SHAR_EOF > 'src/list.c'
- /* list,save 11/19/91
- * Copyright 1983-1992 Albert Davis
- * list and save commands.
- * save is list with direction to file
- */
- #include "ecah.h"
- #include "branch.h"
- #include "dev.h"
- #include "error.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_list(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern const char head[];
- /*--------------------------------------------------------------------------*/
- void cmd_list(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- branch_t *brh;
-
- *cnt = 0; /* back up to beginning of input line */
- (void)outset(cmd,cnt,(char*)NULL,"ckt"); /* is it list or save?? */
- /* (outset will re-eat words save or list)*/
- /* its purpose is to set up where to send */
- /* the stuff. */
-
- mprintf(io.where&~io.mstdout, "%s\n", head);
-
- if (!cmd[*cnt]){ /* no args: list all */
- branch_t *stop;
- brh = firstbranch_all();
- stop = lastbranch_all();
- for (;;){
- print_branch(brh, io.where, NO);
- if (brh == stop)
- break;
- brh = nextbranch_all(brh);
- };
- }else{ /* some args: be selective */
- int arg;
- arg = *cnt;
- brh = findbranch(cmd,cnt, firstbranch_all(), lastbranch_all());
- if (!exists(brh)){
- syntax(cmd,cnt,bERROR);
- }
-
- if (cmd[*cnt] == '-'){ /* there is a dash: a range */
- branch_t *stop;
- (*cnt)++;
- stop = findbranch(cmd,cnt, brh, lastbranch_all());
- if (!exists(stop)){
- syntax(cmd,cnt,bERROR);
- stop = lastbranch_all();
- }
- for (;;){
- print_branch(brh, io.where, NO);
- if (brh == stop)
- break;
- brh = nextbranch_all(brh);
- }
- }else{ /* no dash: a list */
- int next;
- do { /* each arg */
- next = *cnt;
- for (;;){ /* all that match this arg */
- print_branch(brh, io.where, YES);
- if (brh == lastbranch_all())
- break;
- *cnt = arg;
- brh = findbranch(cmd, cnt, nextbranch_all(brh), lastbranch_all());
- if (!exists(brh))
- break;
- }
- } while (*cnt = arg = next,
- brh = findbranch(cmd, cnt, firstbranch_all(), lastbranch_all()),
- exists(brh));
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/main.c'
- then
- echo shar: will not over-write existing file "'src/main.c'"
- else
- cat << \SHAR_EOF > 'src/main.c'
- /* main 01/24/93
- * Copyright 1983-1992 Albert Davis
- * top level module
- * it all starts here
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include <signal.h>
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void main(int,const char*[]);
- static void initialize_io(void);
- static void sign_on(void);
- static void read_startup_files(void);
- static void process_cmd_line(int,const char*[]);
- static void setup_traps(void);
- static void finish(void);
- void cmdproc(const char*);
- /*--------------------------------------------------------------------------*/
- extern struct ioctrl io;
- extern const struct options opt;
-
- extern const double zero;
- extern const char e_int[];
-
- extern int inc_mode;
- extern int errorcount;
- extern int run_mode;
- extern int sim_mode;
- extern int sim_phase;
- extern FILE *stream[]; /* reverse of fileno() */
- extern jmp_buf envp;
- extern int cmdcount;
- /*--------------------------------------------------------------------------*/
- void main(argc,argv)
- int argc;
- const char *argv[];
- {
- initialize(); /* machine dependent initialization */
- initialize_io();
- sign_on();
- if (setjmp(envp)){
- finish(); /* error clean up (from longjmp()) */
- }else{
- read_startup_files();
- process_cmd_line(argc,argv);
- setup_traps();
- }
- for (;;){
- char cmdbuf[BUFLEN];
- cmdcount++;
- (void)getcmd("-->", cmdbuf, BUFLEN);
- run_mode = rEXECUTE;
- cmdproc(cmdbuf);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void initialize_io()
- {
- stream[fileno(stdin )] = stdin;
- stream[fileno(stdout)] = stdout;
- stream[fileno(stderr)] = stderr;
- io.mstdout = io.mstderr = 1<<fileno(stdout);
- }
- /*--------------------------------------------------------------------------*/
- static void sign_on()
- {
- mprintf(io.mstdout,"ACS (Al's Circuit Simulator) 0.05xc\n");
- mprintf(io.mstdout,"Never trust any version less than 1.0\n");
- mprintf(io.mstdout,"Copyright 1992, Albert Davis\n");
- mprintf(io.mstdout,"ACS comes with ABSOLUTELY NO WARRANTY\n");
- mprintf(io.mstdout,"This is free software, and you are welcome\n");
- mprintf(io.mstdout,"to redistribute it under certain conditions.\n");
- mprintf(io.mstdout,"See the file \"COPYING\" for details\n");
- }
- /*--------------------------------------------------------------------------*/
- static void read_startup_files()
- {
- char *name;
- if (name = findfile(SYSTEMSTARTFILE, SYSTEMSTARTPATH, R_OK)){
- char cmdbuf[BUFLEN];
- sprintf(cmdbuf, "get %s", name);
- cmdproc(cmdbuf);
- }
- if (name = findfile(USERSTARTFILE, USERSTARTPATH, R_OK)){
- char cmdbuf[BUFLEN];
- sprintf(cmdbuf, "get %s", name);
- cmdproc(cmdbuf);
- }
- cmdproc("clear");
- }
- /*--------------------------------------------------------------------------*/
- static void process_cmd_line(argc,argv)
- int argc;
- const char *argv[];
- {
- if (argc > 1){
- char cmdbuf[BUFLEN];
- sprintf(cmdbuf, "< %s", argv[1]);
- cmdproc(cmdbuf);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void setup_traps()
- {
- (void)signal(SIGFPE,sig_fpe);
- (void)signal(SIGINT,sig_int);
- }
- /*--------------------------------------------------------------------------*/
- /* finish: clean up after a command
- * deallocates space, closes plot windows, resets i/o redirection, etc.
- * This is done separately for exception handling.
- * If a command aborts, clean-up is still done, leaving a consistent state.
- */
- static void finish()
- {
- dc_finish();
- plclose();
- if (zero!=0.)
- error(bWARNING, e_int, "zero");
- errorcount = 0;
- io.suppresserrors = NO;
- inc_mode = NO;
- outreset();
- dealloc(NO);
- }
- /*--------------------------------------------------------------------------*/
- /* cmdproc: process a command
- * parse, and act on, a command string
- */
- void cmdproc(cmd)
- const char *cmd;
- {
- volatile int cnt = 0;
- static struct time_s timecheck;
- int didsomething = YES;
-
- error(bTRACE, "%s\n", cmd);
-
- time_check(&timecheck);
- time_zstart(&timecheck);
- sim_mode = sNONE;
- sim_phase = pNONE;
- if (argparse(cmd,&cnt,ONEPASS,
- "Ac", aFUNCTION, cmd_ac,
- "ALter", aFUNCTION, cmd_alter,
- "Build", a2FUNCTION, plclear, cmd_build,
- "CHDir", a2FUNCTION, plclear, cmd_chdir,
- "CDir", a2FUNCTION, plclear, cmd_chdir,
- "CLEAR", a2FUNCTION, plclear, cmd_clear,
- "CRTSET", a2FUNCTION, plclear, cmd_crtset,
- ""))
- ; /* split to hide sun lint bug. */
- else if (argparse(cmd,&cnt,ONEPASS,
- "DC", aFUNCTION, cmd_dc,
- "DELete", a2FUNCTION, plclear, cmd_delete,
- "DIsto", aFUNCTION, cmd_disto,
- "Edit", a2FUNCTION, plclear, cmd_edit,
- "END", aFUNCTION, cmd_quit,
- "ENDS", aFUNCTION, cmd_ends,
- "EXIt", a2FUNCTION, plclear, cmd_quit,
- "FAult", aFUNCTION, cmd_fault,
- ""))
- ; /* split to hide sun lint bug. */
- else if (argparse(cmd,&cnt,ONEPASS,
- "FOurier", aFUNCTION, cmd_fourier,
- "Generator",a2FUNCTION, plclear, cmd_generator,
- "GET", a2FUNCTION, plclear, cmd_get,
- "Help", a2FUNCTION, plclear, cmd_help,
- "IC", aFUNCTION, cmd_ic,
- "INsert", a2FUNCTION, plclear, cmd_insert,
- "List", a2FUNCTION, plclear, cmd_list,
- "LOg", aFUNCTION, cmd_log,
- ""))
- ; /* split to hide sun lint bug. */
- else if (argparse(cmd,&cnt,ONEPASS,
- "MArk", aFUNCTION, cmd_keep,
- "MErge", a2FUNCTION, plclear, cmd_merge,
- "MODEl", aFUNCTION, cmd_model,
- "Modify", a2FUNCTION, plclear, cmd_modify,
- "Network", a2FUNCTION, plclear, cmd_network,
- "NODeset", aFUNCTION, cmd_nodeset,
- "NOIse", aFUNCTION, cmd_noise,
- "OP", aFUNCTION, cmd_op,
- ""))
- ; /* split to hide sun lint bug. */
- else if (argparse(cmd,&cnt,ONEPASS,
- "OPTions", a2FUNCTION, plclear, cmd_options,
- "PAuse", aFUNCTION, cmd_pause,
- "PLot", a2FUNCTION, plclear, cmd_plot,
- "PRint", a2FUNCTION, plclear, cmd_print,
- "PRobe", a2FUNCTION, plclear, cmd_print,
- "Quit", a2FUNCTION, plclear, cmd_quit,
- "Restore", a2FUNCTION, plclear, cmd_restore,
- "SAve", a2FUNCTION, plclear, cmd_list,
- ""))
- ; /* split to hide sun lint bug. */
- else if (argparse(cmd,&cnt,ONEPASS,
- "SENs", aFUNCTION, cmd_sens,
- "SEt", a2FUNCTION, plclear, cmd_options,
- "SPectrum", aFUNCTION, cmd_fourier,
- "STatus", a2FUNCTION, plclear, cmd_status,
- "SUbckt", aFUNCTION, cmd_subckt,
- "SWeep", a2FUNCTION, plclear, cmd_sweep,
- "TEmp", aFUNCTION, cmd_temp,
- "TF", aFUNCTION, cmd_tf,
- ""))
- ; /* split to hide sun lint bug. */
- else if (argparse(cmd,&cnt,ONEPASS,
- "TItle", a2FUNCTION, plclear, cmd_title,
- "TRansient",aFUNCTION, cmd_tr,
- "UNFault", aFUNCTION, cmd_unfault,
- "UNMark", aFUNCTION, cmd_unkeep,
- "Width", aFUNCTION, cmd_options,
- "!", a2FUNCTION, plclear, cmd_system,
- "<", aFUNCTION, cmd_run,
- ""))
- ; /* split to hide sun lint bug. */
- else if (argparse(cmd,&cnt,ONEPASS,
- ">", aFUNCTION, cmd_file,
- ""))
- ;
- else{ /* comment or error */
- cmd_comment(cmd,&cnt);
- didsomething = NO;
- }
- if (opt.acct && didsomething){
- time_check(&timecheck);
- mprintf(io.mstdout," user=%8.2f sys=%8.2f\n",
- timecheck.last_user, timecheck.last_system);
- mprintf(io.mstdout,"total user=%8.2f sys=%8.2f\n",
- timecheck.total_user, timecheck.total_system);
- }
- finish();
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/match.c'
- then
- echo shar: will not over-write existing file "'src/match.c'"
- else
- cat << \SHAR_EOF > 'src/match.c'
- /* match 01/11/93
- * Copyright 1983-1992 Albert Davis
- * string compare
- * compares characters until end of first string
- * any non-alpha character is a terminator
- * returns offset into string to legal start of next token
- * (skips trailing spaces and comma, if any)
- * if they match so far, and enough matched, else NO (0)
- * Characters in reference string in UPPER case must match.
- * Always requires at least one character to match.
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- int pmatch(const char*,int*,const char*);
- int match(const char*,const char*);
- static int is_alpha(int);
- void setmatch(const char*,int*);
- int rematch(const char*);
- /*--------------------------------------------------------------------------*/
- /* pmatch: partial match -- match a keyword from command string
- * tries to match a partial string &cmd[*cnt] against reference str2
- * calls match, therefore depends on its definition of a match
- * if no match, returns 0 and leaves cnt alone
- * if match, updates cnt, (to eat string that was matched)
- * and returns the number of characters eaten. (non zero)
- * return value is usually interpreted as a truth value:
- * true if match exists.
- */
- int pmatch(cmd,cnt,str2)
- const char *cmd, *str2;
- int *cnt;
- {
- int ind;
- *cnt += ind = match(&cmd[*cnt],str2);
- return ind;
- }
- /*--------------------------------------------------------------------------*/
- /* match: match str1 (under test) against str2 (reference)
- * if no match, returns 0
- * if match, returns the number of characters that match,
- * ---including whitespace---
- * return value is usually interpreted as a truth value:
- * true if match exists.
- * str1 (being tested) is considered to be case-insensitive
- * is terminated by a non-alpha character
- * str2 (reference) has special considerations:
- * upper case characters must match, and must be present
- * lower case characters must match if present, but may be omitted
- * strings are alpha only.
- */
- int match (str1,str2)
- const char *str1, *str2;
- {
- volatile int skp = 0;
-
- skipbl (str1,&skp);
- while (to_lower(str1[skp]) == to_lower(*str2)){
- str2++;
- if (!is_alpha(str1[skp++]) || (!is_alpha(str1[skp]) && !isupper(*str2))){
- skipcom(str1,&skp);
- return skp;
- }
- }
- return 0;
- }
- /*--------------------------------------------------------------------------*/
- /* is_alpha: a real function for isalpha
- * because side-effects of c screw up the isalpha macro
- */
- static int is_alpha(c)
- int c;
- {
- return isalpha(toascii(c));
- }
- /*--------------------------------------------------------------------------*/
- /* setmatch, rematch: switch statement for strings
- * call setmatch once, for the string being tested.
- * repeated calls to rematch, one for each case
- * pmatch always refers to the most recent setmatch: no nesting allowed
- */
- static const char *cmdp;
- static int *cntp;
-
- /* setmatch: call with string being tested
- */
- void setmatch(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- cmdp = cmd;
- cntp = cnt;
- }
-
- /* rematch: test for match.
- * returns true (actually, see pmatch) if string in most recent call to
- * setmatch matches its argument (see match), and updates i, so another
- * call will match the next token
- * returns false if match fails
- */
- int rematch(ref)
- const char *ref;
- {
- return pmatch(cmdp,cntp,ref);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/modify.c'
- then
- echo shar: will not over-write existing file "'src/modify.c'"
- else
- cat << \SHAR_EOF > 'src/modify.c'
- /* modify 12/29/92
- * Copyright 1983-1992 Albert Davis
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_modify(const char*,int*);
- void cmd_restore(void);
- void cmd_fault(const char*,int*);
- static double sweep_fix(const char*,int*,const branch_t*,double);
- static int faultbranch(branch_t*,double);
- void cmd_unfault(void);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
-
- extern const char e_int[], e_om[];
- extern const int crtplot;
- extern const int swp_type[];
- extern const int swp_count[], swp_steps[];
- extern const int swp_nest;
-
- static branch_t *faultlist;
- static unsigned fcount = 0;
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_modify(cmd,cnt)
- const char *cmd ; /* command string */
- int *cnt ; /* pointer to cmd string counter */
- {
- branch_t *brh;
- volatile int cc; /* character counter */
- int next = 0; /* remember char counter, for next arg */
- int count; /* count number of changes */
- double value; /* new value */
-
- dealloc(YES);
- for ( ; isalpha(cmd[*cnt]) ; *cnt=next){
- count = 0;
- for (brh = firstbranch_all();
- cc= *cnt, brh = findbranch(cmd,&cc,brh,lastbranch_all()), exists(brh);
- /**/ brh = nextbranch_all(brh)){
- value = ctof(cmd,&cc);
-
- brh->val = value;
- count++;
- next = cc;
- }
- if (count == 0)
- break;
- }
- syntax(cmd,cnt,bWARNING);
- }
- /*--------------------------------------------------------------------------*/
- void cmd_restore()
- {
- cmd_unfault();
- cmd_unkeep();
- }
- /*--------------------------------------------------------------------------*/
- void cmd_fault(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- branch_t *brh;
- volatile int cc; /* character counter */
- int next = 0; /* remember char counter, for next arg */
- int count; /* count number of faults */
- double value; /* new value */
-
- dealloc(YES);
- for ( ; isalpha(cmd[*cnt]) ; *cnt=next){
- count = 0;
- for (brh = firstbranch_all();
- cc= *cnt, brh = findbranch(cmd,&cc,brh,lastbranch_all()), exists(brh);
- /**/ brh = nextbranch_all(brh)){
- value = ctof(cmd,&cc);
- value = sweep_fix(cmd,&cc,brh,value);
-
- if (!faultbranch(brh,value))
- error(bWARNING, e_int, "fault");
- count++;
- next = cc;
- }
- if (count == 0)
- break;
- }
- syntax(cmd,cnt,bWARNING);
- }
- /*--------------------------------------------------------------------------*/
- static double sweep_fix(cmd,cc,brh,value)
- const char *cmd; /* fix the value for sweep command. */
- int *cc; /* if not sweeping, return value. */
- const branch_t *brh;
- double value;
- {
- if (swp_steps[swp_nest] != 0 && isfloat(cmd[*cc])){
- double end, offset;
-
- end = ctof(cmd,cc);
- offset = (double)swp_count[swp_nest] / (double)swp_steps[swp_nest];
- if (swp_type[swp_nest]=='L'){
- if (value == 0.)
- error(bERROR, "log sweep can't pass zero\n");
- else
- value *= pow( (end/value), offset );
- }else{
- value += (end-value) * offset;
- }
-
- if (!crtplot)
- mprintf( io.mstdout, "%u> sweep %s =%s\n",
- swp_count[swp_nest]+1,
- printlabel(brh,NO),
- ftos(value," ",7,0)
- );
- }
- return value;
- }
- /*--------------------------------------------------------------------------*/
- /* faultbranch: "fault" a single branch. (temporarily change a value)
- * save the existing branch in "faultlist"
- * put the modified branch in the parts list
- * does not fix extensions here, up to caller
- * needs rework for pointers, extensions, etc.
- * unreliable. does not maintain list consistency
- */
- static int faultbranch(brh,value)
- branch_t *brh;
- double value;
- {
- if (!isdevice(brh))
- return NO;
-
- if (faultlist)
- faultlist=(branch_t*)realloc((void*)faultlist,(fcount+1)*sizeof(branch_t));
- else
- faultlist = (branch_t*)calloc(fcount+1, sizeof(branch_t));
- if (!faultlist)
- error(bERROR, e_om, "fault");
- faultlist[fcount] = *brh;
- fcount++;
-
- brh->val = value;
- brh->x = (generic_t*)NULL;
- brh->subckt = (branch_t*)NULL;
-
- return YES;
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_unfault: (command) remove faults and restore pre-fault values
- * the warnings are notices about known bugs
- * editing a list that has faults can corrupt it.
- */
- void cmd_unfault() /* remove all faults, and restore to normal */
- { /* can be a command */
- branch_t *prev;
- branch_t *next;
-
- while (fcount-- > 0){
- prev = faultlist[fcount].prev;
- next = faultlist[fcount].next;
- if (prev->next != next->prev)
- error(bERROR, e_int, "unfault: inconsistent links");
- if (prev != prev->next->prev)
- error(bERROR, e_int, "unfault: missing back link");
- if (next != next->prev->next)
- error(bERROR, e_int, "unfault: missing fwd link");
- *(prev->next) = faultlist[fcount];
- }
- fcount = 0;
- qfree((void**)&faultlist);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/network.c'
- then
- echo shar: will not over-write existing file "'src/network.c'"
- else
- cat << \SHAR_EOF > 'src/network.c'
- /* network 12/29/92
- * Copyright 1983-1992 Albert Davis
- * Prints out a list of all node connections.
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "io.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_network(const char*,int*);
- static void checklist(const branch_t*,int);
- /*--------------------------------------------------------------------------*/
- extern struct ioctrl io;
- extern const struct status stats;
- /*--------------------------------------------------------------------------*/
- void cmd_network(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- int nod; /* the node we are trying to determine connections */
- int start, stop;
-
- io.where |= io.mstdout;
-
- for (start = stop = -1; ; ){
- if (isdigit(cmd[*cnt])){
- int temp;
- temp = ctoi(cmd,cnt);
- if (cmd[*cnt] == '-'){
- ++*cnt;
- start = temp;
- }else if (start < 0){
- start = temp;
- if (stop < 0)
- stop = start;
- }else{
- stop = temp;
- }
- }else if (cmd[*cnt] == '-'){
- ++*cnt;
- skipbl(cmd,cnt);
- if (isdigit(cmd[*cnt]))
- stop = ctoi(cmd,cnt);
- }else if (outset(cmd,cnt,(char*)NULL," ")){
- /*nothing*/;
- }else{
- syntax(cmd,cnt,bWARNING);
- break;
- }
- }
-
- initio(io.where,(FILE*)NULL);
- if (start < 0)
- start = 0;
- if (stop < 0 || stop > stats.total_nodes)
- stop = stats.user_nodes;
- if (!exists(firstbranch_all()))
- error(bERROR, "no circuit\n");
- if (start>stats.total_nodes)
- error(bERROR, "%u nodes\n", stats.total_nodes);
-
- mprintf(io.where,"Node: Branches\n");
- for (nod = start; nod <= stop; ++nod){
- mprintf(io.where,"%4u:",nod);
- checklist(firstbranch_dev(),nod);
- mputc('\n',io.where);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void checklist(brh,nod)
- const branch_t *brh;
- int nod;
- {
- const branch_t *stop;
- stop = brh;
- do {
- if (isdevice(brh)){
- int ii;
- for (ii = 0; brh->n[ii].t != INVALIDNODE; ii++){
- if (nod == brh->n[ii].t)
- mprintf(io.where," %s",printlabel(brh,NO));
- }
- if (brh->tracesubckt)
- checklist(brh->subckt,nod);
- }
- } while (brh = nextbranch_dev(brh), brh != stop);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/nodes.c'
- then
- echo shar: will not over-write existing file "'src/nodes.c'"
- else
- cat << \SHAR_EOF > 'src/nodes.c'
- /* nodes.c 01/11/93
- * Copyright 1983-1992 Albert Davis
- * functions to handle node mapping
- */
- #include "ecah.h"
- #include "branch.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- int newnode_subckt(void);
- int newnode_model(void);
- int parsenodes(branch_t*,const char*,int*,int);
- void printnodes(const branch_t*,int);
- static int name2number(const char*,int*);
- static char* number2name(char*,int);
- /*--------------------------------------------------------------------------*/
- extern struct status stats;
- /*--------------------------------------------------------------------------*/
- /* newnode_subckt: get a new node number, unique internal nodes in subckts
- */
- int newnode_subckt()
- {
- ++stats.subckt_nodes;
- return ++stats.total_nodes;
- }
- /*--------------------------------------------------------------------------*/
- /* newnode_model: get a new node number, unique internal nodes in models
- */
- int newnode_model()
- {
- ++stats.model_nodes;
- return ++stats.total_nodes;
- }
- /*--------------------------------------------------------------------------*/
- /* parsenodes: parse circuit connections from input string
- * result in brh.
- * n array must hold at least nodecount+1
- * cnt updated.
- */
- int parsenodes(brh,cmd,cnt,nodecount)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- int nodecount;
- {
- int ii;
- int count = 0;
- for (ii = 0; ii < nodecount; ii++){
- brh->n[ii].t = brh->n[ii].e = name2number(cmd,cnt);
- if (brh->n[ii].e != INVALIDNODE)
- count = ii+1;
- }
- brh->n[ii].t = brh->n[ii].e = INVALIDNODE;
- return count;
- }
- /*--------------------------------------------------------------------------*/
- /* printnodes: print a node list
- */
- void printnodes(brh,where)
- const branch_t *brh;
- int where;
- {
- int ii;
- for (ii = 0; brh->n[ii].e != INVALIDNODE; ii++){
- char name[LABELEN+1];
- mprintf(where, " %s ", number2name(name,brh->n[ii].e));
- }
- }
- /*--------------------------------------------------------------------------*/
- /* name2number: convert node name to node number
- * returns node number
- * cnt updated
- */
- static int name2number(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- int test;
- int node;
-
- test = *cnt;
- node = ctoi(cmd,cnt);
- return (test == *cnt) ? INVALIDNODE : node;
- }
- /*--------------------------------------------------------------------------*/
- /* number2name: convert node number to node name
- * result in name (must be big enough)
- * returns name
- */
- static char* number2name(name,node)
- char *name;
- int node;
- {
- (void)sprintf(name, "%d", node);
- return name;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/nodeset.c'
- then
- echo shar: will not over-write existing file "'src/nodeset.c'"
- else
- cat << \SHAR_EOF > 'src/nodeset.c'
- /* nodeset.c 01/03/93
- * Copyright 1983-1992 Albert Davis
- * nodeset and ic commands
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "error.h"
- #include "io.h"
- #include "nodeset.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_ic(const char*,int*);
- void cmd_nodeset(const char*,int*);
- static void nic(const char*,int*,nodeset_t*);
- static void addnodeset(nodeset_t*,int,double);
- static void clearnodeset(nodeset_t*,nodeset_t*);
- static void deletenodeset(nodeset_t*,int);
- static void listnodeset(const nodeset_t*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern const char e_om[];
- static nodeset_t ictop;
- static nodeset_t nstop;
- /*--------------------------------------------------------------------------*/
- void cmd_ic(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- nic(cmd,cnt,&ictop);
- }
- /*--------------------------------------------------------------------------*/
- void cmd_nodeset(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- nic(cmd,cnt,&nstop);
- }
- /*--------------------------------------------------------------------------*/
- static void nic(cmd,cnt,top)
- const char *cmd;
- int *cnt;
- nodeset_t *top;
- {
- if (!cmd[*cnt]){
- listnodeset(top);
- return;
- }
-
- if (pmatch(cmd,cnt,"CLEAR")){
- clearnodeset(top,top);
- }else{
- while (pmatch(cmd,cnt,"V")){
- int node = ctoi(cmd,cnt);
- int cntold = *cnt;
- double voltage = ctof(cmd,cnt);
- if (cntold == *cnt){ /* no voltage value = unset */
- deletenodeset(top,node);
- }else{
- addnodeset(top,node,voltage);
- }
- }
- syntax(cmd,cnt,bWARNING);
- }
- }
- /*--------------------------------------------------------------------------*/
- /* addnodeset: add a new nodeset or ic
- */
- static void addnodeset(top,node,voltage)
- nodeset_t *top;
- int node;
- double voltage;
- {
- nodeset_t *ptr,*new;
-
- for (ptr=top; (ptr->next)&&(ptr->next->node<node); ptr=ptr->next)
- /* nothing */;
-
- if ((ptr->next)&&(ptr->next->node==node)){
- error(bWARNING, "replacing nodeset/ic at node %u\n", node);
- }else{
- new = (nodeset_t*)calloc(1,sizeof(nodeset_t));
- if (!new)
- error(bERROR, e_om, "addnodeset");
- new->node = node;
- new->next = ptr->next;
- ptr->next = new;
- }
-
- ptr = ptr->next;
- ptr->voltage = voltage;
- }
- /*--------------------------------------------------------------------------*/
- /* clearnodeset: deallocate and clear all from ptr on,
- * but leave top allocated (recursive)
- */
- static void clearnodeset(top,ptr)
- nodeset_t *top,*ptr;
- {
- if (ptr->next)
- clearnodeset(top,ptr->next);
- if (ptr != top){
- free((void*)ptr);
- }else{
- top->next=NULL;
- top->node=0;
- top->voltage=0.;
- }
- }
- /*--------------------------------------------------------------------------*/
- /* deletenodeset: delete a node set (unset a node)
- */
- static void deletenodeset(top,node)
- nodeset_t *top;
- int node;
- {
- nodeset_t *ptr;
-
- for(ptr=top; (ptr->next)&&(ptr->next->node<node); ptr=ptr->next)
- /* nothing */; /* scan for node match */
-
- if ((ptr->next)&&(ptr->next->node==node)){
- nodeset_t *link;
- link = ptr->next->next;
- free((void*)ptr->next);
- ptr->next = link;
- }
- }
- /*--------------------------------------------------------------------------*/
- /* listnodeset: list all nodes set
- */
- static void listnodeset(top)
- const nodeset_t *top;
- {
- nodeset_t *ptr;
-
- for (ptr=top->next; ptr; ptr=ptr->next){
- mprintf(io.mstdout,"V(%d)=%s ",ptr->node,ftos(ptr->voltage,"",7,0));
- }
- mprintf(io.mstdout,"\n");
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/options.c'
- then
- echo shar: will not over-write existing file "'src/options.c'"
- else
- cat << \SHAR_EOF > 'src/options.c'
- /* options 01/26/93
- * Copyright 1983-1992 Albert Davis
- * set and view options and user controllable variables
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "error.h"
- #include "io.h"
- #include "options.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_options(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern struct options opt;
- /*--------------------------------------------------------------------------*/
- void cmd_options(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- int where;
- int dummy;
- int ii;
- double arg1, arg2;
-
- where = (cmd[*cnt])? 0 : io.mstdout;
- while (cmd[*cnt]){
- /* didsomething avoids heap space problem in MSC */
- int didsomething = argparse(cmd,cnt,REPEAT,
- "ACCT", aENUM, &opt.acct, YES,
- "NOACCT", aENUM, &opt.acct, NO,
- "LIST", aENUM, &opt.list, YES,
- "NOLIST", aENUM, &opt.list, NO,
- "MOD", aENUM, &opt.nomod, NO,
- "NOMOD", aENUM, &opt.nomod, YES,
- "PAGE", aENUM, &opt.page, YES,
- "NOPAGE", aENUM, &opt.page, NO,
- "NODE", aENUM, &opt.node, YES,
- "NONODE", aENUM, &opt.node, NO,
- "OPTS", aENUM, &opt.opts, YES,
- "NOOPTS", aENUM, &opt.opts, NO,
- "GMIN", aUDOUBLE, &opt.gmin,
- "RELTOL", aUDOUBLE, &opt.reltol,
- "ABSTOL", aUDOUBLE, &opt.abstol,
- "VNTOL", aUDOUBLE, &opt.vntol,
- "TRTOL", aUDOUBLE, &opt.trtol,
- "CHGTOL", aUDOUBLE, &opt.chgtol,
- "PIVTOL", aUDOUBLE, &opt.pivtol,
- "PIVREL", aUDOUBLE, &opt.pivrel,
- "NUMDGT", aFINT, &opt.numdgt,
- "TNOM", aODOUBLE, &opt.tnom, -ABS_ZERO,
- "CPTIME", aFINT, &opt.cptime,
- "LIMTIM", aFINT, &opt.limtim,
- "LIMPTS", aFINT, &opt.limpts,
- "LVLCOD", aFINT, &opt.lvlcod,
- "LVLTIM", aFINT, &opt.lvltim,
- "METHOD", aENUM, &dummy, YES,
- "GEAR", aENUM, &opt.method, mGEAR,
- "TRAPezoidal", aENUM, &opt.method, mTRAPEZOID,
- "MAXORD", aFINT, &opt.maxord,
- "");
- if (didsomething)
- ;
- else if (argparse(cmd,cnt,REPEAT,
- "Seed", aFINT, &opt.seed,
- "WCZero", aUDOUBLE, &opt.wczero,
- "Damp", aUDOUBLE, &opt.damp,
- "Floor", aUDOUBLE, &opt.floor,
- "Tempamb", aODOUBLE, &opt.tempamb, -ABS_ZERO,
- "Short", aUDOUBLE, &opt.shortckt,
- "TRansits", aFINT, &opt.transits,
- "INwidth", aFINT, &opt.inwidth,
- "OUTwidth", aFINT, &opt.outwidth,
- "XDivisions", aUDOUBLE, &opt.xdivisions,
- "YDivisions", aUDOUBLE, &opt.ydivisions,
- ""))
- ;
- else if (argparse(cmd,cnt,REPEAT,
- "NAG", aENUM, &opt.picky, bNOERROR,
- "NONag", aENUM, &opt.picky, bTRACE,
- "TRACe", aENUM, &opt.picky, bTRACE,
- "NOTrace", aENUM, &opt.picky, bLOG,
- "LOG", aENUM, &opt.picky, bLOG,
- "NOLog", aENUM, &opt.picky, bDEBUG,
- "DEBug", aENUM, &opt.picky, bDEBUG,
- "NODebug", aENUM, &opt.picky, bPICKY,
- "PICky", aENUM, &opt.picky, bPICKY,
- "NOPicky", aENUM, &opt.picky, bWARNING,
- "WARning", aENUM, &opt.picky, bWARNING,
- "NOWarn", aENUM, &opt.picky, bDANGER,
- "ERRor", aENUM, &opt.picky, bERROR,
- "NOError", aENUM, &opt.picky, bDISASTER,
- "DISaster", aENUM, &opt.picky, bDISASTER,
- ""))
- ;
- else if (argparse(cmd,cnt,REPEAT,
- "ORder", aENUM, &dummy, YES,
- "REVerse", aENUM, &opt.order, oREVERSE,
- "FORward", aENUM, &opt.order, oFORWARD,
- "AUTo", aENUM, &opt.order, oAUTO,
- "MODe", aENUM, &dummy, YES,
- "ANAlog", aENUM, &opt.mode, mANALOG,
- "DIGital", aENUM, &opt.mode, mDIGITAL,
- "MIXed", aENUM, &opt.mode, mMIXED,
- "DUPcheck", aENUM, &opt.dupcheck, YES,
- "NODUPcheck", aENUM, &opt.dupcheck, NO,
- "BYPass", aENUM, &opt.bypass, YES,
- "NOBYPass", aENUM, &opt.bypass, NO,
- "VBYPass", aENUM, &opt.bypass, bVOLT,
- "INCmode", aENUM, &opt.incmode, YES,
- "NOIncmode", aENUM, &opt.incmode, NO,
- "LIMIT", aUDOUBLE, &opt.limit,
- "MRT", aUDOUBLE, &opt.mrt,
- "FOOOO", aFINT, &opt.foooo,
- ""))
- dealloc(YES);
- else if (ii=*cnt, argparse(cmd,cnt,ONEPASS,
- "ITL", a2DOUBLE, &arg1, &arg2,
- "")){
- if ((int)arg1 >= 1 && (int)arg1 <= 8){
- opt.itl[(int)arg1] = (int)arg2;
- }else{
- *cnt = ii;
- syntax(cmd,cnt,bWARNING);
- skiparg(cmd,cnt);
- }
- }else{
- syntax(cmd,cnt,bWARNING);
- skiparg(cmd,cnt);
- }
- }
-
- opt.lowlim = 1 - opt.reltol;
- opt.uplim = 1 + opt.reltol;
-
- #ifdef NOTIME
- opt.acct = NO;
- #endif
-
- if (where){
- mprintf(where, ".options ");
- if (opt.acct) mprintf(where," acct ");
- if (opt.list) mprintf(where," list ");
- if (opt.nomod) mprintf(where," nomod ");
- if (opt.page) mprintf(where," page ");
- if (opt.node) mprintf(where," node ");
- if (opt.opts) mprintf(where," opts ");
- mprintf(where, " gmin=%s ", ftos(opt.gmin, "", 7, 0));
- mprintf(where, " reltol=%s ", ftos(opt.reltol, "", 7, 0));
- mprintf(where, " abstol=%s ", ftos(opt.abstol, "", 7, 0));
- mprintf(where, " vntol=%s ", ftos(opt.vntol, "", 7, 0));
- mprintf(where, " trtol=%s ", ftos(opt.trtol, "", 7, 0));
- mprintf(where, " chgtol=%s ", ftos(opt.chgtol, "", 7, 0));
- mprintf(where, " pivtol=%s ", ftos(opt.pivtol, "", 7, 0));
- mprintf(where, " pivrel=%s ", ftos(opt.pivrel, "", 7, 0));
- mprintf(where, " numdgt=%d ", opt.numdgt);
- mprintf(where, " tnom=%s ", ftos(opt.tnom+ABS_ZERO, "", 7, 0));
- mprintf(where, " cptime=%d ", opt.cptime);
- mprintf(where, " limtim=%d ", opt.limtim);
- mprintf(where, " limpts=%d ", opt.limpts);
- mprintf(where, " lvlcod=%d ", opt.lvlcod);
- mprintf(where, " lvltim=%d ", opt.lvltim);
- if (opt.method == mTRAPEZOID) mprintf(where, " method=trapezoid ");
- else if (opt.method == mGEAR) mprintf(where, " method=gear ");
- mprintf(where, " maxord=%d ", opt.maxord);
- for (ii=1; ii<=8; ii++)
- mprintf(where, " itl%d=%d ", ii, opt.itl[ii]);
- mprintf(where, " seed=%d ", opt.seed);
- mprintf(where, " wczero=%s ", ftos(opt.wczero, "", 7, 0));
- mprintf(where, " damp=%s ", ftos(opt.damp, "", 7, 0));
- mprintf(where, " floor=%s ", ftos(opt.floor, "", 7, 0));
- mprintf(where, " tempamb=%s ",ftos(opt.tempamb+ABS_ZERO, "", 7, 0));
- mprintf(where, " short=%s ", ftos(opt.shortckt,"", 7, 0));
- mprintf(where, " in=%d ", opt.inwidth);
- mprintf(where, " out=%d ", opt.outwidth);
- mprintf(where, " xdivisions=%s ", ftos(opt.xdivisions, "", 7, 0));
- mprintf(where, " ydivisions=%s ", ftos(opt.ydivisions, "", 7, 0));
- if (opt.order == oREVERSE) mprintf(where, " order=reverse ");
- else if (opt.order == oFORWARD) mprintf(where, " order=forward ");
- else if (opt.order == oAUTO) mprintf(where, " order=auto ");
- if (opt.mode == mANALOG) mprintf(where, " mode=analog ");
- else if (opt.mode == mDIGITAL) mprintf(where, " mode=digital ");
- else if (opt.mode == mMIXED) mprintf(where, " mode=mixed ");
- mprintf(where, " transits=%d ",opt.transits);
- mprintf(where," %sdupcheck ", ((opt.dupcheck)?"":"no"));
- if (opt.bypass == NO) mprintf(where, " nobypass ");
- else if (opt.bypass == YES) mprintf(where, " bypass ");
- else if (opt.bypass == bVOLT) mprintf(where, " vbypass ");
- mprintf(where," %sincmode ", ((opt.incmode)?"":"no"));
- mprintf(where, " limit=%s ", ftos(opt.limit,"", 7, 0));
- mprintf(where, " mrt=%s ", ftos(opt.mrt,"", 7, 0));
- mputc('\n',where);
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/outset.c'
- then
- echo shar: will not over-write existing file "'src/outset.c'"
- else
- cat << \SHAR_EOF > 'src/outset.c'
- /* outset 03/07/92
- * Copyright 1983-1992 Albert Davis
- * Sets up output direction and format for most commands
- * returns NO if it did nothing
- * fORD if nothing with a file
- * fOUT if it set up an output file
- * fIN if is set up an input file
- * updates pointers into the string
- * outreset starts it all over
- */
- #include "ecah.h"
- #include "error.h"
- #include "formats.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void initio(int,FILE*);
- void decipher(char*);
- void outreset(void);
- int outset(const char*,int*,const char*,const char*);
- static FILE* file_open(const char*,int*,const char*,const char*,FILE*);
- /*--------------------------------------------------------------------------*/
- extern struct ioctrl io;
- static FILE *fn; /* write file */
- /*--------------------------------------------------------------------------*/
- /* initio: initialize file encryption, etc
- */
- void initio(Where,Whence)
- int Where;
- FILE *Whence;
- {
- char *tag;
- tag = "''''";
- if (io.outcipher) /* if writing an encrypted file, */
- mprintf(Where,"%s\n",tag); /* mark it as encrypted */
- if (Whence){
- char buf[BUFLEN];
- if (!fgets(buf, BUFLEN, Whence)) /* if the first line deciphers to */
- return; /* the cipher tag, it is encrypted */
- io.incipher = YES; /* otherwise, */
- decipher(buf); /* rewind and read normally */
- if (strcmp(buf,tag) != 0){ /* mismatch */
- io.incipher = NO;
- (void)fseek(Whence,0L,SEEK_SET);
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /* decipher: un-encrypt a line of text in place
- */
- void decipher(buf)
- char *buf;
- {
- if (io.incipher){
- for ( ; isprint(buf[1]); buf++ ){
- int fixed;
- fixed = (int)buf[1] - (int)buf[0];
- while (!isascii(fixed) || !isprint(fixed))
- fixed += (0x7f-0x20);
- buf[0] = (char)fixed;
- }
- buf[0] = '\0';
- }
- }
- /*--------------------------------------------------------------------------*/
- /* outreset: close files and set i/o flags to standard values
- */
- void outreset()
- {
- xclose(&fn);
- xclose(&io.whence);
- io.where = io.formaat = 0;
- io.incipher = io.outcipher = io.pack = NO;
- if (io.echoflag)
- io.where |= io.mstdout;
- if (io.printflag)
- io.where |= io.mprint;
- }
- /*--------------------------------------------------------------------------*/
- /* outset: set up i/o for a command
- * return whether or not it did anything
- */
- int outset(cmd,cnt,inext,outext)
- const char *cmd;
- int *cnt;
- const char *inext, *outext;
- {
- int retcode = NO;
-
- for (;;){
- if (pmatch(cmd,cnt,"Printer")){
- io.where |= io.mprint;
- }else if (pmatch(cmd,cnt,"Noprint")){
- io.where &= ~io.mprint;
- }else if (pmatch(cmd,cnt,"Basic")){
- io.formaat = FMTEXP;
- }else if (pmatch(cmd,cnt,"Cipher")){
- io.outcipher = io.pack = YES;
- }else if (pmatch(cmd,cnt,"Pack")){
- io.pack = YES;
- }else if (pmatch(cmd,cnt,"Quiet")){
- io.where &= ~io.mstdout;
- }else if (pmatch(cmd,cnt,"Echo") || pmatch(cmd,cnt,"List")){
- io.where |= io.mstdout;
- }else if (outext && pmatch(cmd,cnt,"SAve")){
- fn = file_open(cmd,cnt,outext,"w",fn);
- io.where |= 1<<fileno(fn);
- }else if (outext && pmatch(cmd,cnt,">")){
- char *access;
- access = (pmatch(cmd,cnt,">")) ? "a" : "w";
- fn = file_open(cmd,cnt,outext,access,fn);
- io.where |= 1<<fileno(fn);
- io.formaat = FMTEXP;
- }else if (inext && pmatch(cmd,cnt,"<")){
- io.whence = file_open(cmd,cnt,inext,"r",io.whence);
- }else{
- break;
- }
- retcode = YES;
- }
- return retcode;
- }
- /*--------------------------------------------------------------------------*/
- /* file_open: a different interface for xopen
- */
- static FILE *file_open(cmd,cnt,ext,access,fileptr)
- const char *cmd, *ext, *access;
- int *cnt;
- FILE *fileptr;
- {
- xclose(&fileptr);
- fileptr = xopen(cmd,cnt,ext,access);
- if (!fileptr)
- error(bERROR, "");
- return fileptr;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/outtext.c'
- then
- echo shar: will not over-write existing file "'src/outtext.c'"
- else
- cat << \SHAR_EOF > 'src/outtext.c'
- /* outtext 10/08/91
- * Copyright 1983-1992 Albert Davis
- * output text to files, devices, or whatever
- * m???? = multiple output to a bunch of io devices.
- * with character count (so tab will work)
- * Will start a new line first if the entire output will not fit.
- * so wrap will not break a word or number.
- * Where is a bit mask of places to send the output.
- * A possible portability problem exists with the handle numbers.
- * It assumes they start at 0, and count up, and that there are no more than
- * the number of bits in an integer (MAXHANDLE).
- * but I have yet to find a system that did not meet this form.
- */
- #include "ecah.h"
- #include "io.h"
- #include "options.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void mtab(int,int);
- void mprintf();
- void mputs(const char*,int);
- void mputc(int,int);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern const struct options opt;
-
- int cpos[MAXHANDLE+1]; /* character counter */
- FILE *stream[MAXHANDLE+1]; /* reverse of fileno() */
- /*--------------------------------------------------------------------------*/
- /* mtab: tab to column "count" on output devices "where"
- * by outputting spaces.
- * If already beyond, start new line, then tab to column.
- */
- void mtab(count,where)
- int count;
- int where;
- {
- int ii,mm;
- for (ii=0, mm=1; ii<=MAXHANDLE; ++ii, mm<<=1){
- if (where & mm){
- if (cpos[ii] > count)
- mputc('\n',mm);
- while (cpos[ii]<count)
- mputc(' ',mm);
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /* mprintf: multiple printf
- * printf to "m" style files.
- */
- /*VARARGS2*/
- void mprintf(where,fmt,va_alist)
- int where;
- const char *fmt;
- va_dcl /* ; */
- {
- char buffer[BIGBUFLEN];
- va_list arg_ptr;
-
- va_start(arg_ptr);
- vsprintf(buffer,fmt,arg_ptr);
- va_end(arg_ptr);
-
- mputs(buffer,where);
- }
- /*--------------------------------------------------------------------------*/
- #ifdef ANSI /* ANSI C varargs (stdarg.h) */
- void mprintf(where,fmt)
- int where;
- char *fmt;
- {
- char buffer[BIGBUFLEN];
- va_list arg_ptr;
-
- va_start(arg_ptr,fmt);
- vsprintf(buffer,fmt,arg_ptr);
- va_end(arg_ptr);
-
- mputs(buffer,where);
- }
- #endif
- /*--------------------------------------------------------------------------*/
- /* mputs: multiple puts.
- * puts to "m" style files.
- * also....
- * starts new line, prefixes it with + if it would exceed width
- * width is handled separately for each file to support different widths
- * (which are not currently handled by .options)
- * and it is possible that current contents of lines may be different
- */
- void mputs(str,where)
- const char *str;
- int where;
- {
- int ii; /* file counter */
- int mm; /* file counter mask */
- int sl; /* length of output string */
- int newline; /* true if any destination is at beginning of line */
-
- newline = NO;
- sl = strlen(str);
- for (ii=0, mm=1; ii<=MAXHANDLE; ++ii, mm<<=1){
- if (where & mm && (sl+cpos[ii]) > opt.outwidth){
- mputc('\n',mm);
- mputc('+',mm);
- }
- if (cpos[ii]==0)
- newline = YES;
- }
- if (io.outcipher && newline)
- mputc('\t',where);
- while (*str)
- mputc(*str++,where);
- }
- /*--------------------------------------------------------------------------*/
- /* mputc: multiple putc
- * multiple putc
- * also....
- * crunch spaces, if selected
- * encripts, if selected
- * keeps track of character count
- */
- void mputc(chr,where)
- int chr;
- int where;
- {
- int ii,mm,suppress,count;
- static int old = '\0';
- static unsigned int cchr = 'w'; /* starting encryption seed */
- /* arbitrary printable character */
- if (chr=='\t'){
- chr = ' ';
- count = NO;
- }else{
- count = YES;
- }
-
- suppress = (io.pack && old==' ' && chr==' ');
- old = chr;
- if (io.outcipher && !suppress && isprint(chr)){
- cchr += (unsigned int)chr;
- while (!isascii(cchr) || !isprint(cchr))
- cchr -= (0x7f-0x20);
- chr = (char)cchr;
- }
-
- for (ii=0, mm=1; ii<=MAXHANDLE; ++ii, mm<<=1)
- if (where & mm){
- if (chr=='\b'){
- --cpos[ii];
- (void)fflush(stream[ii]);
- }else if (count){
- ++cpos[ii];
- }
- if (chr=='\n'){
- cpos[ii] = 0;
- (void)fflush(stream[ii]);
- #ifdef CRLF_FIX
- (void)fputc('\r',stream[ii]);
- #endif
- }else if (chr=='\r'){
- if (cpos[ii] == 0){
- suppress = YES;
- }else{
- cpos[ii] = 0;
- (void)fflush(stream[ii]);
- }
- }
- if (!suppress)
- (void)fputc(chr,stream[ii]);
- }
- if (chr=='\n')
- ccck();
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- # End of shell archive
- exit 0
-