Remove vestiges of quest text data file

This commit is contained in:
Pasi Kallinen
2019-11-25 16:30:54 +02:00
parent b66bcc2f5a
commit ddd8b7d9a5
6 changed files with 4 additions and 475 deletions

View File

@@ -1119,12 +1119,6 @@ struct instance_globals {
/* questpgr.c */
char cvt_buf[CVT_BUF_SIZE];
struct qtlists qt_list;
#ifdef DLB
struct dlb_handle *msg_file;
#else
FILE *msg_file;
#endif
/* used by ldrname() and neminame(), then copied into cvt_buf */
char nambuf[CVT_BUF_SIZE];

View File

@@ -5,114 +5,4 @@
#ifndef QTEXT_H
#define QTEXT_H
#define N_HDR 16 /* Maximum number of categories */
/* (i.e., num roles + 1) */
#define LEN_HDR 3 /* Maximum length of a category name */
struct qtmsg {
int msgnum;
char delivery;
long offset, size, summary_size;
};
#if defined(MAKEDEFS_C) || defined(MDLIB_C) /***** MAKEDEFS *****/
#define N_MSG 100 /* arbitrary */
struct msghdr {
int n_msg;
struct qtmsg qt_msg[N_MSG];
};
struct qthdr {
int n_hdr;
char id[N_HDR][LEN_HDR];
long offset[N_HDR];
};
/* Error message macros */
#define CREC_IN_MSG "Control record encountered during message - line %d\n"
#define DUP_MSG "Duplicate message number at line %d\n"
#define END_NOT_IN_MSG "End record encountered before message - line %d\n"
#define TEXT_NOT_IN_MSG "Text encountered outside message - line %d\n"
#define UNREC_CREC "Unrecognized Control record at line %d\n"
#define MAL_SUM "Malformed summary in End record - line %d\n"
#define DUMB_SUM "Summary for single line message is useless - line %d\n"
#define CTRL_TRUNC "Control record truncated at line %d\n"
#define TEXT_TRUNC "Text record truncated at line %d\n"
#define OUT_OF_HEADERS \
"Too many message types (line %d)\nAdjust N_HDR in qtext.h and " \
"recompile.\n"
#define OUT_OF_MESSAGES \
"Too many messages in class (line %d)\nAdjust N_MSG in qtext.h and " \
"recompile.\n"
#else /***** !MAKEDEFS && !MDLIB_C *****/
struct qtlists {
struct qtmsg *common,
#if 0 /* UNUSED but available */
*chrace,
#endif
*chrole;
};
/*
* Quest message defines. Used in quest.c to trigger off "realistic"
* dialogue to the player.
*/
#define QT_FIRSTTIME 1
#define QT_NEXTTIME 2
#define QT_OTHERTIME 3
#define QT_GUARDTALK 5 /* 5 random things guards say before quest */
#define QT_GUARDTALK2 10 /* 5 random things guards say after quest */
#define QT_FIRSTLEADER 15
#define QT_NEXTLEADER 16
#define QT_OTHERLEADER 17
#define QT_LASTLEADER 18
#define QT_BADLEVEL 19
#define QT_BADALIGN 20
#define QT_ASSIGNQUEST 21
#define QT_ENCOURAGE 25 /* 1-10 random encouragement messages */
#define QT_FIRSTLOCATE 35
#define QT_NEXTLOCATE 36
#define QT_FIRSTGOAL 40
#define QT_NEXTGOAL 41
#define QT_ALTGOAL 42 /* alternate to QT_NEXTGOAL if artifact is absent */
#define QT_FIRSTNEMESIS 50
#define QT_NEXTNEMESIS 51
#define QT_OTHERNEMESIS 52
#define QT_NEMWANTSIT 53 /* you somehow got the artifact */
#define QT_DISCOURAGE 60 /* 1-10 random maledictive messages */
#define QT_GOTIT 70
#define QT_KILLEDNEM 80
#define QT_OFFEREDIT 81
#define QT_OFFEREDIT2 82
#define QT_POSTHANKS 90
#define QT_HASAMULET 91
/*
* Message defines for common text used in maledictions.
*/
#define COMMON_ID "-" /* Common message id value */
#define QT_ANGELIC 10
#define QTN_ANGELIC 10
#define QT_DEMONIC 30
#define QTN_DEMONIC 20
#define QT_BANISHED 60
#endif /***** !MAKEDEFS && !MDLIB_C *****/
#endif /* QTEXT_H */

View File

@@ -576,8 +576,6 @@ const struct instance_globals g_init = {
/* questpgr.c */
UNDEFINED_VALUES, /* cvt_buf */
UNDEFINED_VALUES, /* qt_list */
UNDEFINED_PTR, /* msg_file */
UNDEFINED_VALUES, /* nambuf */
/* read.c */

View File

@@ -26,9 +26,6 @@ static void FDECL(convert_line, (char *,char *));
static void FDECL(deliver_by_pline, (const char *));
static void FDECL(deliver_by_window, (const char *, int));
static boolean FDECL(skip_pager, (BOOLEAN_P));
#if 0
static struct qtmsg *FDECL(msg_in, (struct qtmsg *, int));
#endif
short
quest_info(typ)
@@ -190,22 +187,6 @@ char who, /* 'd' => deity, 'l' => leader, 'n' => nemesis, 'o' => artifact */
return;
}
#if 0
static struct qtmsg *
msg_in(qtm_list, msgnum)
struct qtmsg *qtm_list;
int msgnum;
{
struct qtmsg *qt_msg;
for (qt_msg = qtm_list; qt_msg->msgnum > 0; qt_msg++)
if (qt_msg->msgnum == msgnum)
return qt_msg;
return (struct qtmsg *) 0;
}
#endif
static void
convert_arg(c)
char c;

View File

@@ -55,3 +55,7 @@ CHGRP=true
VARDIRPERM = 0755
VARFILEPERM = 0600
GAMEPERM = 0755
CC=clang
CFLAGS+=-fsanitize=address -fno-omit-frame-pointer
LFLAGS+=-fsanitize=address -fno-omit-frame-pointer

View File

@@ -1873,353 +1873,15 @@ do_permonst()
}
/* Start of Quest text file processing. */
#include "qtext.h"
static struct qthdr qt_hdr;
static struct msghdr msg_hdr[N_HDR];
static struct qtmsg *curr_msg;
static int qt_line;
static boolean in_msg;
#define NO_MSG 1 /* strlen of a null line returned by fgets() */
static boolean
qt_comment(s)
char *s;
{
if (s[0] == '#')
return TRUE;
return (boolean) (!in_msg && strlen(s) == NO_MSG);
}
static boolean
qt_control(s)
char *s;
{
return (boolean) (s[0] == '%' && (s[1] == 'C' || s[1] == 'E'));
}
static int
get_hdr(code)
char *code;
{
int i;
for (i = 0; i < qt_hdr.n_hdr; i++)
if (!strncmp(code, qt_hdr.id[i], LEN_HDR))
return ++i;
return 0;
}
static boolean
new_id(code)
char *code;
{
if (qt_hdr.n_hdr >= N_HDR) {
Fprintf(stderr, OUT_OF_HEADERS, qt_line);
return FALSE;
}
strncpy(&qt_hdr.id[qt_hdr.n_hdr][0], code, LEN_HDR);
msg_hdr[qt_hdr.n_hdr].n_msg = 0;
qt_hdr.offset[qt_hdr.n_hdr++] = 0L;
return TRUE;
}
static boolean
known_msg(num, id)
int num, id;
{
int i;
for (i = 0; i < msg_hdr[num].n_msg; i++)
if (msg_hdr[num].qt_msg[i].msgnum == id)
return TRUE;
return FALSE;
}
static void
new_msg(s, num, id)
char *s;
int num, id;
{
struct qtmsg *qt_msg;
if (msg_hdr[num].n_msg >= N_MSG) {
Fprintf(stderr, OUT_OF_MESSAGES, qt_line);
} else {
qt_msg = &(msg_hdr[num].qt_msg[msg_hdr[num].n_msg++]);
qt_msg->msgnum = id;
qt_msg->delivery = s[2];
qt_msg->offset = qt_msg->size = qt_msg->summary_size = 0L;
curr_msg = qt_msg;
}
}
/* check %E record for "[summary text]" that nethack can stuff into the
message history buffer when delivering text via window instead of pline */
static char *
valid_qt_summary(s, parsing)
char *s; /* end record: "%E" optionally followed by " [summary]" */
boolean parsing; /* curr_msg is valid iff this is True */
{
static char summary[BUFSZ];
char *p;
if (*s != '%' || *(s + 1) != 'E')
return (char *) 0;
if ((p = index(s, '[')) == 0)
return (char *) 0;
/* note: opening '[' and closing ']' will be retained in the output;
anything after ']' will be discarded by putting a newline there */
Strcpy(summary, p);
/* have an opening bracket; summary[] holds it and all text that follows
*/
p = eos(summary);
/* find closing bracket */
while (p > summary && *(p - 1) != ']')
--p;
if (p == summary) {
/* we backed up all the way to the start without finding a bracket */
if (parsing) /* malformed summary */
Fprintf(stderr, MAL_SUM, qt_line);
} else if (p == summary + 1) {
; /* ignore empty [] */
} else { /* got something */
/* p points one spot past ']', usually to '\n';
we need to include the \n as part of the size */
if (parsing) {
/* during the writing pass we won't be able to recheck
delivery, so any useless summary for a pline mode
message has to be carried along to the output file */
if (curr_msg->delivery == 'p')
Fprintf(stderr, DUMB_SUM, qt_line);
/* +1 is for terminating newline */
curr_msg->summary_size = (long) (p - summary) + 1L;
} else {
/* caller is writing rather than just parsing;
force newline after the closing bracket */
Strcpy(p, "\n");
}
return summary;
}
return (char *) 0;
}
static void
do_qt_control(s)
char *s;
{
char code[BUFSZ];
int num, id = 0;
if (!index(s, '\n'))
Fprintf(stderr, CTRL_TRUNC, qt_line);
switch (s[1]) {
case 'C':
if (in_msg) {
Fprintf(stderr, CREC_IN_MSG, qt_line);
break;
} else {
in_msg = TRUE;
if (sscanf(&s[4], "%s %5d", code, &id) != 2) {
Fprintf(stderr, UNREC_CREC, qt_line);
break;
}
num = get_hdr(code);
if (!num && !new_id(code))
break;
num = get_hdr(code) - 1;
if (known_msg(num, id))
Fprintf(stderr, DUP_MSG, qt_line);
else
new_msg(s, num, id);
}
break;
case 'E':
if (!in_msg) {
Fprintf(stderr, END_NOT_IN_MSG, qt_line);
} else {
/* sets curr_msg->summary_size if applicable */
(void) valid_qt_summary(s, TRUE);
in_msg = FALSE;
}
break;
default:
Fprintf(stderr, UNREC_CREC, qt_line);
break;
}
}
static void
do_qt_text(s)
char *s;
{
if (!in_msg) {
Fprintf(stderr, TEXT_NOT_IN_MSG, qt_line);
} else if (!index(s, '\n')) {
Fprintf(stderr, TEXT_TRUNC, qt_line);
}
curr_msg->size += strlen(s);
return;
}
static void
adjust_qt_hdrs()
{
int i, j;
long count = 0L, hdr_offset = sizeof(int)
+ (sizeof(char) * LEN_HDR + sizeof(long))
* qt_hdr.n_hdr;
for (i = 0; i < qt_hdr.n_hdr; i++) {
qt_hdr.offset[i] = hdr_offset;
hdr_offset += sizeof(int) + sizeof(struct qtmsg) * msg_hdr[i].n_msg;
}
for (i = 0; i < qt_hdr.n_hdr; i++)
for (j = 0; j < msg_hdr[i].n_msg; j++) {
msg_hdr[i].qt_msg[j].offset = hdr_offset + count;
count +=
msg_hdr[i].qt_msg[j].size + msg_hdr[i].qt_msg[j].summary_size;
}
return;
}
static void
put_qt_hdrs()
{
int i;
/*
* The main header record.
*/
if (debug)
Fprintf(stderr, "%ld: header info.\n", ftell(ofp));
(void) fwrite((genericptr_t) & (qt_hdr.n_hdr), sizeof(int), 1, ofp);
(void) fwrite((genericptr_t) & (qt_hdr.id[0][0]), sizeof(char) * LEN_HDR,
qt_hdr.n_hdr, ofp);
(void) fwrite((genericptr_t) & (qt_hdr.offset[0]), sizeof(long),
qt_hdr.n_hdr, ofp);
if (debug) {
for (i = 0; i < qt_hdr.n_hdr; i++)
Fprintf(stderr, "%s @ %ld, ", qt_hdr.id[i], qt_hdr.offset[i]);
Fprintf(stderr, "\n");
}
/*
* The individual class headers.
*/
for (i = 0; i < qt_hdr.n_hdr; i++) {
if (debug)
Fprintf(stderr, "%ld: %s header info.\n", ftell(ofp),
qt_hdr.id[i]);
(void) fwrite((genericptr_t) & (msg_hdr[i].n_msg), sizeof(int), 1,
ofp);
(void) fwrite((genericptr_t) & (msg_hdr[i].qt_msg[0]),
sizeof(struct qtmsg), msg_hdr[i].n_msg, ofp);
if (debug) {
int j;
for (j = 0; j < msg_hdr[i].n_msg; j++) {
Fprintf(stderr, "msg %d @ %ld (%ld)",
msg_hdr[i].qt_msg[j].msgnum,
msg_hdr[i].qt_msg[j].offset,
msg_hdr[i].qt_msg[j].size);
if (msg_hdr[i].qt_msg[j].summary_size)
Fprintf(stderr, " [%ld]",
msg_hdr[i].qt_msg[j].summary_size);
Fprintf(stderr, "\n");
}
}
}
}
void
do_questtxt()
{
char *line;
/* Make sure they know */
printf("DEPRECATION WARNINGS:\n");
printf("'makedefs -q' is no longer required. Remove all references\n");
printf(" to it from the build process.\n");
printf("'dat/quest.txt' is no longer part of the source tree.\n");
Sprintf(filename, DATA_IN_TEMPLATE, QTXT_I_FILE);
if (!(ifp = fopen(filename, RDTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
filename[0] = '\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), DATA_TEMPLATE, QTXT_O_FILE);
if (!(ofp = fopen(filename, WRBMODE))) {
perror(filename);
Fclose(ifp);
exit(EXIT_FAILURE);
}
qt_hdr.n_hdr = 0;
qt_line = 0;
in_msg = FALSE;
while ((line = fgetline(ifp)) != 0) {
SpinCursor(3);
qt_line++;
if (qt_control(line))
do_qt_control(line);
else if (qt_comment(line)) {
free(line);
continue;
} else
do_qt_text(line);
free(line);
}
(void) rewind(ifp);
in_msg = FALSE;
adjust_qt_hdrs();
put_qt_hdrs();
while ((line = fgetline(ifp)) != 0) {
if (qt_control(line)) {
char *summary_p = 0;
in_msg = (line[1] == 'C');
if (!in_msg)
summary_p = valid_qt_summary(line, FALSE);
/* don't write anything unless we've got a summary */
if (!summary_p) {
free(line);
continue;
}
/* we have summary text; replace raw %E record with it */
Strcpy(line, summary_p); /* (guaranteed to fit) */
} else if (qt_comment(line)) {
free(line);
continue;
}
if (debug)
Fprintf(stderr, "%ld: %s", ftell(stdout), line);
(void) fputs(xcrypt(line), ofp);
free(line);
}
Fclose(ifp);
Fclose(ofp);
return;
}