DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/programs.h
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_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 styles, switch parsing stops at --
00047                 either_except   // Both DOS and GNU styles, except for paths to executables
00048         };
00049 public:
00050         CommandLine(int argc,char const * const argv[],enum opt_style opt=CommandLine::either);
00051         CommandLine(char const * const name,char const * const cmdline,enum opt_style opt=CommandLine::either);
00052         const char * GetFileName(){ return file_name.c_str();}
00053 
00054         bool FindExist(char const * const name,bool remove=false);
00055         bool FindHex(char const * const name,int & value,bool remove=false);
00056         bool FindInt(char const * const name,int & value,bool remove=false);
00057         bool FindString(char const * const name,std::string & value,bool remove=false);
00058         bool FindCommand(unsigned int which,std::string & value);
00059         bool FindStringBegin(char const * const begin,std::string & value, bool remove=false);
00060         bool FindStringRemain(char const * const name,std::string & value);
00061         bool FindStringRemainBegin(char const * const name,std::string & value);
00062         bool GetStringRemain(std::string & value);
00063         int GetParameterFromList(const char* const params[], std::vector<std::string> & output);
00064         void FillVector(std::vector<std::string> & vector);
00065         unsigned int GetCount(void);
00066         void Shift(unsigned int amount=1);
00067         Bit16u Get_arglength();
00068 
00069         bool BeginOpt(bool eat_argv=true);
00070         bool GetOpt(std::string &name);
00071         bool NextOptArgv(std::string &argv);
00072         bool GetOptGNUSingleCharCheck(std::string &name);
00073         void ChangeOptStyle(enum opt_style opt_style);
00074         void EndOpt();
00075 
00076     bool GetCurrentArgv(std::string &argv);
00077     bool CurrentArgvEnd(void);
00078     void EatCurrentArgv(void);
00079     void NextArgv(void);
00080 
00081     const std::string &GetRawCmdline(void);
00082 private:
00083         typedef std::list<std::string>::iterator cmd_it;
00084         std::string opt_gnu_getopt_singlechar;          /* non-empty if we hit GNU options like -abcd => -a -b -c -d */
00085         cmd_it opt_scan;
00086         bool opt_eat_argv = false;
00087         std::list<std::string> cmds;
00088         std::string file_name;
00089     std::string raw_cmdline;
00090         enum opt_style opt_style;
00091         bool FindEntry(char const * const name,cmd_it & it,bool neednext=false);
00092 };
00093 
00099 class Program {
00100 public:
00101         Program();                                          
00102         virtual ~Program(){                                 
00103                 if (cmd != NULL) delete cmd;
00104                 if (psp != NULL) delete psp;
00105         }
00106 
00109         unsigned char exit_status;                          
00110 
00111         std::string temp_line;                              
00112         CommandLine * cmd;                                  
00113         DOS_PSP * psp;                                      
00114         virtual void Run(void)=0;                           
00115         bool GetEnvStr(const char * entry,std::string & result); 
00116         bool GetEnvNum(Bitu want_num,std::string & result);      
00117         Bitu GetEnvCount(void);                             
00118         bool SetEnv(const char * entry,const char * new_string); 
00119         void WriteOut(const char * format,...);                         
00120         void WriteOut_NoParsing(const char * format);           
00121         void ChangeToLongCmd();                             
00122         void DebugDumpEnv();                                
00123         void WriteExitStatus();                             
00124 };
00125 
00126 typedef void (PROGRAMS_Main)(Program * * make);
00127 void PROGRAMS_MakeFile(char const * const name,PROGRAMS_Main * SDL_main);
00128 
00129 #endif