From 44d90e5cf4469bfb22bda420c05422dddf20df9c Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Mon, 22 Aug 2005 19:31:27 +0000 Subject: [PATCH] implemented feature request 1242202: "getting config values via z:\config" Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2283 --- include/shell.h | 5 ++++- src/misc/programs.cpp | 33 ++++++++++++++++++++++++++++++++- src/shell/shell.cpp | 14 +++++++------- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/include/shell.h b/include/shell.h index 4d3eaaef..ca690e6f 100644 --- a/include/shell.h +++ b/include/shell.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: shell.h,v 1.12 2005-04-21 21:17:45 qbix79 Exp $ */ +/* $Id: shell.h,v 1.13 2005-08-22 19:31:26 qbix79 Exp $ */ #ifndef DOSBOX_SHELL_H #define DOSBOX_SHELL_H @@ -36,6 +36,9 @@ #define CMD_MAXCMDS 20 #define CMD_OLDSIZE 4096 extern Bitu call_shellstop; +/* first_shell is used to add and delete stuff from the shell env + * by "external" programs. (config) */ +extern Program * first_shell; class DOS_Shell; diff --git a/src/misc/programs.cpp b/src/misc/programs.cpp index 0011a3b9..d996feb3 100644 --- a/src/misc/programs.cpp +++ b/src/misc/programs.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: programs.cpp,v 1.21 2005-08-11 18:56:57 qbix79 Exp $ */ +/* $Id: programs.cpp,v 1.22 2005-08-22 19:31:27 qbix79 Exp $ */ #include #include @@ -30,6 +30,7 @@ #include "support.h" #include "cross.h" #include "setup.h" +#include "shell.h" Bitu call_program; @@ -226,6 +227,35 @@ void CONFIG::Run(void) { return; } + /* Code for getting the current configuration. * + * Official format: config -get "section property" * + * As a bonus it will set %CONFIG% to this value as well */ + if(cmd->FindString("-get",temp_line,true)) { + std::string temp2 = ""; + cmd->GetStringRemain(temp2);//So -get n1 n2= can be used without quotes + if(temp2 != "") temp_line = temp_line + " " + temp2; + + std::string::size_type space = temp_line.find(" "); + if(space == std::string::npos) { + WriteOut(MSG_Get("PROGRAM_CONFIG_GET_SYNTAX")); + return; + } + //Copy the found property to a new string and erase from templine (mind the space) + std::string prop = temp_line.substr(space+1); temp_line.erase(space); + + Section* sec = control->GetSection(temp_line.c_str()); + if(!sec) { + WriteOut(MSG_Get("PROGRAM_CONFIG_SECTION_ERROR"),temp_line.c_str()); + return; + } + char* val = sec->GetPropValue(prop.c_str()); + WriteOut("%s",val); + first_shell->SetEnv("CONFIG",val); + return; + } + + + /* Code for the configuration changes * * Official format: config -set "section property=value" * * Accepted: without quotes and/or without -set and/or without section * @@ -305,4 +335,5 @@ void PROGRAMS_Init(Section* sec) { MSG_Add("PROGRAM_CONFIG_USAGE","Config tool:\nUse -writeconf filename to write the current config.\nUse -writelang filename to write the current language strings.\n"); MSG_Add("PROGRAM_CONFIG_SECTION_ERROR","Section %s doesn't exist.\n"); MSG_Add("PROGRAM_CONFIG_PROPERTY_ERROR","Property %s doesn't have a section.\n"); + MSG_Add("PROGRAM_CONFIG_GET_SYNTAX","Correct syntax: config -get \"section property\""); } diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 236dcabb..857b65bd 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: shell.cpp,v 1.61 2005-05-31 20:19:13 qbix79 Exp $ */ +/* $Id: shell.cpp,v 1.62 2005-08-22 19:31:27 qbix79 Exp $ */ #include #include @@ -31,7 +31,7 @@ Bitu call_shellstop; /* Larger scope so shell_del autoexec can use it to * remove things from the environment */ -Program * new_program = 0; +Program * first_shell = 0; static Bitu shellstop_handler(void) { return CBRET_STOP; @@ -84,7 +84,7 @@ AutoexecObject::~AutoexecObject(){ if(!test) continue; *test = 0; //If the shell is running/exists update the environment - if(new_program) new_program->SetEnv(after_set,""); + if(first_shell) first_shell->SetEnv(after_set,""); } } else it++; } @@ -511,8 +511,8 @@ void SHELL_Init() { dos.psp(psp_seg); - SHELL_ProgramStart(&new_program); - new_program->Run(); - delete new_program; - new_program = 0;//Make clear that it shouldn't be used anymore + SHELL_ProgramStart(&first_shell); + first_shell->Run(); + delete first_shell; + first_shell = 0;//Make clear that it shouldn't be used anymore }