-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathrince.c
More file actions
124 lines (114 loc) · 2.77 KB
/
rince.c
File metadata and controls
124 lines (114 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/** 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<<17} ;
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<<17,&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();
}