/* $VER: HTTXPlugin 3.0 (15.8.99) by Gabriele Favrin Convert current document to text using HTTX */ options results options failat 999 if ~Show('L', 'rexxsupport.library') then do call addlib('rexxsupport.library', 0, -30, 0) end parse ARG mode mode_data . parse SOURCE . . . resolved . plugin_path=FindPath(resolved) prefs_info=0 prefs_preview=0 prefs_report=1 prefs_savedir="ram:" prefs_donotaskdir=0 prefs_save_noheader=0 prefs_print_noheader=0 prefs_temppath="T:" req_title = '"Save as text"' temp_out = prefs_temppath"temp_HTTXP_Output.txt" temp_name = prefs_temppath"temp_HTTXP_file" temp_inc = prefs_temppath"temp_HTTXP_header" del_list = '"'prefs_temppath'temp_HTTXP_#?"' eol = '0A'x trg = "" force = "" append = "" string = "" option = "" converted = 0 Call ReadCfg() if (mode == "TARGET") then do trg="TARGET" mode_data end 'Get URL VAR' doc_url trg if rc ~= 0 then do 'Request 'req_title' "No document displayed, save aborted." "_Ok"' exit 0 end 'Get TITLE VAR' doc_title trg 'Get FRAMES ALL' trg 'STEM' frms if (frms.0 = 0) then do if getName() == 1 then do Call SaveHTML() Call Convert() Call CleanUp(1) end end else do prefs_report=0 'Request 'req_title' "Selected document contains frames." "Convert _All|_Select frame(s)|_Cancel"' if rc == 5 then exit 0 option=result if option == 1 then do if ~getName() then do exit 0 end end do ct=0 for (frms.0)+1 if ct > 0 then do doc_url=frms.ct.url doc_title=frms.ct.name trg="TARGET" frms.ct.id end if option == 1 then do 'Get FRAMESET' trg if (result == 0) then do if converted then do drop append string=eol||"----"||eol end Call SaveHTML() Call Convert() Call CleanUp(0) end end else do 'Open "'doc_url'"' 'Wait "'doc_url'"' 'Get FRAMESET' if (result == 0) then do 'Request 'req_title' "Convert this document?" "_Yes|_No|_Cancel"' if (rc == 5) then do Call CleanUp(1) if (ct > 0) then do 'GO' ct 'BACK' end exit 0 end if result == 1 then do trg="" string="" if getName() == 1 then do Call SaveHTML() Call Convert() Call CleanUp(0) end end end end end if option == 1 then do if (prefs_preview == 1) then do if (Preview() == 1) then do Call DisplayOutput() end end else do Call DisplayOutput() end Call CleanUp(1) end else do if (option == 2) & (ct > 0) then do 'GO' ct-1 'BACK' end Call CleanUp(1) end end exit 0 CleanUp: parse ARG mode_all address command 'C:Delete >NIL: QUIET' del_list if mode_all == 1 then do local_savedir=FindPath(save_file) if prefs_savedir ~= local_savedir then do prefs_savedir=local_savedir address REXX setclip('HTTXPlugin_savedir', prefs_savedir) end end return SaveHTML: 'SaveAs "'temp_name'" NOICON' trg if (rc ~= 0) then do 'Request 'req_title' "Error while saving HTML on temporary path*N *N'prefs_temppath'" "_Ok" NOWAIT' exit 0 end return GetName: html_name=Translate(doc_url,,'`~"=#?/:;\*%()[]<>'||"'") html_name=Word(html_name, Words(html_name)) ext=lastpos('.', html_name) if ext > 0 then html_name=left(html_name, ext)'txt' else html_name=html_name'.txt' if prefs_donotaskdir = 0 then do 'RequestFile 'req_title' FILE="'prefs_savedir||html_name'" SAVEMODE' if (rc == 5) then return 0 save_file=result if (Right(save_file, 1) == ":") | (Right(save_file, 1) == "/") then save_file=save_file||html_name end else save_file=prefs_savedir||html_name html_name=prefs_temppath||html_name return 1 Convert: 'Get MIME VAR' mtype trg if (Upper(mtype) == "TEXT/HTML") then do drop force end else do force="" end Call PrepareFile() res=httx() if (res == 212) then do 'Request 'req_title' "File is not HTML, save anyway?" "_Save|_Cancel"' if (rc ~= 5) then do address command 'C:Copy "'temp_name'" "'save_file'"' prefs_report=0 res=0 Call DisplayOutput() end end else do if option ~= 1 then do if (res ~= 0) then do del_list=del_list '"'save_file'"' if option ~= 2 then do Call DisplayOutput() end end else do if prefs_preview == 1 then do if Preview() == 1 then do if option ~= 2 then do Call DisplayOutput() end end end else do if option ~= 2 then do Call DisplayOutput() end end end end end converted=1 return httx: address command '"'plugin_path'HTTX" >"'temp_out'" "'temp_name'" "'save_file'" INCLUDE="'temp_inc'" NOHEADER GETNOTE' force append return rc DisplayOutput: if (prefs_report == 1) then do 'Open "file:///'temp_out'" RELOAD' 'Wait "file:///'temp_out'"' end else do if (res ~= 0) then do address command 'sys:rexxc/rxset HTTXPlugin_fault `fault' res'`' err=getclip(HTTXPlugin_fault) 'Request 'req_title' "Error 'err'" "_Ok" NOWAIT' end end return Preview: 'Get SCREEN VAR' prefs_screen address command 'SYS:Utilities/Multiview "'save_file'" pubscreen="'prefs_screen'"' drop result if prefs_donotaskdir = 0 then 'Request 'req_title' "File converted." "_Ok (save)|_Delete file"' else 'Request 'req_title' "File converted.*NSave as *"'save_file'*" ?" "_Ok (save)|_Delete file"' if (result ~= 1) then do del_list=del_list '"'save_file'"' end return result PrepareFile: if Open(fp, temp_inc, 'W') then do if (prefs_save_noheader == 0) then do if (prefs_info == 1) then do 'Get INFO STEM' infos trg if (infos.0 > 0) then do string=string||eol||"Header:"||eol do ctx=1 for infos.0 if (infos.ctx.type ~= "CACHE") then do string=string||infos.ctx.value||eol if infos.ctx.type == "LINK" then string=string||eol||infos.ctx.url end end end end string=string||eol||'URL : 'doc_url||eol'Title: 'doc_title end WriteCH(fp, string) Call Close(fp) end return ReadCfg: if Open(rcfg_fp, 'ENV:HTTXPlugin.config', 'R') then do cfg=ReadLN(rcfg_fp) if Left(cfg, 6) == "prefs_" then do interpret translate(strip(cfg), ';',' ') prefs_savedir=Translate(prefs_savedir, ' ', ';') end Call Close(rcfg_fp) end if prefs_donotaskdir = 0 then do prefs_savedir2=getclip('HTTXPlugin_savedir') if prefs_savedir2 ~= "" then prefs_savedir=prefs_savedir2 end return FindPath: procedure parse ARG pathf dir_pos=Max(lastpos('/', pathf), lastpos(':', pathf)) if dir_pos > 0 then do return(left(pathf,dir_pos)) end else do return('') end