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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [expect/] [exp_noevent.c] - Blame information for rev 1767

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

Line No. Rev Author Line
1 578 markom
/* interact (with only one process) - give user keyboard control
2
 
3
Written by: Don Libes, NIST, 2/6/90
4
 
5
Design and implementation of this program was paid for by U.S. tax
6
dollars.  Therefore it is public domain.  However, the author and NIST
7
would appreciate credit if this program or parts of it are used.
8
*/
9
 
10
/* This file exists for deficient versions of UNIX that lack select,
11
poll, or some other multiplexing hook.  Instead, this code uses two
12
processes per spawned process.  One sends characters from the spawnee
13
to the spawner; a second send chars the other way.
14
 
15
This will work on any UNIX system.  The only sacrifice is that it
16
doesn't support multiple processes.  Eventually, it should catch
17
SIGCHLD on dead processes and do the right thing.  But it is pretty
18
gruesome to imagine so many processes to do all this.  If you change
19
it successfully, please mail back the changes to me.  - Don
20
*/
21
 
22
#include "expect_cf.h"
23
#include <stdio.h>
24
#include <sys/types.h>
25
#include <sys/time.h>
26
 
27
#ifdef HAVE_SYS_WAIT_H
28
#include <sys/wait.h>
29
#endif
30
 
31
#include "tcl.h"
32
#include "exp_prog.h"
33
#include "exp_command.h"        /* for struct exp_f defs */
34
#include "exp_event.h"
35
 
36
/*ARGSUSED*/
37
void
38
exp_arm_background_filehandler(m)
39
int m;
40
{
41
}
42
 
43
/*ARGSUSED*/
44
void
45
exp_disarm_background_filehandler(m)
46
int m;
47
{
48
}
49
 
50
/*ARGSUSED*/
51
void
52
exp_disarm_background_filehandler_force(m)
53
int m;
54
{
55
}
56
 
57
/*ARGSUSED*/
58
void
59
exp_unblock_background_filehandler(m)
60
int m;
61
{
62
}
63
 
64
/*ARGSUSED*/
65
void
66
exp_block_background_filehandler(m)
67
int m;
68
{
69
}
70
 
71
/*ARGSUSED*/
72
void
73
exp_event_disarm(fd)
74
int fd;
75
{
76
}
77
 
78
/* returns status, one of EOF, TIMEOUT, ERROR or DATA */
79
/*ARGSUSED*/
80
int
81
exp_get_next_event(interp,masters, n,master_out,timeout,key)
82
Tcl_Interp *interp;
83
int *masters;
84
int n;                  /* # of masters */
85
int *master_out;        /* 1st event master, not set if none */
86
int timeout;            /* seconds */
87
int key;
88
{
89
        int m;
90
        struct exp_f *f;
91
 
92
        if (n > 1) {
93
                exp_error(interp,"expect not compiled with multiprocess support");
94
                /* select a different INTERACT_TYPE in Makefile */
95
                return(TCL_ERROR);
96
        }
97
 
98
        m = *master_out = masters[0];
99
        f = exp_fs + m;
100
 
101
        if (f->key != key) {
102
                f->key = key;
103
                f->force_read = FALSE;
104
                return(EXP_DATA_OLD);
105
        } else if ((!f->force_read) && (f->size != 0)) {
106
                return(EXP_DATA_OLD);
107
        }
108
 
109
        return(EXP_DATA_NEW);
110
}
111
 
112
/*ARGSUSED*/
113
int
114
exp_get_next_event_info(interp,fd,ready_mask)
115
Tcl_Interp *interp;
116
int fd;
117
int ready_mask;
118
{
119
}
120
 
121
/* There is no portable way to do sub-second sleeps on such a system, so */
122
/* do the next best thing (without a busy loop) and fake it: sleep the right */
123
/* amount of time over the long run.  Note that while "subtotal" isn't */
124
/* reinitialized, it really doesn't matter for such a gross hack as random */
125
/* scheduling pauses will easily introduce occasional one second delays. */
126
int     /* returns TCL_XXX */
127
exp_dsleep(interp,sec)
128
Tcl_Interp *interp;
129
double sec;
130
{
131
        static double subtotal = 0;
132
        int seconds;
133
 
134
        subtotal += sec;
135
        if (subtotal < 1) return TCL_OK;
136
        seconds = subtotal;
137
        subtotal -= seconds;
138
 restart:
139
        if (Tcl_AsyncReady()) {
140
                int rc = Tcl_AsyncInvoke(interp,TCL_OK);
141
                if (rc != TCL_OK) return(rc);
142
        }
143
        sleep(seconds);
144
        return TCL_OK;
145
}
146
 
147
#if 0
148
/* There is no portable way to do sub-second sleeps on such a system, so */
149
/* do the next best thing (without a busy loop) and fake it: sleep the right */
150
/* amount of time over the long run.  Note that while "subtotal" isn't */
151
/* reinitialized, it really doesn't matter for such a gross hack as random */
152
/* scheduling pauses will easily introduce occasional one second delays. */
153
int     /* returns TCL_XXX */
154
exp_usleep(interp,usec)
155
Tcl_Interp *interp;
156
long usec;              /* microseconds */
157
{
158
        static subtotal = 0;
159
        int seconds;
160
 
161
        subtotal += usec;
162
        if (subtotal < 1000000) return TCL_OK;
163
        seconds = subtotal/1000000;
164
        subtotal = subtotal%1000000;
165
 restart:
166
        if (Tcl_AsyncReady()) {
167
                int rc = Tcl_AsyncInvoke(interp,TCL_OK);
168
                if (rc != TCL_OK) return(exp_tcl2_returnvalue(rc));
169
        }
170
        sleep(seconds);
171
        return TCL_OK;
172
}
173
#endif /*0*/
174
 
175
/* set things up for later calls to event handler */
176
void
177
exp_init_event()
178
{
179
        exp_event_exit = 0;
180
}

powered by: WebSVN 2.1.0

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