erebus
diff src/main.cc @ 40:9d6368850fe1
minor enhancements and bugfixes to the console stuff
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 10 Jun 2014 10:53:19 +0300 |
parents | fd45cf0fc912 |
children | 2e817711d0f6 |
line diff
1.1 --- a/src/main.cc Mon Jun 09 23:57:24 2014 +0300 1.2 +++ b/src/main.cc Tue Jun 10 10:53:19 2014 +0300 1.3 @@ -574,8 +574,11 @@ 1.4 1.5 static void con_parse(const char *line) 1.6 { 1.7 - char *buf = (char*)alloca(strlen(line) + 1); 1.8 - strcpy(buf, line); 1.9 + int len = strlen(line); 1.10 + if(!len) return; 1.11 + 1.12 + char *buf = (char*)alloca(len + 1); 1.13 + memcpy(buf, line, len + 1); 1.14 1.15 std::vector<char*> args; 1.16 char *tok; 1.17 @@ -587,8 +590,29 @@ 1.18 args.push_back(0); 1.19 int argc = args.size() - 1; 1.20 1.21 - if(strcmp(args[0], "exit") == 0) { 1.22 + if(!args[0]) return; 1.23 + 1.24 + if(strcmp(args[0], "exit") == 0 || strcmp(args[0], "quit") == 0) { 1.25 exit(0); 1.26 + 1.27 + } else if(strcmp(args[0], "clear") == 0) { 1.28 + erb_clear(erb); 1.29 + 1.30 + } else if(strcmp(args[0], "stop") == 0) { 1.31 + erb_end_frame(erb); 1.32 + 1.33 + } else if(strcmp(args[0], "render") == 0) { 1.34 + long tm = 0; 1.35 + if(args[1]) { 1.36 + char *endp; 1.37 + tm = strtol(args[1], &endp, 10); 1.38 + if(endp == args[1]) { 1.39 + con.printf("the argument to render must be a time value in milliseconds\n"); 1.40 + return; 1.41 + } 1.42 + } 1.43 + begin_frame(tm); 1.44 + 1.45 } else if(strcmp(args[0], "load") == 0) { 1.46 for(int i=1; i<argc; i++) { 1.47 if(erb_load_scene(erb, args[i]) == -1) { 1.48 @@ -597,12 +621,15 @@ 1.49 begin_frame(0); 1.50 } 1.51 } 1.52 - } else { 1.53 1.54 - if(erb_proc_cmd(erb, line) == -1) { 1.55 - con.puts("invalid command\n"); 1.56 + } else if(strcmp(args[0], "add") == 0) { 1.57 + if(erb_proc_cmd(erb, line + 4) == -1) { 1.58 + con.puts("invalid add command\n"); 1.59 } else { 1.60 begin_frame(0); 1.61 } 1.62 + 1.63 + } else { 1.64 + con.printf("unrecognized command: %s\n", args[0]); 1.65 } 1.66 }