/* ----------------------------------------------------------------
 *	xacts.c
 *
 *	this is a simple program to generate commands for
 *	testxlog to use. This is used in testing the spam code.
 * ----------------------------------------------------------------
 */

static char xacts_c[] = "$Header: xacts.c,v 1.2 89/02/02 17:00:08 dillon Exp $";

#include <stdio.h>

#define FUNCTION

/* ----------------------------------------------------------------
 *	usage examples
 *	========
 *	xacts 10 >! file	create 10 random commit commands
 *	xacts 100 s 1 >! file	create 100 commit commands starting
 *				at transaction id 1.
 * ----------------------------------------------------------------
 */

void FUNCTION
   usage(s)
char *s;
{
   printf("usage: %s <n> [s <y>]	generate <n> transaction cmds\n");
   printf("			 	  s == sequential staring at y\n");
   exit(0);
}
/* ----------------------------------------------------------------
 *	printcmd - print a specified commit command
 * ----------------------------------------------------------------
 */

void FUNCTION
   printcmd(s)
int s;
{
   printf("cp%d;\n", s);
}

/* ----------------------------------------------------------------
 *	randcmd	- print a random commit command
 * ----------------------------------------------------------------
 */

void FUNCTION
   randcmd()
{
   long l;
   unsigned short *i = (unsigned short *) &l;

   l = random();
   printf("cp%d;\n", *i);
}

/* ----------------------------------------------------------------
 *	main
 * ----------------------------------------------------------------
 */

void FUNCTION
   main(ac, av)
int ac;
char **av;
{
   int i, n;

   if (ac < 2)
      usage(av[0]);

   n = atoi(av[1]);
	    
   if (ac < 4) 
      for (i=0; i<n; i++)
	 randcmd();
   else if (av[2][0] == 's') {
      int s;
      s = atoi(av[3]);
      for (i=0; i<n; i++)
	 printcmd(i+s);
   }
      
}

     
