Remove vestiges of quest text data file
This commit is contained in:
338
util/makedefs.c
338
util/makedefs.c
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user