*+JMJ_---^---------^---------^---------^---------^---------^---------^--
* twgidx - Generate blog-like index.html file for TWOG directory
* Copyright 2014 David Meyer <papa@twenex.org>

      program twgidx

      character twgdir*14, filist*15, indxht*10, dirlin*132, prevdt*10
      integer extpos

      twgdir = 'PAPA.HTML.TWOG'         ! TWOG directory on twenex.org
      filist = 'DIRECTORY.FILES'        ! @DIRECTORY file list
      indxht = 'INDEX.HTML'             ! HTML index output file
      open(20, directory=twgdir, file=filist)
      open(21, directory=twgdir, file=indxht)
      call hthead

100   read(20,110, end=900) dirlin
110      format(a132)
         extpos = index(dirlin, '.TXT.') ! Position of extension ".TXT"
                                         !  in file name
         if (dirlin(2:2) .ne. ' ' .and. extpos .gt. 0) then
            call artfil(twgdir, dirlin(2:extpos + 3), prevdt)
         end if
         go to 100
900   continue

      call htfoot
      close(20)
      close(21)

      stop
      end


* artfil - Read title and date from named file to generate article link 

      subroutine artfil (fildir, filnam, prevdt)

      character*(*) fildir, filnam, prevdt
      character*80 artitl, datlin, arttxt(4), filler, artdat*10
      integer i, trimrt

      open(22, directory=fildir, file=filnam)
      read(22,110) artitl, filler, datlin, filler, arttxt
110   format(a80)
      close(22)
      artdat = datlin(7:16)
      if (artdat .ne. prevdt) then
         write(21,120) artdat
120      format(' <h2>',a10,'</h2>')
         prevdt = artdat
      end if
      write(21,140) filnam, artitl, arttxt, filnam
140   format('<h3><a href="',a,'">',a,'</a></h3>'/'<blockquote>'/
     +a/a/a/a/'<a href="',a,'">...</a></blockquote>')

      return
      end


* hthead - Output HTML file header section

      subroutine hthead

      write(21,10)
10    format('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ',
     +'"http://www.w3.org/TR/html4/strict.dtd">'/
     +'<html><head><title>TWOG - The Twenex Log</title>'/
     +'<link rel="stylesheet" type="text/css" ',
     +'href="http://papa.sdf.org/style/retrogreen.css">',
     +'<link rel="stylesheet" type="text/css" ',
     +'href="http://papa.sdf.org/style/twog.css">',
     +'</head><body>'/
     +'<h1>TWOG - The Twenex Log</h1>',
     +'<p style="text-align: center">',
     +'<a href="INDEX.HTML">HOME</a> ',
     +'<a href="/~PAPA">PAPA''S CAVE</a> ',
     +'<a href="ATOM.XML">SUBSCRIBE</a> ',
     +'<a href="ABOUT.HTML">ABOUT</a> ',
     +'<a href="CONTACT.HTML">CONTACT</a></p>'/
     +'<p>Comments and questions are welcome via the ',
     +'<a href="CONTACT.HTML">CONTACT</a> form.</p>')

      return
      end


* htfoot - Output HTML file footer section
      
      subroutine htfoot

      write(21,10)
10    format('<div class="divider"><p>Powered by: ',
     +'<a href="http://sdf.org">SDF Public Access UNIX</a></p>'/
     +'<p class="centered">+JMJ</p></div></body></html>')

      return
      end


* trimrt - Return position of last non-space character in string

      integer function trimrt(string, maxlen)

      character*(*) string
      integer maxlen, i

      i = maxlen
100   if (i .gt. 1 .and. string(i:i) .eq. ' ') then
         i = i - 1
         go to 100
      endif
      if (string(i:i) .eq. ' ') then
         trimrt = 0
      else
         trimrt = i
      endif

      return
      end

      
*+JMJ_---^---------^---------^---------^---------^---------^---------^--