1: # include   "ctlmod.h"
   2: # include   <resp.h>
   3: # include   <sccs.h>
   4: 
   5: SCCSID(@(#)call_fn.c	8.1	12/31/84)
   6: 
   7: /*
   8: **  CALL_FN -- call a local function
   9: **
  10: **	This routine, given a pointer to a local function descriptor,
  11: **	calls the local function.
  12: **
  13: **	Parameters:
  14: **		fno -- function definition vector number.
  15: **		pc -- the parameter count
  16: **		pv -- the parameter vector, gets passed to the
  17: **			function.
  18: **
  19: **	Returns:
  20: **		none
  21: **
  22: **	Side Effects:
  23: **		Sets 'Resp' to the response vector for this function.
  24: **		The old 'Resp' is completely obliterated.
  25: **
  26: **	Trace Flags:
  27: **		3
  28: */
  29: 
  30: # ifdef xMONITOR
  31: struct monitor  MonBuf[CM_MAXST];
  32: # endif xMONITOR
  33: 
  34: call_fn(fno, pc, pv)
  35: int fno;
  36: int pc;
  37: PARM    **pv;
  38: {
  39:     register struct fn_def  *f;
  40:     register char       *gp;
  41:     register int        i;
  42: # ifdef xMONITOR
  43:     extern struct monitor   CmMonBuf;
  44:     struct monitor      mon;
  45:     struct monitor      *savemon;
  46:     extern char     *cvt_time();
  47: # endif
  48:     extern char     *Proc_name;
  49:     short           *tvect;
  50:     char            *oldname;
  51:     extern short        *tT;
  52:     extern char     *malloc();
  53: 
  54:     f = FuncVect[fno];
  55:     if (fno > NumFunc || f->fn_fn == NULL || fno < 0)
  56:         syserr("call_fn: undef fn %d", fno);
  57:     Ctx.ctx_fn = f;
  58: # ifdef xCTR1
  59:     if (tTf(3, 0))
  60:         lprintf("call_fn: fn %d (%s)\n", fno, f->fn_name);
  61: # endif
  62: 
  63:     /*
  64: 	**  Save function globals.
  65: 	**	If the function we want to call is already active,
  66: 	**	and if it has a global data area, allocate space
  67: 	**	and save that area.
  68: 	*/
  69: 
  70:     if (f->fn_active > 0 && f->fn_gptr != NULL)
  71:     {
  72:         /* save globals */
  73:         gp = malloc(f->fn_gsize);
  74:         bmove(f->fn_gptr, gp, f->fn_gsize);
  75:         Ctx.ctx_glob = gp;
  76:     }
  77:     else
  78:         Ctx.ctx_glob = gp = NULL;
  79: 
  80:     /*
  81: 	**  Clear the response vector to a known state and call
  82: 	**  the function.
  83: 	*/
  84: 
  85:     oldname = Proc_name;
  86:     Ctx.ctx_name = Proc_name = f->fn_name;
  87:     tvect = tT;
  88:     Ctx.ctx_tvect = tT = f->fn_tvect;
  89:     clrmem(&Resp, sizeof Resp);
  90:     Resp.resp_tups = -1;
  91:     markopen(&Ctx.ctx_ofiles);
  92: # ifdef xCTR2
  93:     if (tTf(3, 1))
  94:     {
  95:         lprintf("call_fn: calling %s\n", Proc_name);
  96:         prvect(pc, pv);
  97:     }
  98: # endif
  99: # ifdef xCTR3
 100:     if (tTf(3, 2))
 101:     {
 102:         lprintf("call_fn: Ctx.ctx_ppb ");
 103:         pb_dump(Ctx.ctx_ppb, FALSE);
 104:     }
 105: # endif xCTR3
 106: # ifdef xMONITOR
 107:     savemon = Ctx.ctx_mon;
 108:     Ctx.ctx_mon = &mon;
 109:     clrmem(&mon, sizeof mon);
 110:     markperf(&mon);
 111: # endif xMONITOR
 112: 
 113:     i = (*f->fn_fn)(pc, pv);
 114: 
 115: # ifdef xMONITOR
 116:     markperf(&CmMonBuf);
 117:     Ctx.ctx_mon = savemon;
 118:     if (savemon != NULL)
 119:         add_mon(&mon, savemon);
 120:     add_mon(&mon, &MonBuf[Ctx.ctx_ppb->pb_st]);
 121: # endif xMONITOR
 122: # ifdef xCTR1
 123:     if (tTf(3, 3))
 124:         lprintf("call_fn: returns %d\n", i);
 125: # endif
 126: # ifdef xMONITOR
 127:     if (tTf(0, 0))
 128:         printf("CPU time for %s = %s sec\n", Proc_name,
 129:                cvt_time(mon.mon_utime + mon.mon_stime));
 130: # endif xMONITOR
 131:     Resp.resp_resp = i;
 132:     closeall(TRUE, Ctx.ctx_ofiles);
 133: 
 134:     /*
 135: 	**  Restore old global memory, if there was any.
 136: 	*/
 137: 
 138:     if (gp != NULL)
 139:     {
 140:         bmove(gp, f->fn_gptr, f->fn_gsize);
 141:         Ctx.ctx_glob = NULL;
 142:         free(gp);
 143:     }
 144:     Ctx.ctx_name = Proc_name = oldname;
 145:     Ctx.ctx_tvect = tT = tvect;
 146: }

Defined functions

call_fn defined in line 34; used 1 times

Defined variables

MonBuf defined in line 31; used 1 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 660
Valid CSS Valid XHTML 1.0 Strict