-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathWGET.rexx
80 lines (80 loc) · 5.63 KB
/
WGET.rexx
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
Call TCPInit()
/* -------------------------------------------------------------------
* Display primary "ISPF" like Menu
* -------------------------------------------------------------------
*/
call display_HTML('35.192.97.153')
return 0
/* -------------------------------------------------------------------
* Render fetched HTML struing
* -------------------------------------------------------------------
*/
Select_primary:
parse arg select
if select=2 then return display_HTML('35.192.97.153','info')
if select=3 then return display_HTML('35.192.97.153','moon')
if select=10 then return display_HTML('35.192.97.153','news')
else return 8
return 0
/* -------------------------------------------------------------------
* Display ISPF like Web site
* -------------------------------------------------------------------
*/
Display_HTML:
if wgetx(arg(1),arg(2),80)=0 then do /* result is in _html */
call render_html
call fmtlist 0,'.','','','SELECT'
return 0
end
return 8
/* -------------------------------------------------------------------
* Render fetched HTML struing
* -------------------------------------------------------------------
*/
Render_html:
parse value _html with '<body'_html'</body>'
keep=''
pp1=pos('<',_html)
pp2=pos('>',_html)
if pp2<pp1 then _html=substr(_html,pp2+1)
_html=changestr('─',_html,'_')
_html=changestr('25'x,_html,'15'x)
_html=changestr('<pre',_html,'15'x'<pre')
do until tag=''
parse value _html with prefix'<'tag'>'_html
keep=keep''prefix
end
keep=keep''_html
i=0
do until keep=''
parse value keep with line '15'x keep
if strip(line)='' then iterate
i=i+1
buffer.i=line
end
buffer.0=i
return 0
/* --------------------------------------------------------------------
* WGET Call Web site and fetch data
* --------------------------------------------------------------------
*/
WGETx: Procedure expose _html
parse arg tcp,page,port
if port='' then port=80
/* Call TCPInit() */
rc=TCPOpen(tcp,port)
if rc<>0 then return 8
call TCPSend(_fd, e2a("GET /"page "HTTP/1.1"
call TCPSend(_fd, e2a("Host: "tcp
call TCPSend(_fd, e2a("User-Agent: " || V
call TCPSend(_fd, e2a("Accept: */*"
call TCPSend(_fd, e2a(""
len = 0
_html=''
len = TCPReceive(_fd,5) /* Use longer time out wait for first call
Do until len <= 0
_html=_html||a2e(_data)
len = TCPReceive(_fd,1) /* Use short time out wait for next calls *
End
Call TCPClose(_fd)
return 0