OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [expect/] [example/] [chesslib.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* chesslib.c - test expectlib */
2
 
3
#include <stdio.h>
4
#include "expect.h"
5
 
6
timedout()
7
{
8
        fprintf(stderr,"timed out\n");
9
        exit(-1);
10
}
11
 
12
char move[100];
13
 
14
read_first_move(fd)
15
int fd;
16
{
17
        if (EXP_TIMEOUT == exp_expectl(fd,
18
                        exp_glob,"first\r\n1.*\r\n",0,
19
                        exp_end)) {
20
                timedout();
21
        }
22
        sscanf(exp_match,"%*s 1. %s",move);
23
}
24
 
25
/* moves and counter-moves are printed out in different formats, sigh... */
26
 
27
read_counter_move(fd)
28
int fd;
29
{
30
        switch (exp_expectl(fd,exp_glob,"*...*\r\n",0,exp_end)) {
31
        case EXP_TIMEOUT: timedout();
32
        case EXP_EOF: exit(-1);
33
        }
34
 
35
        sscanf(exp_match,"%*s %*s %*s %*s ... %s",move);
36
}
37
 
38
read_move(fd)
39
int fd;
40
{
41
        switch (exp_expectl(fd,exp_glob,"*...*\r\n*.*\r\n",0,exp_end)) {
42
        case EXP_TIMEOUT: timedout();
43
        case EXP_EOF: exit(-1);
44
        }
45
 
46
        sscanf(exp_match,"%*s %*s ... %*s %*s %s",move);
47
}
48
 
49
send_move(fd)
50
int fd;
51
{
52
        write(fd,move,strlen(move));
53
}
54
 
55
main(){
56
        int fd1, fd2;
57
 
58
        exp_loguser = 1;
59
        exp_timeout = 3600;
60
 
61
        fd1 = exp_spawnl("chess","chess",(char *)0);
62
 
63
        if (-1 == exp_expectl(fd1,exp_glob,"Chess\r\n",0,exp_end)) exit;
64
 
65
        if (-1 == write(fd1,"first\r",6)) exit;
66
 
67
        read_first_move(fd1);
68
 
69
        fd2 = exp_spawnl("chess","chess",(char *)0);
70
 
71
        if (-1 == exp_expectl(fd2,exp_glob,"Chess\r\n",0,exp_end)) exit;
72
 
73
        for (;;) {
74
                send_move(fd2);
75
                read_counter_move(fd2);
76
 
77
                send_move(fd1);
78
                read_move(fd1);
79
        }
80
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.