/*
 * File used to generate the substitution files
 */

#include <stdio.h>
#include <string.h>
#define MAX 1000

int main(int argc, char **argv) {
  FILE *fp;int i; int max=100; int divider=0;int asize=0;
  char name[100]; char scan_rate[20];

  printf("argc: %d\n",argc);

  if(argc==5) {
    if ((max=atoi(argv[1]))>MAX) max= MAX;
    printf("Using %d templates\n",max);
    divider = atoi(argv[2]);
    asize = atoi(argv[4]);
    switch(divider) {
      case 1:
	sprintf(scan_rate,"1 second");
        break;
      case 10:
	sprintf(scan_rate,".1 second");
        break;
      case 100:
	sprintf(scan_rate,".01 second");
        break;
      case 1000:
	sprintf(scan_rate,".001 second");
        break;
      default:
	sprintf(scan_rate,"1 second");
        break;
    }
  }

  else {
    printf("Usage:\n\na.out <num ch> <scan_divider> <test_name> <array_size>\n");
    return -1;
  }
  
  sprintf(name,"test%d_%d_%d.substitutions",max,divider,asize);
  fp = fopen(name,"w");
  fprintf(fp,"file test.db {\n  pattern\{TEST, NUM, NUM1, NUM2, SCAN, NMAX}\n");
  for(i=0;i<max;i++) {
    fprintf(fp,"  { \"%s\", %d, %d, %d, \"%s\", %d}\n",argv[3],i,2*i,2*i+1,scan_rate,asize);
  }
  fprintf(fp,"}\n");
  fclose(fp);
}

