home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / wcst2url.zip / HTMLBuilder.cmd < prev    next >
OS/2 REXX Batch file  |  1998-01-01  |  12KB  |  367 lines

  1. /*
  2.  *
  3.  * HTMLBuilder v1.0 - (c) 1997
  4.  * Create an HTML file out of WarpCast URLs created by createURL.cmd
  5.  *
  6.  * G.Aprile A.Resmini P.Rossi
  7.  * resmini@netsis.it
  8.  *
  9.  * Needless to say, this is absolutely FREEWARE, comes with no
  10.  * warranties whatsoever, and does not work in Windows.
  11.  * Actually, you would need some 10MBs program to do this, in Windows.
  12.  * ;)
  13.  *
  14.  * G.Aprile and A.Resmini are members of teamOS2 Italy
  15.  *
  16.  * This Rexx procedure creates a simple HTML file which keeps track of
  17.  * Warpcast URLs. The HTML source code uses no frames.
  18.  * 
  19.  * URLs are tracked and assigned a NORMAL, NEW or UPDATED state.
  20.  * As a default an URL becomes NORMAL if 7 days pass without it being
  21.  * updated. You can set this value changing the ExpireDate variable.
  22.  * An URL is NEW if it has never been broadcasted before.
  23.  * NEW and UPDATED URLs are assigned corresponding icons, while NORMAL
  24.  * URLs have no distinctive sign.
  25.  * You can set your preferred images for the NEW or UPDATED status by
  26.  * changing the newJPG and updJPG variables, or by overwriting the
  27.  * new.jpg and upd.jpg in the HTMLBuilder folder.
  28.  *
  29.  * You will need the FILEREXX rexx extensions, available on Hobbes as
  30.  * filerx.zip (should be in the \rexx directory)
  31.  *
  32.  */
  33.  
  34.     call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  35.     call SysLoadFuncs
  36.     call RxFuncAdd 'FileLoadFuncs', 'FILEREXX', 'FileLoadFuncs'
  37.     call FileLoadFuncs
  38.  
  39.  /* Set a bunch of variables and explain them */
  40.  
  41.  /*
  42.   * This is the amount of time after which an URL which is not updated
  43.   * is set to normal status.
  44.   */
  45.  
  46.     ExpireDate = 7
  47.  
  48.  /*
  49.   * Set the images used in the HTML file for signalling a NEW or UPDATED
  50.   * link. The double quotes are used for writing it in HTML style,
  51.   * <img src = "new.jpg ">
  52.   */
  53.    
  54.     newJPG = '"new.jpg"'
  55.     updJPG = '"upd.jpg"'
  56.  
  57.  
  58.  /*
  59.   * This is the data file created by createURL.cmd.
  60.   * If you change this, change it in both files.
  61.   */
  62.  
  63.     NameDat = 'wcastidx.dtf'
  64.  
  65.  /*
  66.   * A dat file which holds all of your URLs from Warpcast.
  67.   * This is the main archive. If you delete it, you loose track of what
  68.   * is new and what is not.
  69.   */
  70.  
  71.     HTMLDat = 'warpcast.dtf'
  72.  
  73.  /* The HTML file */
  74.  
  75.     nameHTML = 'warpcast.html'
  76.  
  77.  /* Handles. Just leave them alone. */
  78.  
  79.     handle.0 = 3
  80.     handle.1 = 0
  81.     handle.2 = 0
  82.     handle.3 = 0
  83.  
  84.     handle.1 = FileOpen(NameDat,'rw','e')
  85.     if handle.1 = 0 then
  86.      do
  87.        if FileClose(handle.1) = 0 then handle.1 = 0
  88.        say 'Wow, an OS error while creating the file ' || NameDat
  89.      end
  90.      dateUpdated = FileGets(handle.1,'t')
  91.      nDateControlExpire = DateToNumber(dateUpdated)
  92.      nCount = 0
  93.      do while FileErr <> 0
  94.         err = FileGets(handle.1,'t')
  95.         if FileErr <> 0 then
  96.            do
  97.            nCount = nCount + 1
  98.            aDatiWCast.nCount.Titolo = err
  99.            aDatiWCast.nCount.Url = FileGets(handle.1,'t')
  100.            aDatiWCast.nCount.Flag = FileGets(handle.1,'t')
  101.            end
  102.      end
  103.  
  104.         aDatiWCast.0 = nCount
  105.  
  106.     if FileClose(handle.1) = 0 then handle.1 = 0
  107.  
  108.     handle.2 = FileOpen(HTMLDat,'rw','en')
  109.     if handle.2 = 0 then
  110.      do
  111.        if FileClose(handle.2) = 0 then handle.2 = 0
  112.        say 'Wow, an OS error while creating the file ' || HTMLDat
  113.      end
  114.  
  115.      dateUpdatedHtml = FileGets(handle.2,'t')
  116.      nCount = 0
  117.      do while FileErr <> 0
  118.         err = FileGets(handle.2,'t')
  119.         if FileErr <> 0 then
  120.            do
  121.                 nCount = nCount+1
  122.                 aDatiHtml.nCount.Titolo = err
  123.                 aDatiHtml.nCount.Url = FileGets(handle.2,'t')
  124.                 aDatiHtml.nCount.Data = FileGets(handle.2,'t')
  125.                 aDatiHtml.nCount.Flag = FileGets(handle.2,'t')
  126.                 if  nDateControlExpire - DateToNumber(aDatiHtml.nCount.Data) >= ExpireDate then
  127.                     do
  128.                      aDatiHtml.nCount.Flag = 'Normal'
  129.                     end
  130.            end
  131.      end
  132.         aDatiHtml.0 = nCount
  133.  
  134.        if FileClose(handle.2) = 0 then handle.2 = 0
  135.  
  136.  /* Start first loop */
  137.  
  138.        do wcast = 1 to aDatiWCast.0
  139.           Matching = 0
  140.  
  141.  /* Start second loop */
  142.  
  143.        do wHtml = 1 to aDatiHtml.0
  144.  
  145.            if aDatiWCast.wcast.Url = aDatiHtml.wHtml.Url then
  146.               do
  147.                 aDatiHtml.wHtml.Data = dateUpdated
  148.                 aDatiHtml.wHtml.Flag = aDatiWCast.wcast.Flag
  149.                 Matching = 1
  150.               end
  151.        end
  152.  
  153.  /* End second loop */
  154.  
  155.          if Matching = 0 Then
  156.  
  157.             do
  158.              aDatiHtml.0 = aDatiHtml.0 + 1
  159.              nTemp = aDatiHtml.0
  160.              aDatiHtml.nTemp.Titolo = aDatiWCast.wCast.Titolo
  161.              aDatiHtml.nTemp.Url = aDatiWCast.wCast.Url
  162.              aDatiHtml.nTemp.Data = dateUpdated
  163.              aDatiHtml.nTemp.Flag = aDatiWCast.wCast.Flag
  164.             end
  165.  
  166.        end
  167.  
  168.  /* End first loop */
  169.  
  170.     handle.2 = FileOpen(HTMLDat,'rw','on')
  171.     if handle.2 = 0 then
  172.      do
  173.        if FileClose(handle.2) = 0 then handle.2 = 0
  174.        say 'Wow, an OS error while creating the file ' || HTMLDat
  175.      end
  176.      err = Fileputs(handle.2,dateupdated)
  177.  
  178.           do wHtml = 1 to aDatiHtml.0
  179.  
  180.            err=FilePuts(handle.2, aDatiHtml.wHtml.Titolo)
  181.            err=FilePuts(handle.2, aDatiHtml.wHtml.Url)
  182.            err=FilePuts(handle.2, aDatiHtml.wHtml.Data)
  183.            err=FilePuts(handle.2, aDatiHtml.wHtml.Flag)
  184.  
  185.           end
  186.  
  187.        if FileClose(handle.2) = 0 then handle.2 = 0
  188.  
  189.         Call Sort
  190.     handle.3 = FileOpen(nameHTML,'rw','on')
  191.     if handle.3 = 0 then
  192.      do
  193.        if FileClose(handle.3) = 0 then handle.3 = 0
  194.        say 'Wow, an OS error while creating the file ' || nameHTML
  195.      end
  196.  
  197.  /*
  198.   * Now let's start writing something which resembles HTML code
  199.   * into the file.
  200.   */
  201.  
  202.   err=FilePuts(handle.3,'<!-- doctype html public "-//wc3//dtd html 3.2//en" -->')
  203.   err=FilePuts(handle.3,'<!-- document ' || nameHTML || ' created on ' || dateUpdated || '  -->' )
  204.   err=FilePuts(handle.3,'')
  205.   err=FilePuts(handle.3,'<html>')
  206.   err=FilePuts(handle.3,'  <head>')
  207.   err=FilePuts(handle.3,'    <meta name="generator" content="HTMLBuilder v1.0">')
  208.   err=FilePuts(handle.3,'    <title>WarpCast New and Updated Links for ' || dateUpdated || '</title>')
  209.   err=FilePuts(handle.3,'  </head>')
  210.   err=FilePuts(handle.3,'')
  211.   err=FilePuts(handle.3,'  <!-- body of the HTML document begins -->')
  212.   err=FilePuts(handle.3,'')
  213.   err=FilePuts(handle.3,'  <body text="#000000" bgcolor="#ffffff" link="#0000cc" vlink="#970000" alink="#00a000">')
  214.   err=FilePuts(handle.3,'')
  215.   err=FilePuts(handle.3,'  <center>')
  216.   err=FilePuts(handle.3,'    <img src="wcast.jpg">')
  217.   err=FilePuts(handle.3,'  </center>')
  218.   err=FilePuts(handle.3,'')
  219.   err=FilePuts(handle.3,'  <table>')
  220.  
  221.           do wHtml = 1 to aDatiHtml.0
  222.                   err=FilePuts(handle.3,'   <tr>')
  223.  
  224.               Select
  225.                  When aDatiHtml.wHtml.Flag = 'UpDated' then
  226.                    do
  227.                     err=FilePuts(handle.3,'     <td width = "20%">')
  228.                     err=FilePuts(handle.3,'       <img src= ' || updJPG || ' >')
  229.                     err=FilePuts(handle.3,'     </td>')
  230.                    End
  231.                  When aDatiHtml.wHtml.Flag = 'New' then
  232.                    do
  233.                     err=FilePuts(handle.3,'     <td width = "20%">')
  234.                     err=FilePuts(handle.3,'       <img src= ' || newJPG || ' >')
  235.                     err=FilePuts(handle.3,'     </td>')
  236.                    End
  237.                   Otherwise
  238.                    do
  239.                     err=FilePuts(handle.3,'     <td width = "20%">')
  240.                     err=FilePuts(handle.3,'')
  241.                     err=FilePuts(handle.3,'     </td>')
  242.                    End
  243.               End
  244.                 err=FilePuts(handle.3,'     <td width = "80%" valign="top">' )
  245.                 err=FilePuts(handle.3,'       <font color="#880000">')
  246.                 err=FilePuts(handle.3,'         <h3><a href="' || aDatiHtml.wHtml.Url || '">' || aDatiHtml.wHtml.Titolo || '</a><br>')
  247.                 err=FilePuts(handle.3,'         Last updated ' || aDatiHtml.wHtml.Data || '<br>')
  248.                 err=FilePuts(handle.3,'       </font>')
  249.                 err=FilePuts(handle.3,'       <p>')
  250.                 err=FilePuts(handle.3,'     </td>')
  251.                 err=FilePuts(handle.3,'   </tr>')
  252.           end
  253.  
  254.   err=FilePuts(handle.3,' </table>')
  255.   err=FilePuts(handle.3,'')
  256.   err=FilePuts(handle.3,'  <pre>')
  257.   err=FilePuts(handle.3,'  </pre>')
  258.   err=FilePuts(handle.3,'')
  259.   err=FilePuts(handle.3,'  <center>')
  260.   err=FilePuts(handle.3,'    <font size="-1">')
  261.   err=FilePuts(handle.3,'      WarpCast New and Updated links - ' || date('L') || '<br>')
  262.   err=FilePuts(handle.3,'      Created by HTMLBuilder v1.0 - December 1997<br>')
  263.   err=FilePuts(handle.3,'    </font>')
  264.   err=FilePuts(handle.3,'  </center>')
  265.   err=FilePuts(handle.3,'')
  266.   err=FilePuts(handle.3,'  </body>')
  267.   err=FilePuts(handle.3,'')
  268.   err=FilePuts(handle.3,'  <!-- body of the HTML document ends -->')
  269.   err=FilePuts(handle.3,'')
  270.   err=FilePuts(handle.3,'</html>')
  271.  
  272.        if FileClose(handle.3) = 0 then handle.3 = 0
  273.  
  274.  /*
  275.   * Bonus: create an object for the Warpcast HTML file so you can drag it
  276.   * on Netscape/2 or WebExplorer or whatever.
  277.   *
  278.   * This instruction was used when we were about to create an URL for it. 
  279.   * dir = translate( directory() || '/', '|/', ':\')
  280.   * Now it's just shadowed. :)
  281.   */
  282.  
  283.    dir = directory() || '\'
  284.  
  285.    classname = 'WPShadow' 
  286.    title = 'Warpcast links'
  287.    location = '<WP_DESKTOP>'
  288.    setup = 'SHADOWID =' || dir || nameHTML
  289.    flag = 'U'
  290.  
  291.    rc = SysCreateObject(classname, title, location, setup, flag)
  292.  
  293.  
  294.  /*
  295.   * This is stolen directly from the Allfigures.txt in the rexxwps.zip
  296.   * package you can find as usual on Hobbes. Straight from the original txt:
  297.   *
  298.   * "What follows, is a *complete* ASCII-list of the figures I submitted
  299.   * Miller & Freeman (producer of "OS/2 Developer") together with my article
  300.   * for this year's "REXX Report, Summer '95", September 95).  So it includes
  301.   * also the tables for all documented keyword/value pairs of the discussed
  302.   * WPS object classes."
  303.   *
  304.   * The author is Rony G. Flatscher and the file is an ASCII version of his
  305.   * article 'The Workplace Shell: Objects to the Core'.
  306.   * We are using here just a sort function, but the file contains lots of
  307.   * interesting examples and infos.
  308.   *
  309.   * 'One of Knuth's algorithms; sort object classes in stem ObjCls.'
  310.   */
  311.  
  312.   Sort:
  313.  
  314.    M = 1
  315.    DO WHILE (9 * M + 4) < aDatiHtml.0
  316.       M = M * 3 + 1
  317.    END
  318.  
  319.    DO WHILE M > 0
  320.       K = aDatiHtml.0 - M
  321.       DO J = 1 TO K
  322.          Q = J
  323.          DO WHILE Q > 0
  324.             L = Q + M
  325.  
  326.             IF TRANSLATE(aDatiHtml.Q.Titolo) <<= TRANSLATE(aDatiHtml.L.Titolo) THEN
  327.                LEAVE
  328.             tmp      = aDatiHtml.Q.Titolo
  329.             aDatiHtml.Q.Titolo = aDatiHtml.L.Titolo
  330.             aDatiHtml.L.Titolo = tmp
  331.             Q = Q - M
  332.          END
  333.       END
  334.       M = M % 3
  335.    END
  336.    RETURN
  337.  
  338.  
  339.  /*
  340.   * This function handles the string => date translations we need,
  341.   * since we have dates in 'Mon, 15 Dec 1997' format.
  342.   */
  343.  
  344.   DateToNumber:
  345.  
  346.    parse arg dDate
  347.    parse var dDate cTemp.1 cTemp.2 cTemp.3 cTemp.4
  348.  
  349.    Select
  350.     when cTemp.3 = 'Jan' then cTemp.3 = 1
  351.     when cTemp.3 = 'Feb' then cTemp.3 = 2
  352.     when cTemp.3 = 'Mar' then cTemp.3 = 3
  353.     when cTemp.3 = 'Apr' then cTemp.3 = 4
  354.     when cTemp.3 = 'May' then cTemp.3 = 5
  355.     when cTemp.3 = 'Jun' then cTemp.3 = 6
  356.     when cTemp.3 = 'Jul' then cTemp.3 = 7
  357.     when cTemp.3 = 'Aug' then cTemp.3 = 8
  358.     when cTemp.3 = 'Sep' then cTemp.3 = 9
  359.     when cTemp.3 = 'Oct' then cTemp.3 = 10
  360.     when cTemp.3 = 'Nov' then cTemp.3 = 11
  361.     when cTemp.3 = 'Dec' then cTemp.3 = 12
  362.    End
  363.  
  364.   nDays = cTemp.2 + cTemp.3*30 + cTemp.4 * 365
  365.  
  366.   Return nDays
  367.