Reformat all C files.

I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
This commit is contained in:
Sean Hunt
2015-05-09 13:43:16 -04:00
parent 167800afdf
commit 97d6fade74
270 changed files with 182649 additions and 173878 deletions
+189 -173
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 getline.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 getline.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.27 $ */
/* NetHack 3.6 getline.c $Date: 2011/12/11 01:54:56 $ $Revision: 1.18 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -14,15 +14,16 @@
#include "wintty.h"
#include "func_tab.h"
char morc = 0; /* tell the outside world what char you chose */
char morc = 0; /* tell the outside world what char you chose */
STATIC_DCL boolean FDECL(ext_cmd_getlin_hook, (char *));
typedef boolean FDECL((*getlin_hook_proc), (char *));
STATIC_DCL void FDECL(hooked_tty_getlin, (const char*,char*,getlin_hook_proc));
extern int NDECL(extcmd_via_menu); /* cmd.c */
STATIC_DCL void FDECL(hooked_tty_getlin,
(const char *, char *, getlin_hook_proc));
extern int NDECL(extcmd_via_menu); /* cmd.c */
extern char erase_char, kill_char; /* from appropriate tty.c file */
extern char erase_char, kill_char; /* from appropriate tty.c file */
/*
* Read a line closed with '\n' into the array char bufp[BUFSZ].
@@ -44,166 +45,177 @@ const char *query;
register char *bufp;
getlin_hook_proc hook;
{
register char *obufp = bufp;
register int c;
struct WinDesc *cw = wins[WIN_MESSAGE];
boolean doprev = 0;
register char *obufp = bufp;
register int c;
struct WinDesc *cw = wins[WIN_MESSAGE];
boolean doprev = 0;
if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more();
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
pline("%s ", query);
*obufp = 0;
for(;;) {
(void) fflush(stdout);
Strcat(strcat(strcpy(toplines, query), " "), obufp);
c = pgetchar();
if (c == '\033' || c == EOF) {
if (c == '\033' && obufp[0] != '\0') {
obufp[0] = '\0';
bufp = obufp;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(query);
addtopl(" ");
addtopl(obufp);
} else {
obufp[0] = '\033';
obufp[1] = '\0';
break;
}
}
if (ttyDisplay->intr) {
ttyDisplay->intr--;
*bufp = 0;
}
if(c == '\020') { /* ctrl-P */
if (iflags.prevmsg_window != 's') {
int sav = ttyDisplay->inread;
ttyDisplay->inread = 0;
(void) tty_doprev_message();
ttyDisplay->inread = sav;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(query);
addtopl(" ");
*bufp = 0;
addtopl(obufp);
} else {
if (!doprev)
(void) tty_doprev_message();/* need two initially */
(void) tty_doprev_message();
doprev = 1;
continue;
}
} else if (doprev && iflags.prevmsg_window == 's') {
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
doprev = 0;
addtopl(query);
addtopl(" ");
*bufp = 0;
addtopl(obufp);
}
if(c == erase_char || c == '\b') {
if(bufp != obufp) {
if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP))
more();
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
pline("%s ", query);
*obufp = 0;
for (;;) {
(void) fflush(stdout);
Strcat(strcat(strcpy(toplines, query), " "), obufp);
c = pgetchar();
if (c == '\033' || c == EOF) {
if (c == '\033' && obufp[0] != '\0') {
obufp[0] = '\0';
bufp = obufp;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(query);
addtopl(" ");
addtopl(obufp);
} else {
obufp[0] = '\033';
obufp[1] = '\0';
break;
}
}
if (ttyDisplay->intr) {
ttyDisplay->intr--;
*bufp = 0;
}
if (c == '\020') { /* ctrl-P */
if (iflags.prevmsg_window != 's') {
int sav = ttyDisplay->inread;
ttyDisplay->inread = 0;
(void) tty_doprev_message();
ttyDisplay->inread = sav;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(query);
addtopl(" ");
*bufp = 0;
addtopl(obufp);
} else {
if (!doprev)
(void) tty_doprev_message(); /* need two initially */
(void) tty_doprev_message();
doprev = 1;
continue;
}
} else if (doprev && iflags.prevmsg_window == 's') {
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
doprev = 0;
addtopl(query);
addtopl(" ");
*bufp = 0;
addtopl(obufp);
}
if (c == erase_char || c == '\b') {
if (bufp != obufp) {
#ifdef NEWAUTOCOMP
char *i;
char *i;
#endif /* NEWAUTOCOMP */
bufp--;
bufp--;
#ifndef NEWAUTOCOMP
putsyms("\b \b");/* putsym converts \b */
#else /* NEWAUTOCOMP */
putsyms("\b");
for (i = bufp; *i; ++i) putsyms(" ");
for (; i > bufp; --i) putsyms("\b");
*bufp = 0;
#endif /* NEWAUTOCOMP */
} else tty_nhbell();
putsyms("\b \b"); /* putsym converts \b */
#else /* NEWAUTOCOMP */
putsyms("\b");
for (i = bufp; *i; ++i)
putsyms(" ");
for (; i > bufp; --i)
putsyms("\b");
*bufp = 0;
#endif /* NEWAUTOCOMP */
} else
tty_nhbell();
#if defined(apollo)
} else if(c == '\n' || c == '\r') {
} else if (c == '\n' || c == '\r') {
#else
} else if(c == '\n') {
} else if (c == '\n') {
#endif
#ifndef NEWAUTOCOMP
*bufp = 0;
*bufp = 0;
#endif /* not NEWAUTOCOMP */
break;
} else if(' ' <= (unsigned char) c && c != '\177' &&
(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)) {
/* avoid isprint() - some people don't have it
' ' is not always a printing char */
break;
} else if (' ' <= (unsigned char) c && c != '\177'
&& (bufp - obufp < BUFSZ - 1 && bufp - obufp < COLNO)) {
/* avoid isprint() - some people don't have it
' ' is not always a printing char */
#ifdef NEWAUTOCOMP
char *i = eos(bufp);
char *i = eos(bufp);
#endif /* NEWAUTOCOMP */
*bufp = c;
bufp[1] = 0;
putsyms(bufp);
bufp++;
if (hook && (*hook)(obufp)) {
putsyms(bufp);
*bufp = c;
bufp[1] = 0;
putsyms(bufp);
bufp++;
if (hook && (*hook)(obufp)) {
putsyms(bufp);
#ifndef NEWAUTOCOMP
bufp = eos(bufp);
#else /* NEWAUTOCOMP */
/* pointer and cursor left where they were */
for (i = bufp; *i; ++i) putsyms("\b");
} else if (i > bufp) {
char *s = i;
bufp = eos(bufp);
#else /* NEWAUTOCOMP */
/* pointer and cursor left where they were */
for (i = bufp; *i; ++i)
putsyms("\b");
} else if (i > bufp) {
char *s = i;
/* erase rest of prior guess */
for (; i > bufp; --i) putsyms(" ");
for (; s > bufp; --s) putsyms("\b");
/* erase rest of prior guess */
for (; i > bufp; --i)
putsyms(" ");
for (; s > bufp; --s)
putsyms("\b");
#endif /* NEWAUTOCOMP */
}
} else if(c == kill_char || c == '\177') { /* Robert Viduya */
/* this test last - @ might be the kill_char */
}
} else if (c == kill_char || c == '\177') { /* Robert Viduya */
/* this test last - @ might be the kill_char */
#ifndef NEWAUTOCOMP
while(bufp != obufp) {
bufp--;
putsyms("\b \b");
}
#else /* NEWAUTOCOMP */
for (; *bufp; ++bufp) putsyms(" ");
for (; bufp != obufp; --bufp) putsyms("\b \b");
*bufp = 0;
while (bufp != obufp) {
bufp--;
putsyms("\b \b");
}
#else /* NEWAUTOCOMP */
for (; *bufp; ++bufp)
putsyms(" ");
for (; bufp != obufp; --bufp)
putsyms("\b \b");
*bufp = 0;
#endif /* NEWAUTOCOMP */
} else
tty_nhbell();
}
ttyDisplay->toplin = 2; /* nonempty, no --More-- required */
ttyDisplay->inread--;
clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */
} else
tty_nhbell();
}
ttyDisplay->toplin = 2; /* nonempty, no --More-- required */
ttyDisplay->inread--;
clear_nhwindow(WIN_MESSAGE); /* clean up after ourselves */
}
void
xwaitforspace(s)
register const char *s; /* chars allowed besides return */
register const char *s; /* chars allowed besides return */
{
register int c, x = ttyDisplay ? (int) ttyDisplay->dismiss_more : '\n';
morc = 0;
while (
#ifdef HANGUPHANDLING
!program_state.done_hup &&
!program_state.done_hup &&
#endif
(c = tty_nhgetch()) != EOF) {
if (c == '\n') break;
(c = tty_nhgetch()) != EOF) {
if (c == '\n')
break;
if(iflags.cbreak) {
if (c == '\033') {
if (ttyDisplay) ttyDisplay->dismiss_more = 1;
morc = '\033';
break;
}
if ((s && index(s,c)) || c == x) {
morc = (char) c;
break;
}
tty_nhbell();
}
if (iflags.cbreak) {
if (c == '\033') {
if (ttyDisplay)
ttyDisplay->dismiss_more = 1;
morc = '\033';
break;
}
if ((s && index(s, c)) || c == x) {
morc = (char) c;
break;
}
tty_nhbell();
}
}
}
@@ -221,25 +233,25 @@ register const char *s; /* chars allowed besides return */
*/
STATIC_OVL boolean
ext_cmd_getlin_hook(base)
char *base;
char *base;
{
int oindex, com_index;
int oindex, com_index;
com_index = -1;
for (oindex = 0; extcmdlist[oindex].ef_txt != (char *)0; oindex++) {
if (!strncmpi(base, extcmdlist[oindex].ef_txt, strlen(base))) {
if (com_index == -1) /* no matches yet */
com_index = oindex;
else /* more than 1 match */
return FALSE;
}
}
if (com_index >= 0) {
Strcpy(base, extcmdlist[com_index].ef_txt);
return TRUE;
}
com_index = -1;
for (oindex = 0; extcmdlist[oindex].ef_txt != (char *) 0; oindex++) {
if (!strncmpi(base, extcmdlist[oindex].ef_txt, strlen(base))) {
if (com_index == -1) /* no matches yet */
com_index = oindex;
else /* more than 1 match */
return FALSE;
}
}
if (com_index >= 0) {
Strcpy(base, extcmdlist[com_index].ef_txt);
return TRUE;
}
return FALSE; /* didn't match anything */
return FALSE; /* didn't match anything */
}
/*
@@ -249,33 +261,37 @@ ext_cmd_getlin_hook(base)
int
tty_get_ext_cmd()
{
int i;
char buf[BUFSZ];
int i;
char buf[BUFSZ];
if (iflags.extmenu) return extcmd_via_menu();
/* maybe a runtime option? */
/* hooked_tty_getlin("#", buf, flags.cmd_comp ? ext_cmd_getlin_hook : (getlin_hook_proc) 0); */
hooked_tty_getlin("#", buf, in_doagain ? (getlin_hook_proc)0
: ext_cmd_getlin_hook);
(void) mungspaces(buf);
if (buf[0] == 0 || buf[0] == '\033') return -1;
if (iflags.extmenu)
return extcmd_via_menu();
/* maybe a runtime option? */
/* hooked_tty_getlin("#", buf, flags.cmd_comp ? ext_cmd_getlin_hook :
* (getlin_hook_proc) 0); */
hooked_tty_getlin("#", buf, in_doagain ? (getlin_hook_proc) 0
: ext_cmd_getlin_hook);
(void) mungspaces(buf);
if (buf[0] == 0 || buf[0] == '\033')
return -1;
for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++)
if (!strcmpi(buf, extcmdlist[i].ef_txt)) break;
for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++)
if (!strcmpi(buf, extcmdlist[i].ef_txt))
break;
if (!in_doagain) {
int j;
for (j = 0; buf[j]; j++)
savech(buf[j]);
savech('\n');
}
if (!in_doagain) {
int j;
for (j = 0; buf[j]; j++)
savech(buf[j]);
savech('\n');
}
if (extcmdlist[i].ef_txt == (char *)0) {
pline("%s: unknown extended command.", buf);
i = -1;
}
if (extcmdlist[i].ef_txt == (char *) 0) {
pline("%s: unknown extended command.", buf);
i = -1;
}
return i;
return i;
}
#endif /* TTY_GRAPHICS */
+806 -774
View File
File diff suppressed because it is too large Load Diff
+359 -322
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 topl.c $NHDT-Date: 1430040322 2015/04/26 09:25:22 $ $NHDT-Branch: master $:$NHDT-Revision: 1.29 $ */
/* NetHack 3.6 topl.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -10,11 +10,11 @@
#include "wintty.h"
#include <ctype.h>
#ifndef C /* this matches src/cmd.c */
#define C(c) (0x1f & (c))
#ifndef C /* this matches src/cmd.c */
#define C(c) (0x1f & (c))
#endif
STATIC_DCL void FDECL(redotoplin, (const char*));
STATIC_DCL void FDECL(redotoplin, (const char *));
STATIC_DCL void FDECL(topl_putsym, (CHAR_P));
STATIC_DCL void NDECL(remember_topl);
STATIC_DCL void FDECL(removetopl, (int));
@@ -28,36 +28,41 @@ tty_doprev_message()
winid prevmsg_win;
int i;
if ((iflags.prevmsg_window != 's') && !ttyDisplay->inread) { /* not single */
if(iflags.prevmsg_window == 'f') { /* full */
if ((iflags.prevmsg_window != 's')
&& !ttyDisplay->inread) { /* not single */
if (iflags.prevmsg_window == 'f') { /* full */
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
cw->maxcol = cw->maxrow;
i = cw->maxcol;
do {
if(cw->data[i] && strcmp(cw->data[i], "") )
if (cw->data[i] && strcmp(cw->data[i], ""))
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
putstr(prevmsg_win, 0, toplines);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
} else if (iflags.prevmsg_window == 'c') { /* combination */
} else if (iflags.prevmsg_window == 'c') { /* combination */
do {
morc = 0;
if (cw->maxcol == cw->maxrow) {
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
ttyDisplay->dismiss_more =
C('p'); /* <ctrl/P> allowed at --More-- */
redotoplin(toplines);
cw->maxcol--;
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} else if (cw->maxcol == (cw->maxrow - 1)){
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
} else if (cw->maxcol == (cw->maxrow - 1)) {
ttyDisplay->dismiss_more =
C('p'); /* <ctrl/P> allowed at --More-- */
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} else {
@@ -67,7 +72,7 @@ tty_doprev_message()
cw->maxcol = cw->maxrow;
i = cw->maxcol;
do {
if(cw->data[i] && strcmp(cw->data[i], "") )
if (cw->data[i] && strcmp(cw->data[i], ""))
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
@@ -84,12 +89,14 @@ tty_doprev_message()
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
putstr(prevmsg_win, 0, toplines);
cw->maxcol=cw->maxrow-1;
if(cw->maxcol < 0) cw->maxcol = cw->rows-1;
cw->maxcol = cw->maxrow - 1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
do {
putstr(prevmsg_win, 0, cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} while (cw->maxcol != cw->maxrow);
@@ -99,8 +106,8 @@ tty_doprev_message()
cw->maxcol = cw->maxrow;
ttyDisplay->dismiss_more = 0;
}
} else if(iflags.prevmsg_window == 's') { /* single */
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
} else if (iflags.prevmsg_window == 's') { /* single */
ttyDisplay->dismiss_more = C('p'); /* <ctrl/P> allowed at --More-- */
do {
morc = 0;
if (cw->maxcol == cw->maxrow)
@@ -108,7 +115,8 @@ tty_doprev_message()
else if (cw->data[cw->maxcol])
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
if (cw->maxcol < 0) cw->maxcol = cw->rows-1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
if (!cw->data[cw->maxcol])
cw->maxcol = cw->maxrow;
} while (morc == C('p'));
@@ -119,22 +127,22 @@ tty_doprev_message()
STATIC_OVL void
redotoplin(str)
const char *str;
const char *str;
{
int otoplin = ttyDisplay->toplin;
home();
if(*str & 0x80) {
/* kludge for the / command, the only time we ever want a */
/* graphics character on the top line */
g_putch((int)*str++);
ttyDisplay->curx++;
}
end_glyphout(); /* in case message printed during graphics output */
putsyms(str);
cl_end();
ttyDisplay->toplin = 1;
if(ttyDisplay->cury && otoplin != 3)
more();
int otoplin = ttyDisplay->toplin;
home();
if (*str & 0x80) {
/* kludge for the / command, the only time we ever want a */
/* graphics character on the top line */
g_putch((int) *str++);
ttyDisplay->curx++;
}
end_glyphout(); /* in case message printed during graphics output */
putsyms(str);
cl_end();
ttyDisplay->toplin = 1;
if (ttyDisplay->cury && otoplin != 3)
more();
}
STATIC_OVL void
@@ -144,14 +152,15 @@ remember_topl()
int idx = cw->maxrow;
unsigned len = strlen(toplines) + 1;
if ((cw->flags & WIN_LOCKHISTORY) || !*toplines) return;
if ((cw->flags & WIN_LOCKHISTORY) || !*toplines)
return;
if (len > (unsigned)cw->datlen[idx]) {
if (cw->data[idx]) free(cw->data[idx]);
len += (8 - (len & 7)); /* pad up to next multiple of 8 */
cw->data[idx] = (char *)alloc(len);
cw->datlen[idx] = (short)len;
if (len > (unsigned) cw->datlen[idx]) {
if (cw->data[idx])
free(cw->data[idx]);
len += (8 - (len & 7)); /* pad up to next multiple of 8 */
cw->data[idx] = (char *) alloc(len);
cw->datlen[idx] = (short) len;
}
Strcpy(cw->data[idx], toplines);
*toplines = '\0';
@@ -164,7 +173,7 @@ const char *s;
{
register struct WinDesc *cw = wins[WIN_MESSAGE];
tty_curs(BASE_WINDOW,cw->curx+1,cw->cury);
tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury);
putsyms(s);
cl_end();
ttyDisplay->toplin = 1;
@@ -176,33 +185,34 @@ more()
struct WinDesc *cw = wins[WIN_MESSAGE];
/* avoid recursion -- only happens from interrupts */
if(ttyDisplay->inmore++)
return;
if (ttyDisplay->inmore++)
return;
if(ttyDisplay->toplin) {
tty_curs(BASE_WINDOW, cw->curx+1, cw->cury);
if(cw->curx >= CO - 8) topl_putsym('\n');
if (ttyDisplay->toplin) {
tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury);
if (cw->curx >= CO - 8)
topl_putsym('\n');
}
if(flags.standout)
standoutbeg();
if (flags.standout)
standoutbeg();
putsyms(defmorestr);
if(flags.standout)
standoutend();
if (flags.standout)
standoutend();
xwaitforspace("\033 ");
if(morc == '\033')
cw->flags |= WIN_STOP;
if (morc == '\033')
cw->flags |= WIN_STOP;
if(ttyDisplay->toplin && cw->cury) {
docorner(1, cw->cury+1);
cw->curx = cw->cury = 0;
home();
} else if(morc == '\033') {
cw->curx = cw->cury = 0;
home();
cl_end();
if (ttyDisplay->toplin && cw->cury) {
docorner(1, cw->cury + 1);
cw->curx = cw->cury = 0;
home();
} else if (morc == '\033') {
cw->curx = cw->cury = 0;
home();
cl_end();
}
ttyDisplay->toplin = 0;
ttyDisplay->inmore = 0;
@@ -210,88 +220,94 @@ more()
void
update_topl(bp)
register const char *bp;
register const char *bp;
{
register char *tl, *otl;
register int n0;
int notdied = 1;
struct WinDesc *cw = wins[WIN_MESSAGE];
register char *tl, *otl;
register int n0;
int notdied = 1;
struct WinDesc *cw = wins[WIN_MESSAGE];
/* If there is room on the line, print message on same line */
/* But messages like "You die..." deserve their own line */
n0 = strlen(bp);
if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) &&
cw->cury == 0 &&
n0 + (int)strlen(toplines) + 3 < CO-8 && /* room for --More-- */
(notdied = strncmp(bp, "You die", 7))) {
Strcat(toplines, " ");
Strcat(toplines, bp);
cw->curx += 2;
if(!(cw->flags & WIN_STOP))
addtopl(bp);
return;
} else if (!(cw->flags & WIN_STOP)) {
if(ttyDisplay->toplin == 1) more();
else if(cw->cury) { /* for when flags.toplin == 2 && cury > 1 */
docorner(1, cw->cury+1); /* reset cury = 0 if redraw screen */
cw->curx = cw->cury = 0;/* from home--cls() & docorner(1,n) */
}
}
remember_topl();
(void) strncpy(toplines, bp, TBUFSZ);
toplines[TBUFSZ - 1] = 0;
/* If there is room on the line, print message on same line */
/* But messages like "You die..." deserve their own line */
n0 = strlen(bp);
if ((ttyDisplay->toplin == 1 || (cw->flags & WIN_STOP)) && cw->cury == 0
&& n0 + (int) strlen(toplines) + 3 < CO - 8 && /* room for --More-- */
(notdied = strncmp(bp, "You die", 7))) {
Strcat(toplines, " ");
Strcat(toplines, bp);
cw->curx += 2;
if (!(cw->flags & WIN_STOP))
addtopl(bp);
return;
} else if (!(cw->flags & WIN_STOP)) {
if (ttyDisplay->toplin == 1)
more();
else if (cw->cury) { /* for when flags.toplin == 2 && cury > 1 */
docorner(1, cw->cury + 1); /* reset cury = 0 if redraw screen */
cw->curx = cw->cury = 0; /* from home--cls() & docorner(1,n) */
}
}
remember_topl();
(void) strncpy(toplines, bp, TBUFSZ);
toplines[TBUFSZ - 1] = 0;
for(tl = toplines; n0 >= CO; ){
otl = tl;
for(tl+=CO-1; tl != otl && !isspace(*tl); --tl) ;
if(tl == otl) {
/* Eek! A huge token. Try splitting after it. */
tl = index(otl, ' ');
if (!tl) break; /* No choice but to spit it out whole. */
}
*tl++ = '\n';
n0 = strlen(tl);
}
if(!notdied) cw->flags &= ~WIN_STOP;
if(!(cw->flags & WIN_STOP)) redotoplin(toplines);
for (tl = toplines; n0 >= CO;) {
otl = tl;
for (tl += CO - 1; tl != otl && !isspace(*tl); --tl)
;
if (tl == otl) {
/* Eek! A huge token. Try splitting after it. */
tl = index(otl, ' ');
if (!tl)
break; /* No choice but to spit it out whole. */
}
*tl++ = '\n';
n0 = strlen(tl);
}
if (!notdied)
cw->flags &= ~WIN_STOP;
if (!(cw->flags & WIN_STOP))
redotoplin(toplines);
}
STATIC_OVL
void
topl_putsym(c)
char c;
char c;
{
register struct WinDesc *cw = wins[WIN_MESSAGE];
if(cw == (struct WinDesc *) 0) panic("Putsym window MESSAGE nonexistant");
switch(c) {
if (cw == (struct WinDesc *) 0)
panic("Putsym window MESSAGE nonexistant");
switch (c) {
case '\b':
if(ttyDisplay->curx == 0 && ttyDisplay->cury > 0)
tty_curs(BASE_WINDOW, CO, (int)ttyDisplay->cury-1);
backsp();
ttyDisplay->curx--;
cw->curx = ttyDisplay->curx;
return;
if (ttyDisplay->curx == 0 && ttyDisplay->cury > 0)
tty_curs(BASE_WINDOW, CO, (int) ttyDisplay->cury - 1);
backsp();
ttyDisplay->curx--;
cw->curx = ttyDisplay->curx;
return;
case '\n':
cl_end();
ttyDisplay->curx = 0;
ttyDisplay->cury++;
cw->cury = ttyDisplay->cury;
cl_end();
ttyDisplay->curx = 0;
ttyDisplay->cury++;
cw->cury = ttyDisplay->cury;
#ifdef WIN32CON
(void) putchar(c);
(void) putchar(c);
#endif
break;
break;
default:
if(ttyDisplay->curx == CO-1)
topl_putsym('\n'); /* 1 <= curx <= CO; avoid CO */
if (ttyDisplay->curx == CO - 1)
topl_putsym('\n'); /* 1 <= curx <= CO; avoid CO */
#ifdef WIN32CON
(void) putchar(c);
(void) putchar(c);
#endif
ttyDisplay->curx++;
ttyDisplay->curx++;
}
cw->curx = ttyDisplay->curx;
if(cw->curx == 0) cl_end();
if (cw->curx == 0)
cl_end();
#ifndef WIN32CON
(void) putchar(c);
#endif
@@ -299,10 +315,10 @@ topl_putsym(c)
void
putsyms(str)
const char *str;
const char *str;
{
while(*str)
topl_putsym(*str++);
while (*str)
topl_putsym(*str++);
}
STATIC_OVL void
@@ -310,14 +326,15 @@ removetopl(n)
register int n;
{
/* assume addtopl() has been done, so ttyDisplay->toplin is already set */
while (n-- > 0) putsyms("\b \b");
while (n-- > 0)
putsyms("\b \b");
}
extern char erase_char; /* from xxxtty.c; don't need kill_char */
extern char erase_char; /* from xxxtty.c; don't need kill_char */
char
tty_yn_function(query,resp, def)
const char *query,*resp;
tty_yn_function(query, resp, def)
const char *query, *resp;
char def;
/*
* Generic yes/no function. 'def' is the default (returned by space or
@@ -331,148 +348,163 @@ char def;
* be shown in the prompt to the user but will be acceptable as input.
*/
{
register char q;
char rtmp[40];
boolean digit_ok, allow_num, preserve_case = FALSE;
struct WinDesc *cw = wins[WIN_MESSAGE];
boolean doprev = 0;
char prompt[BUFSZ];
register char q;
char rtmp[40];
boolean digit_ok, allow_num, preserve_case = FALSE;
struct WinDesc *cw = wins[WIN_MESSAGE];
boolean doprev = 0;
char prompt[BUFSZ];
if(ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP)) more();
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
if (resp) {
char *rb, respbuf[QBUFSZ];
if (ttyDisplay->toplin == 1 && !(cw->flags & WIN_STOP))
more();
cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++;
if (resp) {
char *rb, respbuf[QBUFSZ];
allow_num = (index(resp, '#') != 0);
Strcpy(respbuf, resp);
/* normally we force lowercase, but if any uppercase letters
are present in the allowed response, preserve case;
check this before stripping the hidden choices */
for (rb = respbuf; *rb; ++rb)
if ('A' <= *rb && *rb <= 'Z') {
preserve_case = TRUE;
break;
}
/* any acceptable responses that follow <esc> aren't displayed */
if ((rb = index(respbuf, '\033')) != 0) *rb = '\0';
(void)strncpy(prompt, query, QBUFSZ-1);
prompt[QBUFSZ-1] = '\0';
Sprintf(eos(prompt), " [%s]", respbuf);
if (def) Sprintf(eos(prompt), " (%c)", def);
/* not pline("%s ", prompt);
trailing space is wanted here in case of reprompt */
Strcat(prompt, " ");
pline("%s", prompt);
} else {
/* no restriction on allowed response, so always preserve case */
/* preserve_case = TRUE; -- moot since we're jumping to the end */
pline("%s ", query);
q = readchar();
goto clean_up;
}
allow_num = (index(resp, '#') != 0);
Strcpy(respbuf, resp);
/* normally we force lowercase, but if any uppercase letters
are present in the allowed response, preserve case;
check this before stripping the hidden choices */
for (rb = respbuf; *rb; ++rb)
if ('A' <= *rb && *rb <= 'Z') {
preserve_case = TRUE;
break;
}
/* any acceptable responses that follow <esc> aren't displayed */
if ((rb = index(respbuf, '\033')) != 0)
*rb = '\0';
(void) strncpy(prompt, query, QBUFSZ - 1);
prompt[QBUFSZ - 1] = '\0';
Sprintf(eos(prompt), " [%s]", respbuf);
if (def)
Sprintf(eos(prompt), " (%c)", def);
/* not pline("%s ", prompt);
trailing space is wanted here in case of reprompt */
Strcat(prompt, " ");
pline("%s", prompt);
} else {
/* no restriction on allowed response, so always preserve case */
/* preserve_case = TRUE; -- moot since we're jumping to the end */
pline("%s ", query);
q = readchar();
goto clean_up;
}
do { /* loop until we get valid input */
q = readchar();
if (!preserve_case) q = lowc(q);
if (q == '\020') { /* ctrl-P */
if (iflags.prevmsg_window != 's') {
int sav = ttyDisplay->inread;
ttyDisplay->inread = 0;
(void) tty_doprev_message();
ttyDisplay->inread = sav;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(prompt);
} else {
if(!doprev)
(void) tty_doprev_message(); /* need two initially */
(void) tty_doprev_message();
doprev = 1;
}
q = '\0'; /* force another loop iteration */
continue;
} else if (doprev) {
/* BUG[?]: this probably ought to check whether the
character which has just been read is an acceptable
response; if so, skip the reprompt and use it. */
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
doprev = 0;
addtopl(prompt);
q = '\0'; /* force another loop iteration */
continue;
}
digit_ok = allow_num && digit(q);
if (q == '\033') {
if (index(resp, 'q'))
q = 'q';
else if (index(resp, 'n'))
q = 'n';
else
q = def;
break;
} else if (index(quitchars, q)) {
q = def;
break;
}
if (!index(resp, q) && !digit_ok) {
tty_nhbell();
q = (char)0;
} else if (q == '#' || digit_ok) {
char z, digit_string[2];
int n_len = 0;
long value = 0;
addtopl("#"), n_len++;
digit_string[1] = '\0';
if (q != '#') {
digit_string[0] = q;
addtopl(digit_string), n_len++;
value = q - '0';
q = '#';
}
do { /* loop until we get a non-digit */
z = readchar();
if (!preserve_case) z = lowc(z);
if (digit(z)) {
value = (10 * value) + (z - '0');
if (value < 0) break; /* overflow: try again */
digit_string[0] = z;
addtopl(digit_string), n_len++;
} else if (z == 'y' || index(quitchars, z)) {
if (z == '\033') value = -1; /* abort */
z = '\n'; /* break */
} else if (z == erase_char || z == '\b') {
if (n_len <= 1) { value = -1; break; }
else { value /= 10; removetopl(1), n_len--; }
} else {
value = -1; /* abort */
tty_nhbell();
break;
}
} while (z != '\n');
if (value > 0) yn_number = value;
else if (value == 0) q = 'n'; /* 0 => "no" */
else { /* remove number from top line, then try again */
removetopl(n_len), n_len = 0;
q = '\0';
}
}
} while(!q);
do { /* loop until we get valid input */
q = readchar();
if (!preserve_case)
q = lowc(q);
if (q == '\020') { /* ctrl-P */
if (iflags.prevmsg_window != 's') {
int sav = ttyDisplay->inread;
ttyDisplay->inread = 0;
(void) tty_doprev_message();
ttyDisplay->inread = sav;
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
addtopl(prompt);
} else {
if (!doprev)
(void) tty_doprev_message(); /* need two initially */
(void) tty_doprev_message();
doprev = 1;
}
q = '\0'; /* force another loop iteration */
continue;
} else if (doprev) {
/* BUG[?]: this probably ought to check whether the
character which has just been read is an acceptable
response; if so, skip the reprompt and use it. */
tty_clear_nhwindow(WIN_MESSAGE);
cw->maxcol = cw->maxrow;
doprev = 0;
addtopl(prompt);
q = '\0'; /* force another loop iteration */
continue;
}
digit_ok = allow_num && digit(q);
if (q == '\033') {
if (index(resp, 'q'))
q = 'q';
else if (index(resp, 'n'))
q = 'n';
else
q = def;
break;
} else if (index(quitchars, q)) {
q = def;
break;
}
if (!index(resp, q) && !digit_ok) {
tty_nhbell();
q = (char) 0;
} else if (q == '#' || digit_ok) {
char z, digit_string[2];
int n_len = 0;
long value = 0;
addtopl("#"), n_len++;
digit_string[1] = '\0';
if (q != '#') {
digit_string[0] = q;
addtopl(digit_string), n_len++;
value = q - '0';
q = '#';
}
do { /* loop until we get a non-digit */
z = readchar();
if (!preserve_case)
z = lowc(z);
if (digit(z)) {
value = (10 * value) + (z - '0');
if (value < 0)
break; /* overflow: try again */
digit_string[0] = z;
addtopl(digit_string), n_len++;
} else if (z == 'y' || index(quitchars, z)) {
if (z == '\033')
value = -1; /* abort */
z = '\n'; /* break */
} else if (z == erase_char || z == '\b') {
if (n_len <= 1) {
value = -1;
break;
} else {
value /= 10;
removetopl(1), n_len--;
}
} else {
value = -1; /* abort */
tty_nhbell();
break;
}
} while (z != '\n');
if (value > 0)
yn_number = value;
else if (value == 0)
q = 'n'; /* 0 => "no" */
else { /* remove number from top line, then try again */
removetopl(n_len), n_len = 0;
q = '\0';
}
}
} while (!q);
if (q != '#') {
Sprintf(rtmp, "%c", q);
addtopl(rtmp);
}
clean_up:
ttyDisplay->inread--;
ttyDisplay->toplin = 2;
if (ttyDisplay->intr) ttyDisplay->intr--;
if(wins[WIN_MESSAGE]->cury)
tty_clear_nhwindow(WIN_MESSAGE);
if (q != '#') {
Sprintf(rtmp, "%c", q);
addtopl(rtmp);
}
clean_up:
ttyDisplay->inread--;
ttyDisplay->toplin = 2;
if (ttyDisplay->intr)
ttyDisplay->intr--;
if (wins[WIN_MESSAGE]->cury)
tty_clear_nhwindow(WIN_MESSAGE);
return q;
return q;
}
/* shared by tty_getmsghistory() and tty_putmsghistory() */
@@ -482,14 +514,15 @@ static char **snapshot_mesgs = 0;
optionally, purge that data from the active circular buffer set as we go */
STATIC_OVL void
msghistory_snapshot(purge)
boolean purge; /* clear message history buffer as we copy it */
boolean purge; /* clear message history buffer as we copy it */
{
char *mesg;
int i, inidx, outidx;
struct WinDesc *cw;
/* paranoia (too early or too late panic save attempt?) */
if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE]) return;
if (WIN_MESSAGE == WIN_ERR || !wins[WIN_MESSAGE])
return;
cw = wins[WIN_MESSAGE];
/* flush toplines[], moving most recent message to history */
@@ -497,49 +530,52 @@ boolean purge; /* clear message history buffer as we copy it */
/* for a passive snapshot, we just copy pointers, so can't allow further
history updating to take place because that could clobber them */
if (!purge) cw->flags |= WIN_LOCKHISTORY;
if (!purge)
cw->flags |= WIN_LOCKHISTORY;
snapshot_mesgs = (char **)alloc((cw->rows + 1) * sizeof (char *));
snapshot_mesgs = (char **) alloc((cw->rows + 1) * sizeof(char *));
outidx = 0;
inidx = cw->maxrow;
for (i = 0; i < cw->rows; ++i) {
snapshot_mesgs[i] = (char *)0;
mesg = cw->data[inidx];
if (mesg && *mesg) {
snapshot_mesgs[outidx++] = mesg;
if (purge) {
/* we're taking this pointer away; subsequest history
updates will eventually allocate a new one to replace it */
cw->data[inidx] = (char *)0;
cw->datlen[inidx] = 0;
}
}
inidx = (inidx + 1) % cw->rows;
snapshot_mesgs[i] = (char *) 0;
mesg = cw->data[inidx];
if (mesg && *mesg) {
snapshot_mesgs[outidx++] = mesg;
if (purge) {
/* we're taking this pointer away; subsequest history
updates will eventually allocate a new one to replace it */
cw->data[inidx] = (char *) 0;
cw->datlen[inidx] = 0;
}
}
inidx = (inidx + 1) % cw->rows;
}
snapshot_mesgs[cw->rows] = (char *)0; /* sentinel */
snapshot_mesgs[cw->rows] = (char *) 0; /* sentinel */
/* for a destructive snapshot, history is now completely empty */
if (purge) cw->maxcol = cw->maxrow = 0;
if (purge)
cw->maxcol = cw->maxrow = 0;
}
/* release memory allocated to message history snapshot */
STATIC_OVL void
free_msghistory_snapshot(purged)
boolean purged; /* True: took history's pointers, False: just cloned them */
boolean purged; /* True: took history's pointers, False: just cloned them */
{
if (snapshot_mesgs) {
/* snapshot pointers are no longer in use */
if (purged) {
int i;
/* snapshot pointers are no longer in use */
if (purged) {
int i;
for (i = 0; snapshot_mesgs[i]; ++i)
free((genericptr_t)snapshot_mesgs[i]);
}
for (i = 0; snapshot_mesgs[i]; ++i)
free((genericptr_t) snapshot_mesgs[i]);
}
free((genericptr_t)snapshot_mesgs), snapshot_mesgs = (char **)0;
free((genericptr_t) snapshot_mesgs), snapshot_mesgs = (char **) 0;
/* history can resume being updated at will now... */
if (!purged) wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY;
/* history can resume being updated at will now... */
if (!purged)
wins[WIN_MESSAGE]->flags &= ~WIN_LOCKHISTORY;
}
}
@@ -562,17 +598,17 @@ boolean init;
char *result = 0;
if (init) {
msghistory_snapshot(FALSE);
nxtidx = 0;
msghistory_snapshot(FALSE);
nxtidx = 0;
}
if (snapshot_mesgs) {
nextmesg = snapshot_mesgs[nxtidx++];
if (nextmesg) {
result = (char *)nextmesg;
} else {
free_msghistory_snapshot(FALSE);
}
nextmesg = snapshot_mesgs[nxtidx++];
if (nextmesg) {
result = (char *) nextmesg;
} else {
free_msghistory_snapshot(FALSE);
}
}
return result;
}
@@ -603,28 +639,29 @@ boolean restoring_msghist;
int idx;
if (restoring_msghist && !initd) {
/* we're restoring history from the previous session, but new
messages have already been issued this session ("Restoring...",
for instance); collect current history (ie, those new messages),
and also clear it out so that nothing will be present when the
restored ones are being put into place */
msghistory_snapshot(TRUE);
initd = TRUE;
/* we're restoring history from the previous session, but new
messages have already been issued this session ("Restoring...",
for instance); collect current history (ie, those new messages),
and also clear it out so that nothing will be present when the
restored ones are being put into place */
msghistory_snapshot(TRUE);
initd = TRUE;
}
if (msg) {
/* move most recent message to history, make this become most recent */
remember_topl();
Strcpy(toplines, msg);
/* move most recent message to history, make this become most recent
*/
remember_topl();
Strcpy(toplines, msg);
} else if (snapshot_mesgs) {
/* done putting arbitrary messages in; put the snapshot ones back */
for (idx = 0; snapshot_mesgs[idx]; ++idx) {
remember_topl();
Strcpy(toplines, snapshot_mesgs[idx]);
}
/* now release the snapshot */
free_msghistory_snapshot(TRUE);
initd = FALSE; /* reset */
/* done putting arbitrary messages in; put the snapshot ones back */
for (idx = 0; snapshot_mesgs[idx]; ++idx) {
remember_topl();
Strcpy(toplines, snapshot_mesgs[idx]);
}
/* now release the snapshot */
free_msghistory_snapshot(TRUE);
initd = FALSE; /* reset */
}
}
+1891 -1802
View File
File diff suppressed because it is too large Load Diff