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 */