/
winargs.c
80 lines (66 loc) · 2.55 KB
/
winargs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*----------------------------------------------------------------------*\
winargs - Argument handling for arun on WINDOWS and CYGWIN
Handles the various startup methods on all machines.
Main function args() will set up global variables adventureName,
adventureFileName and the flags, the terminal will also be set up
and connected if necessary.
\*----------------------------------------------------------------------*/
#ifdef __windows__
#include <windows.h>
#endif
/*======================================================================*/
void args(int argc, char * argv[])
{
char *programName;
char *exePoint;
#ifdef ARGSDISPLAY
int i;
MessageBox(NULL, "Hello!", "Windows Arun interpreter", MB_OK);
MessageBox(NULL, GetCommandLine(), "", MB_OK);
for (i = 0; i < argc; i++) {
char buf[199];
sprintf(buf, "arg %d :\"%s\"", i, argv[i]);
MessageBox(NULL, buf, "Alan V3 compiler", MB_OK);
}
#endif
#ifdef HAVE_WINGLK
argv[0] = GetCommandLine();
#endif
if ((programName = strrchr(argv[0], '\\')) == NULL
&& (programName = strrchr(argv[0], '/')) == NULL
&& (programName = strrchr(argv[0], ':')) == NULL)
programName = strdup(argv[0]);
else
programName = strdup(&programName[1]);
if (strlen(programName) > 4 && (((exePoint = strstr(programName, ".EXE")) != NULL) || (exePoint = strstr(programName, ".exe")) != NULL))
*exePoint = '\0';
/* Now look at the switches and arguments */
switches(argc, argv);
#ifdef ARGSDISPLAY
{
char buf[100];
sprintf(buf, "programName = '%s'\nadventureFileName = '%s'", programName, adventureFileName);
MessageBox(NULL, buf, "Alan V3 compiler", MB_OK);
}
#endif
// TODO This is the same as in unixargs.c
if (adventureFileName == NULL) {
/* No game given, try program name */
if (differentInterpreterName(programName)) {
// TODO break out as a function
FILE *adventureFile;
adventureFileName = allocate(strlen(programName)
+strlen(ACODEEXTENSION)+1);
strcpy(adventureFileName, programName);
strcat(adventureFileName, ACODEEXTENSION);
// TODO break out as utils::fileExists()
if ((adventureFile = fopen(adventureFileName, "r")) == NULL) {
free(adventureFileName);
adventureFileName = NULL;
} else
fclose(adventureFile);
}
}
adventureName = gameName(adventureFileName);
free(programName);
}