]>
git.gir.st - minesVIiper.git/blob - mines_2017.c
1 /*******************************************************************************
3 By Tobias Girstmair, 2015 - 2018
6 (see ./minesviiper -h for full list of options)
8 MOUSE MODE: - left click to open and choord
9 - right click to flag/unflag
10 VI MODE: - hjkl to move cursor left/down/up/right
11 - bduw to jump left/down/up/right by 5 cells
12 - o to open and choord
15 GNU GPL v3, see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt
16 *******************************************************************************/
19 #define _POSIX_C_SOURCE 2 /*for getopt, sigaction in c99*/
35 #define MIN(a,b) (a>b?b:a)
36 #define MAX(a,b) (a>b?a:b)
37 #define CLAMP(a,m,M) (a<m?m:(a>M?M:a))
38 #define printm(num, str) for (int i = 0; i < num; i++) fputs (str, stdout)
39 #define print(str) fputs (str, stdout)
42 unsigned m
:2; /* mine?1:killmine?2:0 */
43 unsigned o
:1; /* open?1:0 */
44 unsigned f
:2; /* flagged?1:questioned?2:0 */
45 unsigned n
:4; /* 0<= neighbours <=8 */
49 //TODO: rename w, h to L, C
52 int m
; /* number of mines */
54 int f
; /* flags counter */
55 int t
; /* time of game start */
56 int p
[2]; /* cursor position {line, col} */
57 int s
; /* space mode */
61 struct minescheme
* scheme
;
62 int mode
; /* allow flags? quesm? */
72 void fill_minefield (int, int);
74 void cursor_move (int, int);
75 void to_next_boundary (int l
, int c
, char direction
);
76 int getch (unsigned char*);
77 int getctrlseq (unsigned char*);
78 int everything_opened ();
79 int wait_mouse_up (int, int);
80 void partial_show_minefield (int, int, int);
81 void show_minefield (int);
82 int get_neighbours (int, int, int);
83 int uncover_square (int, int);
84 void flag_square (int, int);
85 void quesm_square (int, int);
86 int choord_square (int, int);
87 int do_uncover (int*);
88 struct minecell
** alloc_array (int, int);
90 int screen2field_l (int);
91 int screen2field_c (int);
92 int field2screen_l (int);
93 int field2screen_c (int);
95 void signal_handler (int signum
);
96 void timer_setup (int);
109 enum fieldopenstates
{
125 /* for getctrlseq() */
131 CTRSEQ_MOUSE_LEFT
= -4,
132 CTRSEQ_MOUSE_MIDDLE
= -5,
133 CTRSEQ_MOUSE_RIGHT
= -6,
141 void signal_handler (int signum
) {
144 move (1, f
.w
*op
.scheme
->cell_width
-(op
.scheme
->cell_width
%2)-3);
145 printf ("[%03d]", f
.t
?(int)difftime (time(NULL
), f
.t
):0);
152 /* http://users.csc.calpoly.edu/~phatalsk/357/lectures/code/sigalrm.c */
153 struct termios saved_term_mode
;
154 struct termios
set_raw_term_mode() {
155 struct termios cur_term_mode
, raw_term_mode
;
157 tcgetattr(STDIN_FILENO
, &cur_term_mode
);
158 raw_term_mode
= cur_term_mode
;
159 raw_term_mode
.c_lflag
&= ~(ICANON
| ECHO
);
160 raw_term_mode
.c_cc
[VMIN
] = 1 ;
161 raw_term_mode
.c_cc
[VTIME
] = 0;
162 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &raw_term_mode
);
164 return cur_term_mode
;
166 void restore_term_mode(struct termios saved_term_mode
) {
167 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &saved_term_mode
);
171 int main (int argc
, char** argv
) {
172 struct sigaction saction
;
173 saved_term_mode
= set_raw_term_mode();
177 saction
.sa_handler
= signal_handler
;
178 sigemptyset(&saction
.sa_mask
);
179 saction
.sa_flags
= 0;
180 if (sigaction(SIGALRM
, &saction
, NULL
) < 0 ) {
185 if (sigaction(SIGINT
, &saction
, NULL
) < 0 ) {
189 /* end screen setup */
195 f
.c
= NULL
; /*to not free() array before it is allocated*/
197 op
.scheme
= &symbols_mono
;
202 opterr
= 0; /* don't print message on unrecognized option */
203 while ((optget
= getopt (argc
, argv
, "+hnfqcdx")) != -1) {
205 case 'n': op
.mode
= NOFLAG
; break;
206 case 'f': op
.mode
= FLAG
; break; /*default*/
207 case 'q': op
.mode
= QUESM
; break;
208 case 'c': op
.scheme
= &symbols_col1
; break;
209 case 'd': op
.scheme
= &symbols_doublewidth
; break;
212 fprintf (stderr
, "%s [OPTIONS] [FIELDSPEC]\n"
216 " -q(uestion marks)\n"
217 " -c(olored symbols)\n"
218 " -d(ec charset symbols)\n"
220 " WxHxM (width 'x' height 'x' mines)\n"
221 " defaults to 30x16x99\n"
223 "hjkl: move 1 left/down/up/right\n"
224 "bduw: move 5 left/down/up/right\n"
225 "^Gg$: move to the left/bottom/top/right\n"
226 "left mouse/o: open/choord\n"
227 "right mouse/i: flag/unflag\n"
228 "space: modeful cursor (either open or flag)\n"
229 "a: toggle mode for space (open/flag)\n"
230 ":D / r: start a new game\n"
231 "q: quit\n", argv
[0]);
235 /* end parse options*/
237 sscanf (argv
[optind
], "%dx%dx%d", &(f
.w
), &(f
.h
), &(f
.m
));
239 /* check boundaries */
240 if (f
.m
> (f
.w
-1) * (f
.h
-1)) {
241 f
.m
= (f
.w
-1) * (f
.h
-1);
242 fprintf (stderr
, "too many mines. reduced to %d.\r\n", f
.m
);
247 f
.c
= alloc_array (f
.h
, f
.w
);
257 struct line_col markers
[26];
258 for (int i
=26; i
; markers
[--i
].l
= -1);
260 /* switch to alternate screen */
261 printf ("\033[?47h");
263 /* reset cursor, clear screen */
264 printf ("\033[H\033[J");
266 /* swich charset, if necessary */
267 if (op
.scheme
->init_seq
!= NULL
) print (op
.scheme
->init_seq
);
269 show_minefield (NORMAL
);
271 /* enable mouse, hide cursor */
272 printf ("\033[?1000h\033[?25l");
277 unsigned char mouse
[3];
279 action
= getch(mouse
);
282 if (f
.s
== MODE_OPEN
||
283 f
.c
[f
.p
[0]][f
.p
[1]].o
== OPENED
) {
284 switch (do_uncover(&is_newgame
)) {
285 case GAME_LOST
: goto lose
;
286 case GAME_WON
: goto win
;
288 } else if (f
.s
== MODE_FLAG
) {
289 flag_square (f
.p
[0], f
.p
[1]);
290 } else if (f
.s
== MODE_QUESM
) {
291 quesm_square (f
.p
[0], f
.p
[1]);
295 f
.s
= (f
.s
+1)%(op
.mode
+1);
296 show_minefield (cheatmode
?SHOWMINES
:NORMAL
);
298 case CTRSEQ_MOUSE_LEFT
:
299 f
.p
[0] = screen2field_l (mouse
[2]);
300 f
.p
[1] = screen2field_c (mouse
[1]);
301 /* :D clicked: TODO: won't work in single-width mode! */
302 if (mouse
[2] == LINE_OFFSET
-1 &&
303 (mouse
[1] == f
.w
+COL_OFFSET
||
304 mouse
[1] == f
.w
+COL_OFFSET
+1)) {
308 if (f
.p
[1] < 0 || f
.p
[1] >= f
.w
||
309 f
.p
[0] < 0 || f
.p
[0] >= f
.h
) break; /*out of bound*/
312 switch (do_uncover(&is_newgame
)) {
313 case GAME_LOST
: goto lose
;
314 case GAME_WON
: goto win
;
317 case CTRSEQ_MOUSE_RIGHT
:
318 f
.p
[0] = screen2field_l (mouse
[2]);
319 f
.p
[1] = screen2field_c (mouse
[1]);
320 if (f
.p
[1] < 0 || f
.p
[1] >= f
.w
||
321 f
.p
[0] < 0 || f
.p
[0] >= f
.h
) break; /*out of bound*/
323 case 'i': flag_square (f
.p
[0], f
.p
[1]); break;
324 case '?':quesm_square (f
.p
[0], f
.p
[1]); break;
325 case 'h': cursor_move (f
.p
[0], f
.p
[1]-1 ); break;
326 case 'j': cursor_move (f
.p
[0]+1, f
.p
[1] ); break;
327 case 'k': cursor_move (f
.p
[0]-1, f
.p
[1] ); break;
328 case 'l': cursor_move (f
.p
[0], f
.p
[1]+1 ); break;
329 case 'w': to_next_boundary (f
.p
[0], f
.p
[1], '>'); break;
330 case 'b': to_next_boundary (f
.p
[0], f
.p
[1], '<'); break;
331 case 'u': to_next_boundary (f
.p
[0], f
.p
[1], '^'); break;
332 case 'd': to_next_boundary (f
.p
[0], f
.p
[1], 'v'); break;
333 case '0': /* fallthrough */
334 case '^': cursor_move (f
.p
[0], 0 ); break;
335 case '$': cursor_move (f
.p
[0], f
.w
-1 ); break;
336 case 'g': cursor_move (0, f
.p
[1] ); break;
337 case 'G': cursor_move (f
.h
-1, f
.p
[1] ); break;
339 action
= tolower(getch(mouse
));
340 if (action
< 'a' || action
> 'z') break;/*out of bound*/
341 markers
[action
-'a'].l
= f
.p
[0];
342 markers
[action
-'a'].c
= f
.p
[1];
344 case'\'': /* fallthrough */
346 action
= tolower(getch(mouse
));
347 if (action
< 'a' || action
> 'z' /* out of bound or */
348 || markers
[action
-'a'].l
== -1) break; /* unset */
349 cursor_move (markers
[action
-'a'].l
, markers
[action
-'a'].c
);
351 case 'r': /* start a new game */
356 case '\014': /* Ctrl-L -- redraw */
357 show_minefield (NORMAL
);
362 fill_minefield (-1, -1);
365 show_minefield (cheatmode
?NORMAL
:SHOWMINES
);
366 cheatmode
= !cheatmode
;
373 timer_setup(0); /* stop timer */
374 show_minefield (SHOWMINES
);
377 unsigned char mouse
[3];
378 gotaction
= getch(mouse
);
379 /* :D clicked: TODO: won't work in single-width mode! */
380 if (gotaction
==CTRSEQ_MOUSE_LEFT
&& mouse
[2]==LINE_OFFSET
-1 &&
381 (mouse
[1]==f
.w
+COL_OFFSET
|| mouse
[1]==f
.w
+COL_OFFSET
+1)) {
384 } else if (gotaction
== 'r') {
387 } else if (gotaction
== 'q') {
397 move(0,0); //move(f.h+LINE_OFFSET+2, 0);
398 /* disable mouse, show cursor */
399 printf ("\033[?9l\033[?25h");
400 /* reset charset, if necessary */
401 if (op
.scheme
&& op
.scheme
->reset_seq
) print (op
.scheme
->reset_seq
);
402 /* revert to primary screen */
403 if (alt_screen
) printf ("\033[?47l");
405 restore_term_mode(saved_term_mode
);
408 /* I haven't won as long as a cell exists, that
409 - I haven't opened, and
411 int everything_opened () {
412 for (int row
= 0; row
< f
.h
; row
++)
413 for (int col
= 0; col
< f
.w
; col
++)
414 if (f
.c
[row
][col
].o
== CLOSED
&&
415 f
.c
[row
][col
].m
== NO_MINE
) return 0;
419 int wait_mouse_up (int l
, int c
) {
420 unsigned char mouse2
[3];
425 move (1, field2screen_c (f
.w
/2)-1); print (":o");
427 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
428 /* show a pushed-in button if cursor is on minefield */
429 move (l
+LINE_OFFSET
, field2screen_c(c
));
430 fputs (op
.scheme
->mouse_highlight
, stdout
);
434 if (getctrlseq (mouse2
) == CTRSEQ_MOUSE
) {
435 /* ignore mouse wheel events: */
436 if (mouse2
[0] & 0x40) continue;
438 else if (mouse2
[0]&3 == 3) level
--; /* release event */
439 else level
++; /* another button pressed */
443 move (1, field2screen_c (f
.w
/2)-1); print (":D");
444 if (!(l
< 0 || l
>= f
.h
|| c
< 0 || c
>= f
.w
)) {
445 partial_show_minefield (l
, c
, NORMAL
);
447 c2
= screen2field_c(mouse2
[1]);
448 l2
= screen2field_l(mouse2
[2]);
449 return ((l2
== l
) && (c2
== c
));
452 int choord_square (int line
, int col
) {
453 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
454 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
455 if (f
.c
[l
][c
].f
!= FLAG
) {
456 if (uncover_square (l
, c
))
465 int uncover_square (int l
, int c
) {
466 f
.c
[l
][c
].o
= OPENED
;
467 f
.c
[l
][c
].f
= NOFLAG
; /*must not be QUESM, otherwise rendering issues*/
468 partial_show_minefield (l
, c
, NORMAL
);
471 f
.c
[l
][c
].m
= DEATH_MINE
;
475 /* check for chording */
476 if (f
.c
[l
][c
].n
== 0) {
477 for (int choord_l
= -1; choord_l
<= 1; choord_l
++) {
478 for (int choord_c
= -1; choord_c
<= 1; choord_c
++) {
479 int newl
= l
+ choord_l
;
480 int newc
= c
+ choord_c
;
481 if (newl
>= 0 && newl
< f
.h
&&
482 newc
>= 0 && newc
< f
.w
&&
483 f
.c
[newl
][newc
].o
== CLOSED
&&
484 uncover_square (newl
, newc
)) {
494 void flag_square (int l
, int c
) {
495 if (f
.c
[l
][c
].o
!= CLOSED
) return;
496 /* cycles through flag/quesm/noflag (uses op.mode to detect which ones
498 f
.c
[l
][c
].f
= (f
.c
[l
][c
].f
+ 1) % (op
.mode
+ 1);
499 if (f
.c
[l
][c
].f
==FLAG
) f
.f
++;
500 else f
.f
--; //WARN: breaks on `-q'!
501 partial_show_minefield (l
, c
, NORMAL
);
502 move (1, op
.scheme
->cell_width
);
503 printf ("[%03d]", f
.f
);
506 void quesm_square (int l
, int c
) {
507 /* toggle question mark / none. won't turn flags into question marks.
508 unlike flag_square, this function doesn't respect `-q'. */
509 if (f
.c
[l
][c
].o
!= CLOSED
) return;
510 else if (f
.c
[l
][c
].f
== NOFLAG
) f
.c
[l
][c
].f
= QUESM
;
511 else if (f
.c
[l
][c
].f
== QUESM
) f
.c
[l
][c
].f
= NOFLAG
;
512 partial_show_minefield (l
, c
, NORMAL
);
515 int do_uncover (int* is_newgame
) {
518 fill_minefield (f
.p
[0], f
.p
[1]);
522 if (f
.c
[f
.p
[0]][f
.p
[1]].f
== FLAG
) return GAME_INPROGRESS
;
523 if (f
.c
[f
.p
[0]][f
.p
[1]].o
== CLOSED
) {
524 if (uncover_square (f
.p
[0], f
.p
[1])) return GAME_LOST
;
525 } else if (get_neighbours (f
.p
[0], f
.p
[1], 1) == 0) {
526 if (choord_square (f
.p
[0], f
.p
[1])) return GAME_LOST
;
528 if (everything_opened()) return GAME_WON
;
530 return GAME_INPROGRESS
;
533 void fill_minefield (int l
, int c
) {
537 int line
= rand() % f
.h
;
538 int col
= rand() % f
.w
;
540 if (f
.c
[line
][col
].m
) {
541 /* skip if field already has a mine */
543 } else if ((line
== l
) && (col
== c
)) {
544 /* don't put a mine on the already opened (first click) field */
548 f
.c
[line
][col
].m
= STD_MINE
;
552 /* precalculate neighbours */
553 for (int l
=0; l
< f
.h
; l
++)
554 for (int c
=0; c
< f
.w
; c
++)
555 f
.c
[l
][c
].n
= get_neighbours (l
, c
, NORMAL
);
558 void move (int line
, int col
) {
559 printf ("\033[%d;%dH", line
+1, col
+1);
562 /* absolute coordinates! */
563 void cursor_move (int l
, int c
) {
564 partial_show_minefield (f
.p
[0], f
.p
[1], NORMAL
);
566 f
.p
[0] = CLAMP(l
, 0, f
.h
-1);
567 f
.p
[1] = CLAMP(c
, 0, f
.w
-1);
568 move (f
.p
[0]+LINE_OFFSET
, field2screen_c(f
.p
[1]));
569 //fputs (op.scheme->mouse_highlight, stdout);
571 if (!f
.c
[f
.p
[0]][f
.p
[1]].f
) print("\033[7m");//invert unless ! or ?
572 partial_show_minefield (f
.p
[0], f
.p
[1], HIGHLIGHT
);
573 print("\033[0m");//un-invert
576 /* to_next_boundary(): move into the supplied direction until a change in open-
577 state or flag-state is found and move there. falls back to BIG_MOVE. */
578 #define FIND_NEXT(X, L, C, L1, C1, MAX, OP) do {\
579 new_ ## X OP ## = BIG_MOVE;\
580 for (int i = X OP 1; i > 0 && i < f.MAX-1; i OP ## OP)\
581 if ((f.c[L ][C ].o<<2 + f.c[L ][C ].f) \
582 != (f.c[L1][C1].o<<2 + f.c[L1][C1].f)) {\
587 void to_next_boundary (int l
, int c
, char direction
) {
591 case '>': FIND_NEXT(c
, l
, i
, l
, i
+1, w
, +); break;
592 case '<': FIND_NEXT(c
, l
, i
, l
, i
-1, w
, -); break;
593 case '^': FIND_NEXT(l
, i
, c
, i
-1, c
, h
, -); break;
594 case 'v': FIND_NEXT(l
, i
, c
, i
+1, c
, h
, +); break;
597 cursor_move (new_l
, new_c
);
601 char* cell2schema (int l
, int c
, int mode
) {
602 struct minecell cell
= f
.c
[l
][c
];
603 /* move past invert-ctrlsequence when highlighting the cursor: */
604 int offset
= ((mode
==HIGHLIGHT
)*op
.scheme
->flag_offset
);
606 if (mode
== SHOWMINES
) return (
607 cell
.f
== FLAG
&& cell
.m
? op
.scheme
->field_flagged
+offset
:
608 cell
.f
== FLAG
&& !cell
.m
? op
.scheme
->mine_wrongf
+offset
:
609 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
610 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
611 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
612 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
614 cell
.f
== FLAG
? op
.scheme
->field_flagged
+offset
:
615 cell
.f
== QUESM
? op
.scheme
->field_question
+offset
:
616 cell
.o
== CLOSED
? op
.scheme
->field_closed
:
617 cell
.m
== STD_MINE
? op
.scheme
->mine_normal
:
618 cell
.m
== DEATH_MINE
? op
.scheme
->mine_death
:
619 /*.......................*/ op
.scheme
->number
[f
.c
[l
][c
].n
]);
622 void partial_show_minefield (int l
, int c
, int mode
) {
623 move (l
+LINE_OFFSET
, field2screen_c(c
));
625 print (cell2schema(l
, c
, mode
));
628 void show_minefield (int mode
) {
630 static char modechar
[] = {'*', '!', '?'};
637 dtime
= difftime (time(NULL
), f
.t
);
641 print (op
.scheme
->border_top_l
);
642 printm (f
.w
*op
.scheme
->cell_width
,op
.scheme
->border_top_m
);
643 printf ("%s\r\n", op
.scheme
->border_top_r
);
645 print (op
.scheme
->border_status_l
);
646 printf("[%03d]", f
.f
);
647 printm (f
.w
*op
.scheme
->cell_width
/2-6, " ");
648 printf ("%s", mode
==SHOWMINES
?":C":":D");
649 printm (f
.w
*op
.scheme
->cell_width
/2-6-4, " ");
650 printf ("[%c] [%03d]", modechar
[f
.s
], dtime
);
651 print (op
.scheme
->border_status_r
);
654 print (op
.scheme
->border_spacer_l
);
655 printm (f
.w
*op
.scheme
->cell_width
,op
.scheme
->border_spacer_m
);
656 print (op
.scheme
->border_spacer_r
);
659 for (int l
= 0; l
< f
.h
; l
++) {
660 print (op
.scheme
->border_field_l
);
661 for (int c
= 0; c
< f
.w
; c
++) {
662 print (cell2schema(l
, c
, mode
));
664 print (op
.scheme
->border_field_r
); print ("\r\n");
667 print (op
.scheme
->border_bottom_l
);
668 printm (f
.w
*op
.scheme
->cell_width
,op
.scheme
->border_bottom_m
);
669 print (op
.scheme
->border_bottom_r
);
673 int get_neighbours (int line
, int col
, int reduced_mode
) {
674 /* counts mines surrounding a square
675 modes: 0=normal; 1=reduced */
679 for (int l
= MAX(line
-1, 0); l
<= MIN(line
+1, f
.h
-1); l
++) {
680 for (int c
= MAX(col
-1, 0); c
<= MIN(col
+1, f
.w
-1); c
++) {
681 if (!l
&& !c
) continue;
683 count
+= !!f
.c
[l
][c
].m
;
684 count
-= reduced_mode
* f
.c
[l
][c
].f
==FLAG
;
690 struct minecell
** alloc_array (int lines
, int cols
) {
691 struct minecell
** a
= malloc (lines
* sizeof(struct minecell
*));
692 if (a
== NULL
) return NULL
;
693 for (int l
= 0; l
< lines
; l
++) {
694 a
[l
] = calloc (cols
, sizeof(struct minecell
));
695 if (a
[l
] == NULL
) goto unalloc
;
700 for (int l
= 0; l
< lines
; l
++)
706 if (f
.c
== NULL
) return;
707 for (int l
= 0; l
< f
.h
; l
++) {
713 int screen2field_l (int l
) {
714 return (l
-LINE_OFFSET
) - 1;
716 /* some trickery is required to extract the mouse position from the cell width,
717 depending on wheather we are using full width characters or double line width.
718 WARN: tested only with scheme.cell_width = 1 and scheme.cell_width = 2. */
719 int screen2field_c (int c
) {
720 return (c
-COL_OFFSET
+1 - 2*(op
.scheme
->cell_width
%2))/2 - op
.scheme
->cell_width
/2;
722 int field2screen_l (int l
) {
723 return 0; //TODO: is never used, therefore not implemented
725 int field2screen_c (int c
) {
726 return (op
.scheme
->cell_width
*c
+COL_OFFSET
- (op
.scheme
->cell_width
%2));
735 int getctrlseq (unsigned char* buf
) {
738 int offset
= 0x20; /* never sends control chars as data */
739 while ((c
= getchar()) != EOF
) {
743 case '\033': state
=ESC_SENT
; break;
749 case '[': state
=CSI_SENT
; break;
750 default: return CTRSEQ_INVALID
;
755 case 'M': state
=MOUSE_EVENT
; break;
756 default: return CTRSEQ_INVALID
;
761 buf
[1] = getchar() - offset
;
762 buf
[2] = getchar() - offset
;
765 return CTRSEQ_INVALID
;
771 int getch(unsigned char* buf
) {
772 /* returns a character, EOF, or constant for an escape/control sequence - NOT
773 compatible with the ncurses implementation of same name */
774 int action
= getctrlseq(buf
);
778 l
= screen2field_l (buf
[2]);
779 c
= screen2field_c (buf
[1]);
781 if (buf
[0] > 3) break; /* ignore all but left/middle/right/up */
782 int success
= wait_mouse_up(l
, c
);
784 /* mouse moved while pressed: */
785 if (!success
) return CTRSEQ_INVALID
;
788 case 0: return CTRSEQ_MOUSE_LEFT
;
789 case 1: return CTRSEQ_MOUSE_MIDDLE
;
790 case 2: return CTRSEQ_MOUSE_RIGHT
;
797 void timer_setup (int enable
) {
798 static struct itimerval tbuf
;
799 tbuf
.it_interval
.tv_sec
= 1;
800 tbuf
.it_interval
.tv_usec
= 0;
804 tbuf
.it_value
.tv_sec
= 1;
805 tbuf
.it_value
.tv_usec
= 0;
806 if (setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1) {
811 tbuf
.it_value
.tv_sec
= 0;
812 tbuf
.it_value
.tv_usec
= 0;
813 if ( setitimer(ITIMER_REAL
, &tbuf
, NULL
) == -1 ) {