1 /*
2  *  Copyright (C) 2002-2010  The DOSBox Team
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 /* $Id: shell.h,v 1.28 2009-07-03 19:36:57 qbix79 Exp $ */
20 
21 #ifndef DOSBOX_SHELL_H
22 #define DOSBOX_SHELL_H
23 
24 #include <ctype.h>
25 #ifndef DOSBOX_DOSBOX_H
26 #include "dosbox.h"
27 #endif
28 #ifndef DOSBOX_PROGRAMS_H
29 #include "programs.h"
30 #endif
31 
32 #include <string>
33 #include <list>
34 
35 #define CMD_MAXLINE 4096
36 #define CMD_MAXCMDS 20
37 #define CMD_OLDSIZE 4096
38 extern Bitu call_shellstop;
39 /* first_shell is used to add and delete stuff from the shell env
40  * by "external" programs. (config) */
41 extern Program * first_shell;
42 
43 class DOS_Shell;
44 
45 class BatchFile {
46 public:
47 	BatchFile(DOS_Shell * host,char const* const resolved_name,char const* const entered_name, char const * const cmd_line);
48 	virtual ~BatchFile();
49 	virtual bool ReadLine(char * line);
50 	bool Goto(char * where);
51 	void Shift(void);
52 	Bit16u file_handle;
53 	Bit32u location;
54 	bool echo;
55 	DOS_Shell * shell;
56 	BatchFile * prev;
57 	CommandLine * cmd;
58 	std::string filename;
59 };
60 
61 class AutoexecEditor;
62 class DOS_Shell : public Program {
63 private:
64 	friend class AutoexecEditor;
65 	std::list<std::string> l_history, l_completion;
66 
67 	char *completion_start;
68 	Bit16u completion_index;
69 
70 public:
71 
72 	DOS_Shell();
73 
74 	void Run(void);
75 	void RunInternal(void); //for command /C
76 /* A load of subfunctions */
77 	void ParseLine(char * line);
78 	Bitu GetRedirection(char *s, char **ifn, char **ofn,bool * append);
79 	void InputCommand(char * line);
80 	void ShowPrompt();
81 	void DoCommand(char * cmd);
82 	bool Execute(char * name,char * args);
83 	/* Checks if it matches a hardware-property */
84 	bool CheckConfig(char* cmd_in,char*line);
85 /* Some internal used functions */
86 	char * Which(char * name);
87 /* Some supported commands */
88 	void CMD_HELP(char * args);
89 	void CMD_CLS(char * args);
90 	void CMD_COPY(char * args);
91 	void CMD_DIR(char * args);
92 	void CMD_DELETE(char * args);
93 	void CMD_ECHO(char * args);
94 	void CMD_EXIT(char * args);
95 	void CMD_MKDIR(char * args);
96 	void CMD_CHDIR(char * args);
97 	void CMD_RMDIR(char * args);
98 	void CMD_SET(char * args);
99 	void CMD_IF(char * args);
100 	void CMD_GOTO(char * args);
101 	void CMD_TYPE(char * args);
102 	void CMD_REM(char * args);
103 	void CMD_RENAME(char * args);
104 	void CMD_CALL(char * args);
105 	void SyntaxError(void);
106 	void CMD_PAUSE(char * args);
107 	void CMD_SUBST(char* args);
108 	void CMD_LOADHIGH(char* args);
109 	void CMD_CHOICE(char * args);
110 	void CMD_ATTRIB(char * args);
111 	void CMD_PATH(char * args);
112 	void CMD_SHIFT(char * args);
113 	void CMD_VER(char * args);
114 	/* The shell's variables */
115 	Bit16u input_handle;
116 	BatchFile * bf;
117 	bool echo;
118 	bool exit;
119 	bool call;
120 };
121 
122 struct SHELL_Cmd {
123 	const char * name;								/* Command name*/
124 	Bit32u flags;									/* Flags about the command */
125 	void (DOS_Shell::*handler)(char * args);		/* Handler for this command */
126 	const char * help;								/* String with command help */
127 };
128 
129 /* Object to manage lines in the autoexec.bat The lines get removed from
130  * the file if the object gets destroyed. The environment is updated
131  * as well if the line set a a variable */
132 class AutoexecObject{
133 private:
134 	bool installed;
135 	std::string buf;
136 public:
AutoexecObject()137 	AutoexecObject():installed(false){ };
138 	void Install(std::string const &in);
139 	void InstallBefore(std::string const &in);
140 	~AutoexecObject();
141 private:
142 	void CreateAutoexec(void);
143 };
144 
145 #endif
146