Welcome to mirror list, hosted at ThFree Co, Russian Federation.

shell.h « include - github.com/dosbox-staging/dosbox-staging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 58afb82ff841ad8709573d3013f96abf97555373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 *  Copyright (C) 2002-2021  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 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.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef DOSBOX_SHELL_H
#define DOSBOX_SHELL_H

#include "dosbox.h"

#include <cctype>
#include <list>
#include <memory>
#include <string>

#ifndef DOSBOX_PROGRAMS_H
#include "programs.h"
#endif

#include "help_util.h"

#define CMD_MAXLINE 4096
#define CMD_MAXCMDS 20
#define CMD_OLDSIZE 4096
extern Bitu call_shellstop;
class DOS_Shell;

/* first_shell is used to add and delete stuff from the shell env 
 * by "external" programs. (config) */
extern DOS_Shell * first_shell;


class BatchFile {
public:
	BatchFile(DOS_Shell * host,char const* const resolved_name,char const* const entered_name, char const * const cmd_line);
	BatchFile(const BatchFile&) = delete; // prevent copying
	BatchFile& operator=(const BatchFile&) = delete; // prevent assignment
	virtual ~BatchFile();
	virtual bool ReadLine(char * line);
	bool Goto(char * where);
	void Shift();
	uint16_t file_handle = 0;
	uint32_t location = 0;
	bool echo = false;
	DOS_Shell *shell = nullptr;
	std::shared_ptr<BatchFile> prev = {}; // shared with Shell.bf
	std::unique_ptr<CommandLine> cmd = {};
	std::string filename{};
};

class AutoexecEditor;

struct SHELL_Cmd {
	void (DOS_Shell::*handler)(char *args) = nullptr; // Handler for this command
	const char *help = "";                       // String with command help
	HELP_Filter filter = HELP_Filter::Common;
	HELP_Category category = HELP_Category::Misc;
};

class DOS_Shell : public Program {
private:
	void PrintHelpForCommands(HELP_Filter req_filter);
	void AddShellCmdsToHelpList();
	bool WriteHelp(const std::string &command, char* args);

	friend class AutoexecEditor;
	std::list<std::string> l_history{};
	std::list<std::string> l_completion{};

	char *completion_start = nullptr;
	uint16_t completion_index = 0;
	bool exit_cmd_called = false;
	static inline bool help_list_populated = false;

public:

	DOS_Shell();
	~DOS_Shell() override;
	DOS_Shell(const DOS_Shell&) = delete; // prevent copy
	DOS_Shell& operator=(const DOS_Shell&) = delete; // prevent assignment
	void Run() override;
	void RunInternal(); // for command /C
	/* A load of subfunctions */
	void ParseLine(char * line);
	void GetRedirection(char *s, std::string &ifn, std::string &ofn, std::string &pipe, bool * append);
	void InputCommand(char * line);
	void ProcessCmdLineEnvVarStitution(char *line);
	void ShowPrompt();
	void DoCommand(char * cmd);
	bool Execute(char * name,char * args);
	/* Checks if it matches a hardware-property */
	bool CheckConfig(char* cmd_in,char*line);
	/* Internal utilities for testing */
	virtual bool execute_shell_cmd(char *name, char *arguments);

	/* Some internal used functions */
	const char *Which(const char *name) const;

	/* Commands */
	void CMD_HELP(char * args);
	void CMD_CLS(char * args);
	void CMD_COPY(char * args);
	void CMD_DATE(char * args);
	void CMD_TIME(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 CMD_PAUSE(char * args);
	void CMD_SUBST(char* args);
	void CMD_LOADHIGH(char* args);
	void CMD_CHOICE(char * args);
	void CMD_ATTRIB(char * args);
	void CMD_PATH(char * args);
	void CMD_SHIFT(char * args);
	void CMD_VER(char * args);
	void CMD_LS(char *args);

	/* The shell's variables */
	uint16_t input_handle = 0;
	std::shared_ptr<BatchFile> bf = {}; // shared with BatchFile.prev
	bool echo = false;
	bool call = false;
};

/* 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:
	bool installed = false;
	std::string buf = {};

public:
	void Install(std::string const &in);
	void InstallBefore(std::string const &in);
	const std::string &GetLine() const { return buf; }
	~AutoexecObject();
private:
	void CreateAutoexec();
};

#endif