DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
include/shell.h
00001 /*
00002  *  Copyright (C) 2002-2015  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
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 
00034 #define CMD_MAXLINE 4096
00035 #define CMD_MAXCMDS 20
00036 #define CMD_OLDSIZE 4096
00037 extern Bitu call_shellstop;
00038 /* first_shell is used to add and delete stuff from the shell env 
00039  * by "external" programs. (config) */
00040 extern Program * first_shell;
00041 
00042 class DOS_Shell;
00043 
00044 class BatchFile {
00045 public:
00046         BatchFile(DOS_Shell * host,char const* const resolved_name,char const* const entered_name, char const * const cmd_line);
00047         virtual ~BatchFile();
00048         virtual bool ReadLine(char * line);
00049         bool Goto(char * where);
00050         void Shift(void);
00051         Bit16u file_handle;
00052         Bit32u location;
00053         bool echo;
00054         DOS_Shell * shell;
00055         BatchFile * prev;
00056         CommandLine * cmd;
00057         std::string filename;
00058 };
00059 
00060 class AutoexecEditor;
00061 
00066 class DOS_Shell : public Program {
00067 private:
00068         friend class AutoexecEditor;
00069         std::list<std::string> l_history, l_completion;
00070 
00071         Bit16u completion_index;
00072         
00073 private:
00074         void ProcessCmdLineEnvVarStitution(char * line);
00075 
00076 public:
00077 
00078         DOS_Shell();
00079         virtual ~DOS_Shell();
00080 
00083         void Run(void);
00084 
00087         void RunInternal(void); //for command /C
00088 
00089 /* A load of subfunctions */
00090 
00093         void ParseLine(char * line);
00094 
00097         Bitu GetRedirection(char *s, char **ifn, char **ofn,bool * append);
00098 
00101         void InputCommand(char * line);
00102 
00105         void ShowPrompt();
00106 
00109         void DoCommand(char * cmd);
00110 
00113         bool Execute(char * name,char * args);
00114 
00116         bool CheckConfig(char* cmd_in,char*line);
00117 
00120         char * Which(char * name);
00121 
00124         void CMD_INT2FDBG(char * args);
00125 
00128         void CMD_HELP(char * args);
00129 
00132         void CMD_CLS(char * args);
00133 
00136         void CMD_COPY(char * args);
00137 
00140         void CMD_DATE(char * args);
00141 
00144         void CMD_TIME(char * args);
00145 
00148         void CMD_DIR(char * args);
00149 
00152         void CMD_DELETE(char * args);
00153 
00156         void CMD_ECHO(char * args);
00157 
00160         void CMD_EXIT(char * args);
00161 
00164         void CMD_MKDIR(char * args);
00165 
00168         void CMD_CHDIR(char * args);
00169 
00172         void CMD_RMDIR(char * args);
00173 
00176         void CMD_SET(char * args);
00177 
00180         void CMD_IF(char * args);
00181 
00184         void CMD_GOTO(char * args);
00185 
00188         void CMD_TYPE(char * args);
00189 
00192         void CMD_REM(char * args);
00193 
00196         void CMD_RENAME(char * args);
00197 
00200         void CMD_CALL(char * args);
00201 
00204         void SyntaxError(void);
00205 
00208         void CMD_PAUSE(char * args);
00209 
00212         void CMD_SUBST(char* args);
00213 
00216         void CMD_LOADHIGH(char* args);
00217 
00220         void CMD_CHOICE(char * args);
00221 
00224         void CMD_ATTRIB(char * args);
00225 
00228         void CMD_PATH(char * args);
00229 
00232         void CMD_SHIFT(char * args);
00233 
00236         void CMD_VER(char * args);
00237 
00240         void CMD_ADDKEY(char * args);
00241 
00244         void CMD_VOL(char * args);
00245 
00248         void CMD_PROMPT(char * args);
00249 
00252         void CMD_LABEL(char * args);
00253 
00256         void CMD_MORE(char * args);
00257 
00260         void CMD_CTTY(char * args);
00261 
00264         void CMD_FOR(char * args);
00265 
00266 #if C_DEBUG
00267 
00269         void CMD_DEBUGBOX(char * args);
00270 #endif
00271         /* The shell's variables */
00272         Bit16u input_handle;
00273         BatchFile * bf;                     
00274         bool echo;
00275         bool exit;
00276         bool call;
00277     /* Status */
00278     bool input_eof;                     
00279 };
00280 
00281 struct SHELL_Cmd {
00282         const char * name;                                                              /* Command name*/
00283         Bit32u flags;                                                                   /* Flags about the command */
00284         void (DOS_Shell::*handler)(char * args);                /* Handler for this command */
00285         const char * help;                                                              /* String with command help */
00286 };
00287 
00288 /* Object to manage lines in the autoexec.bat The lines get removed from
00289  * the file if the object gets destroyed. The environment is updated
00290  * as well if the line set a a variable */
00291 class AutoexecObject{
00292 private:
00293         bool installed;
00294         std::string buf;
00295 public:
00296         AutoexecObject():installed(false){ };
00297         void Install(std::string const &in);
00298         void InstallBefore(std::string const &in);
00299         void Uninstall();
00300         ~AutoexecObject();
00301 private:
00302         void CreateAutoexec(void);
00303 };
00304 
00305 #endif