diff options
Diffstat (limited to 'src/m_argv.c')
-rw-r--r-- | src/m_argv.c | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/src/m_argv.c b/src/m_argv.c index 4d321bbc..2a126c4b 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -29,9 +29,10 @@ #include <stdlib.h> #include <string.h> -#include "doomdef.h" +#include "doomtype.h" #include "i_system.h" #include "m_misc.h" +#include "m_argv.h" // haleyjd 20110212: warning fix int myargc; char** myargv; @@ -60,13 +61,25 @@ int M_CheckParmWithArgs(char *check, int num_args) return 0; } +// +// M_ParmExists +// +// Returns true if the given parameter exists in the program's command +// line arguments, false if not. +// + +boolean M_ParmExists(char *check) +{ + return M_CheckParm(check) != 0; +} + int M_CheckParm(char *check) { return M_CheckParmWithArgs(check, 0); } #define MAXARGVS 100 - + static void LoadResponseFile(int argv_index) { FILE *handle; @@ -95,14 +108,23 @@ static void LoadResponseFile(int argv_index) // Read in the entire file // Allocate one byte extra - this is in case there is an argument - // at the end of the response file, in which case a '\0' will be + // at the end of the response file, in which case a '\0' will be // needed. file = malloc(size + 1); - if (fread(file, 1, size, handle) < size) + i = 0; + + while (i < size) { - I_Error("Failed to read entire response file"); + k = fread(file + i, 1, size - i, handle); + + if (k < 0) + { + I_Error("Failed to read full contents of '%s'", response_filename); + } + + i += k; } fclose(handle); @@ -120,7 +142,7 @@ static void LoadResponseFile(int argv_index) newargv[i] = myargv[i]; ++newargc; } - + infile = file; k = 0; @@ -131,7 +153,7 @@ static void LoadResponseFile(int argv_index) while(k < size && isspace(infile[k])) { ++k; - } + } if (k >= size) { @@ -142,7 +164,7 @@ static void LoadResponseFile(int argv_index) // the contents as a single argument. This allows long filenames // to be specified. - if (infile[k] == '\"') + if (infile[k] == '\"') { // Skip the first character(") ++k; @@ -156,9 +178,9 @@ static void LoadResponseFile(int argv_index) ++k; } - if (k >= size || infile[k] == '\n') + if (k >= size || infile[k] == '\n') { - I_Error("Quotes unclosed in response file '%s'", + I_Error("Quotes unclosed in response file '%s'", response_filename); } @@ -184,7 +206,7 @@ static void LoadResponseFile(int argv_index) ++k; } - } + } // Add arguments following the response file argument @@ -227,3 +249,21 @@ void M_FindResponseFile(void) } } +// Return the name of the executable used to start the program: + +char *M_GetExecutableName(void) +{ + char *sep; + + sep = strrchr(myargv[0], DIR_SEPARATOR); + + if (sep == NULL) + { + return myargv[0]; + } + else + { + return sep + 1; + } +} + |