/* ecmfeed.m
   Feeder source example for elliptic curve method (ECM).
   Compile with:
   
   > cc -O ecmfeed.m Feeder.o -s -o ecm.feed
   
   Then the executable ecm.feed assumes, at run time, the existence
   of the actual ecm program "ecm."
   
   Copyright 1991 NeXT, Inc.  All Rights Reserved.
 */
 
#include <stdio.h>
#include <sys/time.h>
#include "Feeder.h"

void set_random_seed() 
/* Start the random number generator at a new position. */
{
  struct timeval tp;

  gettimeofday(&tp,NULL);
  srandom((int)tp.tv_usec + (int)getpid());
}


void main(int argc, char **argv)
{
  id feed = [Feeder new];
  int n,seed,sgn,q;
  char cmd[256],host[16];
  char letter[8];
  int err;
  
  set_random_seed();
  n = [feed numMachines];
  while(n--) {
    if(![feed isLaunchable:n]) continue;
    [feed getHostname:host for:n];
    seed = random();  	 /* Every machine gets a 32-bit random seed. */
    sgn = 1;
    q = 128;  /* We are going to try to factor F12 = 2^4096 + 1.  */
    if(sgn<0) strcpy(letter,"m"); else strcpy(letter,"f");	
    sprintf(cmd, "cd Zfactor; ecm %d %d %d 10000 0 24  > log.%s%d.%s",sgn,q,seed,letter,q,host);
    [feed changeHost:n user:NULL password:NULL command:cmd]; 
    }
  [feed launchAll];
}
