From 82155f2b42b3b0c0406bbd51d3d44e70578b6061 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Wed, 17 Dec 2003 21:50:59 +0000 Subject: [PATCH] moved shell_inc.h to include and added subst and loadhigh (Srecko) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1493 --- src/shell/shell.cpp | 17 +++-- src/shell/shell_batch.cpp | 2 +- src/shell/shell_cmds.cpp | 62 ++++++++++++++++- src/shell/shell_inc.h | 142 -------------------------------------- src/shell/shell_misc.cpp | 4 +- 5 files changed, 73 insertions(+), 154 deletions(-) delete mode 100644 src/shell/shell_inc.h diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 5cf3ddd6..eea7529b 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -16,13 +16,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: shell.cpp,v 1.36 2003-10-14 23:34:28 harekiet Exp $ */ +/* $Id: shell.cpp,v 1.37 2003-12-17 21:50:59 qbix79 Exp $ */ #include #include #include #include "setup.h" -#include "shell_inc.h" +#include "shell.h" Bitu call_shellstop; @@ -71,7 +71,7 @@ Bitu DOS_Shell::GetRedirection(char *s, char **ifn, char **ofn,bool * append) { char ch; Bitu num=0; - while (ch=*lr++) { + while ( (ch=*lr++) ) { switch (ch) { case '>': *append=((*lr)=='>'); @@ -283,10 +283,12 @@ void SHELL_Init() { MSG_Add("SHELL_CMD_DIR_BYTES_FREE","%5d Dir(s) %17s Bytes free\n"); MSG_Add("SHELL_EXECUTE_DRIVE_NOT_FOUND","Drive %c does not exist!\n"); MSG_Add("SHELL_EXECUTE_ILLEGAL_COMMAND","Illegal command: %s.\n"); - MSG_Add("SHELL_CMD_PAUSE","Press any key to continue.\n"); + MSG_Add("SHELL_CMD_PAUSE","Press any key to continue.\n"); MSG_Add("SHELL_CMD_PAUSE_HELP","Waits for 1 keystroke to continue.\n"); MSG_Add("SHELL_CMD_COPY_FAILURE","Copy failure : %s.\n"); MSG_Add("SHELL_CMD_COPY_SUCCESS"," %d File(s) copied.\n"); + MSG_Add("SHELL_CMD_SUBST_NO_REMOVE","Removing drive not supported. Doing nothing.\n"); + MSG_Add("SHELL_CMD_SUBST_FAILURE","SUBST failed. You either made an error in your commandline or the target drive is already used.\nIt's only possible to use SUBST on Local drives"); MSG_Add("SHELL_STARTUP","DOSBox Shell v" VERSION "\n" "This version runs some protected mode games!\n" @@ -311,10 +313,13 @@ void SHELL_Init() { MSG_Add("SHELL_CMD_REM_HELP","Add comments in a batch file.\n"); MSG_Add("SHELL_CMD_NO_WILD","This is a simple version of the command, no wildcards allowed!\n"); MSG_Add("SHELL_CMD_RENAME_HELP","Renames files.\n"); - MSG_Add("SHELL_CMD_DELETE_HELP","Removes files.\n"); + MSG_Add("SHELL_CMD_DELETE_HELP","Removes files.\n"); MSG_Add("SHELL_CMD_COPY_HELP","Copy files.\n"); MSG_Add("SHELL_CMD_CALL_HELP","Start a batch file from within another batch file.\n"); - /* Regular startup */ + MSG_Add("SHELL_CMD_SUBST_HELP","Assign an internal directory to a drive\n"); + MSG_Add("SHELL_CMD_LOADHIGH_HELP","Run a program. For batch file compatibility only.\n"); + + /* Regular startup */ call_shellstop=CALLBACK_Allocate(); /* Setup the startup CS:IP to kill the last running machine when exitted */ RealPt newcsip=CALLBACK_RealPointer(call_shellstop); diff --git a/src/shell/shell_batch.cpp b/src/shell/shell_batch.cpp index 538f3e30..735b3f88 100644 --- a/src/shell/shell_batch.cpp +++ b/src/shell/shell_batch.cpp @@ -19,7 +19,7 @@ #include #include -#include "shell_inc.h" +#include "shell.h" BatchFile::BatchFile(DOS_Shell * host,char * name, char * cmd_line) { diff --git a/src/shell/shell_cmds.cpp b/src/shell/shell_cmds.cpp index f942c2e8..32a246ea 100644 --- a/src/shell/shell_cmds.cpp +++ b/src/shell/shell_cmds.cpp @@ -16,13 +16,14 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: shell_cmds.cpp,v 1.35 2003-11-11 18:47:25 qbix79 Exp $ */ +/* $Id: shell_cmds.cpp,v 1.36 2003-12-17 21:50:59 qbix79 Exp $ */ #include -#include "shell_inc.h" +#include "shell.h" #include "callback.h" #include "regs.h" +#include "../dos/drives.h" static SHELL_Cmd cmd_list[]={ { "CHDIR", 0, &DOS_Shell::CMD_CHDIR, "SHELL_CMD_CHDIR_HELP"}, @@ -49,7 +50,10 @@ static SHELL_Cmd cmd_list[]={ { "REN", 1, &DOS_Shell::CMD_RENAME, "SHELL_CMD_RENAME_HELP"}, { "PAUSE", 0, &DOS_Shell::CMD_PAUSE, "SHELL_CMD_PAUSE_HELP"}, { "CALL", 0, &DOS_Shell::CMD_CALL, "SHELL_CMD_CALL_HELP"}, -{ 0,0,0,0} +{ "SUBST", 0, &DOS_Shell::CMD_SUBST, "SHELL_CMD_SUBST_HELP"}, +{ "LOADHIGH", 0, &DOS_Shell::CMD_LOADHIGH, "SHELL_CMD_LOADHIGH_HELP"}, +{ "LH", 1, &DOS_Shell::CMD_LOADHIGH, "SHELL_CMD_LOADHIGH_HELP"}, +{0,0,0,0} }; void DOS_Shell::DoCommand(char * line) { @@ -586,3 +590,55 @@ void DOS_Shell::CMD_CALL(char * args){ this->call=false; } +void DOS_Shell::CMD_SUBST (char * args) { +/* If more that one type can be substed think of something else + * E.g. make basedir member dos_drive instead of localdrive + */ + localDrive* ldp=0; + char mountstring[DOS_PATHLENGTH+CROSS_LEN+20]; + char temp_str[2] = { 0,0 }; + try { + strcpy(mountstring,"MOUNT "); + StripSpaces(args); + std::string arg; + CommandLine command(0,args); + + if (command.GetCount() != 2) throw 0 ; + command.FindCommand(2,arg); + if((arg=="/D" ) || (arg=="/d")) throw 1; //No removal (one day) + + command.FindCommand(1,arg); + if(arg[1] !=':') throw(0); + temp_str[0]=toupper(args[0]); + if(Drives[temp_str[0]-'A'] ) throw 0; //targetdrive in use + strcat(mountstring,temp_str); + strcat(mountstring," "); + + command.FindCommand(2,arg); + Bit8u drive;char fulldir[DOS_PATHLENGTH]; + if (!DOS_MakeName(const_cast(arg.c_str()),fulldir,&drive)) throw 0; + + if( ( ldp=dynamic_cast(Drives[drive])) == 0 ) throw 0; + char newname[CROSS_LEN]; + strcpy(newname, ldp->basedir); + strcat(newname,fulldir); + CROSS_FILENAME(newname); + ldp->dirCache.ExpandName(newname); + strcat(mountstring, newname); + this->ParseLine(mountstring); + } + catch(int a){ + if(a == 0) { + WriteOut(MSG_Get("SHELL_CMD_SUBST_FAILURE")); + } else { + WriteOut(MSG_Get("SHELL_CMD_SUBST_NO_REMOVE")); + } + return; + } + + return; +} + +void DOS_Shell::CMD_LOADHIGH(char *args){ + this->ParseLine(args); +} diff --git a/src/shell/shell_inc.h b/src/shell/shell_inc.h deleted file mode 100644 index 18a1c1ce..00000000 --- a/src/shell/shell_inc.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (C) 2002-2003 The DOSBox Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* $Id: shell_inc.h,v 1.17 2003-09-08 18:19:28 qbix79 Exp $ */ - -#include -#include -#include "dosbox.h" -#include "mem.h" -#include "programs.h" -#include "dos_inc.h" -#include "regs.h" -#include "support.h" -#include "callback.h" -#include "setup.h" - -#include -#include - -#define CMD_MAXLINE 4096 -#define CMD_MAXCMDS 20 -#define CMD_OLDSIZE 4096 -extern Bitu call_shellstop; -class DOS_Shell; - - -class BatchFile { -public: - BatchFile(DOS_Shell * host,char * name, char * cmd_line); - ~BatchFile(); - bool ReadLine(char * line); - bool Goto(char * where); - Bit16u file_handle; - bool echo; - DOS_Shell * shell; - BatchFile * prev; - CommandLine * cmd; -}; - -class DOS_Shell : public Program { - -private: - - std::list l_history, l_completion; - - char *completion_start; - Bit16u completion_index; - -public: - - DOS_Shell(); - - void Run(void); - void RunInternal(void); //for command /C -/* A load of subfunctions */ - void ParseLine(char * line); - Bitu GetRedirection(char *s, char **ifn, char **ofn,bool * append); - void InputCommand(char * line); - void ShowPrompt(); - void DoCommand(char * cmd); - void Execute(char * name,char * args); -/* Some internal used functions */ - char * Which(char * name); -/* Some supported commands */ - void CMD_HELP(char * args); - void CMD_CLS(char * args); - void CMD_COPY(char * args); - void CMD_DIR(char * args); - void CMD_DELETE(char * args); - void CMD_ECHO(char * args); - void CMD_EXIT(char * args); - void CMD_MKDIR(char * args); - void CMD_CHDIR(char * args); - void CMD_RMDIR(char * args); - void CMD_SET(char * args); - void CMD_IF(char * args); - void CMD_GOTO(char * args); - void CMD_TYPE(char * args); - void CMD_REM(char * args); - void CMD_RENAME(char * args); - void CMD_CALL(char * args); - void SyntaxError(void); - void CMD_PAUSE(char * args); - /* The shell's variables */ - Bit16u input_handle; - BatchFile * bf; - bool echo; - bool exit; - bool call; -}; - -struct SHELL_Cmd { - const char * name; /* Command name*/ - Bit32u flags; /* Flags about the command */ - void (DOS_Shell::*handler)(char * args); /* Handler for this command */ - const char * help; /* String with command help */ -}; - -static inline void StripSpaces(char*&args) -{ - while(*args && (*args == ' ')) - args++; -} - - -static inline char* ExpandDot(char*args, char* buffer) -{ - if(*args=='.') - { - if(*(args+1)==0) - { - strcpy(buffer,"*.*"); - return buffer; - } - if( (*(args+1)!='.') && (*(args+1)!='\\') ) - { - buffer[0]='*'; - buffer[1]=0; - strcat(buffer,args); - return buffer; - } - } - else strcpy(buffer,args); - return buffer; -} - - diff --git a/src/shell/shell_misc.cpp b/src/shell/shell_misc.cpp index c688f83c..4465ffad 100644 --- a/src/shell/shell_misc.cpp +++ b/src/shell/shell_misc.cpp @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: shell_misc.cpp,v 1.26 2003-10-10 09:21:35 qbix79 Exp $ */ +/* $Id: shell_misc.cpp,v 1.27 2003-12-17 21:50:59 qbix79 Exp $ */ #include #include -#include "shell_inc.h" +#include "shell.h" #include "regs.h"