/*
 * process.c
 * pieces to process single events along the timeline
 * [eichin:19880330.1915EST]
 */


#include <msimdecl.h>

process_event(chg)		/* chg is the wire that changed */
     Wire chg;
{
  Wire achg = chg;
  Deps pdeps;
  Timeline tmpline;
  
  
  find_item(achg, WIRE, FUTURE);
  tmpline = achg->data.WIRE.future;
  START(tmpline);

  achg = chg;
  find_item(achg, WIRE, NOW);
  INC((achg->data.WIRE.now));	/* bump up NOW to real one */
  
  achg = chg;
  find_item(achg, WIRE, THEN);
  INC((achg->data.WIRE.then));	/* bump up THEN to next one */
  
  achg = chg;
  find_item(achg, WIRE, DEPENDS);
  pdeps = achg->data.DEPS.generics;

  START(pdeps);
  while(pdeps->tag.CTL != END)
    {
      Generics tdep = pdeps->data.DEPS.generics;
      PFI funn;

      START(tdep);
      ASSERT(tdep->tag.GENERIC == FUNC);
      
      funn = tdep->data.GENERIC.genfunc;
      INC(tdep);
      
      funn(tdep);
      INC(pdeps);
    }
}

Wire find_named_wire();
Event_tag named_event();

#define LOWTIME 0
#include <string.h>

process_file(chg, wl)
     WFileptr chg;
     Wirelist wl;
{
  char buf[BUFSIZ], *inbf;
  Wire awr;
  Timeline atl;

  if(!chg->filedesc)		/* error trap for bad filedesc */
    {
      chg->next = LOWTIME;	/* so we don't get called again */
      return;
    }
  for(;;) {
    if(!fgets(buf, BUFSIZ, chg->filedesc))
      {
	chg->next = LOWTIME;
	break;
      }
    if(!strncmp(buf, "wait", 4))
      {
	chg->next += atoi(&buf[4]);
	break;
      }
    inbf = strchr(buf, ' ');
    *(inbf++) = '\0';
    awr = find_named_wire(buf, wl);
    find_item(awr, WIRE, FUTURE);
    atl = awr->data.WIRE.future;
    add_event(atl, named_event(inbf), chg->next);
  };
}
