summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/d_main.c163
-rw-r--r--src/m_argv.c166
-rw-r--r--src/m_argv.h1
3 files changed, 167 insertions, 163 deletions
diff --git a/src/d_main.c b/src/d_main.c
index 881e4dd9..cdf5dc35 100644
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -590,167 +590,6 @@ static boolean D_AddFile(char *filename)
return handle != NULL;
}
-
-#define MAXARGVS 100
-
-static void LoadResponseFile(int argv_index)
-{
- FILE *handle;
- int size;
- char *infile;
- char *file;
- char *response_filename;
- char **newargv;
- int newargc;
- int i, k;
-
- response_filename = myargv[argv_index] + 1;
-
- // READ THE RESPONSE FILE INTO MEMORY
- handle = fopen(response_filename, "r");
-
- if (handle == NULL)
- {
- printf ("\nNo such response file!");
- exit(1);
- }
-
- printf("Found response file %s!\n", response_filename);
-
- // Find size of file
-
- fseek(handle, 0, SEEK_END);
- size = ftell(handle);
- fseek(handle, 0, SEEK_SET);
-
- // 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
- // needed.
-
- file = malloc(size + 1);
- fread(file, size, 1, handle);
- fclose(handle);
-
- // Create new arguments list array
-
- newargv = malloc(sizeof(char *) * MAXARGVS);
- newargc = 0;
- memset(newargv, 0, sizeof(char *) * MAXARGVS);
-
- // Copy all the arguments in the list up to the response file
-
- for (i=0; i<argv_index; ++i)
- {
- newargv[i] = myargv[i];
- ++newargc;
- }
-
- infile = file;
- k = 0;
-
- while(k < size)
- {
- // Skip past space characters to the next argument
-
- while(k < size && isspace(infile[k]))
- {
- ++k;
- }
-
- if (k >= size)
- {
- break;
- }
-
- // If the next argument is enclosed in quote marks, treat
- // the contents as a single argument. This allows long filenames
- // to be specified.
-
- if (infile[k] == '\"')
- {
- // Skip the first character(")
- ++k;
-
- newargv[newargc++] = &infile[k];
-
- // Read all characters between quotes
-
- while (k < size && infile[k] != '\"' && infile[k] != '\n')
- {
- ++k;
- }
-
- if (k >= size || infile[k] == '\n')
- {
- I_Error("Quotes unclosed in response file '%s'",
- response_filename);
- }
-
- // Cut off the string at the closing quote
-
- infile[k] = '\0';
- ++k;
- }
- else
- {
- // Read in the next argument until a space is reached
-
- newargv[newargc++] = &infile[k];
-
- while(k < size && !isspace(infile[k]))
- {
- ++k;
- }
-
- // Cut off the end of the argument at the first space
-
- infile[k] = '\0';
-
- ++k;
- }
- }
-
- // Add arguments following the response file argument
-
- for (i=argv_index + 1; i<myargc; ++i)
- {
- newargv[newargc] = myargv[i];
- ++newargc;
- }
-
- myargv = newargv;
- myargc = newargc;
-
-#if 0
- // Disabled - Vanilla Doom does not do this.
- // Display arguments
-
- printf("%d command-line args:\n", myargc);
-
- for (k=1; k<myargc; k++)
- {
- printf("'%s'\n", myargv[k]);
- }
-#endif
-}
-
-//
-// Find a Response File
-//
-void FindResponseFile (void)
-{
- int i;
-
- for (i = 1; i < myargc; i++)
- {
- if (myargv[i][0] == '@')
- {
- LoadResponseFile(i);
- }
- }
-}
-
// Startup banner
void PrintBanner(char *msg)
@@ -935,7 +774,7 @@ void D_DoomMain (void)
char file[256];
char demolumpname[9];
- FindResponseFile ();
+ M_FindResponseFile ();
// Undocumented "search for IWADs" parameter used by the setup
// tool.
diff --git a/src/m_argv.c b/src/m_argv.c
index fd04631c..9e119876 100644
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -24,9 +24,13 @@
//-----------------------------------------------------------------------------
-
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include "i_system.h"
+
int myargc;
char** myargv;
@@ -52,6 +56,166 @@ int M_CheckParm (char *check)
return 0;
}
+#define MAXARGVS 100
+
+static void LoadResponseFile(int argv_index)
+{
+ FILE *handle;
+ int size;
+ char *infile;
+ char *file;
+ char *response_filename;
+ char **newargv;
+ int newargc;
+ int i, k;
+
+ response_filename = myargv[argv_index] + 1;
+
+ // Read the response file into memory
+ handle = fopen(response_filename, "r");
+
+ if (handle == NULL)
+ {
+ printf ("\nNo such response file!");
+ exit(1);
+ }
+
+ printf("Found response file %s!\n", response_filename);
+
+ // Find size of file
+
+ fseek(handle, 0, SEEK_END);
+ size = ftell(handle);
+ fseek(handle, 0, SEEK_SET);
+
+ // 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
+ // needed.
+
+ file = malloc(size + 1);
+ fread(file, size, 1, handle);
+ fclose(handle);
+
+ // Create new arguments list array
+
+ newargv = malloc(sizeof(char *) * MAXARGVS);
+ newargc = 0;
+ memset(newargv, 0, sizeof(char *) * MAXARGVS);
+
+ // Copy all the arguments in the list up to the response file
+
+ for (i=0; i<argv_index; ++i)
+ {
+ newargv[i] = myargv[i];
+ ++newargc;
+ }
+
+ infile = file;
+ k = 0;
+
+ while(k < size)
+ {
+ // Skip past space characters to the next argument
+
+ while(k < size && isspace(infile[k]))
+ {
+ ++k;
+ }
+
+ if (k >= size)
+ {
+ break;
+ }
+
+ // If the next argument is enclosed in quote marks, treat
+ // the contents as a single argument. This allows long filenames
+ // to be specified.
+
+ if (infile[k] == '\"')
+ {
+ // Skip the first character(")
+ ++k;
+
+ newargv[newargc++] = &infile[k];
+
+ // Read all characters between quotes
+
+ while (k < size && infile[k] != '\"' && infile[k] != '\n')
+ {
+ ++k;
+ }
+
+ if (k >= size || infile[k] == '\n')
+ {
+ I_Error("Quotes unclosed in response file '%s'",
+ response_filename);
+ }
+
+ // Cut off the string at the closing quote
+
+ infile[k] = '\0';
+ ++k;
+ }
+ else
+ {
+ // Read in the next argument until a space is reached
+
+ newargv[newargc++] = &infile[k];
+
+ while(k < size && !isspace(infile[k]))
+ {
+ ++k;
+ }
+
+ // Cut off the end of the argument at the first space
+
+ infile[k] = '\0';
+
+ ++k;
+ }
+ }
+
+ // Add arguments following the response file argument
+
+ for (i=argv_index + 1; i<myargc; ++i)
+ {
+ newargv[newargc] = myargv[i];
+ ++newargc;
+ }
+
+ myargv = newargv;
+ myargc = newargc;
+
+#if 0
+ // Disabled - Vanilla Doom does not do this.
+ // Display arguments
+
+ printf("%d command-line args:\n", myargc);
+
+ for (k=1; k<myargc; k++)
+ {
+ printf("'%s'\n", myargv[k]);
+ }
+#endif
+}
+
+//
+// Find a Response File
+//
+void M_FindResponseFile(void)
+{
+ int i;
+
+ for (i = 1; i < myargc; i++)
+ {
+ if (myargv[i][0] == '@')
+ {
+ LoadResponseFile(i);
+ }
+ }
+}
+
diff --git a/src/m_argv.h b/src/m_argv.h
index bd1518b9..315bb97b 100644
--- a/src/m_argv.h
+++ b/src/m_argv.h
@@ -38,5 +38,6 @@ extern char** myargv;
// in the arg list (0 if not found).
int M_CheckParm (char* check);
+void M_FindResponseFile(void);
#endif