DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
include/programs.h
00001 /*
00002  *  Copyright (C) 2002-2013  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_PROGRAMS_H
00021 #define DOSBOX_PROGRAMS_H
00022 
00023 #ifndef DOSBOX_DOSBOX_H
00024 #include "dosbox.h"
00025 #endif
00026 #ifndef DOSBOX_DOS_INC_H
00027 #include "dos_inc.h"
00028 #endif
00029 
00030 #ifndef CH_LIST
00031 #define CH_LIST
00032 #include <list>
00033 #endif
00034 
00035 #ifndef CH_STRING
00036 #define CH_STRING
00037 #include <string>
00038 #endif
00039 
00040 class CommandLine {
00041 public:
00042         enum opt_style {
00043                 dos=0,          // MS-DOS style /switches
00044                 gnu,            // GNU style --switches or -switches, switch parsing stops at --
00045                 gnu_getopt,     // GNU style --long or -a -b -c -d or -abcd (short as single char), switch parsing stops at --
00046                 either          // both dos and gnu, switch parsing stops at --
00047         };
00048 public:
00049         CommandLine(int argc,char const * const argv[],enum opt_style opt=CommandLine::either);
00050         CommandLine(char const * const name,char const * const cmdline,enum opt_style opt=CommandLine::either);
00051         const char * GetFileName(){ return file_name.c_str();}
00052 
00053         bool FindExist(char const * const name,bool remove=false);
00054         bool FindHex(char const * const name,int & value,bool remove=false);
00055         bool FindInt(char const * const name,int & value,bool remove=false);
00056         bool FindString(char const * const name,std::string & value,bool remove=false);
00057         bool FindCommand(unsigned int which,std::string & value);
00058         bool FindStringBegin(char const * const begin,std::string & value, bool remove=false);
00059         bool FindStringRemain(char const * const name,std::string & value);
00060         bool FindStringRemainBegin(char const * const name,std::string & value);
00061         bool GetStringRemain(std::string & value);
00062         int GetParameterFromList(const char* const params[], std::vector<std::string> & output);
00063         void FillVector(std::vector<std::string> & vector);
00064         unsigned int GetCount(void);
00065         void Shift(unsigned int amount=1);
00066         Bit16u Get_arglength();
00067 
00068         bool BeginOpt(bool eat_argv=true);
00069         bool GetOpt(std::string &name);
00070         bool NextOptArgv(std::string &argv);
00071         bool GetOptGNUSingleCharCheck(std::string &name);
00072         void ChangeOptStyle(enum opt_style opt_style);
00073         void EndOpt();
00074 
00075     bool GetCurrentArgv(std::string &argv);
00076     bool CurrentArgvEnd(void);
00077     void EatCurrentArgv(void);
00078     void NextArgv(void);
00079 private:
00080         typedef std::list<std::string>::iterator cmd_it;
00081         std::string opt_gnu_getopt_singlechar;          /* non-empty if we hit GNU options like -abcd => -a -b -c -d */
00082         cmd_it opt_scan;
00083         bool opt_eat_argv;
00084         std::list<std::string> cmds;
00085         std::string file_name;
00086         enum opt_style opt_style;
00087         bool FindEntry(char const * const name,cmd_it & it,bool neednext=false);
00088 };
00089 
00095 class Program {
00096 public:
00097         Program();                                          
00098         virtual ~Program(){                                 
00099                 if (cmd != NULL) delete cmd;
00100                 if (psp != NULL) delete psp;
00101         }
00102 
00105         unsigned char exit_status;                          
00106 
00107         std::string temp_line;                              
00108         CommandLine * cmd;                                  
00109         DOS_PSP * psp;                                      
00110         virtual void Run(void)=0;                           
00111         bool GetEnvStr(const char * entry,std::string & result); 
00112         bool GetEnvNum(Bitu num,std::string & result);      
00113         Bitu GetEnvCount(void);                             
00114         bool SetEnv(const char * entry,const char * new_string); 
00115         void WriteOut(const char * format,...);                         
00116         void WriteOut_NoParsing(const char * format);           
00117         void ChangeToLongCmd();                             
00118         void DebugDumpEnv();                                
00119         void WriteExitStatus();                             
00120 };
00121 
00122 typedef void (PROGRAMS_Main)(Program * * make);
00123 void PROGRAMS_MakeFile(char const * const name,PROGRAMS_Main * main);
00124 
00125 #endif