-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
135 lines (102 loc) · 2.34 KB
/
main.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>
#include "r136.h"
/* init.c */
void Initialize();
void Deinitialize();
/* loadsave.c */
void SaveStatus();
char LoadStatus();
/* status.c */
void RoomStatus();
char BeastStatus();
/* use.c */
bool DoAction();
#define START_MESSAGE 0
#define SPLASH_SCREEN 1
extern char *language;
void PrintHelp(progname)
char *progname;
{
DIR *d;
struct direct *entry;
struct stat st;
char langpath[256];
printf("Usage: %s -l <language>\n", progname);
printf("Options:\n");
printf(" -l <language> Set the language to use. Available languages (default is %s):\n", language);
d = opendir("data");
if (d)
{
while (entry = readdir(d))
{
sprintf(langpath, "data/%s", entry->d_name);
if (!stat(langpath, &st) && S_ISDIR(st.st_mode)
&& strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
{
printf(" * %s\n", entry->d_name);
}
}
closedir(d);
}
printf(" -h, -? Display this help\n\n");
}
bool ParseArgs(argc, argv)
int argc;
char *argv[];
{
struct stat st;
int opt;
char langpath[256];
while ((opt = getopt(argc, argv, "l:h?")) != -1)
{
if (opt == 'l')
{
sprintf(langpath, "data/%s", optarg);
if (!stat(langpath, &st) && S_ISDIR(st.st_mode))
{
language = (char *)malloc(strlen(optarg) + 1);
strcpy(language, optarg);
return TRUE;
}
}
PrintHelp(argv[0]);
return FALSE;
}
return TRUE;
}
int main(argc, argv)
int argc;
char *argv[];
{
Progdata progdata;
if (!ParseArgs(argc, argv))
return 0;
Initialize(&progdata);
PrintFile('s', SPLASH_SCREEN, TRUE);
if (!LoadStatus(&progdata))
{
clrscr();
PrintFile('s', START_MESSAGE, FALSE);
}
while (TRUE)
{
RoomStatus(&progdata);
if (!BeastStatus(&progdata) || !DoAction(&progdata))
break;
}
SaveStatus(&progdata);
getch();
Deinitialize(&progdata);
return 0;
}
void ForceExit(progdata)
Progdata *progdata;
{
getch();
unlink(DATA_FILE);
Deinitialize(&progdata);
exit(0);
}