comparison ueda/libueda/popopt.c @ 0:cd92449fdb51

initial import of ueda and ifctf-part-lib from ifctfvax CVS
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 20 Jul 2015 00:24:37 +0000
parents
children c91e7a30fab3
comparison
equal deleted inserted replaced
-1:000000000000 0:cd92449fdb51
1 /*
2 * These are the libueda routines for handling population options.
3 */
4
5 #include <stdio.h>
6 #include <ctype.h>
7 #include <strings.h>
8 #include "mcl.h"
9
10 extern char *get_comp_attr();
11
12 #define MAX_POPOPT_LIST 10
13 static int popopt_list[MAX_POPOPT_LIST], npopopt = 1;
14 static int all_popopt;
15
16 set_popopt_list(arg)
17 char *arg;
18 {
19 register char *cp, *np;
20 register int i;
21
22 if (!strcmp(arg, "all")) {
23 all_popopt = 1;
24 return;
25 }
26 for (cp = arg, i = 0; *cp; ) {
27 if (*cp == ',') {
28 cp++;
29 continue;
30 }
31 if (!isdigit(*cp)) {
32 fprintf(stderr,
33 "%s: invalid population option specification\n",
34 arg);
35 exit(1);
36 }
37 for (np = cp; isdigit(*cp); cp++)
38 ;
39 if (i >= MAX_POPOPT_LIST) {
40 fprintf(stderr,
41 "%s: too many population options listed\n",
42 arg);
43 exit(1);
44 }
45 popopt_list[i++] = atoi(np);
46 }
47 npopopt = i;
48 }
49
50 check_component_popopt(comp)
51 struct component *comp;
52 {
53 register char *popopt_string;
54 register int popopt, i;
55
56 if (all_popopt)
57 return(1);
58 popopt_string = get_comp_attr(comp, "population_option");
59 if (!popopt_string)
60 popopt_string = "0";
61 if (!strcmp(popopt_string, "NO"))
62 return(0);
63 popopt = atoi(popopt_string);
64 for (i = 0; i < npopopt; i++)
65 if (popopt_list[i] == popopt)
66 return(1);
67 return(0);
68 }