home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Internet / AWeb / Plugins / HTTX / HTTXPluginPRT.awebrx < prev   
Text File  |  1999-10-02  |  4KB  |  239 lines

  1. /*
  2.     $VER: HTTXPluginPRT 3.0 (14.8.99) by Gabriele Favrin
  3.     Print current document as text using HTTX
  4. */
  5.  
  6. options results
  7. options Failat 999
  8.  
  9. if ~Show('L', 'rexxsupport.library') then do
  10.     call addlib('rexxsupport.library', 0, -30, 0)      
  11. end
  12.  
  13. parse ARG mode mode_data .
  14. parse SOURCE . . . resolved .
  15.  
  16. plugin_path=FindPath(resolved)
  17. prefs_info=0
  18. prefs_report=1
  19. prefs_save_noheader=0
  20. prefs_print_noheader=0
  21. prefs_temppath="T:"
  22.  
  23. req_title = '"Print as text"'
  24. temp_out     = prefs_temppath"temp_HTTXP_Output.txt"
  25. temp_name = prefs_temppath"temp_HTTXP_file"
  26. temp_inc  = prefs_temppath"temp_HTTXP_header"
  27. del_list     = '"'prefs_temppath'temp_HTTXP_#?"'
  28. eol         = '0A'x
  29. trg         = ""
  30. force         = ""
  31. string     = ""
  32. option     = ""
  33. append     = ""
  34. converted = 0
  35.  
  36. Call ReadCfg()
  37.  
  38. if (mode == "TARGET") then do
  39.     trg="TARGET" mode_data
  40. end
  41.  
  42. 'Get URL VAR' doc_url trg
  43. if rc ~= 0 then do
  44.     'Request 'req_title' "No document displayed, save aborted." "_Ok"'
  45.     exit 0
  46. end
  47.  
  48. 'Get TITLE VAR' doc_title trg
  49. 'Get FRAMES ALL' trg 'STEM' frms
  50.  
  51. if (frms.0 = 0) then do
  52.     Call SaveHTML()
  53.     Call Convert()
  54.     Call CleanUp()
  55. end
  56. else do
  57.     prefs_report=0
  58.  
  59.     'Request' req_title '"Selected document contains frames." "Convert _All|_Select frame(s)|_Cancel"'
  60.     if rc == 5 then exit 0
  61.     option=result
  62.  
  63.     do ct=0 for (frms.0)+1
  64.         if ct > 0 then do
  65.             doc_url=frms.ct.url
  66.             doc_title=frms.ct.name
  67.             trg="TARGET="frms.ct.id
  68.         end
  69.  
  70.         if option == 1 then do
  71.             'Get FRAMESET' trg
  72.             if (result == 0) then do
  73.                 if converted then do
  74.                     drop append
  75.                     string=eol||"----"||eol
  76.                 end
  77.  
  78.                 Call SaveHTML()
  79.                 Call Convert()
  80.                 Call CleanUp()
  81.             end
  82.         end
  83.         else do
  84.             'Open "'doc_url'"'
  85.             'Wait "'doc_url'"'
  86.  
  87.             'Get FRAMESET'
  88.             if (result == 0) then do
  89.                 'Request' req_title '"Convert this document?" "_Yes|_No|_Cancel"'
  90.                 if (rc == 5) then do
  91.                     Call CleanUp()
  92.                     if (ct > 0) then do
  93.                         'GO' ct 'BACK'
  94.                     end
  95.                     exit 0
  96.                 end
  97.  
  98.                 if result == 1 then do
  99.                     trg=""
  100.                     string=""
  101.                     Call SaveHTML()
  102.                     Call Convert()
  103.                     Call CleanUp()
  104.                 end
  105.             end
  106.         end
  107.     end
  108.  
  109.     if option == 1 then do
  110.         Call displayOutput()
  111.         Call CleanUp()
  112.     end
  113.     else do
  114.         if (option == 2) & (ct > 0) then do
  115.             'GO' ct 'BACK'
  116.         end
  117.         Call CleanUp()
  118.     end
  119. end
  120.  
  121. exit 0
  122.  
  123.  
  124. CleanUp:
  125.     address command 'C:Delete >NIL: QUIET' del_list
  126.     return
  127.  
  128.  
  129. SaveHTML:
  130.     'SaveAs "'temp_name'" NOICON' trg
  131.     if (rc ~= 0) then do
  132.         'Request 'req_title' "Error while saving HTML on temporary path*N *N'prefs_temppath'" "_Ok" NOWAIT'
  133.         exit 0
  134.     end
  135.     return
  136.  
  137.  
  138. Convert:
  139.     'Get MIME VAR' mtype trg
  140.     if (Upper(mtype) == "TEXT/HTML") then do
  141.         drop force
  142.     end
  143.     else do
  144.         force=""
  145.     end
  146.  
  147.     Call PrepareFile()
  148.  
  149.     res=httx()
  150.     if (res == 212) then do
  151.         'Request 'req_title' "File is not HTML, print anyway?" "_Print|_Cancel"'
  152.  
  153.         if (rc ~= 5) then do
  154.             address command 'C:Copy "'temp_name'" "PRT:"'
  155.             prefs_report=0
  156.             res=0
  157.             Call displayOutput()
  158.         end
  159.     end
  160.     else do
  161.         if option == "" then do
  162.             Call displayOutput()
  163.         end
  164.     end
  165.     converted=1
  166.     return
  167.  
  168.  
  169. httx:
  170.     address command '"'plugin_path'HTTX" >"'temp_out'" "'temp_name'" PRINT NOHEADER GETNOTE CFG=HTTXprt.prefs INCLUDE="'temp_inc'"' force append
  171.     return rc
  172.  
  173.  
  174. DisplayOutput:
  175.     if (prefs_report == 1) then do
  176.         'Open "file:///'temp_out'" RELOAD'
  177.         'Wait "file:///'temp_out'"'
  178.     end
  179.     else do
  180.         if (res ~= 0) then do
  181.             address command 'sys:rexxc/rxset HTTXPlugin_fault `fault' res'`'
  182.             err=getclip(HTTXPlugin_fault)
  183.             'Request 'req_title' "Error 'err'" "_Ok" NOWAIT'
  184.         end
  185.     end
  186.     return
  187.  
  188.  
  189. PrepareFile:
  190.     if Open(fp, temp_inc, 'W') then do
  191.         if (prefs_save_noheader == 0) then do
  192.             if (prefs_info == 1) then do
  193.                 'Get INFO STEM' infos trg
  194.                 if (infos.0 > 0) then do
  195.                     string=string||eol||"Header:"||eol
  196.  
  197.                     do ctx=1 for infos.0
  198.                         if (infos.ctx.type ~= "CACHE") then do
  199.                             string=string||infos.ctx.value||eol
  200.                             if infos.ctx.type == "LINK" then string=string||eol||infos.ctx.url
  201.                         end
  202.                     end
  203.                 end
  204.             end
  205.  
  206.             string=string||eol||'URL  : 'doc_url||eol'Title: 'doc_title
  207.         end
  208.  
  209.         WriteCH(fp, string)
  210.         Call Close(fp)
  211.     end
  212.     return
  213.  
  214.  
  215. ReadCfg:
  216.     if Open(rcfg_fp, 'ENV:HTTXPlugin.config', 'R') then do
  217.         cfg=ReadLN(rcfg_fp)
  218.  
  219.         if Left(cfg, 6) == "prefs_" then do
  220.             interpret translate(strip(cfg), ';',' ')
  221.             prefs_savedir=Translate(prefs_savedir, ' ', ';')
  222.         end
  223.  
  224.         Call Close(rcfg_fp)
  225.     end
  226.  
  227.  
  228. FindPath:
  229.     procedure
  230.  
  231.     parse ARG pathf
  232.     dir_pos=Max(lastpos('/', pathf), lastpos(':', pathf))
  233.     if dir_pos > 0    then do
  234.         return(left(pathf,dir_pos))
  235.     end
  236.     else do
  237.         return('')
  238.     end
  239.