Sat, 14 Jul 2012 17:24:21 +0300
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
0 | 1 | /* |
2 | * botc source code | |
3 | * Copyright (C) 2012 Santeri `Dusk` Piippo | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright notice, | |
10 | * this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
12 | * this list of conditions and the following disclaimer in the documentation | |
13 | * and/or other materials provided with the distribution. | |
3 | 14 | * 3. Neither the name of the developer nor the names of its contributors may |
15 | * be used to endorse or promote products derived from this software without | |
16 | * specific prior written permission. | |
0 | 17 | * 4. Redistributions in any form must be accompanied by information on how to |
18 | * obtain complete source code for the software and any accompanying | |
19 | * software that uses the software. The source code must either be included | |
20 | * in the distribution or be available for no more than the cost of | |
21 | * distribution plus a nominal fee, and must be freely redistributable | |
22 | * under reasonable conditions. For an executable file, complete source | |
23 | * code means the source code for all modules it contains. It does not | |
24 | * include source code for modules or files that typically accompany the | |
25 | * major components of the operating system on which the executable file | |
26 | * runs. | |
27 | * | |
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
38 | * POSSIBILITY OF SUCH DAMAGE. | |
39 | */ | |
40 | ||
41 | #include <stdio.h> | |
42 | #include <stdlib.h> | |
43 | #include <string.h> | |
44 | #include "common.h" | |
45 | ||
46 | #include "str.h" | |
47 | #include "scriptreader.h" | |
48 | #include "objwriter.h" | |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
49 | #include "events.h" |
6
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
50 | #include "commands.h" |
0 | 51 | |
52 | #include "bots.h" | |
53 | #include "botcommands.h" | |
54 | ||
55 | int main (int argc, char** argv) { | |
16
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
56 | // Print header |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
57 | str header; |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
58 | str headerline = "-="; |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
59 | header.appendformat ("%s version %d.%d.%d", APPNAME, VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION); |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
60 | headerline.repeat ((header.len()/2)-1); |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
61 | headerline += '-'; |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
62 | printf ("%s\n%s\n", header.chars(), headerline.chars()); |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
63 | |
0 | 64 | if (argc != 3) { |
65 | fprintf (stderr, "usage: %s: <infile> <outFile>\n", argv[0]); | |
66 | exit (1); | |
67 | } | |
68 | ||
6
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
69 | // Read definitions |
16
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
70 | printf ("Reading definitions...\n"); |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
71 | ReadEvents (); |
6
0005527cad62
Command definitions are now read into memory.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
72 | ReadCommands (); |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
73 | |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
74 | // Prepare reader and writer |
2
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
75 | ScriptReader *r = new ScriptReader (argv[1]); |
bb2c45522eb6
Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
76 | ObjWriter *w = new ObjWriter (argv[2]); |
0 | 77 | |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
78 | // We're set, begin parsing :) |
16
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
79 | printf ("Parsing script..\n"); |
0 | 80 | r->BeginParse (w); |
81 | ||
16
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
82 | // Parse done, print statistics |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
83 | printf ("%d states written\n", g_NumStates); |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
84 | printf ("%d events written\n", g_NumEvents); |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
85 | printf ("-- %u bytes written to %s\n", w->numWrittenBytes, argv[2]); |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
86 | |
393359908179
Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
87 | // Clear out the junk |
0 | 88 | delete r; |
89 | delete w; | |
90 | } | |
91 | ||
92 | void error (const char* text, ...) { | |
93 | PERFORM_FORMAT (text, c); | |
94 | fprintf (stderr, "error: %s", c); | |
95 | exit (1); | |
96 | } |