# Makefile for the open-source release of adventure 2.5
-# Note: If you're building from the repository rather than the source tarball,
-# do this to get the linenoise library where you can use it:
-#
-# git submodule update --recursive --remote --init
-#
-# Therafter, you can update it like this:
-#
-# git submodule update --recursive --remote
-#
-# but this should seldom be necessary as that library is pretty stable.
-#
-# You will also need Python 3 YAML. Under Debian or ubuntu:
+# You will need Python 3 YAML. Under Debian or ubuntu:
#
# apt-get install python3-yaml
#
CC?=gcc
CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -Wpedantic -O2
-LIBS=
+LIBS=-ledit
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
- LIBS=-lrt
+ LIBS+=-lrt
endif
OBJS=main.o init.o actions.o score.o misc.o saveresume.o
CHEAT_OBJS=cheat.o init.o actions.o score.o misc.o saveresume.o
-SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control linenoise/linenoise.[ch] make_dungeon.py
+SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control make_dungeon.py
.c.o:
$(CC) $(CCFLAGS) $(DBX) -c $<
-advent: $(OBJS) linenoise.o dungeon.o
- $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o linenoise.o $(LDFLAGS) $(LIBS)
+advent: $(OBJS) dungeon.o
+ $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
-main.o: advent.h dungeon.h linenoise.o
+main.o: advent.h dungeon.h
init.o: advent.h dungeon.h
misc.o: advent.h dungeon.h
-cheat.o: advent.h dungeon.h linenoise.o
+cheat.o: advent.h dungeon.h
saveresume.o: advent.h dungeon.h
dungeon.c dungeon.h: make_dungeon.py adventure.yaml
python3 make_dungeon.py
-linenoise.o: linenoise/linenoise.h
- @test -s linenoise/linenoise.h || { echo -e "linenoise not present. Try:\n\
- git submodule update --recursive --remote --init"; exit 1; }
- $(CC) -c linenoise/linenoise.c
-
-linenoise-dbg: linenoise/linenoise.h
- @test -s linenoise/linenoise.h || { echo -e "linenoise not present. Try:\n\
- git submodule update --recursive --remote --init"; exit 1; }
- $(CC) $(CCFLAGS) -c linenoise/linenoise.c
-
clean:
rm -f *.o advent cheat *.html *.gcno *.gcda
rm -f dungeon.c dungeon.h
cd tests; $(MAKE) --quiet clean
-cheat: $(CHEAT_OBJS) linenoise.o dungeon.o
- $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) linenoise.o dungeon.o $(LDFLAGS) $(LIBS)
+cheat: $(CHEAT_OBJS) dungeon.o
+ $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
check: advent cheat
cd tests; $(MAKE) --quiet
debug: linty
debug: cheat
-debug-ln: linenoise-dbg debug
#include <stdbool.h>
#include <time.h>
#include "advent.h"
-#include "linenoise/linenoise.h"
#include "dungeon.h"
FILE *logfp = NULL, *rfp = NULL;
#include <signal.h>
#include <string.h>
#include "advent.h"
-#include "linenoise/linenoise.h"
#include "dungeon.h"
#define DIM(a) (sizeof(a)/sizeof(a[0]))
}
}
- linenoiseHistorySetMaxLen(350);
-
/* Initialize game variables */
long seedval = initialise();
}
strncpy(inputbuf, input, LINESIZE - 1);
- linenoiseFree(input);
+ free(input);
long tokens[4];
tokenize(inputbuf, tokens);
#include <stdarg.h>
#include <sys/time.h>
#include <ctype.h>
+#include <editline/readline.h>
#include "advent.h"
-#include "linenoise/linenoise.h"
#include "dungeon.h"
char* xstrdup(const char* s)
char* input;
while (true) {
- if (editline)
- input = linenoise(input_prompt);
- else {
- input = NULL;
- size_t n = 0;
- if (isatty(0))
- // LCOV_EXCL_START
- // Should be unreachable in tests, as they will use a non-interactive shell.
- printf("%s", input_prompt);
- // LCOV_EXCL_STOP
- ssize_t numread = getline(&input, &n, stdin);
- if (numread == -1) { // Got EOF; return with it.
- free(input);
- return (NULL);
- }
- }
+ input = readline(input_prompt);
if (input == NULL) // Got EOF; return with it.
return (input);
else if (input[0] == '#') { // Ignore comments.
- linenoiseFree(input);
+ free(input);
continue;
} else // We have a 'normal' line; leave the loop.
break;
// Strip trailing newlines from the input
input[strcspn(input, "\n")] = 0;
- linenoiseHistoryAdd(input);
+ add_history(input);
if (!isatty(0))
echo_input(stdout, input_prompt, input);
if (reply == NULL) {
// LCOV_EXCL_START
// Should be unreachable. Reply should never be NULL
- linenoiseFree(reply);
+ free(reply);
exit(EXIT_SUCCESS);
// LCOV_EXCL_STOP
}
char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
- linenoiseFree(reply);
+ free(reply);
for (int i = 0; i < (int)strlen(firstword); ++i)
firstword[i] = tolower(firstword[i]);
if (reply == NULL) {
// LCOV_EXCL_START
// Should be unreachable. Reply should never be NULL
- linenoiseFree(reply);
+ free(reply);
exit(EXIT_SUCCESS);
// LCOV_EXCL_STOP
}
char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
- linenoiseFree(reply);
+ free(reply);
for (int i = 0; i < (int)strlen(firstword); ++i)
firstword[i] = tolower(firstword[i]);
#include <stdlib.h>
#include <string.h>
+#include <editline/readline.h>
#include "advent.h"
#include "dungeon.h"
-#include "linenoise/linenoise.h"
/*
* (ESR) This replaces a bunch of particularly nasty FORTRAN-derived code;
game.saved = game.saved + 5;
while (fp == NULL) {
- char* name = linenoise("\nFile name: ");
+ char* name = readline("\nFile name: ");
if (name == NULL)
return GO_TOP;
fp = fopen(name, WRITE_MODE);
if (fp == NULL)
printf("Can't open file %s, try again.\n", name);
- linenoiseFree(name);
+ free(name);
}
savefile(fp, VRSION);
}
while (fp == NULL) {
- char* name = linenoise("\nFile name: ");
+ char* name = readline("\nFile name: ");
if (name == NULL)
return GO_TOP;
fp = fopen(name, READ_MODE);
if (fp == NULL)
printf("Can't open file %s, try again.\n", name);
- linenoiseFree(name);
+ free(name);
}
return restore(fp);