Sun, 02 Feb 2014 01:50:23 +0200
- further reformat
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 "main.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "events.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include "commands.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "stringtable.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include "variables.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | #include "data_buffer.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | #include "parser.h" |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | #include "lexer.h" |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
37 | #include "gitinfo.h" |
75
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 | int main (int argc, char** argv) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | try |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | // Intepret command-line parameters: |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | // -l: list commands |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | // I guess there should be a better way to do this. |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | if (argc == 2 && !strcmp (argv[1], "-l")) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | printf ("Begin list of commands:\n"); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | printf ("------------------------------------------------------\n"); |
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 | for (command_info* comm : get_commands()) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | print ("%1\n", get_command_signature (comm)); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | printf ("------------------------------------------------------\n"); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | printf ("End of command list\n"); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | exit (0); |
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 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | // Print header |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | string header; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | string headerline; |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
62 | header = format (APPNAME " version %1", get_version_string (e_long_form)); |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
64 | #ifdef DEBUG |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
65 | header += " (debug build)"; |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
66 | #endif |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
67 | |
86
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
68 | for (int i = 0; i < header.length() / 2; ++i) |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | headerline += "-="; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | headerline += '-'; |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
72 | print ("%2\n\n%1\n\n%2\n\n", header, headerline); |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | if (argc < 2) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | fprintf (stderr, "usage: %s <infile> [outfile] # compiles botscript\n", argv[0]); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | fprintf (stderr, " %s -l # lists commands\n", argv[0]); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | exit (1); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | } |
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 | string outfile; |
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 (argc < 3) |
87 | 84 | outfile = make_object_file_name (argv[1]); |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | else |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | outfile = argv[2]; |
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 | // Prepare reader and writer |
86
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
89 | botscript_parser* parser = new botscript_parser; |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | // We're set, begin parsing :) |
86
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
92 | print ("Parsing script...\n"); |
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
93 | parser->parse_botscript (argv[1]); |
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
94 | print ("Script parsed successfully.\n"); |
75
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 | // Parse done, print statistics and write to file |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | int globalcount = g_GlobalVariables.size(); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | int stringcount = num_strings_in_table(); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | print ("%1 / %2 strings written\n", stringcount, g_max_stringlist_size); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | print ("%1 / %2 global variables\n", globalcount, g_max_global_vars); |
86
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
101 | print ("%1 / %2 events\n", parser->get_num_events(), g_max_events); |
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
102 | print ("%1 state%s1\n", parser->get_num_states()); |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | |
86
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
104 | parser->write_to_file (outfile); |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | // Clear out the junk |
86
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
107 | delete parser; |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | // Done! |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | exit (0); |
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 | catch (script_error& e) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | { |
79
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
77
diff
changeset
|
114 | fprint (stderr, "error: %1\n", e.what()); |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | } |
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 | // ============================================================================ |
87 | 119 | // |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | // Mutates given filename to an object filename |
87 | 121 | // |
122 | string make_object_file_name (string s) | |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | // Locate the extension and chop it out |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | int extdot = s.last ("."); |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | |
86
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
127 | if (extdot >= s.length() - 4) |
43fe4be38a58
- merged object writer into parser
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
128 | s -= (s.length() - extdot); |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | s += ".o"; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | return s; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | // ============================================================================ |
87 | 135 | // |
136 | type_e get_type_by_name (string t) | |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | t = t.to_lowercase(); |
87 | 139 | return (t == "int") ? e_int_type : |
140 | (t == "str") ? e_string_type : | |
141 | (t == "void") ? e_void_type : | |
142 | (t == "bool") ? e_bool_type : | |
143 | e_unknown_type; | |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | // ============================================================================ |
87 | 148 | // |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | // Inverse operation - type name by value |
87 | 150 | // |
151 | string get_type_name (type_e type) | |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | { |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | switch (type) |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | { |
87 | 155 | case e_int_type: return "int"; break; |
156 | case e_string_type: return "str"; break; | |
157 | case e_void_type: return "void"; break; | |
158 | case e_bool_type: return "bool"; break; | |
159 | case e_unknown_type: return "???"; break; | |
75
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | } |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | return ""; |
bf8c57437231
- renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | } |
87 | 164 | |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
165 | // ============================================================================= |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
166 | // |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
167 | string make_version_string (int major, int minor, int patch) |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
168 | { |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
169 | string ver = format ("%1.%2", major, minor); |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
170 | |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
171 | if (patch != 0) |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
172 | { |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
173 | ver += "."; |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
174 | ver += patch; |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
175 | } |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
176 | |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
177 | return ver; |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
178 | } |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
179 | |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
180 | // ============================================================================= |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
181 | // |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
182 | string get_version_string (form_length_e len) |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
183 | { |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
184 | string tag (GIT_DESCRIPTION); |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
185 | string version = tag; |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
186 | |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
187 | if (tag.ends_with ("-pre") && len == e_long_form) |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
188 | version += "-" + string (GIT_HASH).mid (0, 8); |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
189 | |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
190 | return version; |
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
191 | } |