Skip to content

Commit 3f7bd9a

Browse files
author
peter
committed
1.0
1 parent 5a2e8e2 commit 3f7bd9a

File tree

4 files changed

+95
-11
lines changed

4 files changed

+95
-11
lines changed

Makefile.defs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
VERSION := 3.3.4
1+
VERSION := 1.0
22

3-
PREFIX=./
4-
DESTDIR=
3+
DESTDIR=./release/
54

6-
BIN=$(PREFIX)
7-
STEADPATH=$(PREFIX)stead
5+
BIN=./
6+
STEADPATH=./stead
87

98
INSTALLD=install -d -m 0755
109
INSTALLB=install -m 0755

Makefile.mingw

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
include Makefile.common
22

3-
WINDOWS=yes
4-
53
LUA_CFLAGS=-I./windows/
64
LUA_LFLAGS=-llua5.1 -L./windows/
75

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# instead-cli
2+
3+
## Build and run
4+
5+
```
6+
$ git clone https://github.com/instead-hub/instead-cli.git
7+
$ git submodule init
8+
$ git submodule update
9+
# edit Makefile.defs if needed
10+
$ make install
11+
$ cd release
12+
$ ./instead-cli
13+
```
14+
15+
System wide setup:
16+
17+
Edit Makefile.defs
18+
19+
```
20+
DESTDIR=/
21+
BIN=/usr/local/bin
22+
STEADPATH=/usr/local/share/instead-cli/
23+
```
24+
25+
Then:
26+
27+
```
28+
$ make && sudo make install
29+
```
30+
31+
## Run
32+
33+
./instead-cli <gamedir path>
34+
35+
To pass internal command to STEAD use '/' prefix. Some internal commands:
36+
37+
* /save filename
38+
* /load filename
39+
* /quit
40+
* /inv
41+
* /look
42+
43+
Options:
44+
45+
* -d - debug mode;
46+
* -dfile - debug mode + write stderr to file;
47+
* -wnum - line width is num symbols (70 by default);
48+
* -iscript - read script line by line and use it as commands;
49+
* -lfile - write all input commands to file;
50+
* -a - autosave on exit and autoload on start (autosave file)

main.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* Copyright 2009-2021 Peter Kosyh <p.kosyh at gmail.com>
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation files
6+
* (the "Software"), to deal in the Software without restriction,
7+
* including without limitation the rights to use, copy, modify, merge,
8+
* publish, distribute, sublicense, and/or sell copies of the Software,
9+
* and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
125
#include <stdio.h>
226
#include <stdlib.h>
327
#include <string.h>
@@ -15,6 +39,7 @@ static int opt_log = 0;
1539
static int opt_debug = 0;
1640
static int opt_width = WIDTH;
1741
static char *opt_autoload = NULL;
42+
static int opt_autosave = 1;
1843

1944
static int need_restart = 0;
2045
static int need_load = 0;
@@ -170,6 +195,7 @@ int main(int argc, const char **argv)
170195
{
171196
int rc, i;
172197
char *str;
198+
FILE *log_file = NULL;
173199
const char *game = NULL;
174200
char cmd[256 + 64];
175201

@@ -180,11 +206,14 @@ int main(int argc, const char **argv)
180206
for (i = 1; i < argc; i++) {
181207
if (!strncmp(argv[i], "-l", 2)) {
182208
opt_log = 1;
183-
reopen_stderr(argv[i] + 2);
209+
log_file = fopen(argv[i] + 2, "wb");
184210
#ifdef _WIN32
185211
} else if (!strncmp(argv[i], "-cp", 3)) {
186212
opt_codepage = atoi(argv[i] + 3);
187213
#endif
214+
} else if (!strcmp(argv[i], "-a")) {
215+
opt_autoload = strdup("autosave");
216+
opt_autosave = 1;
188217
} else if (!strncmp(argv[i], "-d", 2)) {
189218
opt_debug = 1;
190219
reopen_stderr(argv[i] + 2);
@@ -204,6 +233,7 @@ int main(int argc, const char **argv)
204233
SetConsoleCP(opt_codepage);
205234
#endif
206235
if (!game) {
236+
printf("instead-cli %s (by Peter Kosyh '2021)\n", VERSION);
207237
fprintf(stdout, "Usage: %s [-d<file>] [-w<width>] [-i<script>] [-l<log>] <game>\n", argv[0]);
208238
exit(1);
209239
}
@@ -294,8 +324,12 @@ int main(int argc, const char **argv)
294324
}
295325
if (!parser_mode && !cmd_mode)
296326
footer();
297-
if (opt_log)
298-
fprintf(stderr, "%s\n", p);
327+
if (opt_log) {
328+
if (log_file)
329+
fprintf(log_file, "%s\n", p);
330+
else
331+
fprintf(stderr, "%s\n", p);
332+
}
299333
if (need_restart) {
300334
instead_done();
301335
goto restart;
@@ -331,7 +365,10 @@ int main(int argc, const char **argv)
331365
}
332366
}
333367
}
334-
free(instead_cmd("save autosave", NULL));
368+
if (opt_autosave)
369+
free(instead_cmd("save autosave", NULL));
335370
instead_done();
371+
if (log_file)
372+
fclose(log_file);
336373
exit(0);
337374
}

0 commit comments

Comments
 (0)