Files
Cody Boone Ferguson a28bd67968 Some fixes in 1993/rince
It was stated, perhaps even by me but no longer sure of this (it looks
like my style) that after the program is terminated the terminal might
not be sane and one could do 'stty sane', 'reset' and other things.
Instead I have changed the code to just call endwin() and removed that
information instead. This way the user should not be burdened by it. The
alt code that I had added earlier on also has this fix.

The markdown files have not been completely checked but both README.md
and design.md have had some fixes applied.

The thanks file also points out that Yusuke's fix applies the suggested
fix for select(2) found in the README.md.
2023-11-09 09:21:09 -08:00

125 lines
2.8 KiB
C

/** J.K.Bonfield **
^ <
^ >
< # > v
< <
< > > < v
X X j
x X j
X x ^ k
^ ^
^ #
X X X X
^ v
v v
v #
v X
v x
> # < v
> >
X X l
x X l
41 20
########################################
# #
# < < < < <> < < < #
# > > > <> > > > > #
# < < < < <> < < < #
# > > > <> > > > > #
# < < < < <> < < < #
# > > > <> > > > > #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# X #
########################################*/
#include <stdio.h>
#include <curses.h>
#include <stdlib.h>
#include <setjmp.h>
#include <sys/time.h>
int _tty_ch;
bool _echoit;
bool _rawmode;
int _tty;
#define U char
#define G for(
#define I )malloc(sizeof(
typedef struct z {U x[20]; struct z*y; } j; j*J[2][256];
struct timeval v= {0,1<<Z} ;
U**X,c,*P="noopoqqnr",d;
j*a(int Q, int i) {
G
clear(),noecho(),cbreak(); ;
)
{
int x=0,y=0,W=Q,Q=i-1,k;
G;
y<=Q;
(mvaddch(y,x,X[y][x]),++x^W-1)||(x=0,y++));
k=y=- --x;
G
refresh(),c=select(k,&y,0,0,(v.tv_usec=1<<Z,&v))?getch():0;
k?++x-W||(x=1,++y-Q||(--k,x=W-1,y=Q-1)):--x||(y--,x=W-1),k|y;
)
{
j *t;
G
t=J[1-k][X[y][x]]; t; t=t->y) {
U*f=t->x;
if (d==f[17]|f[17]==c) {
int i=k&2,u=9,k=1,w=x,_=y,T;
G;
--u||(d-f[8]&&(X[y][x]=f[8]),w---_--,i=0,u=8,k--);) {
_+=P[T=i>u?u:i]-'o';
w+=P[4+T]-'p';
if(k) {
if (d-f[i]&&f[i]-X[_][w]) break;
i++;
} else
f[++i+8]-d && (X[_][w]=f[i+8]);
} } } } } }
jmp_buf E;
int main(int open, U**exit) {
FILE*C=fopen (
open-2?__FILE__:*++exit,P+8);
j*t;
volatile int Q,Y=0;
int i,q; d=open-2?'\t':'*'; L:
Q=0; G; setjmp(E)<256; Q--
)
longjmp(E,(J[Y][Q]=0,Q++));
G; ; ) {
if(!C)return 1;
if('\n'==(c=getc(C)))
if(!Y++)goto L; else
{ fscanf(C,"%d %d\n",&i,&q);
X=(U**I P++)*q*(i+1));
Q=0; G; Q<q; Q++)
X[Q]=(U*)&X[q]+Q*i;
fread(*X,(initscr(),q*i),1,C);
a(i,Q);
}
t=(j*I*a(Q--,--Q)));
t->y=J[Y][c]; J[Y][c]=t;
fgets(t->x,20,C); }
endwin();
}