File: shell.h

package info (click to toggle)
dosbox-x 2026.01.02%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 53,220 kB
  • sloc: cpp: 341,269; ansic: 165,494; sh: 1,463; makefile: 967; perl: 385; python: 106; asm: 57
file content (395 lines) | stat: -rw-r--r-- 9,420 bytes parent folder | download | duplicates (2)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/*
 *  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 "programs.h"

#include <SDL.h>
#if SDL_VERSION_ATLEAST(2, 0, 0)
#define SDL_STRING "SDL2"
#else
#define SDL_STRING "SDL1"
#endif

#define CMD_MAXLINE 4096
#define CMD_MAXCMDS 20
#define CMD_OLDSIZE 4096

#define CONFIG_SIZE 4096
#define AUTOEXEC_SIZE 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;

const std::map<int, std::string> langcp_map {
	{437, "en_US"},
	//{850, "de_DE"},
    {852, "hu_HU"},
    {857, "tr_TR"},
	{858, "es_ES"},
	{859, "fr_FR"},
	{860, "pt_BR"},
	{866, "ru_RU"},
	{932, "ja_JP"},
	{936, "zh_CN"},
	{949, "ko_KR"},
	{950, "zh_TW"},
	{951, "zh_TW"},
};

class BatchFile {
public:
	BatchFile(DOS_Shell * host,char const* const resolved_name,char const* const entered_name, char const * const cmd_line);
	virtual ~BatchFile();
	virtual bool ReadLine(char * line);
	bool Goto(const char * where);
	void Shift(void);
	uint16_t file_handle;
	uint32_t location;
	bool echo;
	DOS_Shell * shell;
	BatchFile * prev;
	CommandLine * cmd;
	std::string filename;
};

class AutoexecEditor;

/*! \brief          DOS shell program object
 *
 *  \description    This is the DOS shell, including built-in commands
 */
class DOS_Shell : public Program {
private:
	friend class AutoexecEditor;
	std::list<std::string> l_history, l_completion;
    template<class _Type>
    struct less_ignore_case {
        typedef _Type first_argument_type;
        typedef _Type second_argument_type;
        typedef bool result_type;

        constexpr bool operator()(const _Type& _Left, const _Type& _Right) const {
            return strcasecmp(_Left.c_str(), _Right.c_str()) < 0;
        }
    };
    typedef std::map<std::string, std::string, less_ignore_case<std::string> > cmd_alias_map_t, cmd_assoc_map_t;
    cmd_alias_map_t cmd_alias;
    cmd_assoc_map_t cmd_assoc;
	uint16_t completion_index;
	
private:
	void ProcessCmdLineEnvVarStitution(char * line);
	std::string hasAssociation(const char* name);
	static bool hasExecutableExtension(const char* name);

public:

	DOS_Shell();
	virtual ~DOS_Shell();

	void Prepare(void);
    /*! \brief      Program entry point, when the command is run
     */
	void Run(void) override;

    /*! \brief      Alternate execution if /C switch is given
     */
	void RunInternal(void); //for command /C

/* A load of subfunctions */

    /*! \brief      Line parsing function
     */
	void ParseLine(char * line);

    /*! \brief      Redirection handling
     */
	Bitu GetRedirection(char *s, char **ifn, char **ofn, char **toc,bool * append);

    /*! \brief      Build Tab completion
     */
	bool BuildCompletions(char * line, uint16_t str_len);

    /*! \brief      Command line input and keyboard handling
     */
	void InputCommand(char * line);

    /*! \brief      Render and output command prompt
     */
	void ShowPrompt();

    /*! \brief      Process and execute command (internal or external)
     */
	void DoCommand(char * line);

    /*! \brief      Execute a command
     */
    bool Execute(char* name, const char* args);

	/*! \brief      Checks if it matches a hardware-property */
	bool CheckConfig(char* cmd_in,char*line);

    /*! \brief      Given a command, look up the path using default paths and the PATH variable
     */
	char * Which(char * name);

    /*! \brief      Command history list
     */
	void CMD_HISTORY(char * args);

    /*! \brief      Online HELP for the shell
     */
	void CMD_HELP(char * args);

    /*! \brief      Extended Ctrl+C switch
     */
	void CMD_BREAK(char * args);

    /*! \brief      Clear screen (CLS)
     */
	void CMD_CLS(char * args);

    /*! \brief      File copy command
     */
	void CMD_COPY(char * args);

    /*! \brief      Command to set date (DATE)
     */
	void CMD_DATE(char * args);

    /*! \brief      Command to set time (TIME)
     */
	void CMD_TIME(char * args);

    /*! \brief      Directory listing (DIR)
     */
	void CMD_DIR(char * args);

    /*! \brief      Deletion command (DEL)
     */
	void CMD_DELETE(char * args);

    /*! \brief      Delete directory tree (DELTREE)
     */
	void CMD_DELTREE(char * args);

    /*! \brief      Echo command (ECHO)
     */
	void CMD_ECHO(char * args);

    /*! \brief      Exit command (EXIT)
     */
	void CMD_EXIT(char * args);

    /*! \brief      Directory creation (MKDIR)
     */
	void CMD_MKDIR(char * args);

    /*! \brief      Change current directory (CD)
     */
	void CMD_CHDIR(char * args);

    /*! \brief      Directory deletion (RMDIR)
     */
	void CMD_RMDIR(char * args);

    /*! \brief      Environment variable setting/management (SET)
     */
	void CMD_SET(char * args);

    /*! \brief      Conditional execution (IF)
     */
	void CMD_IF(char * args);

    /*! \brief      Batch file branching (GOTO)
     */
	void CMD_GOTO(char * args);

    /*! \brief      Print file to console (TYPE)
     */
	void CMD_TYPE(char * args);

    /*! \brief      Human readable comment (REM)
     */
	void CMD_REM(char * args);

    /*! \brief      File rename (REN)
     */
	void CMD_RENAME(char * args);

    /*! \brief      Execute batch file as sub-program (CALL)
     */
	void CMD_CALL(char * args);

    /*! \brief      Print generic Syntax Error message to console
     */
	void SyntaxError(void);

    /*! \brief      Pause and wait for user to hit Enter (PAUSE)
     */
	void CMD_PAUSE(char * args);

    /*! \brief      Map drive letter to folder (SUBST)
     */
	void CMD_SUBST(char* args);

    /*! \brief      Load a program into high memory if possible
     */
	void CMD_LOADHIGH(char* args);

    /*! \brief      Prompt for a choice (CHOICE)
     */
	void CMD_CHOICE(char * args);

    /*! \brief      Set file attributes (ATTRIB)
     */
	void CMD_ATTRIB(char * args);

    /*! \brief      Set PATH variable (PATH)
     */
	void CMD_PATH(char * args);

    /*! \brief      Consume one command line argument (SHIFT)
     */
	void CMD_SHIFT(char * args);

    /*! \brief      List directory tree (TREE)
     */
	void CMD_TREE(char * args);

    /*! \brief      File verification switch
     */
	void CMD_VERIFY(char * args);

    /*! \brief      Print DOS version (VER)
     */
	void CMD_VER(char * args);

    /*! \brief      TODO?
     */
	void CMD_ADDKEY(char * args);

    /*! \brief      TODO?
     */
	void CMD_VOL(char * args);

    /*! \brief      Change DOS prompt pattern (PROMPT)
     */
	void CMD_PROMPT(char * args);

    /*! \brief      Text pager (MORE)
     */
	void CMD_MORE(char * args);

    /*! \brief      Change TTY (console) device (CTTY)
     */
	void CMD_CTTY(char * args);

    /*! \brief      Change country code
     */
	void CMD_CHCP(char * args);
	void CMD_COUNTRY(char * args);
	void CMD_PUSHD(char * args);
	void CMD_POPD(char * args);
    void CMD_TRUENAME(char * args);
    void CMD_DXCAPTURE(char * args);

    /*! \brief      Looping execution (FOR)
     */
	void CMD_FOR(char * args);

    /*! \brief      LFN switch for FOR
     */
	void CMD_LFNFOR(char * args);

    /*! \brief      ALIAS
    */
	void CMD_ALIAS(char* args);

    /*! \brief      ALIAS
    */
	void CMD_ASSOC(char* args);

    /*! \brief      VTEXT
    */
	void CMD_VTEXT(char *args);

    /*! \brief      LS
    */
	void CMD_LS(char *args);

#if C_DEBUG
    /*! \brief      Execute command within debugger (break at entry point)
     */
	void CMD_DEBUGBOX(char * args);

    /*! \brief      INT 2Fh debugging tool
     */
	void CMD_INT2FDBG(char * args);
#endif

	virtual bool execute_shell_cmd(char *name, char *arguments);

	/* The shell's variables */
	uint16_t input_handle;
	BatchFile * bf;                     //! Batch file to execute
	bool echo;
	bool exit;
	bool call;
    bool exec;
    bool perm;
	bool lfnfor;
    /* Status */
    bool input_eof;                     //! STDIN has hit EOF
};

struct SHELL_Cmd {
	const char * name;								/* Command name*/
	uint32_t flags;									/* Flags about the command */
	void (DOS_Shell::*handler)(char * args);		/* Handler for this command */
	const char * help;								/* String with command help */
};

/* 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 variable */
class AutoexecObject{
private:
	bool installed = false;
	std::string buf;
public:
	AutoexecObject() {};
	void Install(std::string const &in);
	void InstallBefore(std::string const &in);
	void Uninstall();
	~AutoexecObject();
private:
	void CreateAutoexec(void);
};

size_t GetPauseCount();

#endif