2003-12-17 21:55:42 +00:00
|
|
|
/*
|
2021-01-14 18:29:34 +00:00
|
|
|
* Copyright (C) 2002-2021 The DOSBox Team
|
2003-12-17 21:55:42 +00:00
|
|
|
*
|
|
|
|
* 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
|
2004-08-04 09:12:57 +00:00
|
|
|
* GNU General Public License for more details.
|
2003-12-17 21:55:42 +00:00
|
|
|
*
|
2019-01-25 14:09:58 +00:00
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-12-17 21:55:42 +00:00
|
|
|
*/
|
|
|
|
|
2005-03-25 09:46:53 +00:00
|
|
|
#ifndef DOSBOX_SHELL_H
|
|
|
|
#define DOSBOX_SHELL_H
|
2003-12-17 21:55:42 +00:00
|
|
|
|
|
|
|
#include "dosbox.h"
|
2021-01-01 00:10:26 +01:00
|
|
|
|
|
|
|
#include <cctype>
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
|
2005-03-25 09:46:53 +00:00
|
|
|
#ifndef DOSBOX_PROGRAMS_H
|
2003-12-17 21:55:42 +00:00
|
|
|
#include "programs.h"
|
2005-03-25 09:46:53 +00:00
|
|
|
#endif
|
2003-12-17 21:55:42 +00:00
|
|
|
|
|
|
|
#define CMD_MAXLINE 4096
|
|
|
|
#define CMD_MAXCMDS 20
|
|
|
|
#define CMD_OLDSIZE 4096
|
|
|
|
extern Bitu call_shellstop;
|
2019-04-20 13:48:55 +00:00
|
|
|
class DOS_Shell;
|
|
|
|
|
2005-08-22 19:31:27 +00:00
|
|
|
/* first_shell is used to add and delete stuff from the shell env
|
|
|
|
* by "external" programs. (config) */
|
2019-04-20 13:48:55 +00:00
|
|
|
extern DOS_Shell * first_shell;
|
2003-12-17 21:55:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BatchFile {
|
|
|
|
public:
|
2009-11-30 14:53:00 +00:00
|
|
|
BatchFile(DOS_Shell * host,char const* const resolved_name,char const* const entered_name, char const * const cmd_line);
|
2019-12-07 11:55:38 -08:00
|
|
|
BatchFile(const BatchFile&) = delete; // prevent copying
|
|
|
|
BatchFile& operator=(const BatchFile&) = delete; // prevent assignment
|
2007-10-28 10:58:50 +00:00
|
|
|
virtual ~BatchFile();
|
|
|
|
virtual bool ReadLine(char * line);
|
2003-12-17 21:55:42 +00:00
|
|
|
bool Goto(char * where);
|
2021-01-11 14:28:40 -08:00
|
|
|
void Shift();
|
2021-01-08 14:55:35 -08:00
|
|
|
uint16_t file_handle = 0;
|
|
|
|
uint32_t location = 0;
|
|
|
|
bool echo = false;
|
|
|
|
DOS_Shell *shell = nullptr;
|
|
|
|
BatchFile *prev = nullptr;
|
|
|
|
CommandLine *cmd = nullptr;
|
|
|
|
std::string filename{};
|
2003-12-17 21:55:42 +00:00
|
|
|
};
|
|
|
|
|
2007-10-28 10:58:50 +00:00
|
|
|
class AutoexecEditor;
|
2021-04-19 09:36:23 -07:00
|
|
|
class DOS_Shell final : public Program {
|
2003-12-17 21:55:42 +00:00
|
|
|
private:
|
2007-10-28 10:58:50 +00:00
|
|
|
friend class AutoexecEditor;
|
2021-01-08 14:55:35 -08:00
|
|
|
std::list<std::string> l_history{};
|
|
|
|
std::list<std::string> l_completion{};
|
|
|
|
|
|
|
|
char *completion_start = nullptr;
|
|
|
|
uint16_t completion_index = 0;
|
2003-12-17 21:55:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DOS_Shell();
|
2021-01-08 15:53:41 -08:00
|
|
|
~DOS_Shell() override;
|
2019-12-07 11:55:38 -08:00
|
|
|
DOS_Shell(const DOS_Shell&) = delete; // prevent copy
|
|
|
|
DOS_Shell& operator=(const DOS_Shell&) = delete; // prevent assignment
|
2021-01-08 14:55:35 -08:00
|
|
|
void Run() override;
|
2021-01-11 14:28:40 -08:00
|
|
|
void RunInternal(); // for command /C
|
|
|
|
/* A load of subfunctions */
|
2003-12-17 21:55:42 +00:00
|
|
|
void ParseLine(char * line);
|
|
|
|
Bitu GetRedirection(char *s, char **ifn, char **ofn,bool * append);
|
|
|
|
void InputCommand(char * line);
|
|
|
|
void ShowPrompt();
|
|
|
|
void DoCommand(char * cmd);
|
2005-04-21 21:17:46 +00:00
|
|
|
bool Execute(char * name,char * args);
|
|
|
|
/* Checks if it matches a hardware-property */
|
2007-06-14 08:23:46 +00:00
|
|
|
bool CheckConfig(char* cmd_in,char*line);
|
2020-06-14 19:09:56 +02:00
|
|
|
|
|
|
|
/* Some internal used functions */
|
|
|
|
const char *Which(const char *name) const;
|
|
|
|
|
|
|
|
/* Commands */
|
2003-12-17 21:55:42 +00:00
|
|
|
void CMD_HELP(char * args);
|
|
|
|
void CMD_CLS(char * args);
|
|
|
|
void CMD_COPY(char * args);
|
2011-06-05 18:28:00 +00:00
|
|
|
void CMD_DATE(char * args);
|
|
|
|
void CMD_TIME(char * args);
|
2003-12-17 21:55:42 +00:00
|
|
|
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);
|
2021-01-11 14:28:40 -08:00
|
|
|
void SyntaxError();
|
2003-12-17 21:55:42 +00:00
|
|
|
void CMD_PAUSE(char * args);
|
|
|
|
void CMD_SUBST(char* args);
|
|
|
|
void CMD_LOADHIGH(char* args);
|
2004-09-09 18:36:50 +00:00
|
|
|
void CMD_CHOICE(char * args);
|
|
|
|
void CMD_ATTRIB(char * args);
|
2004-11-13 12:06:39 +00:00
|
|
|
void CMD_PATH(char * args);
|
2006-07-26 11:36:30 +00:00
|
|
|
void CMD_SHIFT(char * args);
|
2006-07-21 09:40:10 +00:00
|
|
|
void CMD_VER(char * args);
|
2020-05-22 19:05:51 +02:00
|
|
|
void CMD_LS(char *args);
|
2003-12-17 21:55:42 +00:00
|
|
|
/* The shell's variables */
|
2021-01-08 14:55:35 -08:00
|
|
|
uint16_t input_handle = 0;
|
|
|
|
BatchFile *bf = nullptr;
|
|
|
|
bool echo = false;
|
|
|
|
bool call = false;
|
2003-12-17 21:55:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SHELL_Cmd {
|
2021-01-08 14:55:35 -08:00
|
|
|
const char *name = nullptr; /* Command name*/
|
|
|
|
uint32_t flags = 0; /* Flags about the command */
|
|
|
|
void (DOS_Shell::*handler)(char *args); /* Handler for this command */
|
|
|
|
const char *help = nullptr; /* String with command help */
|
2003-12-17 21:55:42 +00:00
|
|
|
};
|
|
|
|
|
2005-03-25 09:46:53 +00:00
|
|
|
/* Object to manage lines in the autoexec.bat The lines get removed from
|
|
|
|
* the file if the object gets destroyed. The environment is updated
|
|
|
|
* as well if the line set a a variable */
|
|
|
|
class AutoexecObject{
|
|
|
|
private:
|
2021-01-08 14:55:35 -08:00
|
|
|
bool installed = false;
|
|
|
|
std::string buf{};
|
|
|
|
|
2005-03-25 09:46:53 +00:00
|
|
|
public:
|
2019-12-07 11:55:38 -08:00
|
|
|
AutoexecObject()
|
|
|
|
: installed(false),
|
|
|
|
buf("")
|
|
|
|
{}
|
2007-01-08 19:59:06 +00:00
|
|
|
void Install(std::string const &in);
|
|
|
|
void InstallBefore(std::string const &in);
|
2005-03-25 09:46:53 +00:00
|
|
|
~AutoexecObject();
|
2006-01-12 10:20:20 +00:00
|
|
|
private:
|
2021-01-11 14:28:40 -08:00
|
|
|
void CreateAutoexec();
|
2005-03-25 09:46:53 +00:00
|
|
|
};
|
|
|
|
|
2003-12-17 21:55:42 +00:00
|
|
|
#endif
|