Sun, 19 Jan 2014 20:39:30 +0200
- use the Skulltag 97c2 license which is slightly differently worded
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
85
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
2 | Copyright 2012-2014 Santeri Piippo |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
85
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
7 | are met: |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
85
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
15 | derived from this software without specific prior written permission. |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
85
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | */ |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include <stdlib.h> |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include <stdio.h> |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "main.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include "str.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | #include "commands.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | #include "lexer.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | static list<command_info*> g_commands; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | // ============================================================================ |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
40 | // |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
41 | void add_command_definition (command_info* comm) |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | { |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
43 | // Ensure that there is no conflicts |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
44 | for (command_info* it : g_commands) |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
45 | if (it->number == comm->number) |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
46 | error ("Attempted to redefine command #%1 (%2) as %3", |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
47 | g_commands[comm->number]->name, comm->name); |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
49 | g_commands << comm; |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | // ============================================================================ |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | // Finds a command by name |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | command_info* find_command_by_name (string fname) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | for (command_info* comm : g_commands) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | if (fname.to_uppercase() == comm->name.to_uppercase()) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | return comm; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | return null; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | // ============================================================================ |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | // Returns the prototype of the command |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | string get_command_signature (command_info* comm) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | string text; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | text += GetTypeName (comm->returnvalue); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | text += ' '; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | text += comm->name; |
79
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
73 | |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
74 | if (comm->maxargs != 0) |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
75 | text += ' '; |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
76 | |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | text += '('; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | bool hasoptionals = false; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | for (int i = 0; i < comm->maxargs; i++) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | if (i == comm->numargs) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | hasoptionals = true; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | text += '['; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | if (i) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | text += ", "; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | text += GetTypeName (comm->args[i].type); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | text += ' '; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | text += comm->args[i].name; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | if (i >= comm->numargs) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | { |
79
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
98 | text += " = "; |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | bool is_string = comm->args[i].type == TYPE_STRING; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | if (is_string) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | text += '"'; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | text += string::from_number (comm->args[i].defvalue); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | if (is_string) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | text += '"'; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | if (hasoptionals) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | text += ']'; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | text += ')'; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | return text; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | const list<command_info*> get_commands() |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | return g_commands; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | } |