Don't segv if bs or bc aren't defined in termcap's entry. Misc cleanup.

Fix `|' -> `||'.  Use usleep() instead of delay loop.  Etc.

Submitted by:	Andrew <[3]andrew@ugh.net.au> (bin/8501)
This commit is contained in:
Tim Vanderhoek 2000-05-21 17:44:33 +00:00
parent a274d19ba2
commit f1efd59d2d
3 changed files with 44 additions and 27 deletions

View File

@ -95,12 +95,15 @@ static const char rcsid[] =
*
******************************************************************************/
#include <errno.h>
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <string.h>
#include <unistd.h>
#include "snake.h"
int CMlength;
@ -191,7 +194,7 @@ gto(sp)
struct point *sp;
{
int distance,f,tfield,j;
int distance,f,tfield;
if (cursor.line > LINES || cursor.line <0 ||
cursor.col <0 || cursor.col > COLUMNS)
@ -344,7 +347,7 @@ home(){
}
ll(){
int j,l;
int l;
struct point z;
l = lcnt + 2;
@ -531,14 +534,9 @@ baudrate()
#endif
delay(t)
int t;
unsigned int t;
{
int k,j;
k = baudrate() * t / 300;
for(j=0;j<k;j++){
putchar(PC);
}
while (usleep(t*50000U) == -1 && errno == EINTR) ;
}
done()
@ -552,6 +550,7 @@ cook()
delay(1);
putpad(TE);
putpad(KE);
putpad(VE);
fflush(stdout);
stty(0, &orig);
#ifdef TIOCSLTC
@ -583,7 +582,6 @@ getcap()
char *getenv();
char *term;
char *xPC;
struct point z;
void stop();
#ifdef TIOCGWINSZ
struct winsize win;
@ -649,26 +647,43 @@ getcap()
KR = tgetstr("kr", &ap);
KU = tgetstr("ku", &ap);
KD = tgetstr("kd", &ap);
Klength = strlen(KL);
/* NOTE: If KL, KR, KU, and KD are not
* all the same length, some problems
* may arise, since tests are made on
* all of them together.
*/
if (KL)
Klength = strlen(KL);
else
Klength = strlen(KL);
/*
* NOTE: If KL, KR, KU, and KD are not
* all the same length, some problems
* may arise, since tests are made on
* all of them together.
*/
TI = tgetstr("ti", &ap);
TE = tgetstr("te", &ap);
KS = tgetstr("ks", &ap);
KE = tgetstr("ke", &ap);
VI = tgetstr("vi", &ap);
VE = tgetstr("ve", &ap);
xPC = tgetstr("pc", &ap);
if (xPC)
PC = *xPC;
NDlength = strlen(ND);
BSlength = strlen(BS);
if (ND)
NDlength = strlen(ND);
else
NDlength = 0;
if (BS)
BSlength = strlen(BS);
else
BSlength = 0;
if ((CM == 0) &&
(HO == 0 | UP==0 || BS==0 || ND==0)) {
(HO == 0 || DO == 0 || UP==0 || BS==0 || ND==0))
{
/* XXX as written in rev.1.6, we can assert(DO) */
fprintf(stderr, "Terminal must have addressible ");
fprintf(stderr, "cursor or home + 4 local motions\n");
exit(5);

View File

@ -108,7 +108,7 @@ char **argv;
{
extern char *optarg;
extern int optind;
int ch, i, j, k;
int ch, i;
void stop();
rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664);
@ -174,6 +174,7 @@ char **argv;
signal (SIGINT, stop);
putpad(TI); /* String to begin programs that use cm */
putpad(KS); /* Put terminal in keypad transmit mode */
putpad(VI); /* Hide cursor */
snrand(&finish);
snrand(&you);
@ -368,8 +369,6 @@ mainloop()
if (same(&you,&money))
{
char xp[20];
struct point z;
loot += 25;
if(k < repeat)
pchar(&you,' ');
@ -633,10 +632,10 @@ int w;{
setup();
winnings(cashvalue);
}
snap()
{
struct point p;
int i;
if(you.line < 3){
pchar(point(&p,you.col,0),'-');
@ -669,6 +668,7 @@ snap()
}
fflush(stdout);
}
stretch(ps)
struct point *ps;{
struct point p;
@ -712,7 +712,7 @@ struct point *ps;{
surround(ps)
struct point *ps;{
struct point x;
int i,j;
int j;
if(ps->col == 0)ps->col++;
if(ps->line == 0)ps->line++;
@ -733,6 +733,7 @@ struct point *ps;{
}
apr(point(&x,ps->col-1,ps->line-1)," \ro.o\r\\_/");
}
win(ps)
struct point *ps;
{
@ -873,8 +874,6 @@ stop(){
suspend()
{
char *sh;
ll();
cook();
kill(getpid(), SIGTSTP);

View File

@ -31,6 +31,8 @@
* SUCH DAMAGE.
*
* @(#)snake.h 8.1 (Berkeley) 5/31/93
*
* $FreeBSD$
*/
# include <stdio.h>
@ -50,7 +52,8 @@ char *CL, *UP, *DO, *ND, *BS,
*HO, *CM,
*TA, *LL,
*KL, *KR, *KU, *KD,
*TI, *TE, *KS, *KE;
*TI, *TE, *KS, *KE,
*VI, *VE;
int LINES, COLUMNS; /* physical screen size. */
int lcnt, ccnt; /* user's idea of screen size */
char xBC, PC;