#!/usr/pkg/bin/rexx /*-----------------------------------------------------------------------------+ | Program name: | | | | Subject: home pages maker | | | | File name: 0_make_html_page.rexx | | | | Note: Checked with Regina Rexx and Open Object Rexx | | | | Category: Freeware, BSD Licenced | | | | Copyright (C) by Przemysław Pawełczyk Cracow, April 2007 | | E-Mail: pp_o2@o2.pl | | P2O2 WWW: http://pp.kv.net.pl | +-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------+ | VARIABLES | +-----------------------------------------------------------------------------*/ /* File2Read1 = 'index.tmpl' File2Read2 = '00_html_page.templ' File2Write = 'index.html' */ parse arg ArgFile /*---------------------------------------------------------+ | If no argument show Helper and exit | +---------------------------------------------------------*/ if ArgFile = "" then call Helper parse var ArgFile ArgFileName"."ArgFileExt ArgFileName = strip(ArgFileName) File2Read2 = '00_html_page.templ' File2Read1 = ArgFileName'.tmpl' File2Write = ArgFileName'.html' /*---------------------------------------------------------+ | Defining date | +---------------------------------------------------------*/ dateStr = date('N') parse var dateStr dayStr monStr yearStr /*---------------------------------------------------------+ | End of line character | +---------------------------------------------------------*/ _LF = x2c('0a') /*---------------------------------------------------------+ | Defining number of variables and lists | | TypeNo Stem keeps indexes for List Stems | +---------------------------------------------------------*/ ok = stream(File2Read2, 'c','open read') /* Opening File2Read */ File2Read2_Size = stream(File2Read2, "c", "query size") File2Read2_Tmp = charin(File2Read2, 1, File2Read2_Size) File2Read2_VarNo = countstr("Qvar_" , File2Read2_Tmp) File2Read2_ListNo = countstr("Qlist_", File2Read2_Tmp) File2Read2_TypeNo = countstr("Qltype", File2Read2_Tmp) ok = stream(File2Read2, 'c','close') /* Closing File2Read */ /*---------------------------------------------------------+ | We will read variables from file.tmpl file | | to following compound variables (stems): | +---------------------------------------------------------*/ VarStem. = "" /* Variable Stem */ i_var = 1 TypeStem. = "" /* List Type Stem */ i_type = 1 do i = 1 to File2Read2_ListNo ListStem.i. = "" /* List Stems */ i_list.i = 1 end /*-----------------------------------------------------------------------------+ | >>>>>>>>>>>>>>>>>>>>>>>>> Main program body <<<<<<<<<<<<<<<<<<<<<<<<<<<<< | +-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------+ | File to FileStem - linein way | +-----------------------------------------------------------------------------*/ FileStem. = "" ok = stream(File2Read1, 'c','open read') /* Opening File2Read */ i = 1 do while lines(File2Read1) > 0 /* If File2Read contains lines */ FileStem.i = linein(File2Read1) /* then read them in FileStem */ FileStem.i = strip(FileStem.i) First1Char = substr(FileStem.i, 1, 1) /* selecting comment lines */ First5Chars = substr(FileStem.i, 1, 5) /* "$var_" and "$list" */ First6Chars = substr(FileStem.i, 1, 6) /* "$ltype" */ /*---------------------------------------------------------+ | if empty line or comments go to the next line | +---------------------------------------------------------*/ if First1Char = "#" then do iterate end if First1Char = "" then do iterate end /*---------------------------------------------------------+ | reading variables: Qvar_xQ (from file.tmpl) | +---------------------------------------------------------*/ if First5Chars = "$var_" then do parse var FileStem.i FirstItem "$var_" VarNumber "$" SecItem VarNumber = strip(VarNumber) SecItem = strip(SecItem) if pos("Created", SecItem) = 1 then do parse var SecItem PrevItem "Modified" NextItem PrevItem = strip(PrevItem) NextItem = " - "monStr" "dayStr", "yearStr VarStem.i_var = PrevItem"Modified:"NextItem end else do VarStem.i_var = SecItem end i_var = i_var + 1 iterate end /*---------------------------------------------------------+ | reading variables: QltypeQ (from file.tmpl) | +---------------------------------------------------------*/ if First6Chars = "$ltype" then do parse var FileStem.i FirstItem "$ltype" VarNumber "$" SecItem VarNumber = strip(VarNumber) SecItem = strip(SecItem) TypeStem.VarNumber = SecItem i_type = i_type + 1 iterate end /*---------------------------------------------------------+ | reading variables: Qlist_xQ (from file.tmpl) | +---------------------------------------------------------*/ if First5Chars = "$list" then do parse var FileStem.i FirstItem "$list_"k"$" SecItem SecItem = strip(SecItem) parse var SecItem AddrItem "×" NameItem "×" CommentItem AddrItem = strip(AddrItem) NameItem = strip(NameItem) CommentItem = strip(CommentItem) /* html lists = ol, ul ================================================== */ if TypeStem.k = "list-ul" | TypeStem.k = "list-ol" then do if AddrItem = "section" then /* Section item */ do _AddrItem = "" _NameItem = ""NameItem"" _CommentItem = CommentItem _tmpHtmlStr = '

'_LF ||, '
  • '_AddrItem || _NameItem || _CommentItem'
  • ' end else if AddrItem = "subsection" then /* Section item */ do _AddrItem = "" _NameItem = ' - ' ||, NameItem' - ' _CommentItem = CommentItem _tmpHtmlStr = '
  • '_AddrItem || _NameItem || _CommentItem'
  • ' end else if AddrItem = "chapter" then /* Chapter beginning */ do _AddrItem = "" _NameItem = ""NameItem"" _CommentItem = CommentItem /* html lists = ul or ol*/ if TypeStem.k = "list-ul" then do list_start = '' end else do list_stop = '' end _tmpHtmlStr = list_stop""_LF ||, '' ||, _NameItem''_LF ||, '

    '_LF end /* else if */ else /* List item */ do _AddrItem = '' _NameItem = NameItem'' _CommentItem = ' 'CommentItem _tmpHtmlStr = '
  • ' ||, _AddrItem || _NameItem || _CommentItem ||, '
  • ' end /* if AddrItem = "section" */ end /* if TypeStem.k = "list-ul" */ /* html lists = lm, rm ================================================== */ if TypeStem.k = "list-lm" | TypeStem.k = "list-rm" then do if AddrItem = "section" then /* Section item */ do _AddrItem = "" _NameItem = ""NameItem"" _CommentItem = CommentItem /* font color = lm or rm*/ if TypeStem.k = "list-lm" then do font_col = '#006600' end else do font_col = '#000066' end _tmpHtmlStr = '

    '_LF ||, '

    '_LF ||, ''_LF ||, _NameItem""_LF ||, ''_LF ||, '
    ' end else if AddrItem = "chapter" then /* Chapter beginning */ do _AddrItem = "" _NameItem = ""NameItem"" _CommentItem = CommentItem /* font color = lm or rm*/ if TypeStem.k = "list-lm" then do font_col = '#006600' end else do font_col = '#000066' end _tmpHtmlStr = "

    "_LF ||, ''_LF ||, _NameItem""_LF ||, ''_LF ||, '

    '_LF end /* else if */ else /* List item */ do _AddrItem = '' _NameItem = NameItem'' _CommentItem = ' 'CommentItem _tmpHtmlStr = _AddrItem || _NameItem || _CommentItem'
    '_LF end /* else */ end /* if TypeStem.k = "list-lm" */ /* images lists ========================================================= */ if TypeStem.k = "images" then do _AddrItem = '' _NameItem = ''CommentItem'' _tmpHtmlStr = '

    '_AddrItem || _NameItem || '

    ' _LF || '

     

    '_LF end /* if TypeStem.k = "images" */ /* e-mail lists ========================================================= */ if TypeStem.k = "emails" then do _AddrItem = '' _NameItem = NameItem'' _CommentItem = ' 'CommentItem _tmpHtmlStr = '', _AddrItem || _NameItem || _CommentItem || '' _LF end /* if TypeStem.k = "emails" */ /* hpage lists ========================================================== */ if TypeStem.k = "hpage" then do if countstr("×", SecItem) = 4 then do parse var SecItem Addr1"×"Name1"×"Addr2"×"Name2"×"CommentItem Addr1 = strip(Addr1) Name1 = strip(Name1) Addr2 = strip(Addr2) Name2 = strip(Name2) CommentItem = strip(CommentItem) _Addr1 = '' _Name1 = Name1'' _Addr2 = '' _Name2 = Name2'' _CommentItem = ' 'CommentItem _tmpHtmlStr = '

    '_LF ||, ' '_Addr1''_Name1' -> '_Addr2''_Name2 ||, _CommentItem || _LF ||, '

    ' end /* if countstr("×", SecItem) = 4 */ else do _AddrItem = '' _NameItem = NameItem'' _CommentItem = ' 'CommentItem _tmpHtmlStr = '

    '_LF ||, ' '_AddrItem || _NameItem || _CommentItem || _LF ||, '

    ' end /* else countstr("×", SecItem) = 4 */ end /* if TypeStem.k = "hpage" */ /* definition lists ===================================================== */ if TypeStem.k = "list-dl" then do _AddrItem = '
    'AddrItem'
    ' _NameItem = '
    'NameItem'
    ' _tmpHtmlStr = _AddrItem || _NameItem || _LF end /* if TypeStem.k = "list-dl" */ tmpNo = i_list.k ListStem.k.tmpNo = _tmpHtmlStr ListStem.k.0 = i_list.k i_list.k = i_list.k + 1 iterate end /* if First5Chars */ i = i + 1 end /* do while */ FileStem.0 = i - 1 /* Number of lines copied */ ok = stream(File2Read1, 'c','close') /* Closing File2Read */ /*-----------------------------------------------------------------------------+ | Time to create output HTML page | +-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------+ | FileStem to File - linein way | +-----------------------------------------------------------------------------*/ File2Write_Tmp = charin(File2Read2, 1, File2Read2_Size) do j = 1 to File2Read2_VarNo File2Write_Tmp = changestr("Qvar_"j"Q", File2Write_Tmp, VarStem.j) end do k = 1 to File2Read2_ListNo ListStem_Tmp = "" limit = i_list.k - 1 do j = 1 to limit ListStem_Tmp = ListStem_Tmp || _LF || ListStem.k.j end File2Write_Tmp = changestr("Qlist_"k"Q", File2Write_Tmp, ListStem_Tmp) end ok = charout(File2Write, File2Write_Tmp) ok = stream(File2Write, 'c','close') /*-----------------------------------------------------------------------------+ | FileStem to File - linein way | +-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------+ | >>>>>>>>>>>>>>>>>>>>>> End of Main program body <<<<<<<<<<<<<<<<<<<<<<<<<< | +-----------------------------------------------------------------------------*/ exit /*-----------------------------------------------------------------------------+ | PROCEDURES | +-----------------------------------------------------------------------------*/ Helper: Say ' ' Say '===================================================================' Say 'nbsd_hpage.rexx USAGE' Say '===================================================================' Say ' Program makes homepages: xxxx.HTML files from xxxx.TMPL templates ' Say ' ' Say ' Run it in following ways: ' Say ' ' Say ' 1) for one file.tmpl ' Say ' rexx nbsd_hpage.rexx file.tmpl ' Say ' regina nbsd_hpage.rexx file.tmpl ' Say ' ' Say ' 2) for many *.tmpl files at one time ' Say ' nbsd_hpage.sh' Say ' ' Say ' ATTENTION: ' Say ' Program will not create new html file if old version exists!!!' Say ' This option is controlled by nbsd_hpage.sh' Say '===================================================================' Say ' ' exit return