This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
mgMain.c
176 lines (148 loc) · 3.43 KB
/
mgMain.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* LEAF Visual Novel System For MGL2
* (c) Copyright 2001 TF <[email protected]>
* All rights reserverd.
*
* ORIGINAL LVNS (c) Copyright 1996-1999 LEAF/AQUAPLUS Inc.
*
* $Id: mgMain.c,v 1.6 2001/08/12 11:35:44 tf Exp $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include "Lvns.h"
static void
usage_exit()
{
fprintf(stderr, "usage: mglvns [-v <LVNS version>] [-f <FONT>] [-d] [-h]\n");
fprintf(stderr, " -v <LVNS version>: Specify the version of LVNS\n");
fprintf(stderr, " -f <FONT>: Specify the font.\n");
fprintf(stderr, " -d: Run in the demo mode.\n");
fprintf(stderr, " -h: Show this help and quit\n");
exit(1);
}
static void
parse_arg(Lvns *lvns, int argc, char *argv[])
{
int c;
lvns->version = 1; /* the default is 'sizuku' */
#ifdef FONT_PLUS
lvns->font_file = "PAK FILE"; /* the default font file */
#endif /* FONT_PLUS */
#ifdef FONT_PLUS
while ((c = getopt(argc, argv, "v:dhn:f:")) > 0) {
#else /* FONT_PLUS */
while ((c = getopt(argc, argv, "v:dhn:")) > 0) {
#endif /* FONT_PLUS */
switch (c) {
case 'v':
fprintf(stderr, "LVNS version: %s\n", optarg);
lvns->version = atoi(optarg);
if (lvns->version < 1 || lvns->version > 3) {
fprintf(stderr, "Invalid LVNS version.\n");
exit(1);
}
break;
#ifdef FONT_PLUS
case 'f':
if( strcmp( optarg, "system") == 0){
lvns->font_file = NULL;
} else {
lvns->font_file = optarg;
}
break;
#endif /* FONT_PLUS */
case 'd':
fprintf(stderr, "Run in the demo mode.\n");
lvns->demo_mode = True;
break;
case 'n':
if(strcmp(optarg, "b") == 0){
fprintf(stderr, "Disable the effect on the background screen.\n");
lvns->enable_effect_back = False;
}
if(strcmp(optarg, "e") == 0){
fprintf(stderr, "Disable the effect.\n");
lvns->enable_effect = False;
}
break;
case 'h':
usage_exit();
break;
default:
usage_exit();
}
}
}
/*
* check and preare directories.
*/
static void
init_path(Lvns *lvns)
{
char dir[PATH_LEN];
char *d;
struct stat sb;
if (lvns->data_path) free(lvns->data_path);
/*
* user's home directory
*/
snprintf(dir, sizeof(dir), "%s/%s", getenv("HOME"), ".mglvns");
if (stat(dir, &sb) < 0) {
perror(dir);
dprintf((stderr, "%s: made user directory.\n", dir));
if (mkdir(dir, 0700) < 0) {
perror(dir);
exit(1);
}
} else if (!(sb.st_mode & S_IFDIR)) {
dprintf((stderr, "%s: not directory.\n", dir));
exit(1);
}
lvns->savedata_path = strdup(dir);
/*
* where leafpack archive is
*/
d = getenv("MGLVNS_APPDIR");
if (!d) {
d = MGLVNS_APPDIR;
}
lvns->data_path = strdup(d);
dprintf((stderr, "user dir: %s\n", lvns->savedata_path));
dprintf((stderr, "appdir: %s\n", lvns->data_path));
}
static Lvns *
initialize(int argc, char *argv[])
{
Lvns *lvns;
fprintf(stderr, VERSION);
if (!open_graph()) {
fprintf(stderr, "Can't open display.\n");
exit(1);
}
set_color(COLOR_BLACK);
mgl_set_keymode(MGL_SK_EXTRANSLATED);
clear_screen();
lvns = LvnsNew();
parse_arg(lvns, argc, argv);
init_path(lvns);
mgLvnsInit(lvns);
return lvns;
}
void
mgLvnsQuit(Lvns *lvns)
{
LvnsJump(lvns, LVNS_JUMP_END);
exit(1);
}
int
main(int argc, char *argv[])
{
Lvns *lvns;
lvns = initialize(argc, argv);
LvnsMain(lvns);
return 0;
}