erebus
diff src/main.cc @ 39:fd45cf0fc912
load console command
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 09 Jun 2014 23:57:24 +0300 |
parents | db8a90307386 |
children | 9d6368850fe1 |
line diff
1.1 --- a/src/main.cc Mon Jun 09 18:40:30 2014 +0300 1.2 +++ b/src/main.cc Mon Jun 09 23:57:24 2014 +0300 1.3 @@ -574,11 +574,35 @@ 1.4 1.5 static void con_parse(const char *line) 1.6 { 1.7 - printf("got line: %s\n", line); 1.8 + char *buf = (char*)alloca(strlen(line) + 1); 1.9 + strcpy(buf, line); 1.10 1.11 - if(erb_proc_cmd(erb, line) == -1) { 1.12 - con.puts("invalid command\n"); 1.13 + std::vector<char*> args; 1.14 + char *tok; 1.15 + 1.16 + while((tok = strtok(buf, " \n\r\v\t"))) { 1.17 + buf = 0; 1.18 + args.push_back(tok); 1.19 + } 1.20 + args.push_back(0); 1.21 + int argc = args.size() - 1; 1.22 + 1.23 + if(strcmp(args[0], "exit") == 0) { 1.24 + exit(0); 1.25 + } else if(strcmp(args[0], "load") == 0) { 1.26 + for(int i=1; i<argc; i++) { 1.27 + if(erb_load_scene(erb, args[i]) == -1) { 1.28 + con.printf("failed to load scene: %s\n", args[1]); 1.29 + } else { 1.30 + begin_frame(0); 1.31 + } 1.32 + } 1.33 } else { 1.34 - begin_frame(0); 1.35 + 1.36 + if(erb_proc_cmd(erb, line) == -1) { 1.37 + con.puts("invalid command\n"); 1.38 + } else { 1.39 + begin_frame(0); 1.40 + } 1.41 } 1.42 }