File: random_effect.c

package info (click to toggle)
xbanner 1.31-13
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,108 kB
  • ctags: 832
  • sloc: ansic: 5,084; sh: 263; csh: 168; makefile: 150
file content (60 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
#ifndef vms
#include <malloc.h>
#endif
#include <time.h>
#include <string.h>

#define MAX_CONFIGS 32

void usage(void)
{
  fprintf(stderr,"Usage: random_effect <config_database>\n");
  exit(1);
}

int main(int argc, char *argv[])
{
  time_t now;
  FILE *fin;
  char xb_cmdline[1024];
  char *names[MAX_CONFIGS];
  char line[256];
  int cnt=0;
  int i;

  if(argc!=2)
    usage();

  now = time(NULL);
  srand((unsigned int)now);	/* randomize */
  
  fin=fopen(argv[1],"r");
  if(fin==NULL)
  {
    fprintf(stderr,"Could not open the xbanner configuration-files list\n");
    exit(1);
  }

  fgets(xb_cmdline,1023,fin);	/* get the cmd line to run xbanner */
  xb_cmdline[strlen(xb_cmdline)-1]='\0';	/* trim CR */
  strcat(xb_cmdline," -file ");	/* add the -file option */

  while(fgets(line,255,fin)!=NULL)
  {
    names[cnt]=(char*)malloc(strlen(line)+1);
    if(names[cnt]==NULL)
    {
      fprintf(stderr,"Memory allocation error\n");
      exit(1);
    }
    strcpy(names[cnt],line);
    cnt++;
  }
  i=rand()%cnt;
  strcat(xb_cmdline,names[i]);
  fprintf(stderr,"XBanner Random Effect executing: %s\n",xb_cmdline);
  system(xb_cmdline);
  return 0;
}