DOSBox-X
|
00001 /* 00002 * Copyright (C) 2002-2020 The DOSBox Team 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License along 00015 * with this program; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 00020 #ifndef DOSBOX_SHELL_H 00021 #define DOSBOX_SHELL_H 00022 00023 #include <ctype.h> 00024 #ifndef DOSBOX_DOSBOX_H 00025 #include "dosbox.h" 00026 #endif 00027 #ifndef DOSBOX_PROGRAMS_H 00028 #include "programs.h" 00029 #endif 00030 00031 #include <string> 00032 #include <list> 00033 #include <map> 00034 00035 #include <SDL.h> 00036 #if SDL_VERSION_ATLEAST(2, 0, 0) 00037 #define SDL_STRING "SDL2" 00038 #else 00039 #define SDL_STRING "SDL1" 00040 #endif 00041 00042 #define CMD_MAXLINE 4096 00043 #define CMD_MAXCMDS 20 00044 #define CMD_OLDSIZE 4096 00045 extern Bitu call_shellstop; 00046 class DOS_Shell; 00047 00048 /* first_shell is used to add and delete stuff from the shell env 00049 * by "external" programs. (config) */ 00050 extern DOS_Shell * first_shell; 00051 00052 00053 class BatchFile { 00054 public: 00055 BatchFile(DOS_Shell * host,char const* const resolved_name,char const* const entered_name, char const * const cmd_line); 00056 virtual ~BatchFile(); 00057 virtual bool ReadLine(char * line); 00058 bool Goto(const char * where); 00059 void Shift(void); 00060 Bit16u file_handle; 00061 Bit32u location; 00062 bool echo; 00063 DOS_Shell * shell; 00064 BatchFile * prev; 00065 CommandLine * cmd; 00066 std::string filename; 00067 }; 00068 00069 class AutoexecEditor; 00070 00075 class DOS_Shell : public Program { 00076 private: 00077 friend class AutoexecEditor; 00078 std::list<std::string> l_history, l_completion; 00079 template<class _Type> 00080 struct less_ignore_case { 00081 typedef _Type first_argument_type; 00082 typedef _Type second_argument_type; 00083 typedef bool result_type; 00084 00085 constexpr bool operator()(const _Type& _Left, const _Type& _Right) const { 00086 return strcasecmp(_Left.c_str(), _Right.c_str()) < 0; 00087 } 00088 }; 00089 typedef std::map<std::string, std::string, less_ignore_case<std::string> > cmd_alias_map_t; 00090 cmd_alias_map_t cmd_alias; 00091 00092 Bit16u completion_index; 00093 00094 private: 00095 void ProcessCmdLineEnvVarStitution(char * line); 00096 00097 public: 00098 00099 DOS_Shell(); 00100 virtual ~DOS_Shell(); 00101 00104 void Run(void); 00105 00108 void RunInternal(void); //for command /C 00109 00110 /* A load of subfunctions */ 00111 00114 void ParseLine(char * line); 00115 00118 Bitu GetRedirection(char *s, char **ifn, char **ofn, char **toc,bool * append); 00119 00122 void InputCommand(char * line); 00123 00126 void ShowPrompt(); 00127 00130 void DoCommand(char * line); 00131 00134 bool Execute(char* name, const char* args); 00135 00137 bool CheckConfig(char* cmd_in,char*line); 00138 00141 char * Which(char * name); 00142 00145 void CMD_HELP(char * args); 00146 00149 void CMD_BREAK(char * args); 00150 00153 void CMD_CLS(char * args); 00154 00157 void CMD_COPY(char * args); 00158 00161 void CMD_DATE(char * args); 00162 00165 void CMD_TIME(char * args); 00166 00169 void CMD_DIR(char * args); 00170 00173 void CMD_DELETE(char * args); 00174 00177 void CMD_ECHO(char * args); 00178 00181 void CMD_EXIT(char * args); 00182 00185 void CMD_MKDIR(char * args); 00186 00189 void CMD_CHDIR(char * args); 00190 00193 void CMD_RMDIR(char * args); 00194 00197 void CMD_SET(char * args); 00198 00201 void CMD_IF(char * args); 00202 00205 void CMD_GOTO(char * args); 00206 00209 void CMD_TYPE(char * args); 00210 00213 void CMD_REM(char * args); 00214 00217 void CMD_RENAME(char * args); 00218 00221 void CMD_CALL(char * args); 00222 00225 void SyntaxError(void); 00226 00229 void CMD_PAUSE(char * args); 00230 00233 void CMD_SUBST(char* args); 00234 00237 void CMD_LOADHIGH(char* args); 00238 00241 void CMD_CHOICE(char * args); 00242 00245 void CMD_ATTRIB(char * args); 00246 00249 void CMD_PATH(char * args); 00250 00253 void CMD_SHIFT(char * args); 00254 00257 void CMD_VERIFY(char * args); 00258 00261 void CMD_VER(char * args); 00262 00265 void CMD_ADDKEY(char * args); 00266 00269 void CMD_VOL(char * args); 00270 00273 void CMD_PROMPT(char * args); 00274 00277 void CMD_MORE(char * args); 00278 00281 void CMD_CTTY(char * args); 00282 00285 void CMD_COUNTRY(char * args); 00286 void CMD_TRUENAME(char * args); 00287 void CMD_DXCAPTURE(char * args); 00288 00291 void CMD_FOR(char * args); 00292 00295 void CMD_LFNFOR(char * args); 00296 00299 void CMD_ALIAS(char* args); 00300 00303 void CMD_LS(char *args); 00304 00305 #if C_DEBUG 00306 00308 void CMD_DEBUGBOX(char * args); 00309 00312 void CMD_INT2FDBG(char * args); 00313 #endif 00314 00315 /* The shell's variables */ 00316 Bit16u input_handle; 00317 BatchFile * bf; 00318 bool echo; 00319 bool exit; 00320 bool call; 00321 bool lfnfor; 00322 /* Status */ 00323 bool input_eof; 00324 }; 00325 00326 struct SHELL_Cmd { 00327 const char * name; /* Command name*/ 00328 Bit32u flags; /* Flags about the command */ 00329 void (DOS_Shell::*handler)(char * args); /* Handler for this command */ 00330 const char * help; /* String with command help */ 00331 }; 00332 00333 /* Object to manage lines in the autoexec.bat The lines get removed from 00334 * the file if the object gets destroyed. The environment is updated 00335 * as well if the line set a a variable */ 00336 class AutoexecObject{ 00337 private: 00338 bool installed; 00339 std::string buf; 00340 public: 00341 AutoexecObject():installed(false){ }; 00342 void Install(std::string const &in); 00343 void InstallBefore(std::string const &in); 00344 void Uninstall(); 00345 ~AutoexecObject(); 00346 private: 00347 void CreateAutoexec(void); 00348 }; 00349 00350 #endif