dosbox-wii/include/shell.h

168 lines
4.2 KiB
C
Raw Normal View History

2009-05-02 23:03:37 +02:00
/*
2009-05-03 00:28:34 +02:00
* Copyright (C) 2002-2007 The DOSBox Team
2009-05-02 23:03:37 +02:00
*
* 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
2009-05-03 00:02:15 +02:00
* GNU General Public License for more details.
2009-05-02 23:03:37 +02:00
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2009-05-02 23:43:00 +02:00
2009-05-03 00:28:34 +02:00
/* $Id: shell.h,v 1.20 2007/01/08 19:59:06 qbix79 Exp $ */
2009-05-02 23:53:27 +02:00
2009-05-03 00:18:08 +02:00
#ifndef DOSBOX_SHELL_H
#define DOSBOX_SHELL_H
2009-05-02 23:43:00 +02:00
2009-05-02 23:03:37 +02:00
#include <ctype.h>
2009-05-03 00:18:08 +02:00
#ifndef DOSBOX_DOSBOX_H
2009-05-02 23:03:37 +02:00
#include "dosbox.h"
2009-05-03 00:18:08 +02:00
#endif
#ifndef DOSBOX_PROGRAMS_H
2009-05-02 23:03:37 +02:00
#include "programs.h"
2009-05-03 00:18:08 +02:00
#endif
2009-05-02 23:03:37 +02:00
2009-05-02 23:43:00 +02:00
#include <string>
#include <list>
2009-05-02 23:03:37 +02:00
#define CMD_MAXLINE 4096
#define CMD_MAXCMDS 20
#define CMD_OLDSIZE 4096
extern Bitu call_shellstop;
2009-05-03 00:18:08 +02:00
/* first_shell is used to add and delete stuff from the shell env
* by "external" programs. (config) */
extern Program * first_shell;
2009-05-02 23:03:37 +02:00
class DOS_Shell;
class BatchFile {
public:
BatchFile(DOS_Shell * host,char * name, char * cmd_line);
~BatchFile();
bool ReadLine(char * line);
bool Goto(char * where);
2009-05-03 00:28:34 +02:00
void Shift(void);
2009-05-02 23:03:37 +02:00
Bit16u file_handle;
bool echo;
DOS_Shell * shell;
BatchFile * prev;
2009-05-02 23:20:05 +02:00
CommandLine * cmd;
2009-05-02 23:03:37 +02:00
};
2009-05-02 23:43:00 +02:00
class DOS_Shell : public Program {
private:
std::list<std::string> l_history, l_completion;
char *completion_start;
Bit16u completion_index;
2009-05-02 23:03:37 +02:00
public:
2009-05-02 23:43:00 +02:00
2009-05-02 23:20:05 +02:00
DOS_Shell();
2009-05-02 23:43:00 +02:00
2009-05-02 23:03:37 +02:00
void Run(void);
2009-05-02 23:43:00 +02:00
void RunInternal(void); //for command /C
2009-05-02 23:03:37 +02:00
/* A load of subfunctions */
void ParseLine(char * line);
2009-05-02 23:43:00 +02:00
Bitu GetRedirection(char *s, char **ifn, char **ofn,bool * append);
2009-05-02 23:03:37 +02:00
void InputCommand(char * line);
void ShowPrompt();
void DoCommand(char * cmd);
2009-05-03 00:18:08 +02:00
bool Execute(char * name,char * args);
/* Checks if it matches a hardware-property */
bool CheckConfig(char* cmd,char*line);
2009-05-02 23:03:37 +02:00
/* Some internal used functions */
char * Which(char * name);
/* Some supported commands */
void CMD_HELP(char * args);
void CMD_CLS(char * args);
void CMD_COPY(char * args);
void CMD_DIR(char * args);
2009-05-02 23:35:44 +02:00
void CMD_DELETE(char * args);
2009-05-02 23:03:37 +02:00
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);
2009-05-02 23:20:05 +02:00
void CMD_REM(char * args);
2009-05-02 23:35:44 +02:00
void CMD_RENAME(char * args);
2009-05-02 23:43:00 +02:00
void CMD_CALL(char * args);
2009-05-02 23:03:37 +02:00
void SyntaxError(void);
2009-05-02 23:35:44 +02:00
void CMD_PAUSE(char * args);
2009-05-02 23:53:27 +02:00
void CMD_SUBST(char* args);
void CMD_LOADHIGH(char* args);
2009-05-03 00:02:15 +02:00
void CMD_CHOICE(char * args);
void CMD_ATTRIB(char * args);
2009-05-03 00:08:43 +02:00
void CMD_PATH(char * args);
2009-05-03 00:28:34 +02:00
void CMD_SHIFT(char * args);
void CMD_VER(char * args);
2009-05-02 23:03:37 +02:00
/* The shell's variables */
Bit16u input_handle;
BatchFile * bf;
bool echo;
bool exit;
2009-05-02 23:43:00 +02:00
bool call;
2009-05-02 23:03:37 +02:00
};
struct SHELL_Cmd {
2009-05-03 00:28:34 +02:00
const char * name; /* Command name*/
2009-05-02 23:03:37 +02:00
Bit32u flags; /* Flags about the command */
2009-05-03 00:28:34 +02:00
void (DOS_Shell::*handler)(char * args); /* Handler for this command */
const char * help; /* String with command help */
2009-05-02 23:03:37 +02:00
};
2009-05-03 00:02:15 +02:00
static inline void StripSpaces(char*&args) {
2009-05-03 00:08:43 +02:00
while(args && *args && isspace(*reinterpret_cast<unsigned char*>(args)))
2009-05-02 23:43:00 +02:00
args++;
}
2009-05-03 00:02:15 +02:00
static inline char* ExpandDot(char*args, char* buffer) {
2009-05-02 23:43:00 +02:00
if(*args=='.')
{
if(*(args+1)==0)
{
strcpy(buffer,"*.*");
return buffer;
}
if( (*(args+1)!='.') && (*(args+1)!='\\') )
{
buffer[0]='*';
buffer[1]=0;
strcat(buffer,args);
return buffer;
2009-05-03 00:02:15 +02:00
} else
strcpy (buffer, args);
2009-05-02 23:43:00 +02:00
}
else strcpy(buffer,args);
return buffer;
}
2009-05-03 00:18:08 +02:00
/* 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;
2009-05-03 00:28:34 +02:00
std::string buf;
2009-05-03 00:18:08 +02:00
public:
2009-05-03 00:28:34 +02:00
AutoexecObject():installed(false){ };
void Install(std::string const &in);
void InstallBefore(std::string const &in);
2009-05-03 00:18:08 +02:00
~AutoexecObject();
private:
void CreateAutoexec(void);
};
2009-05-02 23:53:27 +02:00
#endif