-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckin.c
More file actions
99 lines (78 loc) · 2.3 KB
/
Copy pathcheckin.c
File metadata and controls
99 lines (78 loc) · 2.3 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "zeus2d.def"
#ifdef UNICOS
/***********************************************************************
Check if input is pending on stdin. If so, read it and return
it to the caller.
Unicos version.
On a Cray-2, compile with
% cc -Dcray2 checkin.c
Input:
wait Flag to indicate whether to wait for input.
Output:
string Buffer containing the text read from stdin.
*/
#include <sys/time.h>
/* Define some macros which convert FORTRAN strings into something
usable in C. */
typedef int STRING;
#ifdef cray2
#define len(string) ((string & 0x1FFFFFF800000000) >> 35 )
#define addr(string) ((char *)(string & 0xE0000007FFFFFFFF))
#else
#define len(string) ((string & 0x1FFFFFFF00000000) >> 32 )
#define addr(string) ((char *)(string & 0xE0000000FFFFFFFF))
#endif
/**********************************************************************/
int CHECKIN(string,wait)
STRING string;
int *wait;
{
int mask,nfound,i,length;
char *q,*msg;
struct timeval timeout;
/* Check in the standard input is a terminal. */
if(! isatty(0)) return(0);
/* Convert the FORTRAN Unicos calling sequence to something more
usable. */
msg = addr(string);
length = len(string);
/* Something to read? */
mask = 1;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if(*wait)nfound = select(1,&mask,0,0,&timeout);
else nfound = 1;
if(!nfound)return(0);
/* Do a read of the input, and pack it into an integer array. */
nfound = read(0,msg,length) - 1;
q = (char *)msg + nfound;
for(i=nfound; i < length; i++) *q++ = ' ';
return(nfound);
}
#else
/***********************************************************************
Check if input is pending on stdin. If so, read it and return
it to the caller.
Output:
msg Buffer containing the text read from stdin. */
#include <sys/time.h>
int checkin_(msg,wait,length)
int *msg,*wait,length;
{
int mask,nfound,i;
char *q;
struct timeval timeout;
/* Something to read? */
mask = 1;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if(*wait)nfound = select(1,&mask,0,0,&timeout);
else nfound = 1;
if(!nfound)return(0);
/* Do a read of the input, and pack it into an integer array. */
nfound = read(0,msg,length) - 1;
q = (char *)msg + nfound;
for(i=nfound; i < length; i++) *q++ = ' ';
return(nfound);
}
#endif