home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 4
/
AACD04.ISO
/
AACD
/
Online
/
Upd8
/
Upd8
next >
Wrap
Text File
|
1999-11-17
|
53KB
|
1,666 lines
/*******************************************
$VER: Upd8 1.2 by Carl Licke / Turbid design
http://home.swipnet.se/turbid/
*******************************************/
/*** scheme ***/
SIGNAL ON halt
SIGNAL ON break_c
SIGNAL ON failure
SIGNAL ON ioerr
SIGNAL ON syntax
CALL init
CALL readprefsfile
CALL readlistfile
CALL main
CALL writelistfile
CALL TR_DELETEAPP(app)
EXIT 0
/*** various ***/
init:
version ='1.2'
lf =X2C('0A')
cr =X2C('0D')
crlf =X2C('0D0A')
tab =X2C('09')
asterisk =X2C('2A')
null =X2C('00000000')
oldlist.0=0
newlist.0=0
modified =0
failsopen=0
PARSE SOURCE . . . src .
progdir=LEFT(src,MAX(LASTPOS(':',src),LASTPOS('/',src)))
IF ~SHOW('L','tritonrexx.library') THEN IF ~ADDLIB('tritonrexx.library',10,-30,0) THEN DO
SAY 'tritonrexx.library required.'
CALL errorexit
END
taglist='TRCA_Name "Upd8"',
'TRCA_LongName "Upd8"',
'TRCA_Info "Detects updated webpages."',
'TRCA_Version "'version'"',
'TRCA_Date "18.12.1998"',
'TAG_END'
app=TR_CREATEAPP(taglist)
IF app=null THEN CALL report(1,'Could not create application.')
IF ~SHOW('L','rexxsupport.library') THEN IF ~ADDLIB('rexxsupport.library',0,-30,0) THEN CALL report(1,'rexxsupport.library required.')
IF ~SHOW('L','rxsocket.library') THEN IF ~ADDLIB('rxsocket.library',0,-30,0) THEN CALL report(1,'rxsocket.library required.')
IF EXISTS('libs:rmh.library') & EXISTS('libs:openurl.library') THEN DO
ourllib=1
CALL REMLIB('rmh.library')
CALL REMLIB('openurl.library')
CALL ADDLIB('rmh.library',5,-30,0)
CALL ADDLIB('openurl.library',0,-66,3)
END
ELSE ourllib=0
taglist.main=WindowID(1),
PubScreenName('Workbench'),
WindowTitle('Upd8' version),
'VertGroupA',
'HorizGroupA',
'VertGroupA',
'SpaceS',
NamedSeparator('locations'),
'SpaceS',
ListSSN('oldlist',101,0,0) 'TRAT_MinHeight 6',
'HorizGroupEA',
'HorizGroupA',
Button('_verify',111),
Button('_new',105),
Button('_delete',106),
'EndGroup',
'HorizGroupA',
Button('_edit',109),
Button('_browse',107),
Button('_show',114),
'EndGroup',
'EndGroup',
'HorizGroupEA',
'HorizGroupA',
Button('verify mar_ked',113),
ButtonR('verify al_l',104),
'EndGroup',
'EndGroup',
'SpaceS',
NamedSeparator('updated locations'),
'SpaceS',
ListSSC('newlist',102,0,0) 'TRAT_MinHeight 2',
'HorizGroupEA',
'HorizGroupA',
Button('f_orget',126),
'EndGroup',
'HorizGroupA',
Button('d_ata',129),
Button('b_rowse',127),
Button('s_how',134),
'EndGroup',
'EndGroup',
'EndGroup',
'EndGroup',
'SpaceS',
'HorizGroupA',
'SpaceS',
ClippedTextID('No locations verified.',110) 'TRAT_Flags TRTX_NOUNDERSCORE',
'SpaceS',
'EndGroup',
'SpaceS',
Progress(100,0,103),
'HorizGroupA',
Button('_import BookCon',115),
Button('_prefs',112),
ButtonE('_quit',108),
'EndGroup',
'EndGroup',
'EndProject'
taglist.new=WindowID(5),
PubScreenName('Workbench'),
WindowPosition('TRWP_CENTERDISPLAY'),
WindowFlags('TRWF_ACTIVATESTRGAD'),
WindowTitle('Upd8 - new location'),
'VertGroupA',
'SpaceS',
'LineArray',
'BeginLine',
'SpaceS' TextNR('_name') 'TRAT_ID 511 SpaceS',
StringGadget('',511) 'TRAT_Value 512 TRAT_Flags TRST_NORETURNBROADCAST SpaceS',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_URL') 'TRAT_ID 512 SpaceS',
StringGadget('',512) 'TRAT_Value 512 TRAT_Flags TRST_NORETURNBROADCAST SpaceS',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_separate viewing URL') 'TRAT_ID 514 SpaceS',
StringGadget('',514) 'TRAT_Value 512 TRAT_Flags TRST_NORETURNBROADCAST SpaceS',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_force size method') 'TRAT_ID 513 SpaceS',
'HorizGroupSA' CheckBox(513) 'TRAT_Value 0 EndGroup SpaceS',
'EndLine',
'EndArray',
'SpaceS',
'HorizGroupA',
ButtonR('a_dd',502),
ButtonE('_abort',503),
'EndGroup',
'EndGroup',
'EndProject'
RETURN 0
main:
window.main=TR_OPENPROJECT(app,taglist.main)
CALL redrawlists
IF startcheck THEN CALL check
stoploop.main=0
DO UNTIL stoploop.main
CALL TR_WAIT(app,'')
DO WHILE TR_HANDLEMSG(app,'event')
SELECT
WHEN event.trm_class='TRMS_ACTION' THEN SELECT
WHEN event.trm_id=104 THEN CALL check
WHEN event.trm_id=113 THEN CALL check('MARKED')
WHEN event.trm_id=115 THEN CALL importbookcon
WHEN event.trm_id=105 THEN CALL new
WHEN event.trm_id=106 THEN CALL delete
WHEN event.trm_id=108 THEN stoploop.main=1
WHEN event.trm_id=111 THEN CALL check(TR_GETATTRIBUTE(window.main,101,'TRAT_Value')+1)
WHEN event.trm_id=112 THEN CALL prefs
WHEN event.trm_id=126 THEN CALL forget
WHEN event.trm_id=109 THEN DO; CALL getinfo(1); CALL edit; END
WHEN event.trm_id=107 THEN DO; CALL getinfo(1); CALL browse; END
WHEN event.trm_id=114 THEN DO; CALL getinfo(1); CALL showhtml; END
WHEN event.trm_id=129 THEN DO; CALL getinfo(2); CALL data; END
WHEN event.trm_id=127 THEN DO; CALL getinfo(2); CALL browse; END
WHEN event.trm_id=134 THEN DO; CALL getinfo(2); CALL showhtml; END
WHEN event.trm_id=902 THEN DO
CALL TR_CLOSEPROJECT(window.failslist)
failsopen=0
END
OTHERWISE NOP
END
WHEN event.trm_class='TRMS_NEWVALUE' THEN SELECT
WHEN BITAND(D2X(event.trm_qualifier),X2C('0200'))~=X2C('0200') THEN NOP
WHEN event.trm_id=101 THEN CALL mark
WHEN event.trm_id=102 THEN DO; CALL getinfo(2); CALL data; END
OTHERWISE NOP
END
WHEN event.trm_class='TRMS_KEYPRESSED' THEN SELECT
WHEN event.trm_code=64 THEN DO
CALL mark
IF number<oldlist.0 THEN CALL TR_SETATTRIBUTE(window.main,101,'TRAT_Value',number)
END
OTHERWISE NOP
END
WHEN event.trm_class='TRMS_CLOSEWINDOW' THEN DO
IF event.trm_project=window.main THEN stoploop.main=1
ELSE IF event.trm_project=window.failslist THEN DO
CALL TR_CLOSEPROJECT(window.failslist)
failsopen=0
END
END
OTHERWISE NOP
END
END
END
RETURN 0
mark:
number=TR_GETATTRIBUTE(window.main,101,'TRAT_Value')+1
IF SUBSTR(oldlist.number,1,1)==' ' THEN oldlist.number=OVERLAY('>',oldlist.number)
ELSE oldlist.number=OVERLAY(' ',oldlist.number)
CALL TR_SETATTRIBUTE(window.main,101,'TROB_Listview','oldlist')
RETURN 0
redrawlists:
IF oldlist.0>0 THEN DO
CALL TR_SETATTRIBUTE(window.main,104,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,106,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,111,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,109,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,107,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,113,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,114,'TRAT_Disabled',0)
END
ELSE DO
CALL TR_SETATTRIBUTE(window.main,104,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,106,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,111,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,109,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,107,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,113,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,114,'TRAT_Disabled',1)
END
IF newlist.0>0 THEN DO
CALL TR_SETATTRIBUTE(window.main,126,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,129,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,127,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.main,134,'TRAT_Disabled',0)
END
ELSE DO
CALL TR_SETATTRIBUTE(window.main,126,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,129,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,127,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.main,134,'TRAT_Disabled',1)
END
CALL TR_SETATTRIBUTE(window.main,101,'TROB_Listview','oldlist')
CALL TR_SETATTRIBUTE(window.main,102,'TROB_Listview','newlist')
RETURN 0
prefs:
CALL TR_LOCKPROJECT(window.main)
taglist=WindowID(2),
PubScreenName('Workbench'),
WindowPosition('TRWP_CENTERDISPLAY'),
WindowTitle('Upd8 - preferences'),
'VertGroupA',
'SpaceS',
'LineArray',
'BeginLine',
'SpaceS' TextNR('_verify all at start') 'TRAT_ID 211 SpaceS',
'HorizGroupSA' CheckBox(211) 'TRAT_Value' startcheck 'EndGroup',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_continue on error') 'TRAT_ID 219 SpaceS',
'HorizGroupSA' CheckBox(219) 'TRAT_Value' errorcontinue 'EndGroup',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_notify when ready') 'TRAT_ID 221 SpaceS',
'HorizGroupSA' CheckBox(221) 'TRAT_Value' notifyready 'EndGroup',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_mark imported') 'TRAT_ID 220 SpaceS',
'HorizGroupSA' CheckBox(220) 'TRAT_Value' markimported 'EndGroup',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_browser path') 'TRAT_ID 214 SpaceS',
'HorizGroupA',
StringGadget(browser,212) 'TRAT_Value 512 TRAT_Flags TRST_NORETURNBROADCAST',
GetFileButton(214) 'SpaceS',
'EndGroup',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('viewer text_width') 'TRAT_ID 213 SpaceS',
'HorizGroupA',
SliderGadget(1,256,textwidth,213) 'SpaceS',
Integer(textwidth) 'TRAT_ID 201 TRAT_MinWidth 3',
'SpaceS' TextNR('columns') 'SpaceS',
'EndGroup',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('transfer _timeout') 'TRAT_ID 215 SpaceS',
'HorizGroupA',
SliderGadget(0,256,timeout,215) 'SpaceS',
Integer(timeout) 'TRAT_ID 216 TRAT_MinWidth 3',
'SpaceS' TextNR('seconds') 'SpaceS',
'EndGroup',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('size thres_hold') 'TRAT_ID 217 SpaceS',
'HorizGroupA',
SliderGadget(0,256,threshold,217) 'SpaceS',
Integer(threshold) 'TRAT_ID 218 TRAT_MinWidth 3',
'SpaceS' TextNR('bytes') 'SpaceS',
'EndGroup',
'EndLine',
'EndArray',
'SpaceS',
'HorizGroupA',
ButtonR('_save',204),
Button('_use',202),
ButtonE('_abort',203),
'EndGroup',
'EndGroup',
'EndProject'
stoploop.prefs=0
window.prefs=TR_OPENPROJECT(app,taglist)
DO UNTIL stoploop.prefs
CALL TR_WAIT(app,'')
DO WHILE TR_HANDLEMSG(app,'event')
IF event.trm_class='TRMS_CLOSEWINDOW' THEN stoploop.prefs=1
IF event.trm_class='TRMS_NEWVALUE' THEN DO
IF event.trm_id=213 THEN CALL TR_SETATTRIBUTE(window.prefs,201,'TRAT_Value',event.trm_data)
IF event.trm_id=215 THEN CALL TR_SETATTRIBUTE(window.prefs,216,'TRAT_Value',event.trm_data)
IF event.trm_id=217 THEN CALL TR_SETATTRIBUTE(window.prefs,218,'TRAT_Value',event.trm_data)
END
IF event.trm_class='TRMS_ACTION' THEN DO
IF event.trm_id=203 THEN stoploop.prefs=1
IF (event.trm_id=202 | event.trm_id=204) & ~stoploop.prefs THEN DO
startcheck =TR_GETATTRIBUTE(window.prefs,211,'TRAT_Value')
errorcontinue =TR_GETATTRIBUTE(window.prefs,219,'TRAT_Value')
notifyready =TR_GETATTRIBUTE(window.prefs,221,'TRAT_Value')
markimported =TR_GETATTRIBUTE(window.prefs,220,'TRAT_Value')
browser =TR_GETATTRIBUTE(window.prefs,212,'TROB_String')
textwidth =TR_GETATTRIBUTE(window.prefs,213,'TRAT_Value')
timeout =TR_GETATTRIBUTE(window.prefs,215,'TRAT_Value')
threshold =TR_GETATTRIBUTE(window.prefs,217,'TRAT_Value')
stoploop.prefs=1
IF event.trm_id=204 THEN CALL writeprefsfile
END
IF event.trm_id=214 THEN IF ASL_REQUESTFILE(window.prefs,'browser',LoadFile('Upd8 - select browser executable','_Select',progdir,'')) THEN CALL TR_SETATTRIBUTE(window.prefs,212,'TROB_String',browser.1)
END
END
END
CALL TR_CLOSEPROJECT(window.prefs)
CALL TR_UNLOCKPROJECT(window.main)
RETURN 0
report:
IF ARG(1,'E') THEN error=ARG(1)
ELSE error=1
IF ARG(2,'E') THEN reportmsg=ARG(2)
taglist=WindowID(6),
PubScreenName('Workbench'),
WindowPosition('TRWP_CENTERDISPLAY'),
WindowTitle('Upd8 - message'),
'VertGroupA',
'HorizGroupA',
'SpaceS',
'VertGroupA',
'SpaceS',
TextN(reportmsg) 'TRAT_Flags TRTX_NOUNDERSCORE',
'SpaceS',
'EndGroup',
'SpaceS',
'EndGroup',
'HorizGroupA',
ButtonRE('_close',601),
'EndGroup',
'EndGroup',
'EndProject'
CALL TR_AUTOREQUEST(app,null,taglist)
IF error THEN CALL errorexit
RETURN 0
encodeurl:
codeurl =STRIP(ARG(1))
position=1
DO WHILE POS(' ',codeurl,position)>0
position=POS(' ',codeurl,position)
codeurl =INSERT('20',OVERLAY('%',codeurl,position),position)
position=position+3
END
RETURN codeurl
halt:
break_c:
SAY 'line' sigl': interrupted'
CALL writelistfile
CALL TR_DELETEAPP(app)
EXIT 5
errorexit:
CALL TR_DELETEAPP(app)
EXIT 10
failure:
ioerr:
syntax:
SAY 'line' sigl':' SOURCELINE(sigl)||lf'error' rc':' ERRORTEXT(rc)||lf
CALL TR_DELETEAPP(app)
EXIT 10
edit:
CALL TR_LOCKPROJECT(window.main)
PARSE VAR name marked' ('method') 'name
taglist=WindowID(8),
PubScreenName('Workbench'),
WindowPosition('TRWP_CENTERDISPLAY'),
WindowFlags('TRWF_ACTIVATESTRGAD'),
WindowTitle('Upd8 - edit location'),
'VertGroupA',
'SpaceS',
'LineArray',
'BeginLine',
'SpaceS' TextNR('_name') 'TRAT_ID 811 SpaceS',
StringGadget(COMPRESS(name,asterisk),811) 'TRAT_Value 512 TRAT_Flags TRST_NORETURNBROADCAST SpaceS',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_URL') 'TRAT_ID 812 SpaceS',
StringGadget(url,812) 'TRAT_Value 512 TRAT_Flags TRST_NORETURNBROADCAST SpaceS',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_separate viewing URL') 'TRAT_ID 814 SpaceS',
StringGadget(vurl,814) 'TRAT_Value 512 TRAT_Flags TRST_NORETURNBROADCAST SpaceS',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('comparison method:') 'SpaceS',
ClippedText(method) 'SpaceS',
'EndLine',
'BeginLine',
'SpaceS' TextNR('comparison data:') 'SpaceS',
ClippedText(data) 'TRAT_Flags TRTX_NOUNDERSCORE SpaceS',
'EndLine',
'SpaceS',
'BeginLine',
'SpaceS' TextNR('_force size method') 'TRAT_ID 813 SpaceS',
'HorizGroupSA' CheckBox(813) 'TRAT_Value' (method='fsze') 'EndGroup SpaceS',
'EndLine',
'EndArray',
'SpaceS',
'HorizGroupA',
ButtonR('_change',802),
ButtonE('_abort',803),
'EndGroup',
'EndGroup',
'EndProject'
stoploop.edit=0
window.edit =TR_OPENPROJECT(app,taglist)
DO UNTIL stoploop.edit
CALL TR_WAIT(app,'')
DO WHILE TR_HANDLEMSG(app,'event')
IF event.trm_class='TRMS_CLOSEWINDOW' THEN stoploop.edit=1
IF event.trm_class='TRMS_ACTION' THEN DO
stoploop.edit=1
IF event.trm_id=802 THEN DO
IF TR_GETATTRIBUTE(window.edit,813,'TRAT_Value') THEN DO
IF method~='fsze' THEN DO
IF method~='size' THEN data='unverified'
method='fsze'
END
END
ELSE IF method='fsze' THEN DO
method='????'
data ='unverified'
END
number =TR_GETATTRIBUTE(window.main,101,'TRAT_Value')+1
oldlist.number =marked' ('method')' TR_GETATTRIBUTE(window.edit,811,'TROB_String')
oldlist.number.urlstring =encodeurl(TR_GETATTRIBUTE(window.edit,812,'TROB_String'))' 'encodeurl(TR_GETATTRIBUTE(window.edit,814,'TROB_String'))
oldlist.number.datastring=data
modified =1
CALL TR_SETATTRIBUTE(window.main,101,'TROB_Listview','oldlist')
END
END
END
END
CALL TR_CLOSEPROJECT(window.edit)
CALL TR_UNLOCKPROJECT(window.main)
RETURN 0
data:
taglist=WindowID(3),
PubScreenName('Workbench'),
WindowPosition('TRWP_CENTERDISPLAY'),
WindowTitle('Upd8 - location data'),
'VertGroupA',
'SpaceS',
'HorizGroupA',
'SpaceS',
'LineArray',
'Beginline',
TextNR('name:'),
'SpaceS',
TextN(COMPRESS(SUBSTR(name,10),asterisk)) 'TRAT_Flags TRTX_NOUNDERSCORE',
'EndLine',
'BeginLine',
TextNR('URL:'),
'SpaceS',
TextN(url) 'TRAT_Flags TRTX_NOUNDERSCORE',
'EndLine',
'BeginLine',
TextNR('separate viewing URL:'),
'SpaceS',
TextN(vurl) 'TRAT_Flags TRTX_NOUNDERSCORE',
'EndLine',
'BeginLine',
TextNR('comparison method:'),
'SpaceS',
TextN(SUBSTR(name,4,4)),
'EndLine',
'BeginLine',
TextNR('comparison data:'),
'SpaceS',
TextN(data) 'TRAT_Flags TRTX_NOUNDERSCORE',
'EndLine',
'EndArray',
'SpaceS',
'EndGroup',
'SpaceS',
ButtonRE('_close',301),
'EndGroup',
'EndProject'
CALL TR_AUTOREQUEST(app,window.main,taglist)
RETURN 0
browse:
IF ARG(1,'E') THEN url=ARG(1)
ELSE IF vurl~='' THEN url=vurl
IF ~ourllib THEN SELECT
WHEN SHOW('P','IBROWSE.1') THEN ADDRESS 'IBROWSE.1' 'GOTOURL' '"'url'"'
WHEN SHOW('P','IBROWSE') THEN ADDRESS 'IBROWSE' 'GOTOURL' '"'url'"'
WHEN SHOW('P','AWEB.1') THEN ADDRESS 'AWEB.1' 'OPEN' '"'url'"'
WHEN SHOW('P','AWEB.2') THEN ADDRESS 'AWEB.2' 'OPEN' '"'url'"'
WHEN SHOW('P','AWebControlPort') THEN ADDRESS 'AWebControlPort' 'OPEN' '"'url'"'
WHEN SHOW('P','VOYAGER') THEN ADDRESS 'VOYAGER' 'OPENURL' '"'url'"'
OTHERWISE DO
IF browser='' THEN CALL report(0,'No active browser found. Select browser executable.')
ELSE DO
IF EXISTS(browser) THEN ADDRESS COMMAND 'run >NIL:' browser '"'url'"'
ELSE CALL report(0,'The file' browser 'does not exist.')
END
END
END
ELSE IF OPENURL(url)~=1 THEN CALL report(0,'Failed to open URL.')
RETURN 0
showhtml:
CALL TR_LOCKPROJECT(window.main)
IF vurl~='' THEN url=vurl
button2 ='try _browse'
button3 ='_abort'
showpage =1
listfails =0
linelist.0=0
taglist=WindowID(4),
PubScreenName('Workbench'),
WindowPosition('TRWP_CENTERDISPLAY'),
WindowTitle('Upd8 - show location'),
'VertGroupA',
'HorizGroupA',
FWListRO('linelist',401,0) 'TRAT_MinWidth' textwidth,
'EndGroup',
'SpaceS',
'HorizGroupA',
'SpaceS',
ClippedTextID('Preparing...',402) 'TRAT_Flags TRTX_NOUNDERSCORE',
'SpaceS',
'EndGroup',
'SpaceS',
'LineArray',
'BeginLine',
'SpaceS',
TextNR('_URL') 'TRAT_ID 403',
'SpaceS',
StringGadget('',403) 'TRAT_Value' 512,
'EndLine',
'EndArray',
'HorizGroupA',
ButtonR('_get',407),
Button('_abort',404),
Button('_browse',406),
ButtonE('_close',405),
'EndGroup',
'EndGroup',
'EndProject'
window.show=TR_OPENPROJECT(app,taglist)
IF window.show=null THEN CALL report(0,'Could not open show window. Try lower textwidth.')
ELSE DO
CALL TR_SETATTRIBUTE(window.show,403,'TROB_String',url)
CALL showhtmlbridge
DO UNTIL stoploop.show
CALL TR_WAIT(app,'')
DO WHILE TR_HANDLEMSG(app,'event')
IF event.trm_class='TRMS_CLOSEWINDOW' THEN stoploop.show=1
IF event.trm_class='TRMS_ACTION' THEN DO
IF event.trm_id=407 THEN DO
linelist.0=0
CALL TR_SETATTRIBUTE(window.show,401,'TROB_Listview','linelist')
url =TR_GETATTRIBUTE(window.show,403,'TROB_String')
name=' (????) unknown'
CALL showhtmlbridge
END
IF event.trm_id=405 THEN stoploop.show=1
IF event.trm_id=406 THEN CALL browse(TR_GETATTRIBUTE(window.show,403,'TROB_String'))
END
END
END
CALL TR_CLOSEPROJECT(window.show)
END
CALL TR_UNLOCKPROJECT(window.main)
RETURN 0
showhtmlbridge:
infotextadd=''
pagetitle ='no title'
CALL TR_SETATTRIBUTE(window.show,403,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.show,405,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.show,406,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.show,407,'TRAT_Disabled',1)
CALL TR_SETATTRIBUTE(window.show,402,'TRAT_Text','Contacting host...')
CALL TR_SETATTRIBUTE(window.show,404,'TRAT_Disabled',0)
CALL getdata
CALL TR_SETATTRIBUTE(window.show,403,'TROB_String',url)
CALL TR_SETATTRIBUTE(window.show,403,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.show,405,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.show,406,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.show,407,'TRAT_Disabled',0)
CALL TR_SETATTRIBUTE(window.show,404,'TRAT_Disabled',1)
stoploop.show=0
SELECT
WHEN success THEN CALL TR_SETATTRIBUTE(window.show,402,'TRAT_Text',infotextadd'Now showing' COMPRESS(pagetitle,asterisk)'.')
WHEN retry=703 THEN CALL TR_SETATTRIBUTE(window.show,402,'TRAT_Text','Could not get' url'.')
WHEN retry=702 THEN DO
CALL browse(url)
CALL TR_SETATTRIBUTE(window.show,402,'TRAT_Text','Could not get' url'. Tried browse.')
END
OTHERWISE NOP
END
RETURN 0
/*** internal list handling ***/
new:
CALL TR_LOCKPROJECT(window.main)
button2 ='a_dd anyway'
button3 ='_abort'
showpage =0
listfails=0
stoploop.new=0
window.new =TR_OPENPROJECT(app,taglist.new)
DO UNTIL stoploop.new
CALL TR_WAIT(app,'')
DO WHILE TR_HANDLEMSG(app,'event')
IF event.trm_class='TRMS_CLOSEWINDOW' THEN stoploop.new=1
IF event.trm_class='TRMS_ACTION' THEN DO
IF event.trm_id=503 THEN stoploop.new=1
IF event.trm_id=502 THEN DO
name =' (????)' TR_GETATTRIBUTE(window.new,511,'TROB_String')
IF TR_GETATTRIBUTE(window.new,513,'TRAT_Value') THEN name=OVERLAY('fsze',name,4)
url =encodeurl(TR_GETATTRIBUTE(window.new,512,'TROB_String'))
vurl =encodeurl(TR_GETATTRIBUTE(window.new,514,'TROB_String'))
inputurl =url
stoploop.new=1
CALL TR_LOCKPROJECT(window.new)
CALL getdata
IF success | retry=702 THEN DO
IF retry=702 THEN data='unverified'
number=oldlist.0+1
oldlist.number=name
IF SUBSTR(name,4,4)~='fsze' THEN SELECT
WHEN data='unverified' THEN oldlist.number=OVERLAY('????',name,4)
WHEN DATATYPE(data,'N') THEN oldlist.number=OVERLAY('size',name,4)
OTHERWISE oldlist.number=OVERLAY('date',name,4)
END
oldlist.number.urlstring =inputurl' 'vurl
oldlist.number.datastring=data
oldlist.0 =number
modified=1
CALL redrawlists
END
ELSE stoploop.new=0
CALL TR_UNLOCKPROJECT(window.new)
END
END
END
END
CALL TR_CLOSEPROJECT(window.new)
CALL TR_UNLOCKPROJECT(window.main)
RETURN 0
delete:
number=TR_GETATTRIBUTE(window.main,101,'TRAT_Value')+1
IF oldlist.0>0 THEN DO
DO i=number WHILE i<oldlist.0
o=i+1
oldlist.i =oldlist.o
oldlist.i.urlstring =oldlist.o.urlstring
oldlist.i.datastring=oldlist.o.datastring
END
oldlist.0=oldlist.0-1
modified=1
CALL redrawlists
END
RETURN 0
forget:
number=TR_GETATTRIBUTE(window.main,102,'TRAT_Value')+1
IF newlist.0>0 THEN DO
DO i=number WHILE i<newlist.0
o=i+1
newlist.i =newlist.o
newlist.i.urlstring =newlist.o.urlstring
newlist.i.datastring=newlist.o.datastring
END
newlist.0=newlist.0-1
modified=1
CALL redrawlists
END
RETURN 0
getinfo:
number=TR_GETATTRIBUTE(window.main,100+ARG(1),'TRAT_Value')+1
IF ARG(1)=1 THEN DO
name=oldlist.number
url =WORD(oldlist.number.urlstring,1)
vurl=WORD(oldlist.number.urlstring,2)
PARSE VAR oldlist.number.urlstring url' 'vurl
data=oldlist.number.datastring
END
ELSE DO
name=newlist.number
url =WORD(newlist.number.urlstring,1)
vurl=WORD(newlist.number.urlstring,2)
data=newlist.number.datastring
END
RETURN 0
/*** listfile handling ***/
readlistfile:
reportmsg='Listfile' progdir'Upd8.locations is corrupt.'
IF EXISTS(progdir'Upd8.locations') THEN DO
IF ~OPEN('listfile',progdir'Upd8.locations','R') THEN CALL report(1,'Unable to open' progdir'Upd8.locations for reading.')
IF READLN('listfile')~=='Upd8 - locations' THEN CALL report
count =0
newcount=0
DO UNTIL EOF('listfile')
temp=READLN('listfile')
IF temp~='' THEN DO
IF WORD(temp,1)='NAME' THEN DO
count=count+1
oldlist.count=' 'SUBWORD(temp,2)
temp=READLN('listfile')
IF WORD(temp,1)='URL' THEN DO
oldlist.count.urlstring=SUBSTR(temp,6)
temp=READLN('listfile')
IF WORD(temp,1)='DATA' THEN DO
oldlist.count.datastring=SUBWORD(temp,2)
END
ELSE CALL report
END
ELSE CALL report
END
ELSE IF WORD(temp,1)='NEW' THEN DO
newcount=newcount+1
newlist.newcount=' 'SUBWORD(temp,2)
temp=READLN('listfile')
IF WORD(temp,1)='URL' THEN DO
newlist.newcount.urlstring=SUBSTR(temp,6)
temp=READLN('listfile')
IF WORD(temp,1)='DATA' THEN DO
newlist.newcount.datastring=SUBWORD(temp,2)
END
ELSE CALL report
END
ELSE CALL report
END
ELSE CALL report
END
END
oldlist.0=count
newlist.0=newcount
CALL CLOSE('listfile')
END
ELSE CALL defaultlist
RETURN 0
defaultlist:
oldlist.1 =' (????) Turbid design'
oldlist.1.urlstring ='http://home.swipnet.se/turbid/modified.txt http://home.swipnet.se/turbid/'
oldlist.1.datastring='unverified'
oldlist.0 =1
RETURN 0
writelistfile:
IF ~modified THEN RETURN 0
IF ~OPEN('listfile',progdir'Upd8.locations','W') THEN DO
CALL report(0,'Unable to open' progdir'Upd8.locations for writing.')
RETURN 0
END
bigstring='Upd8 - locations'lf
delay=30
DO i=1 TO oldlist.0
bigstring=bigstring||lf'NAME 'SUBSTR(oldlist.i,3)||lf'URL 'oldlist.i.urlstring||lf'DATA 'oldlist.i.datastring||lf
IF i>delay THEN DO
CALL WRITECH('listfile',bigstring)
bigstring=''
delay=delay+30
END
END
DO i=1 TO newlist.0
bigstring=bigstring||lf'NEW 'SUBSTR(newlist.i,3)||lf'URL 'newlist.i.urlstring||lf'DATA 'newlist.i.datastring||lf
IF i>delay THEN DO
CALL WRITECH('listfile',bigstring)
bigstring=''
delay=delay+30
END
END
CALL WRITECH('listfile',bigstring)
CALL CLOSE('listfile')
RETURN 0
importbookcon:
IF ~ASL_REQUESTFILE(window.main,'bookconfile',LoadFileP('Upd8 - select BookCon text file','Import',progdir,'Hotlist.txt','#?.txt')) THEN RETURN 0
CALL TR_LOCKPROJECT(window.main)
count=oldlist.0
IF markimported THEN prefix='> '
ELSE prefix=' '
IF ~OPEN('bookconfile',bookconfile.1,'R') THEN DO
CALL report(0,'Could not open BookCon text file 'bookconfile.1'.')
CALL TR_UNLOCKPROJECT(window.main)
RETURN 0
END
IF POS('BookCon',READLN('bookconfile')||READLN('bookconfile')||READLN('bookconfile'))<1 THEN DO
CALL report(0,bookconfile.1' is not a BookCon text file.')
CALL TR_UNLOCKPROJECT(window.main)
CALL CLOSE('bookconfile')
RETURN 0
END
DO UNTIL EOF('bookconfile')
temp=READLN('bookconfile')
IF SUBSTR(temp,1,6)=='Name: ' THEN DO
count =count+1
oldlist.count=prefix'(????) 'STRIP(SUBSTR(temp,7))
temp =READLN('bookconfile')
IF SUBSTR(temp,1,6)=='URL : ' THEN DO
oldlist.count.urlstring =encodeurl(SUBSTR(temp,7))
oldlist.count.datastring='unverified'
END
ELSE DO
CALL report(0,'BookCon text file 'bookconfile.1' is corrupt.')
CALL TR_UNLOCKPROJECT(window.main)
CALL CLOSE('bookconfile')
RETURN 0
END
END
END
CALL CLOSE('bookconfile')
IF oldlist.0<count THEN modified=1
oldlist.0=count
CALL redrawlists
CALL TR_UNLOCKPROJECT(window.main)
RETURN 0
/*** prefsfile handling ***/
readprefsfile:
reportmsg='Prefsfile' progdir'Upd8.prefs is corrupt.'
CALL defaultprefs
IF EXISTS(progdir'Upd8.prefs') THEN DO
IF ~OPEN('prefsfile',progdir'Upd8.prefs','R') THEN CALL report(1,'Unable to open' progdir'Upd8.prefs for reading.')
IF READLN('prefsfile')~=='Upd8 - preferences' THEN CALL report
DO UNTIL EOF('prefsfile')
temp =READLN('prefsfile')
keyword=WORD(temp,1)
content=SUBWORD(temp,2)
SELECT
WHEN keyword='' THEN NOP
WHEN keyword='STARTCHECK' THEN startcheck =content
WHEN keyword='ERRORCONTINUE' THEN errorcontinue=content
WHEN keyword='NOTIFYREADY' THEN notifyready =content
WHEN keyword='BROWSER' THEN browser =content
WHEN keyword='TEXTWIDTH' THEN textwidth =content
WHEN keyword='TIMEOUT' THEN timeout =content
WHEN keyword='THRESHOLD' THEN threshold =content
WHEN keyword='MARKIMPORTED' THEN markimported =content
OTHERWISE CALL report
END
END
CALL CLOSE('prefsfile')
END
RETURN 0
defaultprefs:
startcheck =0
errorcontinue=1
notifyready =1
markimported =1
browser =''
textwidth =60
timeout =20
threshold =12
RETURN 0
writeprefsfile:
IF ~OPEN('prefsfile',progdir'Upd8.prefs','W') THEN DO
CALL report(0,'Unable to open' progdir'Upd8.prefs for writing.')
RETURN 0
END
CALL WRITELN('prefsfile','Upd8 - preferences'lf||lf'STARTCHECK 'startcheck||lf'ERRORCONTINUE 'errorcontinue||lf'NOTIFYREADY 'notifyready||lf'BROWSER 'browser||lf'TEXTWIDTH 'textwidth||lf'TIMEOUT 'timeout||lf'THRESHOLD 'threshold||lf'MARKIMPORTED 'markimported)
CALL CLOSE('prefsfile')
RETURN 0
/*** file verifying ***/
check:
CALL TR_LOCKPROJECT(window.main)
CALL TR_SETATTRIBUTE(window.main,103,'TRAT_Value',0)
CALL TR_SETATTRIBUTE(window.main,103,'TROB_Progress',oldlist.0)
button2 ='a_bort all'
button3 ='_abort'
showpage =0
progress =0
listfails =0
fails.0 =0
multicheck =0
markedcheck =(ARG(1)='MARKED')
oldlistlength=newlist.0
IF ARG(1,'O') | markedcheck THEN DO
multicheck =1
continuecheck=1
IF markedcheck THEN infotextadd='Verified marked. '
ELSE infotextadd='Verified all. '
IF errorcontinue THEN DO
listfails=1
fails.0 =0
END
DO number=1 WHILE number<=oldlist.0 & continuecheck
IF markedcheck & SUBSTR(oldlist.number,1,1)=' ' THEN ITERATE
name=oldlist.number
url =WORD(oldlist.number.urlstring,1)
data=oldlist.number.datastring
CALL TR_SETATTRIBUTE(window.main,110,'TRAT_Text','Verifying' SUBSTR(name,4,4) 'of' SUBSTR(name,10)'...')
olddata=data; oldurl=url
CALL getdata
IF listfails THEN DO
IF success THEN oldlist.number=OVERLAY(' ',oldlist.number)
ELSE DO
oldlist.number=OVERLAY('> ',oldlist.number)
fails.0 =1+fails.0
temp =fails.0
fails.temp =SUBSTR(oldlist.number,3)' ('failreason')'
END
CALL TR_SETATTRIBUTE(window.main,101,'TROB_Listview','oldlist')
END
IF retry=702 THEN continuecheck=0
IF success THEN CALL verifychange
ELSE infotextadd='Partial verification. '
progress=progress+1
CALL TR_SETATTRIBUTE(window.main,103,'TRAT_Value',progress)
END
IF newlist.0>oldlistlength THEN infotext=infotextadd||newlist.0-oldlistlength 'updates found.'
ELSE infotext=infotextadd'No updates found.'
IF newlist.0=oldlistlength+1 THEN infotext=infotextadd'1 update found.'
END
ELSE DO
progress=oldlist.0
number=ARG(1)
name=oldlist.number
url =WORD(oldlist.number.urlstring,1)
data=oldlist.number.datastring
CALL TR_SETATTRIBUTE(window.main,110,'TRAT_Text','Verifying' SUBSTR(name,4,4) 'of' SUBSTR(name,10)'...')
olddata=data; oldurl=url
CALL getdata
IF success THEN DO
CALL verifychange
IF newlist.0>oldlistlength THEN infotext=SUBSTR(name,10) 'is updated.'
ELSE infotext=SUBSTR(name,10) 'is not updated.'
END
ELSE infotext='Failed to verify' SUBSTR(name,10)'.'
END
CALL TR_SETATTRIBUTE(window.main,103,'TRAT_Value',progress)
CALL TR_SETATTRIBUTE(window.main,110,'TRAT_Text',infotext)
CALL TR_UNLOCKPROJECT(window.main)
IF fails.0>0 THEN DO
IF failsopen THEN DO
CALL TR_SETATTRIBUTE(window.failslist,901,'TROB_Listview','fails')
CALL TR_SETATTRIBUTE(window.failslist,903,'TRAT_Text',infotext)
IF notifyready THEN DO
CALL PROJECTTOFRONT(window.failslist)
CALL ACTIVATEPROJECT(window.failslist)
END
END
ELSE DO
taglist=WindowID(9),
PubScreenName('Workbench'),
WindowPosition('TRWP_CENTERDISPLAY'),
WindowTitle('Upd8 - verification failures'),
'VertGroupA',
'HorizGroupA',
ListRO('fails',901,0) 'TRAT_MinHeight 4',
'EndGroup',
'SpaceS',
'HorizGroupA',
'SpaceS',
ClippedTextID(infotext,903) 'TRAT_Flags TRTX_NOUNDERSCORE',
'SpaceS',
'EndGroup',
'SpaceS',
'HorizGroupA',
ButtonR('_close',902),
'EndGroup',
'EndGroup',
'EndProject'
window.failslist=TR_OPENPROJECT(app,taglist)
IF window.failslist=null THEN CALL report(0,'Could not open fails list window.')
ELSE failsopen=1
END
END
ELSE IF multicheck & notifyready THEN DO
IF failsopen THEN DO
CALL TR_CLOSEPROJECT(window.failslist)
failsopen=0
END
CALL report(0, infotext)
END
RETURN 0
verifychange:
oldmethod=SUBSTR(name,4,4)
IF oldmethod='fsze' THEN method='fsze'
ELSE DO
IF DATATYPE(data,'N') THEN method='size'
ELSE method='date'
END
IF oldmethod~=method | olddata='unverified' THEN DO
modified =1
oldlist.number =OVERLAY(method,oldlist.number,4)
oldlist.number.datastring=data
IF oldmethod~='????' & olddata~='unverified' THEN DO
CALL updated
newlist.x=newlist.x' (method changed)'
END
CALL redrawlists
END
ELSE IF olddata~=data THEN CALL newdata
RETURN 0
newdata:
modified=1
IF method='size' | method='fsze' THEN DO
IF ~DATATYPE(olddata,'N') THEN olddata=data
IF ABS(data-olddata)<threshold THEN DO
oldlist.number.datastring=data
RETURN 0
END
END
oldlist.number.datastring=data
CALL updated
IF DATATYPE(data,'N') THEN DO
IF data-olddata>0 THEN prefix='+'
ELSE prefix=''
newlist.x=newlist.x '('prefix||data-olddata 'bytes)'
END
CALL redrawlists
RETURN 0
updated:
IF multicheck & newlist.0>0 & newlist.0=oldlistlength THEN DO
newlist.0 =newlist.0+1
x =newlist.0
oldlistlength=oldlistlength+1
newlist.x =' (date) ----------------------------------------------------------------'
newlist.x.urlstring ='http://home.swipnet.se/turbid/separator.txt'
newlist.x.datastring='unverified'
END
newlist.0 =newlist.0+1
x =newlist.0
newlist.x =OVERLAY(' ',oldlist.number)
newlist.x.urlstring =oldlist.number.urlstring
newlist.x.datastring=data
RETURN 0
getdata:
redirect=0
DO UNTIL retry=703 | retry=702
retry =703
closesock =0
success =0
failreason='Reason unknown.'
CALL recieve
IF closesock THEN CALL CLOSESOCKET(sock)
IF ~success & redirected THEN redirect=redirect-1
IF ~success & ~listfails THEN DO
taglist=WindowID(7),
PubScreenName('Workbench'),
WindowPosition('TRWP_CENTERDISPLAY'),
WindowTitle('Upd8 - get location'),
'VertGroupA',
'HorizGroupA',
'SpaceS',
'VertGroupA',
'SpaceS',
TextN('Could not get location:'),
'SpaceS',
'LineArray',
'Beginline',
TextNR('name:'),
'SpaceS',
TextN(COMPRESS(SUBSTR(name,10),asterisk)) 'TRAT_Flags TRTX_NOUNDERSCORE',
'EndLine',
'BeginLine',
TextNR('URL:'),
'SpaceS',
TextN(url) 'TRAT_Flags TRTX_NOUNDERSCORE',
'EndLine',
'EndArray',
'SpaceS',
TextN(failreason),
'SpaceS',
'EndGroup',
'SpaceS',
'EndGroup',
'HorizGroupA',
ButtonR('_retry',701),
Button(button2,702),
ButtonE(button3,703),
'EndGroup',
'EndGroup',
'EndProject'
retry=TR_AUTOREQUEST(app,null,taglist)
IF retry=0 THEN DO
report(0,'Verify failed. Requester failed. Aborted.')
retry=703
END
END
END
RETURN 0
recieve:
redirected=0
IF ~parseurl() THEN RETURN 0
DO WHILE statuscode>299 & statuscode<400
redirected=1
redirect =redirect+1
IF redirect>5 THEN DO
failreason='More than five redirections, probably looping.'
RETURN 0
END
DO UNTIL ABBREV(UPPER(line),'LOCATION:')
IF ~getline() THEN RETURN 0
IF line='' THEN DO
failreason='Bad redirection header.'
RETURN 0
END
END
PARSE VAR line .' 'newurl
IF ABBREV(UPPER(newurl),'HTTP://') THEN url=newurl
ELSE DO
IF SUBSTR(newurl,1,1)='/' THEN DO
PARSE VAR url 8 host'/'file
url='http://'host||newurl
END
ELSE DO
PARSE VAR url url'?'
lastslash=LASTPOS('/',url)+1
PARSE VAR url url =lastslash
url=url||newurl
END
END
redirected=0
IF ~parseurl() THEN RETURN 0
END
IF statuscode~=200 THEN DO
failreason='Server replied:' statuscode statusphrase
RETURN 0
END
mime =''
data =''
nodate =1
position =1
forcesize=(SUBSTR(name,4,4)='fsze')
DO UNTIL field=''
IF ~getline() THEN RETURN 0
PARSE VAR line field': 'content
field=UPPER(field)
SELECT
WHEN field='LAST-MODIFIED' & ~forcesize THEN DO
nodate=0
data =content
END
WHEN field='CONTENT-LENGTH' & nodate THEN DO
nodate=0
data =content
END
WHEN field='CONTENT-TYPE' THEN mime=content
OTHERWISE NOP
END
END
IF showpage THEN DO
IF mime~='text/html' & mime~='text/plain' THEN DO
failreason='Filetype' mime 'unknown.'
RETURN 0
END
CALL TR_SETATTRIBUTE(window.show,402,'TRAT_Text','Recieving and formatting as 'mime'...')
buffer =''
tagpart =''
bufferlength=0
datalength =1
count =0
IF mime='text/html' THEN CALL formathtml
IF mime='text/plain' THEN CALL formattext
linelist.0=count
topline=TR_GETATTRIBUTE(window.show,401,'TRLV_Top')
CALL TR_SETATTRIBUTE(window.show,401,'TROB_Listview','linelist')
CALL TR_SETATTRIBUTE(window.show,401,'TRLV_Top',topline)
END
ELSE DO
IF nodate THEN DO
filelength=0
DO UNTIL datalength=0
datalength=RECV(sock,'DATA',4096)
IF datalength=-1 THEN DO
failreason='Recieve failed.'
RETURN 0
END
filelength=filelength+datalength
END
data=filelength
END
END
success=1
RETURN 0
parseurl:
IF closesock THEN CALL CLOSESOCKET(sock)
closesock=0
newurl=STRIP(url)
PARSE VAR newurl newurl'?'arguments
IF ~ABBREV(UPPER(newurl),'HTTP://') THEN DO
IF POS('://',newurl)>0 THEN DO
failreason='Not a HTTP URL.'
RETURN 0
END
newurl='http://'newurl
END
IF POS('/',newurl,8)<1 THEN newurl=newurl'/'
PARSE VAR newurl 8 host'/'file
file='/'file
PARSE VAR host host':'port
IF port='' THEN port=80
IF ~DATATYPE(port,'N') THEN DO
failreason='Bad HTTP URL.'
RETURN 0
END
IF arguments='' THEN url=newurl
ELSE DO
url =newurl'?'arguments
file=file'?'arguments
END
IF ~ISLIBON('SOCKET') THEN DO
failreason='No TCP/IP stack available.'
RETURN 0
END
sock=SOCKET('INET','STREAM')
IF sock=-1 THEN DO
failreason='Could not obtain socket.'
RETURN 0
END
closesock=1
x.ADDRPORT =port
x.ADDRFAMILY='INET'
x.ADDRADDR =RESOLVE(host)
IF x.ADDRADDR=-1 THEN DO
failreason='Unknown host.'
RETURN 0
END
CALL SETSOCKOPT(sock,"SOCKET","RCVTIMEO",timeout)
CALL SETSOCKOPT(sock,"SOCKET","SNDTIMEO",timeout)
IF CONNECT(sock,'X')<0 THEN DO
failreason='Connection failed.'
RETURN 0
END
IF SEND(sock,'GET' file 'HTTP/1.0'crlf'User-Agent: Upd8/'version '(AmigaOS)'crlf'Host:' host||crlf'Pragma: no-cache'crlf||crlf)<0 THEN DO
failreason='Request failed.'
RETURN 0
END
IF ~getline() THEN RETURN 0
IF ABBREV(line,'HTTP/') THEN DO
PARSE VAR line 'HTTP/' . ' 'statuscode' 'statusphrase
IF ~DATATYPE(statuscode,'N') THEN DO
failreason='Bad HTTP response.'
RETURN 0
END
END
ELSE DO
statuscode =200
statusphrase='Fine.'
END
RETURN 1
getline:
IF RECVLINE(sock,'LINE',1024)<1 THEN DO
failreason='Recieve failed.'
RETURN 0
END
line=COMPRESS(line,crlf)
RETURN 1
moredata:
DO WHILE TR_HANDLEMSG(app,'event')
IF (event.trm_class='TRMS_ACTION' & event.trm_id=404) | event.trm_class='TRMS_CLOSEWINDOW' THEN DO
infotextadd='Transfer aborted. '
RETURN 0
END
END
linelist.0=count
topline =TR_GETATTRIBUTE(window.show,401,'TRLV_Top')
CALL TR_SETATTRIBUTE(window.show,401,'TROB_Listview','linelist')
CALL TR_SETATTRIBUTE(window.show,401,'TRLV_Top',topline)
datalength=RECV(sock,'DATA',4096)
IF datalength=-1 THEN DO
infotextadd='Transfer interrupted. '
RETURN 0
END
buffer =buffer||tagpart||TRANSLATE(COMPRESS(data,removechars),' ',tab)
tagpart=''
RETURN 1
formathtml:
removechars=crlf
DO UNTIL (bufferlength=0 & datalength=0)
IF bufferlength<=textwidth & datalength>0 THEN DO
IF ~moredata() THEN RETURN 0
CALL htmltags
END
bufferlength=LENGTH(buffer)
breakpoint =POS(lf,buffer)
IF breakpoint>textwidth | (breakpoint=0 & bufferlength>textwidth) THEN DO
breakpoint=LASTPOS(' ',buffer,textwidth)
IF breakpoint=0 THEN breakpoint=textwidth
END
IF datalength=0 & breakpoint=0 & bufferlength<=textwidth THEN breakpoint=bufferlength
count =count+1
linelist.count=COMPRESS(SUBSTR(buffer,1,breakpoint),lf)
buffer =SUBSTR(buffer,breakpoint+1)
bufferlength =LENGTH(buffer)
END
RETURN 0
formattext:
removechars=cr
pagetitle ='plain text'
DO UNTIL (bufferlength=0 & datalength=0)
IF bufferlength<=textwidth & datalength>0 THEN DO
IF ~moredata() THEN RETURN 0
END
bufferlength=LENGTH(buffer)
breakpoint =POS(lf,buffer)
IF breakpoint>textwidth | (breakpoint=0 & bufferlength>textwidth) THEN DO
breakpoint=LASTPOS(' ',buffer,textwidth)
IF breakpoint=0 THEN breakpoint=textwidth
END
IF datalength=0 & breakpoint=0 & bufferlength<=textwidth THEN breakpoint=bufferlength
count =count+1
linelist.count=COMPRESS(SUBSTR(buffer,1,breakpoint),lf)
buffer =SUBSTR(buffer,breakpoint+1)
bufferlength =LENGTH(buffer)
END
RETURN 0
htmltags:
position=0
taglength=0
DO UNTIL position=0 | taglength<2; position=POS('&',buffer,position+1)
IF position>0 THEN DO; taglength=POS(';',buffer,position+1)-position+1
IF taglength>1 & taglength<10 THEN DO
tag =SUBSTR(buffer,position+1,taglength-2)
replacement='?'
SELECT
WHEN POS('#X',UPPER(tag)) THEN IF DATATYPE(SUBSTR(tag,3),'X') THEN replacement=X2C(SUBSTR(tag,3))
WHEN POS('#',UPPER(tag)) THEN IF DATATYPE(SUBSTR(tag,2),'N') THEN replacement=D2C(SUBSTR(tag,2))
OTHERWISE SELECT
WHEN tag='nbsp' THEN replacement=' '
WHEN tag='copy' THEN replacement='©'
WHEN tag='reg' THEN replacement='®'
WHEN tag='szlig' THEN replacement='ß'
WHEN tag='quot' THEN replacement='"'
WHEN tag='amp' THEN replacement='&'
WHEN tag='lt' THEN replacement='<'
WHEN tag='gt' THEN replacement='>'
WHEN tag='uuml' THEN replacement='ü'
WHEN tag='aring' THEN replacement='å'
WHEN tag='auml' THEN replacement='ä'
WHEN tag='ouml' THEN replacement='ö'
WHEN tag='Uuml' THEN replacement='Ü'
WHEN tag='Aring' THEN replacement='Å'
WHEN tag='Auml' THEN replacement='Ä'
WHEN tag='Ouml' THEN replacement='Ö'
OTHERWISE NOP
END
END
buffer=INSERT(replacement,DELSTR(buffer,position,taglength),position-1)
END
END
END
position =1
taglength=0
DO UNTIL position=0 | taglength<2
position=POS('<',buffer,position)
IF position>0 THEN DO
taglength=POS('>',buffer,position+1)-position+1
IF taglength>1 THEN DO
taghead =UPPER(WORD(SUBSTR(buffer,position+1,taglength-2),1))
tagname =COMPRESS(taghead,'/')
replacement=''
SELECT
WHEN taghead='BR' THEN replacement=lf
WHEN taghead='A' THEN replacement='{'
WHEN taghead='/A' THEN replacement='}'
WHEN taghead='P' THEN replacement=lf||lf
WHEN taghead='/P' THEN replacement=lf
WHEN taghead='HR' THEN replacement=lf'--------------------------------'lf
WHEN taghead='IMG' THEN DO
tag =SUBSTR(buffer,position+1,taglength-2)
alt =''
altpos=POS('ALT=',UPPER(tag))
IF altpos>0 THEN DO
altpos=altpos+4
PARSE VAR tag =altpos '"'alt1'"' =altpos "'"alt2"'"
alt=alt1||alt2
END
replacement='['alt']'
END
WHEN tagname='H1'|tagname='H2'|tagname='H3'|tagname='H4'|tagname='H5'|tagname='H6' THEN replacement=lf
WHEN taghead='TH'|taghead='TD'|taghead='DT'|taghead='/DL'|taghead='/OL'|taghead='/UL' THEN replacement=lf||lf
WHEN tagname='PRE'|tagname='DIV'|tagname='TABLE' THEN replacement=lf
WHEN taghead='DD' THEN replacement=' - '
WHEN taghead='LI' THEN replacement=lf||lf'* '
WHEN taghead='TITLE' THEN DO
titlelength=POS('</TITLE>',UPPER(buffer),position+taglength)-position-taglength
pagetitle =SUBSTR(buffer,position+taglength,titlelength)
taglength =taglength+titlelength+8
END
OTHERWISE NOP
END
IF replacement~='' THEN buffer=INSERT(replacement,DELSTR(buffer,position,taglength),position-1)
ELSE buffer=DELSTR(buffer,position,taglength)
END
ELSE DO
tagpart=SUBSTR(buffer,position)
buffer =DELSTR(buffer,position)
END
END
END
RETURN 0