diff options
Diffstat (limited to 'src/m_argv.c')
-rw-r--r-- | src/m_argv.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/m_argv.c b/src/m_argv.c index 78404d35..1d07a196 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -29,7 +29,7 @@ #include <stdlib.h> #include <string.h> -#include "doomdef.h" +#include "doomtype.h" #include "i_system.h" #include "m_misc.h" @@ -60,8 +60,20 @@ int M_CheckParm (char *check) 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; +} + #define MAXARGVS 100 - + static void LoadResponseFile(int argv_index) { FILE *handle; @@ -74,7 +86,7 @@ static void LoadResponseFile(int argv_index) int i, k; response_filename = myargv[argv_index] + 1; - + // Read the response file into memory handle = fopen(response_filename, "r"); @@ -90,11 +102,25 @@ static void LoadResponseFile(int argv_index) // Read in the entire file // Allocate one byte extra - this is incase 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); - fread(file, size, 1, handle); + + i = 0; + + while (i < size) + { + 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); // Create new arguments list array @@ -110,7 +136,7 @@ static void LoadResponseFile(int argv_index) newargv[i] = myargv[i]; ++newargc; } - + infile = file; k = 0; @@ -121,7 +147,7 @@ static void LoadResponseFile(int argv_index) while(k < size && isspace(infile[k])) { ++k; - } + } if (k >= size) { @@ -132,7 +158,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; @@ -146,9 +172,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); } @@ -174,7 +200,7 @@ static void LoadResponseFile(int argv_index) ++k; } - } + } // Add arguments following the response file argument |