commands.cxx

changeset 7
118d3d5db64f
parent 6
0005527cad62
child 8
c8bfa7e6ae1b
equal deleted inserted replaced
6:0005527cad62 7:118d3d5db64f
46 #include "str.h" 46 #include "str.h"
47 #include "commands.h" 47 #include "commands.h"
48 48
49 CommandDef* g_CommDef; 49 CommandDef* g_CommDef;
50 50
51 #define MAX
51 void ReadCommands () { 52 void ReadCommands () {
52 ScriptReader* r = new ScriptReader ((char*)"commands.def"); 53 ScriptReader* r = new ScriptReader ((char*)"commands.def");
53 g_CommDef = NULL; 54 g_CommDef = NULL;
54 CommandDef* curdef = g_CommDef; 55 CommandDef* curdef = g_CommDef;
55 unsigned int numCommDefs = 0; 56 unsigned int numCommDefs = 0;
56 57
57 while (r->Next()) { 58 while (r->Next()) {
58 CommandDef* comm = new CommandDef; 59 CommandDef* comm = new CommandDef;
60
61 // Any more than 4 is a warning, any less is an error.
62 unsigned int c = r->token.count (const_cast<char*> (":"));
63 if (c < 4)
64 r->ParserError ("not enough parameters: got %d, expected 4", c);
59 65
60 int n = 0; 66 int n = 0;
61 str t = ""; 67 str t = "";
62 for (unsigned int u = 0; u < r->token.len(); u++) { 68 for (unsigned int u = 0; u < r->token.len(); u++) {
63 // If we're at the last character of the string, we need 69 // If we're at the last character of the string, we need
87 else if (!t.compare ("void")) 93 else if (!t.compare ("void"))
88 comm->returnvalue = RETURNVAL_VOID; 94 comm->returnvalue = RETURNVAL_VOID;
89 else if (!t.compare ("bool")) 95 else if (!t.compare ("bool"))
90 comm->returnvalue = RETURNVAL_BOOLEAN; 96 comm->returnvalue = RETURNVAL_BOOLEAN;
91 else 97 else
92 r->ParseError ("bad return value type `%s`", t.chars()); 98 r->ParserError ("bad return value type `%s`", t.chars());
93 break; 99 break;
94 case 3: 100 case 3:
95 // Num args 101 // Num args
96 comm->numargs = i; 102 comm->numargs = i;
97 break; 103 break;
98 case 4: 104 case 4:
99 // Max args 105 // Max args
100 comm->maxargs = i; 106 comm->maxargs = i;
107 break;
108 default:
109 r->ParserWarning ("too many parameters");
101 break; 110 break;
102 } 111 }
103 112
104 n++; 113 n++;
105 t = ""; 114 t = "";

mercurial