/* testcall.c
  L. Stewart June 21, 1982  1:01 PM
 */

extern initpa();
extern wf();
extern wf1();
extern Call0();
extern Call1();
extern Call2();
extern apply();
extern chav();
extern getchar();

extern int pr1, pr2, pr3, pr4;

int argv[8];

main()
  {
  initpa();
  for (;;) {
    wf("straight calls\r");
    print(proc1());
    print(proc2(21));
    print(proc3(31, 32));
    print(proc4(41, 42, 43, 44, 45, 46));
    wf("calln\r");
    print(Call0(pr1));
    print(Call1(pr2, 21));
    print(Call2(pr3, 31, 32));
    wf("apply\r");
    print(apply(argv, pr1, 0));
    argv[0] = 21;
    print(apply(argv, pr2, 1));
    argv[0] = 31;
    argv[1] = 32;
    print(apply(argv, pr3, 2));
    argv[0] = 41;
    argv[1] = 42;
    argv[2] = 43;
    argv[3] = 44;
    argv[4] = 45;
    argv[5] = 46;
    print(apply(argv, pr4, 6));
    if (chav()) {
      getchar();
      getchar();
      };
    };
  };

print(x)
  int x;
  {
  wf1(" returns: %d\r", x);
  };

int proc1()
  {
  wf("p1");
  return(10);
  };

int proc2(a1)
  int a1;
  {
  wf1("p2,  one arg: %d", a1);
  return(20);
  };

int proc3(a1, a2)
  int a1, a2;
  {
  wf2("p3, two args: %d %d", a1, a2);
  return(30);
  };

int proc4(a1, a2, a3, a4, a5, a6)
  int a1, a2, a3, a4, a5, a6;
  {
  wf("p4, six args:");
  wf1(" %d", a1);
  wf1(" %d", a2);
  wf1(" %d", a3);
  wf1(" %d", a4);
  wf1(" %d", a5);
  wf1(" %d", a6);
  return(40);
  };