mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-21 00:51:12 +00:00
- updated m_argv.cpp from Raze.
This commit is contained in:
parent
6847ea027d
commit
40e380f2c0
2 changed files with 84 additions and 16 deletions
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include <string.h>
|
||||
#include "m_argv.h"
|
||||
#include "i_system.h"
|
||||
#include "zstring.h"
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
|
@ -68,6 +68,17 @@ FArgs::FArgs(int argc, char **argv)
|
|||
SetArgs(argc, argv);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FArgs Argv Constructor
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FArgs::FArgs(int argc, const char** argv)
|
||||
{
|
||||
SetArgs(argc, const_cast<char **>(argv)); // Thanks, C++, for the inflexible const casting rules...
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FArgs String Argv Constructor
|
||||
|
@ -128,7 +139,22 @@ void FArgs::FlushArgs()
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
int FArgs::CheckParm(const char *check, int start) const
|
||||
int stricmp(const char** check, const char* str)
|
||||
{
|
||||
for (int i = 0; check[i]; i++)
|
||||
{
|
||||
if (!stricmp(check[i], str)) return 0;
|
||||
}
|
||||
return 1; // we do not care about order here.
|
||||
}
|
||||
|
||||
int FArgs::CheckParm(const char* check, int start) const
|
||||
{
|
||||
const char* array[] = { check, nullptr };
|
||||
return CheckParm(array, start);
|
||||
}
|
||||
|
||||
int FArgs::CheckParm(const char** check, int start) const
|
||||
{
|
||||
for (unsigned i = start; i < Argv.Size(); ++i)
|
||||
{
|
||||
|
@ -155,9 +181,9 @@ int FArgs::CheckParmList(const char *check, FString **strings, int start) const
|
|||
|
||||
if (parmat == 0)
|
||||
{
|
||||
if (strings != NULL)
|
||||
if (strings != nullptr)
|
||||
{
|
||||
*strings = NULL;
|
||||
*strings = nullptr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -168,7 +194,7 @@ int FArgs::CheckParmList(const char *check, FString **strings, int start) const
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (strings != NULL)
|
||||
if (strings != nullptr)
|
||||
{
|
||||
*strings = &Argv[parmat];
|
||||
}
|
||||
|
@ -180,7 +206,7 @@ int FArgs::CheckParmList(const char *check, FString **strings, int start) const
|
|||
// FArgs :: CheckValue
|
||||
//
|
||||
// Like CheckParm, but it also checks that the parameter has a value after
|
||||
// it and returns that or NULL if not present.
|
||||
// it and returns that or nullptr if not present.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
|
@ -191,11 +217,11 @@ const char *FArgs::CheckValue(const char *check) const
|
|||
if (i > 0 && i < (int)Argv.Size() - 1)
|
||||
{
|
||||
i++;
|
||||
return Argv[i][0] != '+' && Argv[i][0] != '-' ? Argv[i].GetChars() : NULL;
|
||||
return Argv[i][0] != '+' && Argv[i][0] != '-' ? Argv[i].GetChars() : nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,7 +284,7 @@ void FArgs::RemoveArgs(const char *check)
|
|||
|
||||
const char *FArgs::GetArg(int arg) const
|
||||
{
|
||||
return ((unsigned)arg < Argv.Size()) ? Argv[arg].GetChars() : NULL;
|
||||
return ((unsigned)arg < Argv.Size()) ? Argv[arg].GetChars() : nullptr;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -271,7 +297,7 @@ const char *FArgs::GetArg(int arg) const
|
|||
|
||||
FString *FArgs::GetArgList(int arg) const
|
||||
{
|
||||
return ((unsigned)arg < Argv.Size()) ? &Argv[arg] : NULL;
|
||||
return ((unsigned)arg < Argv.Size()) ? &Argv[arg] : nullptr;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -338,16 +364,22 @@ void FArgs::RemoveArg(int argindex)
|
|||
//
|
||||
// Takes all arguments after any instance of -param and any arguments before
|
||||
// all switches that end in .extension and combines them into a single
|
||||
// -switch block at the end of the arguments. If extension is NULL, then
|
||||
// -switch block at the end of the arguments. If extension is nullptr, then
|
||||
// every parameter before the first switch is added after this -param.
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FArgs::CollectFiles(const char *param, const char *extension)
|
||||
void FArgs::CollectFiles(const char* param, const char* extension)
|
||||
{
|
||||
const char* array[] = { param, nullptr };
|
||||
CollectFiles(param, array, extension);
|
||||
}
|
||||
|
||||
void FArgs::CollectFiles(const char *finalname, const char **param, const char *extension)
|
||||
{
|
||||
TArray<FString> work;
|
||||
unsigned int i;
|
||||
size_t extlen = extension == NULL ? 0 : strlen(extension);
|
||||
size_t extlen = extension == nullptr ? 0 : strlen(extension);
|
||||
|
||||
// Step 1: Find suitable arguments before the first switch.
|
||||
i = 1;
|
||||
|
@ -387,7 +419,7 @@ void FArgs::CollectFiles(const char *param, const char *extension)
|
|||
}
|
||||
|
||||
// Optional: Replace short path names with long path names
|
||||
#ifdef _WIN32
|
||||
#if 0 //def _WIN32
|
||||
for (i = 0; i < work.Size(); ++i)
|
||||
{
|
||||
work[i] = I_GetLongPathName(work[i]);
|
||||
|
@ -397,7 +429,7 @@ void FArgs::CollectFiles(const char *param, const char *extension)
|
|||
// Step 3: Add work back to Argv, as long as it's non-empty.
|
||||
if (work.Size() > 0)
|
||||
{
|
||||
Argv.Push(param);
|
||||
Argv.Push(finalname);
|
||||
AppendArgs(work.Size(), &work[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#ifndef __M_ARGV_H__
|
||||
#define __M_ARGV_H__
|
||||
|
||||
#include "dobject.h"
|
||||
#include "tarray.h"
|
||||
#include "zstring.h"
|
||||
|
||||
//
|
||||
|
@ -43,23 +43,58 @@
|
|||
class FArgs
|
||||
{
|
||||
public:
|
||||
|
||||
typedef TIterator<FString> iterator;
|
||||
typedef TIterator<const FString> const_iterator;
|
||||
typedef FString value_type;
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return Argv.begin();
|
||||
}
|
||||
const_iterator begin() const
|
||||
{
|
||||
return Argv.begin();
|
||||
}
|
||||
const_iterator cbegin() const
|
||||
{
|
||||
return Argv.begin();
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return Argv.end();
|
||||
}
|
||||
const_iterator end() const
|
||||
{
|
||||
return Argv.end();
|
||||
}
|
||||
const_iterator cend() const
|
||||
{
|
||||
return Argv.end();
|
||||
}
|
||||
|
||||
FArgs();
|
||||
FArgs(const FArgs &args);
|
||||
FArgs(int argc, char **argv);
|
||||
FArgs(int argc, const char** argv);
|
||||
FArgs(int argc, FString *argv);
|
||||
|
||||
FArgs &operator=(const FArgs &other);
|
||||
const FString& operator[](size_t index) { return Argv[index]; }
|
||||
|
||||
void AppendArg(FString arg);
|
||||
void AppendArgs(int argc, const FString *argv);
|
||||
void RemoveArg(int argindex);
|
||||
void RemoveArgs(const char *check);
|
||||
void SetArgs(int argc, char **argv);
|
||||
void CollectFiles(const char *finalname, const char** param, const char* extension);
|
||||
void CollectFiles(const char *param, const char *extension);
|
||||
FArgs *GatherFiles(const char *param) const;
|
||||
void SetArg(int argnum, const char *arg);
|
||||
|
||||
int CheckParm(const char *check, int start=1) const; // Returns the position of the given parameter in the arg list (0 if not found).
|
||||
int CheckParm(const char** check, int start = 1) const; // Returns the position of the given parameter in the arg list (0 if not found). Allows checking for multiple switches
|
||||
int CheckParmList(const char *check, FString **strings, int start=1) const;
|
||||
const char *CheckValue(const char *check) const;
|
||||
const char *GetArg(int arg) const;
|
||||
|
@ -67,6 +102,7 @@ public:
|
|||
FString TakeValue(const char *check);
|
||||
int NumArgs() const;
|
||||
void FlushArgs();
|
||||
TArray<FString>& Array() { return Argv; }
|
||||
|
||||
private:
|
||||
TArray<FString> Argv;
|
||||
|
|
Loading…
Reference in a new issue