]> git.gir.st - solVItaire.git/blob - sol.c
fix `make getfuns`
[solVItaire.git] / sol.c
1 #define _DEFAULT_SOURCE
2 #include <poll.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <time.h>
6 #include <termios.h>
7 #include <unistd.h>
8
9 #include "sol.h"
10 #include "schemes.h"
11
12 #ifdef KLONDIKE
13 #define NUM_PILES 7
14 #define MAX_HIDDEN 6 /*how many cards are turned over at most in a tableu pile*/
15 #define MAX_STOCK 24 /*how many cards can be in the stock at most (=@start)*/
16 #define NUM_DECKS 1
17 #define PILE_SIZE MAX_HIDDEN+NUM_RANKS
18 #elif defined SPIDER
19 #define MAX_HIDDEN 5
20 #define NUM_PILES 10
21 #define MAX_STOCK 50 /*how many cards can be dealt onto the piles*/
22 #define NUM_DECKS 2
23 #define PILE_SIZE DECK_SIZE*NUM_DECKS /* no maximum stack size in spider :/ */
24 #endif
25
26 #define get_suit(card) \
27 ((card-1) % NUM_SUITS)
28 #define get_rank(card) \
29 ((card-1) / NUM_SUITS)
30 #define get_color(card) \
31 ((get_suit(card) ^ get_suit(card)>>1) & 1)
32
33 struct playfield {
34 card_t s[MAX_STOCK]; /* stock */
35 int z; /* stock size */
36 int w; /* waste; index into stock (const -1 in spider) */
37 card_t f[NUM_DECKS*NUM_SUITS][PILE_SIZE]; /* foundation */
38 card_t t[NUM_PILES][PILE_SIZE]; /* tableu piles */
39 struct undo {
40 int f; /* pile cards were taken from */
41 int t; /* pile cards were moved to */
42 int n; /* number of cards moved (if tableu; else index of stock/foundation) */
43 struct undo* prev;
44 struct undo* next;
45 }* u;
46 } f;
47 struct opts {
48 #ifdef SPIDER
49 int m; /* difficulty mode */
50 #endif
51 const struct scheme* s;
52 } op;
53
54 // action table {{{
55 /* stores a function pointer for every takeable action; called by game loop */
56 int (*action[NUM_PLACES][10])(int,int) = {
57 #ifdef KLONDIKE
58 /* 1 2 3 4 5 6 7 stk wst fnd*/
59 /* 1 */ { t2f, t2t, t2t, t2t, t2t, t2t, t2t, nop, nop, t2f },
60 /* 2 */ { t2t, t2f, t2t, t2t, t2t, t2t, t2t, nop, nop, t2f },
61 /* 3 */ { t2t, t2t, t2f, t2t, t2t, t2t, t2t, nop, nop, t2f },
62 /* 4 */ { t2t, t2t, t2t, t2f, t2t, t2t, t2t, nop, nop, t2f },
63 /* 5 */ { t2t, t2t, t2t, t2t, t2f, t2t, t2t, nop, nop, t2f },
64 /* 6 */ { t2t, t2t, t2t, t2t, t2t, t2f, t2t, nop, nop, t2f },
65 /* 7 */ { t2t, t2t, t2t, t2t, t2t, t2t, t2f, nop, nop, t2f },
66 /*stk*/ { nop, nop, nop, nop, nop, nop, nop, nop, s2w, nop },
67 /*wst*/ { w2t, w2t, w2t, w2t, w2t, w2t, w2t, w2s, w2f, w2f },
68 /*fnd*/ { f2t, f2t, f2t, f2t, f2t, f2t, f2t, nop, nop, nop },
69 #elif defined SPIDER
70 /* 1 2 3 4 5 6 7 8 9 10*/
71 /* 1 */ { nop, t2t, t2t, t2t, t2t, t2t, t2t, t2t, t2t, t2t },
72 /* 2 */ { t2t, nop, t2t, t2t, t2t, t2t, t2t, t2t, t2t, t2t },
73 /* 3 */ { t2t, t2t, nop, t2t, t2t, t2t, t2t, t2t, t2t, t2t },
74 /* 4 */ { t2t, t2t, t2t, nop, t2t, t2t, t2t, t2t, t2t, t2t },
75 /* 5 */ { t2t, t2t, t2t, t2t, nop, t2t, t2t, t2t, t2t, t2t },
76 /* 6 */ { t2t, t2t, t2t, t2t, t2t, nop, t2t, t2t, t2t, t2t },
77 /* 7 */ { t2t, t2t, t2t, t2t, t2t, t2t, nop, t2t, t2t, t2t },
78 /* 8 */ { t2t, t2t, t2t, t2t, t2t, t2t, t2t, nop, t2t, t2t },
79 /* 9 */ { t2t, t2t, t2t, t2t, t2t, t2t, t2t, t2t, nop, t2t },
80 /*10 */ { t2t, t2t, t2t, t2t, t2t, t2t, t2t, t2t, t2t, nop },
81 /*stk*/ { s2t, s2t, s2t, s2t, s2t, s2t, s2t, s2t, s2t, s2t },
82 #endif
83 };
84 // }}}
85
86 int main(int argc, char** argv) {
87 (void) argc;(void) argv;
88 op.s = &unicode_large_color;
89 #ifdef SPIDER
90 op.m = MEDIUM; //TODO: make configurable
91 op.m = EASY;
92 #endif
93 screen_setup(1);
94 sol(); //TODO: restart, etc.
95 screen_setup(0);
96 }
97
98 void sol(void) {
99 deal();
100
101 int from, to;
102 print_table(NO_HI);
103 for(;;) {
104 switch (get_cmd(&from, &to)) {
105 case CMD_MOVE:
106 switch (action[from][to](from,to)) {
107 case OK: break;
108 case ERR: visbell(); break;
109 case WON:
110 print_table(NO_HI);
111 win_anim();
112 getchar(); /* consume char left by win_anim() */
113 return;
114 }
115 break;
116 case CMD_QUIT: return;
117 }
118 print_table(NO_HI);
119 }
120 }
121
122 int find_top(card_t* pile) {
123 int i;
124 for(i=PILE_SIZE-1; i>=0 && !pile[i]; i--);
125 return i;
126 }
127 void turn_over(card_t* pile) {
128 int top = find_top(pile);
129 if (pile[top] < 0) pile[top] *= -1;
130 }
131 int check_won(void) {
132 for (int pile = 0; pile < NUM_DECKS*NUM_SUITS; pile++)
133 if (f.f[pile][NUM_RANKS-1] == NO_CARD) return 0;
134
135 return 1;
136 }
137 void win_anim(void) {
138 printf ("\033[?25l"); /* hide cursor */
139 for (;;) {
140 /* set cursor to random location */
141 int row = 1+random()%(24-op.s->width);
142 int col = 1+random()%(80-op.s->height);
143
144 /* draw random card */
145 int face = 1 + random() % 52;
146 for (int l = 0; l < op.s->height; l++) {
147 printf ("\033[%d;%dH", row+l, col);
148 printf ("%s", op.s->card[face][l]);
149 }
150 fflush (stdout);
151
152 /* exit on keypress */
153 struct pollfd p = {STDIN_FILENO, POLLIN, 0};
154 if (poll (&p, 1, 80)) goto fin;
155 }
156 fin:
157 printf ("\033[?25h"); /* show cursor */
158 return;
159 }
160 // takeable actions {{{
161 #ifdef KLONDIKE
162 card_t stack_take(void) { /*NOTE: assert(f.w >= 0) */
163 card_t card = f.s[f.w];
164 /* move stack one over, so there are no gaps in it: */
165 for (int i = f.w; i < f.z-1; i++)
166 f.s[i] = f.s[i+1];
167 f.z--;
168 f.w--; /* make previous card visible again */
169 return card;
170 }
171 int t2f(int from, int to) { /* tableu to foundation */
172 (void) to; //don't need
173 int top_from = find_top(f.t[from]);
174 to = get_suit(f.t[from][top_from]);
175 int top_to = find_top(f.f[to]);
176 if ((top_to < 0 && get_rank(f.t[from][top_from]) == RANK_A)
177 || (top_to >= 0 && get_rank(f.f[to][top_to]) == get_rank(f.t[from][top_from])-1)) {
178 f.f[to][top_to+1] = f.t[from][top_from];
179 f.t[from][top_from] = NO_CARD;
180 turn_over(f.t[from]);
181 if (check_won()) return WON;
182 return OK;
183 } else return ERR;
184 }
185 int w2f(int from, int to) { /* waste to foundation */
186 (void) from; (void) to; //don't need
187 if (f.w < 0) return ERR;
188 to = get_suit(f.s[f.w]);
189 int top_to = find_top(f.f[to]);
190 if ((top_to < 0 && get_rank(f.s[f.w]) == RANK_A)
191 || (top_to >= 0 && get_rank(f.f[to][top_to]) == get_rank(f.s[f.w])-1)) {
192 f.f[to][top_to+1] = stack_take();
193 if (check_won()) return WON;
194 return OK;
195 } else return ERR;
196
197 }
198 int s2w(int from, int to) { /* stock to waste */
199 (void) from; (void) to; //don't need
200 if (f.z == 0) return ERR;
201 f.w++;
202 if (f.w == f.z) f.w = -1;
203 return OK;
204 }
205 int w2s(int from, int to) { /* waste to stock (undoes stock to waste) */
206 (void) from; (void) to; //don't need
207 if (f.z == 0) return ERR;
208 f.w--;
209 if (f.w < -1) f.w = f.z-1;
210 return OK;
211 }
212 int f2t(int from, int to) { /* foundation to tableu */
213 int top_to = find_top(f.t[to]);
214 printf ("take from (1-4): "); fflush (stdout);
215 from = getchar() - '1';
216 if (from < 0 || from > 3) return ERR;
217 int top_from = find_top(f.f[from]);
218
219 if ((get_color(f.t[to][top_to]) != get_color(f.f[from][top_from]))
220 && (get_rank(f.t[to][top_to]) == get_rank(f.f[from][top_from])+1)) {
221 f.t[to][top_to+1] = f.f[from][top_from];
222 f.f[from][top_from] = NO_CARD;
223 return OK;
224 } else return ERR;
225 }
226 int w2t(int from, int to) { /* waste to tableu */
227 (void) from; //don't need
228 int top_to = find_top(f.t[to]);
229 if (((get_color(f.t[to][top_to]) != get_color(f.s[f.w]))
230 && (get_rank(f.t[to][top_to]) == get_rank(f.s[f.w])+1))
231 || (top_to < 0 && get_rank(f.s[f.w]) == RANK_K)) {
232 f.t[to][top_to+1] = stack_take();
233 return OK;
234 } else return ERR;
235 }
236 int t2t(int from, int to) { /* tableu to tableu */
237 int top_to = find_top(f.t[to]);
238 int top_from = find_top(f.t[from]);
239 for (int i = top_from; i >=0; i--) {
240 if (((get_color(f.t[to][top_to]) != get_color(f.t[from][i]))
241 && (get_rank(f.t[to][top_to]) == get_rank(f.t[from][i])+1)
242 && f.t[from][i] > NO_CARD) /* card face up? */
243 || (top_to < 0 && get_rank(f.t[from][i]) == RANK_K)) {
244 /* move cards [i..top_from] to their destination */
245 for (;i <= top_from; i++) {
246 top_to++;
247 f.t[to][top_to] = f.t[from][i];
248 f.t[from][i] = NO_CARD;
249 }
250 turn_over(f.t[from]);
251 return OK;
252 }
253 }
254 return ERR; /* no such move possible */
255 }
256 #elif defined SPIDER
257 int is_consecutive (card_t* pile, int pos) {
258 if (pos+1 >= PILE_SIZE) return 1; /* card is last */
259 if (pile[pos+1] == NO_CARD) return 1; /* card is first */
260
261 if (get_rank(pile[pos+1]) != get_rank(pile[pos])-1) return 0; /*rank consecutive?*/
262 if (get_suit(pile[pos+1]) != get_suit(pile[pos])) return 0; /*same suit?*/
263
264 return 1;
265 }
266 void remove_if_complete (card_t* pile) { //TODO: cleanup
267 static int foundation = 0; /* where to put pile onto (1 set per stack)*/
268 /* test if K...A complete; move to foundation if so */
269 int top_from = find_top(pile);
270 if (get_rank(pile[top_from]) != RANK_A) return;
271 for (int i = top_from; i>=0; i--) {
272 if (!is_consecutive (pile, i)) return;
273 if (i+RANK_K == top_from
274 && get_rank(pile[top_from-RANK_K]) == RANK_K) { //ace to king ok, remove it
275 for (int i = top_from, j = 0; i > top_from-NUM_RANKS; i--, j++) {
276 f.f[foundation][j] = pile[i];
277 pile[i] = NO_CARD;
278 }
279 foundation++;
280 turn_over(pile);
281 return;
282 }
283 }
284 }
285 int t2t(int from, int to) { //TODO: in dire need of cleanup
286 //TODO: segfaulted once on large column
287 //TODO: sometimes moving doesn't work (ERR when it should be OK) XXX
288
289 int top_from = find_top(f.t[from]);
290 int top_to = find_top(f.t[to]);
291 int empty_to = -1; //awful, nondescriptive name :/
292 if (top_to < 0) { /* empty pile? */
293 printf ("\rup to (a23456789xjqk): "); //TODO: automatically do it if only 1 card movable
294 empty_to = getchar();
295 switch (empty_to) {
296 case 'a': case 'A': empty_to = RANK_A; break;
297 case '0': /* fallthrough */
298 case 'x': case 'X': empty_to = RANK_X; break;
299 case 'j': case 'J': empty_to = RANK_J; break;
300 case 'q': case 'Q': empty_to = RANK_Q; break;
301 case 'k': case 'K': empty_to = RANK_K; break;
302 default: empty_to -= '1';
303 }
304 if (empty_to < RANK_A || empty_to > RANK_K) return ERR;
305 }
306 for (int i = top_from; i >= 0; i--) {
307 if (!is_consecutive(f.t[from], i)) break;
308
309 if ((get_rank(f.t[from][i]) == get_rank(f.t[to][top_to])-1) // consecutive?
310 || (empty_to >= RANK_A && get_rank(f.t[from][i]) == empty_to)) { //to empty pile and rank ok?
311 for (;i <= top_from; i++) {
312 top_to++;
313 f.t[to][top_to] = f.t[from][i];
314 f.t[from][i] = NO_CARD;
315 }
316 turn_over(f.t[from]);
317 remove_if_complete (f.t[to]);
318 if (check_won()) return WON;
319 return OK;
320 }
321 }
322
323 return ERR; /* no such move possible */
324 }
325 int s2t(int from, int to) { //TODO: check remove, won
326 (void) from; (void) to; //don't need
327 if (f.z <= 0) return ERR; /* stack out of cards */
328 for (int pile = 0; pile < NUM_PILES; pile++)
329 if (f.t[pile][0]==NO_CARD) return ERR; /*no piles may be empty*/
330 for (int pile = 0; pile < NUM_PILES; pile++) {
331 f.t[pile][find_top(f.t[pile])+1] = f.s[--f.z];
332 }
333 return OK;
334 }
335 #endif
336 int nop(int from, int to) { (void)from;(void)to; return ERR; }
337 // }}}
338
339 int get_cmd (int* from, int* to) {
340 //returns 0 on success or an error code indicating game quit, new game,...
341 //TODO: escape sequences (mouse, cursor keys)
342 //TODO: don't allow taking from empty piles
343 int f, t;
344 f = getchar();
345
346 switch (f) {
347 /* direct addressing: */
348 case '1': *from = TAB_1; break;
349 case '2': *from = TAB_2; break;
350 case '3': *from = TAB_3; break;
351 case '4': *from = TAB_4; break;
352 case '5': *from = TAB_5; break;
353 case '6': *from = TAB_6; break;
354 case '7': *from = TAB_7; break;
355 #ifdef SPIDER
356 case '8': *from = TAB_8; break;
357 case '9': *from = TAB_9; break;
358 case '0': *from = TAB_10; break;
359 #elif defined KLONDIKE
360 case '9': *from = WASTE; break;
361 case '0': *from = FOUNDATION; break;
362 case '8': /* fallthrough */
363 #endif
364 case '\n': /* shortcut for dealing from stock */
365 *from = STOCK;
366 *to = WASTE;
367 return CMD_MOVE;
368 /* cursor keys addressing: */
369 //TODO
370 case 'q': return CMD_QUIT;
371 case 'r': return CMD_NEW; //TODO
372 case 'h': return CMD_HINT; //TODO
373 case '?': return CMD_HELP; //TODO
374 case '/': return CMD_FIND; //TODO: highlight card of given rank (even non-movable)
375 case '\033': return CMD_INVAL; //TODO: cntlseq
376 default: return CMD_INVAL;
377 }
378 print_table(*from);
379
380 t = getchar();
381 if (t < '0' || t > '9') return CMD_INVAL;
382 if (t == '0')
383 #ifdef KLONDIKE
384 *to = FOUNDATION;
385 #elif defined SPIDER
386 *to = TAB_10;
387 #endif
388 else
389 *to = t-'1';
390 return CMD_MOVE;
391 }
392
393 void deal(void) {
394 f = (const struct playfield){0}; /* clear playfield */
395 card_t deck[DECK_SIZE*NUM_DECKS];
396 int avail = DECK_SIZE*NUM_DECKS;
397 for (int i = 0; i < DECK_SIZE*NUM_DECKS; i++) deck[i] = (i%DECK_SIZE)+1;
398 #ifdef SPIDER
399 if (op.m != NORMAL) for (int i = 0; i < DECK_SIZE*NUM_DECKS; i++) {
400 if (op.m == MEDIUM) deck[i] = 1+((deck[i]-1) | 2);
401 if (op.m == EASY) deck[i] = 1+((deck[i]-1) | 2 | 1);
402 /* the 1+ -1 dance gets rid of the offset created by NO_CARD */
403 }
404 #endif
405 srandom (time(NULL));
406 /*XXX*/ long seed = time(NULL);
407 /*XXX*/ srandom (seed);
408 for (int i = DECK_SIZE*NUM_DECKS-1; i > 0; i--) { //fisher-yates
409 int j = random() % (i+1);
410 if (j-i) deck[i]^=deck[j],deck[j]^=deck[i],deck[i]^=deck[j];
411 }
412
413 /* deal cards: */
414 for (int i = 0; i < NUM_PILES; i++) {
415 #ifdef KLONDIKE
416 int closed = i; /* pile n has n closed cards, then 1 open */
417 #elif defined SPIDER
418 int closed = i<4?5:4; /* pile 1-4 have 5, 5-10 have 4 closed */
419 #endif
420 /* face down cards are negated: */
421 for (int j = 0; j < closed; j++) f.t[i][j] = -deck[--avail];
422 f.t[i][closed] = deck[--avail]; /* the face-up card */
423 }
424 /* rest of the cards to the stock; NOTE: assert(avail==50) for spider */
425 for (f.z = 0; avail; f.z++) f.s[f.z] = deck[--avail];
426 f.w = -1; /* @start: nothing on waste (no waste in spider -> const) */
427 }
428
429 int is_movable(card_t* pile, int n) { //TODO cleanup, code deduplication, needs entry in sol.h
430 #ifdef KLONDIKE
431 return(pile[n] > NO_CARD); /*non-movable cards don't exist in klondike*/
432 #elif defined SPIDER
433 int top = find_top(pile);
434 for (int i = top; i >= 0; i--) {
435 if (pile[i] <= NO_CARD) return 0; //card face down?
436 if (!is_consecutive(pile, i)) return 0;
437 if (i == n) return 1; //card reached, must be movable
438 }
439 return 0;
440 #endif
441 }
442 #define print_hi(invert, bold, str) /* for highlighting during get_cmd() */ \
443 printf ("%s%s%s%s%s", (bold)?"\033[1m":"", (invert)?"\033[7m":"", str, \
444 (invert)?"\033[27m":"", (bold)?"\033[22m":"")
445 void print_table(int highlight) { //{{{
446 printf("\033[2J\033[H"); /* clear screen, reset cursor */
447 #ifdef KLONDIKE
448 /* print stock, waste and foundation: */
449 for (int line = 0; line < op.s->height; line++) {
450 /* stock: */
451 print_hi (highlight == STOCK, 1, (
452 (f.w < f.z-1)?op.s->facedown
453 :op.s->placeholder)[line]);
454 /* waste: */
455 print_hi (highlight == WASTE, 1, (
456 /* NOTE: cast, because f.w sometimes is (short)-1 !? */
457 ((short)f.w >= 0)?op.s->card[f.s[f.w]]
458 :op.s->placeholder)[line]);
459 printf ("%s", op.s->card[NO_CARD][line]); /* spacer */
460 /* foundation: */
461 for (int pile = 0; pile < NUM_SUITS; pile++) {
462 int card = find_top(f.f[pile]);
463 print_hi (highlight == FOUNDATION, 1,
464 (card < 0)?op.s->placeholder[line]
465 :op.s->card[f.f[pile][card]][line]);
466 }
467 printf("\n");
468 }
469 printf("\n");
470 #elif SPIDER
471 for (int line = 0; line < op.s->height; line++) {
472 /* available stock: */
473 for (int i = f.z/10; i; i--) {
474 if (i==1) printf ("%s", op.s->facedown[line]);
475 else printf ("%s", op.s->halfstack[line]);
476 }
477 /* spacer: */ //TODO: urgh! cleanup!
478 int xx = 0; for(int i=0;i<NUM_DECKS*NUM_SUITS;i++)if(f.f[i][RANK_K])xx++;
479 int HALFWIDTH = 2; int RIGHTWIDTH = 3;
480 for (int i = f.z?(f.z/10-1)*HALFWIDTH + op.s->width:0;
481 i < NUM_PILES*op.s->width - ((xx?(xx-1)*RIGHTWIDTH:0)+op.s->width);
482 i++)
483 printf (" ");
484 /* foundation (overlapping): */
485 for (int i = 0; i < NUM_DECKS*NUM_SUITS; i++) {
486 int overlap = i? op.s->halfcard[line]: 0;
487 if (f.f[i][RANK_K]) printf ("%s",
488 op.s->card[f.f[i][RANK_K]][line]+overlap);
489 }
490 printf("\n");
491 }
492 printf("\n");
493 #endif
494 /* print tableu piles: */
495 int row[NUM_PILES] = {0};
496 int line[NUM_PILES]= {0};
497 int label[NUM_PILES]={0};// :|
498 int line_had_card; // :|
499 do {
500 line_had_card = 0;
501 for (int pile = 0; pile < NUM_PILES; pile++) {
502 card_t card = f.t[pile][row[pile]];
503 card_t next = f.t[pile][row[pile]+1];
504 int movable = is_movable(f.t[pile], row[pile]);
505
506 print_hi (highlight == pile && movable, movable, (
507 (card<0)?op.s->facedown
508 :op.s->card[card]
509 )[line[pile]]);
510
511 if (++line[pile] >= (next?op.s->overlap:op.s->height) //normal overlap
512 #if 0 //XXX
513 || (line[pile] >= 1 &&
514 f.t[pile][row[pile]] < 0 &&
515 f.t[pile][row[pile]+1] <0) //extreme overlap on closed
516 || (0) //extreme overlap on sequence TODO
517 #endif
518 ) {
519 line[pile]=0;
520 row[pile]++;
521 }
522 if(!card && !label[pile]) { /* tableu labels: */
523 label[pile] = 1;
524 printf ("\b\b%d ", (pile+1) % 10); //XXX: hack
525 }
526 line_had_card |= !!card;
527 }
528 printf ("\n");
529 } while (line_had_card);
530 }//}}}
531
532 void visbell (void) {
533 printf ("\033[?5h"); fflush (stdout);
534 usleep (100000);
535 printf ("\033[?5l"); fflush (stdout);
536 }
537
538 void append_undo (int n, int f, int t) {
539 (void)n;(void)f;(void)t;
540 //check if we have to free redo buffer (.next)
541 //malloc
542 //update pointers
543 //TODO: undo; needs operations to be written by x2y()
544 }
545
546 void screen_setup (int enable) {
547 if (enable) {
548 raw_mode(1);
549 printf ("\033[s\033[?47h"); /* save cursor, alternate screen */
550 printf ("\033[H\033[J"); /* reset cursor, clear screen */
551 //TODO//printf ("\033[?1000h\033[?25l"); /* enable mouse, hide cursor */
552 } else {
553 //TODO//printf ("\033[?9l\033[?25h"); /* disable mouse, show cursor */
554 printf ("\033[?47l\033[u"); /* primary screen, restore cursor */
555 raw_mode(0);
556 }
557 }
558
559 void raw_mode(int enable) { //{{{
560 static struct termios saved_term_mode;
561 struct termios raw_term_mode;
562
563 if (enable) {
564 tcgetattr(STDIN_FILENO, &saved_term_mode);
565 raw_term_mode = saved_term_mode;
566 raw_term_mode.c_lflag &= ~(ICANON | ECHO);
567 raw_term_mode.c_cc[VMIN] = 1 ;
568 raw_term_mode.c_cc[VTIME] = 0;
569 tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw_term_mode);
570 } else {
571 tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_term_mode);
572 }
573 } //}}}
574
575 //vim: foldmethod=marker
Imprint / Impressum