MODULE LOGF1 (NUM, STRING, STRING) (NUM, NUM);
MODULE SH (STRING) (STRING);
MODULE KILL () (STRING, NUM);
MODULE GETPIDBYNAME () (STRING);
MODULE VAR (NUM) ();
MODULE LOG (NUM, STRING) (NUM, STRING);

STACKSIZE   1024;
STACKPOLICY GROW;

SYSTEM: spork
{
  VAR blorf (0);
  SH msh("/bin/sh");
  LOG syslog (0, "");

  SIGUSR1 { syslog (7, "User signal 1!"); }
  SIGUSR2 { syslog (6, "User signal 2!"); }

  PROC shmorky
  {
    blorf = -50;
    IF (blorf < 0 || blorf >= -80 || blorf <= -50 || blorf == 10)
      RETURN TRUE;
    ELSE
      RETURN FALSE;
    ENDIF;
  }

  PROCESS spork 100: fsys
  {
    LOG logfile (0, "");
    LOGF1 logtmp (0, "shmorky", "tmp is %s");
    VAR tmp (0);

    START   { msh ("/bin/spork"); }
    RESTART { msh ("/bin/spork"); }
    SIGCHLD { syslog (5, "I die!"); }

    ISUP 500 { spork = GETPIDBYNAME ("spork"); }
    DEPENDFAIL { KILL ("SIGTERM", spork()); }
    PROC mathtest 1000
    {
      logfile(2, "I am escaping the \" character!");
      logfile(4, "Now I am escaping the ) character\n(without even knowing it!)");
      IF (shmorky)
        logfile(5, "Shmorky!");
      ENDIF;

      tmp = 5;
      blorf = 9;
      LOOP (tmp - 2) // 3 times
        logtmp (8, tmp);
        tmp = tmp - 1;
        LOOP (2)
          logtmp(4, blorf);
          blorf = blorf + 1;
          LOOP (-10)
            logfile (9, "This will never be shown!");
          ENDLOOP;
        ENDLOOP;
      ENDLOOP;

      tmp = 50;
      tmp = tmp() + ((2 * 10) / 5) - 3;
      IF (tmp > 50 && tmp == 51)
        logfile (5, "tmp == 51!");
        RETURN TRUE;
      ELSE
        tmp = 5;
        logfile (tmp, "tmp is not 51!");
        RETURN FALSE;
      ENDIF;

    }  
  }

  PROCESS fsys 100:
  {
    START { fsys = GETPIDBYNAME ("devb-eide"); }
    RESTART { fsys = msh ("/sbin/devb-eide"); }
  }
}

