| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
2
|
|
|
|
|
|
|
#include "perl.h" |
|
3
|
|
|
|
|
|
|
#include "XSUB.h" |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#include "ppport.h" |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#include |
|
8
|
|
|
|
|
|
|
#include |
|
9
|
|
|
|
|
|
|
#if defined(__DARWIN__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
|
10
|
|
|
|
|
|
|
#include |
|
11
|
|
|
|
|
|
|
#endif |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#include |
|
14
|
|
|
|
|
|
|
#include |
|
15
|
|
|
|
|
|
|
#include |
|
16
|
|
|
|
|
|
|
#include |
|
17
|
|
|
|
|
|
|
#include |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
typedef SV * Term_TtyWrite; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
MODULE = Term::TtyWrite PACKAGE = Term::TtyWrite |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
void |
|
24
|
|
|
|
|
|
|
DESTROY(obj) |
|
25
|
|
|
|
|
|
|
Term_TtyWrite obj |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
CODE: |
|
28
|
|
|
|
|
|
|
SV **svp; |
|
29
|
1
|
50
|
|
|
|
|
if ((svp = hv_fetchs((HV*)obj, "fd", FALSE))) { |
|
30
|
1
|
50
|
|
|
|
|
if (SvOK(*svp) && SvIOK(*svp)) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
|
close((int) SvIV(*svp)); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Term_TtyWrite |
|
35
|
|
|
|
|
|
|
new(...) |
|
36
|
|
|
|
|
|
|
INIT: |
|
37
|
|
|
|
|
|
|
char *classname, *devname; |
|
38
|
|
|
|
|
|
|
int fd, i; |
|
39
|
|
|
|
|
|
|
STRLEN len; |
|
40
|
|
|
|
|
|
|
|
|
41
|
3
|
50
|
|
|
|
|
if ( sv_isobject(ST(0)) ) { |
|
42
|
0
|
0
|
|
|
|
|
classname = HvNAME(SvSTASH(SvRV(ST(0)))); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
3
|
50
|
|
|
|
|
classname = (char *)SvPV_nolen(ST(0)); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
CODE: |
|
48
|
3
|
|
|
|
|
|
RETVAL = (Term_TtyWrite)newHV(); |
|
49
|
|
|
|
|
|
|
|
|
50
|
3
|
100
|
|
|
|
|
if (items != 2 || !SvPOK(ST(1))) |
|
|
|
50
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
|
Perl_croak(aTHX_ "Usage: Term::TtyWrite->new(\"/dev/sometty\")\n"); |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
50
|
|
|
|
|
devname = SvPV(ST(1),len); |
|
54
|
20
|
100
|
|
|
|
|
for (i = 0; i < len; i++) { |
|
55
|
19
|
100
|
|
|
|
|
if (devname[i] == '\0') |
|
56
|
1
|
|
|
|
|
|
Perl_croak(aTHX_ "invalid device name\n"); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
1
|
50
|
|
|
|
|
if ((fd = open(devname, O_WRONLY)) < 0) |
|
59
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "could not open '%s': %s", devname, strerror(errno)); |
|
60
|
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
|
hv_stores((HV *)RETVAL, "fd", newSViv(fd) ); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
OUTPUT: |
|
64
|
|
|
|
|
|
|
RETVAL |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
void |
|
67
|
|
|
|
|
|
|
write(obj, ...) |
|
68
|
|
|
|
|
|
|
Term_TtyWrite obj |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
INIT: |
|
71
|
1
|
50
|
|
|
|
|
if (items != 2 || !SvPOK(ST(1))) |
|
|
|
0
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
|
Perl_croak(aTHX_ "Usage: $obj->write(\"some data\")"); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
CODE: |
|
75
|
|
|
|
|
|
|
char *str; |
|
76
|
|
|
|
|
|
|
int fd; |
|
77
|
|
|
|
|
|
|
STRLEN len; |
|
78
|
|
|
|
|
|
|
SV **svp; |
|
79
|
0
|
0
|
|
|
|
|
if ((svp = hv_fetchs((HV*)obj, "fd", FALSE))) { |
|
80
|
0
|
0
|
|
|
|
|
if (SvOK(*svp) && SvIOK(*svp)) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
fd = (int) SvIV(*svp); |
|
82
|
0
|
0
|
|
|
|
|
str = SvPV(ST(1),len); |
|
83
|
0
|
0
|
|
|
|
|
while(len-- > 0) { |
|
84
|
0
|
|
|
|
|
|
ioctl(fd, TIOCSTI, str++); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
} else { |
|
87
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "fd unexpectedly is not set"); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
void |
|
92
|
|
|
|
|
|
|
write_delay(obj, ...) |
|
93
|
|
|
|
|
|
|
Term_TtyWrite obj |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
INIT: |
|
96
|
1
|
50
|
|
|
|
|
if (items != 3 || !SvPOK(ST(1)) || !SvNIOK(ST(2))) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
|
Perl_croak(aTHX_ "Usage: $obj->write_delay(\"some data\", 250)"); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
CODE: |
|
100
|
|
|
|
|
|
|
char *str; |
|
101
|
|
|
|
|
|
|
int fd; |
|
102
|
|
|
|
|
|
|
IV delayms; |
|
103
|
|
|
|
|
|
|
STRLEN len; |
|
104
|
|
|
|
|
|
|
SV **svp; |
|
105
|
|
|
|
|
|
|
useconds_t delay; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if ((svp = hv_fetchs((HV*)obj, "fd", FALSE))) { |
|
108
|
0
|
0
|
|
|
|
|
if (SvOK(*svp) && SvIOK(*svp)) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
fd = (int) SvIV(*svp); |
|
110
|
0
|
0
|
|
|
|
|
str = SvPV(ST(1),len); |
|
111
|
0
|
0
|
|
|
|
|
delayms = SvIV(ST(2)); |
|
112
|
0
|
0
|
|
|
|
|
if (delayms > UINT_MAX / 1000) delayms = UINT_MAX / 1000; |
|
113
|
0
|
|
|
|
|
|
delay = delayms * 1000; |
|
114
|
0
|
0
|
|
|
|
|
while(len-- > 0) { |
|
115
|
0
|
|
|
|
|
|
ioctl(fd, TIOCSTI, str++); |
|
116
|
0
|
|
|
|
|
|
usleep(delay); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} else { |
|
119
|
0
|
|
|
|
|
|
Perl_croak(aTHX_ "fd unexpectedly is not set"); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |