console_cmds.c
changeset 247 1cbc32ff06eb
parent 232 c3d08de192ed
child 262 3076b77dce21
equal deleted inserted replaced
246:de179e5f7c3d 247:1cbc32ff06eb
     8 
     8 
     9 #if defined(WIN32)
     9 #if defined(WIN32)
    10 # define ENABLE_NETWORK
    10 # define ENABLE_NETWORK
    11 #endif
    11 #endif
    12 
    12 
       
    13 
       
    14 // ** scriptfile handling ** //
       
    15 static FILE * _script_file;
       
    16 static bool _script_running;
       
    17 
    13 // ** console command / variable defines ** //
    18 // ** console command / variable defines ** //
       
    19 
    14 #define DEF_CONSOLE_CMD(yyyy) static _iconsole_var * yyyy(byte argc, byte* argv[], byte argt[])
    20 #define DEF_CONSOLE_CMD(yyyy) static _iconsole_var * yyyy(byte argc, byte* argv[], byte argt[])
    15 #define DEF_CONSOLE_CMD_HOOK(yyyy) static bool yyyy(_iconsole_cmd * hookcmd)
    21 #define DEF_CONSOLE_CMD_HOOK(yyyy) static bool yyyy(_iconsole_cmd * hookcmd)
    16 #define DEF_CONSOLE_VAR_HOOK(yyyy) static bool yyyy(_iconsole_var * hookvar)
    22 #define DEF_CONSOLE_VAR_HOOK(yyyy) static bool yyyy(_iconsole_var * hookvar)
       
    23 
       
    24 
       
    25 // ** supporting functions ** //
    17 
    26 
    18 static int32 GetArgumentInteger(byte *arg)
    27 static int32 GetArgumentInteger(byte *arg)
    19 {
    28 {
    20 	int32 result;
    29 	int32 result;
    21 	sscanf((char *)arg, "%u", &result);
    30 	sscanf((char *)arg, "%u", &result);
   123 	return NULL;
   132 	return NULL;
   124 }
   133 }
   125 
   134 
   126 #endif
   135 #endif
   127 
   136 
       
   137 /* ******************************** */
       
   138 /*   script file console commands   */
       
   139 /* ******************************** */
       
   140 
       
   141 DEF_CONSOLE_CMD(ConExec)
       
   142 {
       
   143 	char cmd[1024];
       
   144 	bool doerror;
       
   145 
       
   146 	if (argc<2) return NULL;
       
   147 
       
   148 	doerror = true;
       
   149 	_script_file = fopen(argv[1],"rb");
       
   150 
       
   151 	if (_script_file == NULL) {
       
   152 		if (argc>2) if (atoi(argv[2])==0) doerror=false;
       
   153 		if (doerror) IConsoleError("script file not found");
       
   154 		return NULL;
       
   155 		}
       
   156 
       
   157 	_script_running = true;
       
   158 
       
   159 	while (!feof(_script_file) && _script_running) {
       
   160 
       
   161 		fgets((char *)&cmd, 1024, _script_file);
       
   162 
       
   163 		IConsoleCmdExec((byte *) &cmd);
       
   164 
       
   165 	}
       
   166 
       
   167 	_script_running = false;
       
   168 	fclose(_script_file);
       
   169 	return NULL;
       
   170 }
       
   171 
       
   172 DEF_CONSOLE_CMD(ConReturn)
       
   173 {
       
   174 	_script_running = false;
       
   175 	return NULL;
       
   176 }
       
   177 
   128 /* **************************** */
   178 /* **************************** */
   129 /*   default console commands   */
   179 /*   default console commands   */
   130 /* **************************** */
   180 /* **************************** */
       
   181 
       
   182 DEF_CONSOLE_CMD(ConScript)
       
   183 {
       
   184 	extern FILE* _iconsole_output_file;
       
   185 
       
   186 	if (_iconsole_output_file!=NULL) {
       
   187 		if (argc<2) return NULL;
       
   188 		IConsolePrintF(_iconsole_color_default,"file output complete");
       
   189 		fclose(_iconsole_output_file);
       
   190 	} else {
       
   191 		IConsolePrintF(_iconsole_color_default,"file output started to: %s",argv[1]);
       
   192 		_iconsole_output_file = fopen(argv[1],"ab");
       
   193 		if (_iconsole_output_file == NULL) IConsoleError("could not open file");
       
   194 	}
       
   195 	return NULL;
       
   196 }
       
   197 
   131 
   198 
   132 DEF_CONSOLE_CMD(ConEcho)
   199 DEF_CONSOLE_CMD(ConEcho)
   133 {
   200 {
   134 	if (argc<2) return NULL;
   201 	if (argc<2) return NULL;
   135 	IConsolePrint(_iconsole_color_default, argv[1]);
   202 	IConsolePrint(_iconsole_color_default, argv[1]);
   333 /*  debug commands and variables */
   400 /*  debug commands and variables */
   334 /* ****************************************** */
   401 /* ****************************************** */
   335 
   402 
   336 void IConsoleDebugLibRegister()
   403 void IConsoleDebugLibRegister()
   337 {
   404 {
       
   405 	// stdlib
       
   406 	extern bool _stdlib_con_developer;
       
   407 
       
   408 	IConsoleVarRegister("con_developer",(void *) &_stdlib_con_developer,ICONSOLE_VAR_BOOLEAN);
   338 	IConsoleVarMemRegister("temp_bool",ICONSOLE_VAR_BOOLEAN);
   409 	IConsoleVarMemRegister("temp_bool",ICONSOLE_VAR_BOOLEAN);
   339 	IConsoleVarMemRegister("temp_int16",ICONSOLE_VAR_INT16);
   410 	IConsoleVarMemRegister("temp_int16",ICONSOLE_VAR_INT16);
   340 	IConsoleVarMemRegister("temp_int32",ICONSOLE_VAR_INT32);
   411 	IConsoleVarMemRegister("temp_int32",ICONSOLE_VAR_INT32);
   341 	IConsoleVarMemRegister("temp_pointer",ICONSOLE_VAR_POINTER);
   412 	IConsoleVarMemRegister("temp_pointer",ICONSOLE_VAR_POINTER);
   342 	IConsoleVarMemRegister("temp_uint16",ICONSOLE_VAR_UINT16);
   413 	IConsoleVarMemRegister("temp_uint16",ICONSOLE_VAR_UINT16);
   354 
   425 
   355 void IConsoleStdLibRegister()
   426 void IConsoleStdLibRegister()
   356 {
   427 {
   357 	// stdlib
   428 	// stdlib
   358 	extern byte _stdlib_developer;
   429 	extern byte _stdlib_developer;
   359 	extern bool _stdlib_con_developer;
       
   360 
   430 
   361 #ifdef _DEBUG
   431 #ifdef _DEBUG
   362 	IConsoleDebugLibRegister();
   432 	IConsoleDebugLibRegister();
   363 #else
   433 #else
   364 	(void)ConResetTile; // Silence warning, this is only used in _DEBUG
   434 	(void)ConResetTile; // Silence warning, this is only used in _DEBUG
   371 #endif
   441 #endif
   372 	IConsoleCmdRegister("debug_level",ConDebugLevel);
   442 	IConsoleCmdRegister("debug_level",ConDebugLevel);
   373 	IConsoleCmdRegister("dump_vars",ConListDumpVariables);
   443 	IConsoleCmdRegister("dump_vars",ConListDumpVariables);
   374 	IConsoleCmdRegister("echo",ConEcho);
   444 	IConsoleCmdRegister("echo",ConEcho);
   375 	IConsoleCmdRegister("echoc",ConEchoC);
   445 	IConsoleCmdRegister("echoc",ConEchoC);
       
   446 	IConsoleCmdRegister("exec",ConExec);
   376 	IConsoleCmdRegister("exit",ConExit);
   447 	IConsoleCmdRegister("exit",ConExit);
   377 	IConsoleCmdRegister("help",ConHelp);
   448 	IConsoleCmdRegister("help",ConHelp);
   378 	IConsoleCmdRegister("info_cmd",ConInfoCmd);
   449 	IConsoleCmdRegister("info_cmd",ConInfoCmd);
   379 	IConsoleCmdRegister("info_var",ConInfoVar);
   450 	IConsoleCmdRegister("info_var",ConInfoVar);
   380 	IConsoleCmdRegister("list_cmds",ConListCommands);
   451 	IConsoleCmdRegister("list_cmds",ConListCommands);
   383 	IConsoleCmdRegister("printfc",ConPrintFC);
   454 	IConsoleCmdRegister("printfc",ConPrintFC);
   384 	IConsoleCmdRegister("quit",ConExit);
   455 	IConsoleCmdRegister("quit",ConExit);
   385 	IConsoleCmdRegister("random",ConRandom);
   456 	IConsoleCmdRegister("random",ConRandom);
   386 	IConsoleCmdRegister("resetengines",ConResetEngines);
   457 	IConsoleCmdRegister("resetengines",ConResetEngines);
   387 	IConsoleCmdHook("resetengines",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
   458 	IConsoleCmdHook("resetengines",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
       
   459 	IConsoleCmdRegister("return",ConReturn);
   388 	IConsoleCmdRegister("screenshot",ConScreenShot);
   460 	IConsoleCmdRegister("screenshot",ConScreenShot);
       
   461 	IConsoleCmdRegister("script",ConScript);
   389 	IConsoleCmdRegister("scrollto",ConScrollToTile);
   462 	IConsoleCmdRegister("scrollto",ConScrollToTile);
   390 
   463 
   391 	// variables [please add them alphabeticaly]
   464 	// variables [please add them alphabeticaly]
   392 	IConsoleVarRegister("con_developer",(void *) &_stdlib_con_developer,ICONSOLE_VAR_BOOLEAN);
       
   393 	IConsoleVarRegister("developer",(void *) &_stdlib_developer,ICONSOLE_VAR_BYTE);
   465 	IConsoleVarRegister("developer",(void *) &_stdlib_developer,ICONSOLE_VAR_BYTE);
   394 #ifdef ENABLE_NETWORK
   466 #ifdef ENABLE_NETWORK
   395 	IConsoleVarRegister("net_client_timeout",&_network_client_timeout,ICONSOLE_VAR_UINT16);
   467 	IConsoleVarRegister("net_client_timeout",&_network_client_timeout,ICONSOLE_VAR_UINT16);
   396 	IConsoleVarHook("*net_client_timeout",ICONSOLE_HOOK_ACCESS,ConVarHookNoNetClient);
   468 	IConsoleVarHook("*net_client_timeout",ICONSOLE_HOOK_ACCESS,ConVarHookNoNetClient);
   397 	IConsoleVarRegister("net_ready_ahead",&_network_ready_ahead,ICONSOLE_VAR_UINT16);
   469 	IConsoleVarRegister("net_ready_ahead",&_network_ready_ahead,ICONSOLE_VAR_UINT16);