Debian Codegraph @

terps/alan2/genalan.c

raw symbols SCIP
1 /*----------------------------------------------------------------------*\
2
3 genalan.c
4
5 A small C program to generate a large Alan program...
6
7 \*----------------------------------------------------------------------*/
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <time.h>
12
13 static int objs;
14 static int locs;
15 static int exts;
16 static int acts;
17 static int scrs;
18 static int evts;
19 static int ruls;
20
21
22 static long rnd(long to, long from)
23 {
24 if (to > from)
25 return rand()%(to-from+1)+from;
26 else
27 return rand()%(from-to+1)+to;
28 }
29
30
31 #define OBJS (objs/2+rnd(1,objs))
32
33 static void geobjs(char *initloc)
34 {
35 int objmax = OBJS;
36 int o;
37
38 for (o = 1; o <= objmax; o++) {
39 printf("OBJECT o%d%s%s%s\n", o, initloc?initloc:"", initloc?" AT ":"", initloc?initloc:"");
40 printf("END OBJECT o%d%s.\n\n", o, initloc?initloc:"");
41 }
42 }
43
44
45 #define EXTS (exts/2+rnd(1, exts))
46
47 static void geexts(int maxloc)
48 {
49 int extmax = EXTS;
50 int e;
51
52 for (e = 1; e <= extmax; e++)
53 printf(" EXIT e%d TO l%ld.\n", e, rnd(1, maxloc));
54 }
55
56
57 #define LOCS (locs/2+rnd(1,locs))
58
59 static void gelocs(void)
60 {
61 int locmax = LOCS;
62 int l;
63 char initloc[30];
64
65 for (l = 1; l<=locmax; l++) {
66 printf("LOCATION l%d\n", l);
67 geexts(locmax);
68 printf("END LOCATION l%d.\n\n", l);
69 sprintf(initloc, "l%d", l);
70 geobjs(initloc);
71 }
72 }
73
74
75
76 /* SPA Option handling */
77
78 #include "spa.h"
79
80
81 static SPA_FUN(usage)
82 {
83 printf("Purpose:\nGenerate random Alan source\n\nUsage:\nGENALAN [-help] [options]\n");
84 }
85
86
87 static SPA_ERRFUN(paramError)
88 {
89 char *sevstr;
90
91 switch (sev) {
92 case 'E': sevstr = "error"; break;
93 case 'W': sevstr = "warning"; break;
94 default: sevstr = "internal error"; break;
95 }
96 printf("Parameter %s: %s, %s\n", sevstr, msg, add);
97 usage(NULL, NULL, 0);
98 exit(EXIT_FAILURE);
99 }
100
101 static SPA_FUN(extraArg)
102 {
103 printf("Extra argument: '%s'\n", rawName);
104 usage(NULL, NULL, 0);
105 exit(EXIT_FAILURE);
106 }
107
108 static SPA_FUN(xit) {exit(EXIT_SUCCESS);}
109
110 static SPA_DECLARE(arguments)
111 SPA_FUNCTION("", "extra argument", extraArg)
112 SPA_END
113
114 static SPA_DECLARE(options)
115 SPA_HELP("help", "this help", usage, xit)
116 SPA_INTEGER("objects", "nominal number of objects at each location", objs, 10, NULL)
117 SPA_INTEGER("locations", "nominal number of locations", locs, 10, NULL)
118 SPA_INTEGER("exits", "nominal number of exits in each location", exts, 2, NULL)
119 SPA_INTEGER("actors", "nominal number of actors", acts, 10, NULL)
120 SPA_INTEGER("scripts", "nominal number of scripts for each actor", scrs, 10, NULL)
121 SPA_INTEGER("events", "nominal number of events", evts, 10, NULL)
122 SPA_INTEGER("rules", "nominal number of rules", ruls, 10, NULL)
123 SPA_END
124
125
126 int main(int argc, char **argv)
127 {
128 int nArgs;
129
130 nArgs = spaProcess(argc, argv, arguments, options, paramError);
131 if (nArgs > 0)
132 exit(EXIT_FAILURE);
133
134 srand(time(0));
135
136 geobjs(0);
137 gelocs();
138
139 printf("START AT l1.\n");
140 exit(EXIT_SUCCESS);
141 }
142
143