home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / education / n / spice / docs / FTE / LPR / FRONTEND next >
Encoding:
Text File  |  1988-01-27  |  24.0 KB  |  1,321 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.                         CHAPTER  1
  11.  
  12.  
  13.                         Front End
  14.  
  15.  
  16.  
  17.  
  18.      Note: there is a lot in this section that is  out  of
  19.  
  20. date,  but  the  code  is in such a condition that it will
  21.  
  22. have to be cleaned up a great deal before I can update the
  23.  
  24. documentation...
  25.  
  26.  
  27.      The SPICE3 front end (FTE) is designed to  be  easily
  28.  
  29. adaptable  to different programs. There are several impor-
  30.  
  31. tant parts: the "C-shell parser", which  handles  aliases,
  32.  
  33. history,  and  the other csh-type functions, which is com-
  34.  
  35. pletely modular and may easily be  used  with  other  pro-
  36.  
  37. grams;  the  routines for the various commands; the parser
  38.  
  39. for algebraic expressions; the expression evaluation  rou-
  40.  
  41. tines;  the  complex  math routines; and the plotting rou-
  42.  
  43. tines.
  44.  
  45.  
  46.      The global front-end routines and variables  are  all
  47.  
  48. prefixed  with these characters (there are some exceptions
  49.  
  50. in "std.c"):
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                          1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.                                                          2
  74.  
  75.  
  76.     com_    Front-end command routines
  77.     cp_     C-shell parser routines and variables
  78.     cx_     Complex math routines
  79.     dg_     Diagnostic stuff like stack backtrace routines
  80.     ft_     General front-end routines and variables
  81.     gr_     Graphics routines
  82.     if_     SPICE3 interface routines
  83.     inp_    Input routines
  84.     sp_     SPICE3 variables
  85.     wl_     Routines to do wordlist manipulation
  86.     wl_     Wordlist manipulation routines
  87.     wrd_    Routines in the writedata package
  88.  
  89.  
  90.  
  91. 1.1.  Csh Parser
  92.  
  93.  
  94.      The C-shell parser (cshpar) does  aliasing,  history,
  95.  
  96. quoting,  backquote  evaluation, globbing (expansion of *,
  97.  
  98. ?, ~, {}, and []), filename, command, and keyword  comple-
  99.  
  100. tion,  and  IO redirection. It is supposed to function the
  101.  
  102. same way that the C-shell does, so unless otherwise  noted
  103.  
  104. the  C  Shell  User's  Manual  should be consulted for the
  105.  
  106. details of how these operate.
  107.  
  108.  
  109.      To use  cshpar,  the  file  "FTEcshpar.h"  should  be
  110.  
  111. included.  The host program then must call
  112.  
  113.  
  114.     cp_parse(string);
  115.  
  116.  
  117. If string is non-NULL then the string  will  be  used  for
  118.  
  119. input instead of the current input file.  This will return
  120.  
  121. a doubly-linked list of words in the following format:
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.                                                          3
  140.  
  141.  
  142.     typedef struct wordlist {
  143.             char *wl_word;                  /* The word. */
  144.             struct wordlist *wl_next;               /* Forward link. */
  145.             struct wordlist *wl_prev;               /* Backward link. */
  146.     } wordlist;
  147.  
  148.  
  149. The list will be what the user typed, after alias  substi-
  150.  
  151. tutions, etc.  The user must supply two routines:
  152.  
  153.  
  154.     cp_userset(var, isset)
  155.             struct variable *var;
  156.             bool isset;
  157.  
  158.  
  159. which cshpar calls if a  variable  that  it  doesn't  know
  160.  
  161. about  gets  set (it knows about such variables as prompt,
  162.  
  163. noglob, history, and verbose).  The isset argument is true
  164.  
  165. (bool is typedef'd as char, with true = (char) 1 and false
  166.  
  167. = (char) 0) if the variable has been set, and false if the
  168.  
  169. variable has been unset.  If the host program doesn't care
  170.  
  171. about any variables, the function can just be a dummy rou-
  172.  
  173. tine. Also required is
  174.  
  175.  
  176.     struct variable
  177.     cp_enqvar(word)
  178.             char *word;
  179.  
  180.  
  181. which gets called when cshpar doesn't know about  a  vari-
  182.  
  183. able  mentioned  -  if the host program doesn't know about
  184.  
  185. the variable either it should return NULL.
  186.  
  187.  
  188.      The definition for the variable structure is
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.                                                          4
  206.  
  207.  
  208.     struct variable {
  209.             char va_type;           /* The type (see below). */
  210.             char *va_name;          /* The variable name. */
  211.             union {                 /* The value of the variable. */
  212.                     bool vV_bool;
  213.                     long vV_num;
  214.                     double vV_real;
  215.                     char *vV_string;
  216.                     struct variable *vV_list;
  217.             } va_V;
  218.             struct variable *va_next;               /* Forward link. */
  219.             struct variable *va_prev;               /* Backward link. */
  220.     } ;
  221.  
  222.     #define va_bool         va_V.vV_bool
  223.     #define va_num          va_V.vV_num
  224.     #define va_real         va_V.vV_real
  225.     #define va_string               va_V.vV_string
  226.     #define va_list         va_V.vV_list
  227.  
  228.     #define VT_BOOL         1
  229.     #define VT_NUM          2
  230.     #define VT_REAL         3
  231.     #define VT_STRING               4
  232.     #define VT_LIST         5
  233.  
  234.  
  235.  
  236.      In addition to these entry points,  the  behavior  of
  237.  
  238. cshpar can be changed with the routine
  239.  
  240.  
  241.     cp_modify(c, what)
  242.             char c;
  243.  
  244.  
  245. where what is one of:
  246.  
  247.  
  248.     #define CPM_REGC        1       /* Character made non-special to the parser. */
  249.     #define CPM_DEF 2       /* Character restored to default meaning. */
  250.     #define CPM_BRR 3       /* Break to right of character. */
  251.     #define CPM_BRL 4       /* Break to left of character. */
  252.     #define CPM_ALONE       5       /* Make character a single word. */
  253.     #define CPM_NOBRK       6       /* Don't break at character. */
  254.     #define CPM_NOAL        7       /* No aliasing. */
  255.     #define CPM_AL  8       /* Aliasing. */
  256.     #define CPM_INTER       9       /* Interactive mode. */
  257.     #define CPM_NOINTER 10  /* Noninteractive mode (sources, etc). */
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.                                                          5
  272.  
  273.  
  274. and c is a character, if one is required. (Otherwise it is
  275.  
  276. ignored.)  Making a character non-special usually prevents
  277.  
  278. some action from being carried out -- for instance, making
  279.  
  280. the   character  *  non-special  prevents  it  from  being
  281.  
  282. expanded into filenames. This is done with SPICE3,  as  it
  283.  
  284. is  used  for multiplication. Setting non-interactive mode
  285.  
  286. prevents a prompt from being  displayed  and  command  and
  287.  
  288. keyword  completion  from being done.  To do a source, one
  289.  
  290. would set non-interactive mode with
  291.  
  292.  
  293.     cp_modify((char) 0, CPM_NOINTER);
  294.  
  295.  
  296. and the change the FILE pointer cp_curinput to the desired
  297.  
  298. input  stream. When cp_parse returns NULL, then the end of
  299.  
  300. file has been reached and cp_curinput should be  reset  to
  301.  
  302. whatever it was before.
  303.  
  304.  
  305.      The characters that are used for  the  various  func-
  306.  
  307. tions generally may be changed: the variables (all char's)
  308.  
  309. containing them are as follows:
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.                                                          6
  338.  
  339.  
  340.             Function        Variable        Default
  341.  
  342.             history         cp_bang         !
  343.             substitute      cp_hat          ^       (this is , in the front end)
  344.             variables       cp_dol          $
  345.             wildcard        cp_star         *
  346.             wildcard        cp_huh          ?
  347.             wildcard        cp_obrac        [
  348.             wildcard        cp_cbrac        ]
  349.             home directory  cp_til  ~
  350.             expansion       cp_ocurl        {
  351.             expansion       cp_ccurl        }
  352.             expansion       cp_comma        ,
  353.             input redirect  cp_lt           <
  354.             output redirect cp_gt           >
  355.             error redirect  cp_amp          &
  356.             comment         cp_hash         #       (this is * in the front end)
  357.  
  358.  
  359. If the variable noglob is set, this inhibits expansion  of
  360.  
  361. the wildcard characters *, ?, [, and ].
  362.  
  363.  
  364.      If the host program wants to take advantage of the IO
  365.  
  366. redirection  features  of the front-end, it should use the
  367.  
  368. FILE pointers cp_in, cp_out, and cp_err instead of  stdin,
  369.  
  370. stdout, and stderr. These are reset every time cp_parse is
  371.  
  372. called.  Whenever the user uses '>' or '<', the  appropri-
  373.  
  374. ate  file  is  opened and the cp_ FILE pointers are set to
  375.  
  376. that file.
  377.  
  378.  
  379.      A few routines are available for setting  and  unset-
  380.  
  381. ting  aliases, setting and unsetting variables, and print-
  382.  
  383. ing history, aliases, and variables:
  384.  
  385.  
  386.     cp_setalias(word, substitute)
  387.             char *word;
  388.             wordlist *substitute;
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.                                                          7
  404.  
  405.  
  406.      The substitute list may contain history  substitution
  407.  
  408. characters, which operate on the current argument list.
  409.  
  410.  
  411.     cp_unalias(word)
  412.             char *word;
  413.  
  414.  
  415. If word has an alias then it is removed.
  416.  
  417.  
  418.     cp_vset(varname, type, value)
  419.             char *varname;
  420.             char *value;
  421.  
  422.  
  423. The variable called varname with the type  type  (see  the
  424.  
  425. VT_ defines above) is set to the value pointed to by value
  426.  
  427. (of whatever type is specified by the type argument.)
  428.  
  429.  
  430.     cp_getvar(name, type, value)
  431.             char *name;
  432.             char *value;
  433.  
  434.  
  435. The value of the variable with the given name and type  is
  436.  
  437. stored in the object pointed to by value.  Value should be
  438.  
  439. an array of char's is type is VT_STRING, an int * if it is
  440.  
  441. VT_NUM,  and  so  forth. If the variable is defined with a
  442.  
  443. different type, it is converted to  the  desired  type  if
  444.  
  445. possible.
  446.  
  447.  
  448.     cp_remvar(varname)
  449.             char *varname;
  450.  
  451.  
  452. If there is a variable called varname then it is deleted.
  453.  
  454.  
  455.     cp_vprint()
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.                                                          8
  470.  
  471.  
  472. Print the values of all the variables currently defined.
  473.  
  474.  
  475.     cp_paliases(name)
  476.             char *name;
  477.  
  478.  
  479. Print the alias associated with name, or  all  aliases  if
  480.  
  481. the name is NULL.
  482.  
  483.  
  484.     cp_hprint(eventhi, eventlo)
  485.  
  486.  
  487. Print the history  from  event  number  eventhi  to  event
  488.  
  489. number eventlo.
  490.  
  491.  
  492.     cp_addcomm(word, keywords, filec)
  493.             char *word;
  494.             wordlist *keywords;
  495.             bool filec;
  496.  
  497.  
  498. Add the command word to the list used for command  comple-
  499.  
  500. tion.   If  keywords  is  non-NULL then these keywords are
  501.  
  502. used for keyword completion for this command, in  addition
  503.  
  504. to  the  global keyword list, which is cp_keywords (also a
  505.  
  506. wordlist, which the host program may alter at  any  time).
  507.  
  508. If  the  filec  argument  is true, then instead of keyword
  509.  
  510. completion, filename and user name completion is done  for
  511.  
  512. this  command.  There  is no way to specifiy certain argu-
  513.  
  514. ments as being filenames and  certain  ones  as  keywords,
  515.  
  516. etc.   The  keyword  lists  and file completion flags will
  517.  
  518. also work when a command is aliased, but not through  his-
  519.  
  520. tory substitutions (yet).
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.                                                          9
  536.  
  537.  
  538.      When EOF (control-D) is typed, then cshpar prints out
  539.  
  540. the alternatives that the user may type at this point, and
  541.  
  542. when escape is typed then cshpar attempts to  complete  as
  543.  
  544. much of the command, keyword, or filename already typed as
  545.  
  546. it can.
  547.  
  548.  
  549.     cp_remcomm(word)
  550.             char *word;
  551.  
  552.  
  553. Remove word from the list of commands  that  may  be  com-
  554.  
  555. pleted, if it is there.
  556.  
  557.  
  558.     cp_addkword(word)
  559.             char *word;
  560.  
  561.  
  562. Add a keyword to the default list of keywords for  keyword
  563.  
  564. completion.  These are in addition to keywords specific to
  565.  
  566. particular commands.
  567.  
  568.  
  569.     cp_addkword(word)
  570.             char *word;
  571.  
  572.  
  573. Remove the keyword from the default list, if it is there.
  574.  
  575.  
  576.      There are several  commands  that  the  host  program
  577.  
  578. should  recognise and call the proper routines for -- they
  579.  
  580. all take wordlists as arguments (the cdr of  the  wordlist
  581.  
  582. returned by cp_parse) and are as follows:
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.                                                         10
  602.  
  603.  
  604.             Name    Function
  605.  
  606.             set     cp_cset
  607.             unset   cp_cunset
  608.             alias   cp_calias
  609.             unalias cp_cualias
  610.             history cp_chistory
  611.             echo    cp_cecho
  612.  
  613.  
  614.  
  615.      One note about using cshpar -- if you type a word  as
  616.  
  617. "word",  it  will  be returned by cp_parse with the quotes
  618.  
  619. on, so you should always use cp_unquote() with  it.  (This
  620.  
  621. doesn't  happen with single-quoted arguments -- the reason
  622.  
  623. it is useful with double quotes is to be able  to  distin-
  624.  
  625. guish  between strings and numbers if they are written the
  626.  
  627. same.) The way that cshpar quotes characters  with  single
  628.  
  629. quotes  and  backslashes  is by turning on the eighth bit,
  630.  
  631. which is unfortunately slightly non-portable but is pretty
  632.  
  633. easy to deal with...
  634.  
  635.  
  636. 1.2.  The Basic Command Interpreter
  637.  
  638.  
  639.      The front end maintains a list of the commands avail-
  640.  
  641. able  to  it  --  there is a array called Coms in the file
  642.  
  643. "front.c" of the following structures:
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.                                                         11
  668.  
  669.  
  670.     struct comm {
  671.             char *co_comname;       /* The name of the command. */
  672.             int (*co_func) ();      /* The function that handles the command. */
  673.             bool co_stringargs;     /* Collapse the arguments into a string. */
  674.             bool co_spiceonly;      /* These can't be used from nutmeg. */
  675.             bool co_filec;          /* Do filename completion. */
  676.             int co_minargs;         /* Minimum number of args. */
  677.             int co_maxargs;         /* Maximum number of args. */
  678.             char *co_help;  /* A short help string. */
  679.     } ;
  680.  
  681.  
  682. If the co_stringargs field is true, then the function will
  683.  
  684. be  passed its arguments in a string, otherwise it will be
  685.  
  686. passed a wordlist. If co_spiceonly is true and the program
  687.  
  688. that  is being run is nutmeg, then the command will not be
  689.  
  690. executed, as it is  SPICE3-specific.   The  help  function
  691.  
  692. prints the help string with
  693.  
  694.  
  695.     printf(helpstring, ft_program);
  696.  
  697.  
  698. where ft_program is a global string containing the name of
  699.  
  700. the current program (argv[0]), so the help string may con-
  701.  
  702. tain a "%s" in the place of the program name.
  703.  
  704.  
  705.      Any routines that are added to the front end  may  be
  706.  
  707. made  usable  simply  by  adding  an  entry to the ft_coms
  708.  
  709. array. (Also, if there are any special keywords  for  this
  710.  
  711. command,   see   the  stuff  in  the  function  cpinit  in
  712.  
  713. "front.c". This isn't well done, because it is there  just
  714.  
  715. to show off keyword completion.)
  716.  
  717.  
  718.      If any options are added to SPICE3 (which go  on  the
  719.  
  720. .options  card),  its  name,  type, and code number (as in
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.                                                         12
  734.  
  735.  
  736. PARMdefs.h)  should  be  added  to  the  opts   array   in
  737.  
  738. spiceonly.c.
  739.  
  740.  
  741.      SPICE3 data is stored in the front end in  two  ways.
  742.  
  743. First,  there  is the spicedata format, which is more like
  744.  
  745. the way the data is saved in files (the data arrays are by
  746.  
  747. points  instead of vectors, as this is the way SPICE3 out-
  748.  
  749. puts them), and is used only in the  file  "format.c"  and
  750.  
  751. routines like write and load.
  752.  
  753.  
  754.      The more usual format is defined in "FTEdata.h":
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.                                                         13
  800.  
  801.  
  802.     struct dvec {
  803.             char *v_name;           /* The name of the vector. */
  804.             int v_type;             /* The vector type (see FTEspicedata.h) */
  805.             short v_flags;          /* Flags: */
  806.  
  807.     #define VF_REAL         000001  /* The data is complex. */
  808.     #define VF_COMPLEX      000002  /* The data is real. */
  809.     #define VF_UPLIM        000004  /* An upper limit is in effect (see below). */
  810.     #define VF_LOWLIM       000010  /* A lower limit is in effect. */
  811.     #define VF_ACCUM        000020  /* writedata() should accumulate this vector. */
  812.     #define VF_PLOT         000040  /* writedata() should incrementally plot it. */
  813.     #define VF_PRINT        000100  /* writedata() should print this vector. */
  814.  
  815.             union {
  816.                     double *vU_realdata;
  817.                     complex *vU_compdata;
  818.             } v_U;                  /* The actual data. */
  819.  
  820.     #define v_realdata      v_U.vU_realdata
  821.     #define v_compdata      v_U.vU_compdata
  822.  
  823.     #define isreal(v)       ((v)->v_flags & VF_REAL)
  824.     #define iscomplex(v)    ((v)->v_flags & VF_COMPLEX)
  825.  
  826.             int v_length;           /* Length of the vector. */
  827.             int v_rlength;          /* How much space we really have. */
  828.             double v_yhi;           /* The upper and lower y limits, if this */
  829.             double v_ylo;           /* is a dvec to be plotted. */
  830.             int v_outindex;         /* Index if writedata is building the vector. */
  831.             int v_linestyle;                /* What line style we are using. */
  832.             int v_color;            /* What color we are using. */
  833.             bool v_permanent;               /* Don't garbage collect this dvec. */
  834.  
  835.             struct plot *v_plot;    /* The plot structure (if it has one). */
  836.             struct dvec *v_next;    /* Forward link. */
  837.             struct dvec *v_link2;   /* Extra link for use with some commands. */
  838.     } ;
  839.  
  840.  
  841. All the dvecs that are available are linked together under
  842.  
  843. ft_plots,  which  correspond  to seperate SPICE3 runs. The
  844.  
  845. current plot is where vectors are searched  for  first  by
  846.  
  847. name,  and  is  pointed to by the variable ft_curplot. The
  848.  
  849. plot structure is as follows:
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.                                                         14
  866.  
  867.  
  868.     struct plot {
  869.             char *pl_title;         /* The title card. */
  870.             char *pl_date;          /* Date. */
  871.             char *pl_name;          /* The plot name. */
  872.             struct dvec *pl_dvecs;  /* The data vectors in this plot. */
  873.             struct dvec *pl_scale;  /* The "scale" for the rest of the vectors. */
  874.             struct plot *pl_next;   /* List of plots. */
  875.             wordlist *pl_commands;  /* Commands to execute when this plot is set. */
  876.     } ;
  877.  
  878.  
  879. In order to  get  a  dvec,  given  a  name,  the  function
  880.  
  881. ft_vecbyname(name),  where name is the name of the desired
  882.  
  883. vector, is used. This tries to find the named vector,  and
  884.  
  885. if it can't it then tried "V(name)" and "I(name)". It lim-
  886.  
  887. its the search to the current plot.
  888.  
  889.  
  890. 1.3.  Functions
  891.  
  892.  
  893.      There is a table of data on the  available  functions
  894.  
  895. in the file psubr.c, of the form:
  896.  
  897.  
  898.     struct func {
  899.             char *fu_name;                  /* The print name of the function. */
  900.             complex *(*fu_func)();          /* The function. */
  901.     } ;
  902.  
  903.  
  904. When an expression like sin (foo) is parsed, the  routines
  905.  
  906. in  psubr.c  try  to  find  a  function in the funcs table
  907.  
  908. called sin. If there is one, then a function node is added
  909.  
  910. to  the parse tree (see FTEparse.h), but if there is none,
  911.  
  912. then a vector named sin(foo) is checked for.   Also  if  a
  913.  
  914. name  of the form type(name) is given, where type can be V
  915.  
  916. or I, a vector with name name will match.   When  a  parse
  917.  
  918. tree  is  evaluated with the function evaluate(parsenode),
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.                                                         15
  932.  
  933.  
  934. and a function  node  is  encountered,  then  the  routine
  935.  
  936. apply_func applies the appropriate complex math routine to
  937.  
  938. each point of the data vector to obtain the new vector.
  939.  
  940.  
  941.      To add a new function, it is necessary to add a  func
  942.  
  943. structure  to the above array, and add the function refer-
  944.  
  945. enced by fu_func to "cmath.c".
  946.  
  947.  
  948.      Complex math functions are called  in  the  following
  949.  
  950. manner:
  951.  
  952.  
  953.             char *
  954.             cx_function (data, type, length, newlength, newtype)
  955.                     char *data;
  956.                     short type;
  957.                     int length;
  958.                     int *newlength;
  959.                     short *newtype;
  960.  
  961.  
  962. The function should cast data to either double *  or  com-
  963.  
  964. plex   *,   depending   on  whether  type  is  VF_REAL  or
  965.  
  966. VF_COMPLEX. It should set *newtype likewise, depending  on
  967.  
  968. what  the  result  of its application will be, and also it
  969.  
  970. should set *newlength to the length of the  result.  There
  971.  
  972. are  three  types  of  functions defined so far - the sort
  973.  
  974. that operate pointwise, where  *newlength  =  length,  the
  975.  
  976. sort  that  take  a  scalar  and  return  a  vector,  like
  977.  
  978. cx_vector, where *newlength  =  something  independent  of
  979.  
  980. length,  and  the  sort  that  take  a vector and return a
  981.  
  982. scalar, like cx_mean, where *newlength = 1.
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.                                                         16
  998.  
  999.  
  1000. 1.4.  Operations
  1001.  
  1002.  
  1003.      Operations are done in much the same way  as  complex
  1004.  
  1005. functions  are done. The routine doop(func_name, function,
  1006.  
  1007. arg1, arg2), where function is a  pointer  to  a  function
  1008.  
  1009. returning  a  char * and arg1 and arg2 are dvecs, is used.
  1010.  
  1011. Complex functions are called as follows:
  1012.  
  1013.  
  1014.             char *
  1015.             cx_operation (data1, data2, type1, type2, length)
  1016.                     char *data1, data2;
  1017.                     short type1, type2;
  1018.  
  1019.  
  1020. Vectors that are operated on are made the same length. The
  1021.  
  1022. result is assumed to be of the same length as the operands
  1023.  
  1024. and its type is complex if either of the operands is  com-
  1025.  
  1026. plex.   (The  exception  to  this  is the comma operator.)
  1027.  
  1028. Adding new operations requires changing the ops  table  in
  1029.  
  1030. "psubr.c",  adding  the relevant information to the parser
  1031.  
  1032. (the files "parse.c" and "getpname.c),  adding  a  routine
  1033.  
  1034. like  the  ones in "evaluate.c", and perhaps adding a com-
  1035.  
  1036. plex function to "cmath.c".  The format of the  ops  table
  1037.  
  1038. is:
  1039.  
  1040.  
  1041.     struct op {
  1042.             int op_num;                     /* From parser #defines. */
  1043.             char *op_name;                  /* Printing name. */
  1044.             char op_arity;                  /* One or two. */
  1045.             struct dvec *(*op_func)();      /* The function to do the work. */
  1046.     }
  1047.  
  1048.  
  1049. These functions are actually  dummy  functions  that  call
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.                                                         17
  1064.  
  1065.  
  1066. doop() directly.
  1067.  
  1068.  
  1069.      The parser is a simple operator-precedence parser.
  1070.  
  1071.  
  1072. 1.5.  Plotting Routines
  1073.  
  1074.  
  1075.      The plotting routines use MFB, the Model Frame Buffer
  1076.  
  1077. graphics package. The main stuff is in the file "graf.c".
  1078.  
  1079.  
  1080. 1.6.  Using The Front End With Other Programs
  1081.  
  1082.  
  1083.      The front end  may  be  adapted  to  use  with  other
  1084.  
  1085. circuit-simulation  programs  besides  SPICE3 without much
  1086.  
  1087. difficulty. See the manual page for writedata for  details
  1088.  
  1089. on  how  to  use  this set of routines seperately from the
  1090.  
  1091. rest of the front-end.
  1092.  
  1093.  
  1094.      All SPICE3-specific code is in the file  "spiceif.c".
  1095.  
  1096. The  following  routines  are  defined,  and should be re-
  1097.  
  1098. written for another simulator.  In  general,  pointers  to
  1099.  
  1100. circuits  are  kept  as char *'s, and are only cast to the
  1101.  
  1102. appropriate thing  (CKTcircuit  *'s  for  SPICE3)  in  the
  1103.  
  1104. interface routines.
  1105.  
  1106.  
  1107.     if_run(ckt, what)
  1108.             char *ckt;
  1109.             char *what;
  1110.  
  1111.  
  1112.  
  1113.      This runs a simulation of the circuit.  The  type  of
  1114.  
  1115. simulation  is  determined  by the string what - in SPICE3
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.                                                         18
  1130.  
  1131.  
  1132. the possibilities are "tran", "ac", "dc", "op", "run", and
  1133.  
  1134. "continue" (continue the run that is already in progress).
  1135.  
  1136. XXXXXXXXXXXX
  1137.  
  1138.  
  1139.     if_dump(ckt, fp)
  1140.             char *ckt;
  1141.             FILE *fp;
  1142.  
  1143.  
  1144.  
  1145.      Do a "dump" of the current circuit - with SPICE3  now
  1146.  
  1147. this  is  just a listing of what SPICE3 thinks the circuit
  1148.  
  1149. looks like.
  1150.  
  1151.  
  1152.     if_inpline(ckt, line)
  1153.             char *ckt;
  1154.             char *line;
  1155.  
  1156.  
  1157.  
  1158.      Parse the given line and add it to the circuit. Since
  1159.  
  1160. the  INP  parser  is  incremental this it is possible with
  1161.  
  1162. SPICE3 to add lines to the circuit at any point.
  1163.  
  1164.  
  1165.     char *
  1166.     if_inpdeck(deck)
  1167.             struct card *deck;
  1168.  
  1169.  
  1170.  
  1171.      The card structure, as defined in "FTEinput.h" is  as
  1172.  
  1173. follows:
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.                                                         19
  1196.  
  1197.  
  1198.     struct card {
  1199.             int ca_linenum;
  1200.             char *ca_line;
  1201.             char *ca_error;
  1202.             struct card *ca_next;
  1203.             struct card *ca_actual;
  1204.     } ;
  1205.  
  1206.  
  1207. The complete deck is passed to this routine, which has  it
  1208.  
  1209. parsed and returns a pointer to the circuit structure. See
  1210.  
  1211. the chapter in the INP parser for the details of  how  the
  1212.  
  1213. card structure works.
  1214.  
  1215.  
  1216.     if_option(ckt, name, type, value)
  1217.             char *ckt;
  1218.             char *name;
  1219.             int type;
  1220.             char *value;
  1221.  
  1222.  
  1223.  
  1224.      Add an option to the circuit.  The  name,  type,  and
  1225.  
  1226. value  arguments  are the same as the corresponding fields
  1227.  
  1228. in the variable structure.  If the routine can't  use  the
  1229.  
  1230. option it should just return.
  1231.  
  1232.  
  1233.     if_cktfree(ckt)
  1234.             char *ckt;
  1235.  
  1236.  
  1237.  
  1238.      Free the data occupied by the circuit. This may be  a
  1239.  
  1240. no-op, of course.
  1241.  
  1242.  
  1243.     char *
  1244.     if_errstring(code)
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.                                                         20
  1262.  
  1263.  
  1264.      If code is a number that denotes a particular  SPICE3
  1265.  
  1266. error,  this routine should return a string describing the
  1267.  
  1268. error.
  1269.  
  1270.  
  1271.      Additionally, there is some code  in  "subckt.c"  and
  1272.  
  1273. "fourier.c" that refers to SPICE3 routines, but subcircuit
  1274.  
  1275. expansion can be easily disabled and the file  "CKTfour.c"
  1276.  
  1277. taken from SPICE3 for use with the front-end.
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.