File: chesslib2.c

package info (click to toggle)
expect 5.45.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,016 kB
  • sloc: ansic: 17,965; sh: 7,445; tcl: 384; makefile: 191; exp: 10
file content (84 lines) | stat: -rw-r--r-- 1,343 bytes parent folder | download | duplicates (13)
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
/* testlib.c - test expectlib */

#include <stdio.h>
#include "expect.h"

timedout()
{
	fprintf(stderr,"timed out\n");
	exit(-1);
}

char move[100];

read_first_move(fp)
FILE *fp;
{
	if (EXP_TIMEOUT == exp_fexpectl(fp,
				exp_glob,"first\r\n1.*\r\n",0,
				exp_end)) {
		timedout();
	}
	sscanf(exp_match,"%*s 1. %s",move);
}

/* moves and counter-moves are printed out in different formats, sigh... */

read_counter_move(fp)
FILE *fp;
{
	switch (exp_fexpectl(fp,exp_glob,"*...*\r\n",0, exp_end)) {
	case EXP_TIMEOUT: timedout();
	case EXP_EOF: exit(-1);
	}

	sscanf(exp_match,"%*s %*s %*s %*s ... %s",move);
}

read_move(fp)
FILE *fp;
{
	switch (exp_fexpectl(fp,exp_glob,"*...*\r\n*.*\r\n",0,exp_end)) {
	case EXP_TIMEOUT: timedout();
	case EXP_EOF: exit(-1);
	}

	sscanf(exp_match,"%*s %*s ... %*s %*s %s",move);
}

send_move(fp)
FILE *fp;
{
	fprintf(fp,move);
}

main(){
	FILE *fp1, *fp2;
	int ec;

/*	exp_is_debugging = 1;*/
	exp_loguser = 1;
	exp_timeout = 3600;

	if (0 == (fp1 = exp_popen("chess"))) {
	  perror("chess");
	  exit(-1);
	}

	if (0 > exp_fexpectl(fp1,exp_glob,"Chess\r\n",0,exp_end)) exit(-1);
	fprintf(fp1,"first\r");

	read_first_move(fp1);

	fp2 = exp_popen("chess");

	exp_fexpectl(fp2,exp_glob,"Chess\r\n",0,exp_end);

	for (;;) {
		send_move(fp2);
		read_counter_move(fp2);

		send_move(fp1);
		read_move(fp1);
	}
}