/*
 *    SCCS ID: %Z%%M% %I% %E% SST
 *
 *    Copyright (c) 1992 Mark Soloway.  All rights reserved.
 *    See SST_LEGAL_NOTICE file for terms of the license.
 */

#include <unistd.h>

#include "TTC.h"

void main (int /* argc */, char ** /* argv */)
{
  static int accumulation = 0;

  int        mark;
  TTMessage *message;
  Tt_status  status;
  TTSession  session (TT_X_SESSION, NULL, status);
  int        value;

  if (status == TT_OK)
    status = session.declarePType ("Accumulator");

  while (status == TT_OK) {
    mark = tt_mark ();
    message = session.waitForMessage (status);  

    if (status == TT_OK) {
      status = message->getArgValue (0, value);
      if (status == TT_OK) {
        accumulation += value;
        status = message->setArgValue (0, accumulation);

        if (status == TT_OK) {
          status = session.replyToMessage (*message);
        }
      }
    }

    if (message) delete message;
    tt_release (mark);
  }

  printf ("ToolTalk error: %d\n", status);
  exit (0);
}
