rexxliterate.cls source

00001 /*----------------------------------------------------------------------------*/
00002 /*                                                                            */
00003 /*   Copyright (c) 2004-2009 William  Data  Systems Ltd. and Geoff Stevens.   */
00004 /*   All rights reserved.                                                     */
00005 /*                                                                            */
00006 /*   This program and the  accompanying  materials are made available under   */
00007 /*   the terms of the  Common  Public  License  v1.0 which accompanies this   */
00008 /*   distribution. A  copy  is  also  available  at  the following address:   */
00009 /*   http://www.opensource.org/licenses/cpl1.0.php                            */
00010 /*                                                                            */
00011 /*   Redistribution and use in  source  and  binary  forms, with or without   */
00012 /*   modification, are  permitted  provided  that  the following conditions   */
00013 /*   are met:                                                                 */
00014 /*                                                                            */
00015 /*   Redistributions  of  source  code  must  retain  the  above  copyright   */
00016 /*   notice, this list of conditions and the following disclaimer.            */
00017 /*                                                                            */
00018 /*   Redistributions in  binary  form  must  reproduce  the above copyright   */
00019 /*   notice, this list of  conditions  and  the following disclaimer in the   */
00020 /*   documentation and/or other materials provided with the distribution.     */
00021 /*                                                                            */
00022 /*   Neither the name or trademarks  of  William Data Systems nor the names   */
00023 /*   of its  contributors  may  be  used  to  endorse  or  promote products   */
00024 /*   derived from this software without specific prior written permission.    */
00025 /*                                                                            */
00026 /*   DISCLAIMER                                                               */
00027 /*                                                                            */
00028 /*   THIS SOFTWARE IS PROVIDED  BY  THE  COPYRIGHT HOLDERS AND CONTRIBUTORS   */
00029 /*   "AS IS" AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT   */
00030 /*   LIMITED TO, THE IMPLIED WARRANTIES  OF MERCHANTABILITY AND FITNESS FOR   */
00031 /*   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT   */
00032 /*   OWNER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,   */
00033 /*   SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT NOT   */
00034 /*   LIMITED TO, PROCUREMENT OF SUBSTITUTE  GOODS OR SERVICES; LOSS OF USE,   */
00035 /*   DATA, OR PROFITS; OR BUSINESS  INTERRUPTION) HOWEVER CAUSED AND ON ANY   */
00036 /*   THEORY OF LIABILITY, WHETHER  IN  CONTRACT,  STRICT LIABILITY, OR TORT   */
00037 /*   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN  ANY WAY OUT OF THE USE   */
00038 /*   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
00039 /*                                                                            */
00040 /*----------------------------------------------------------------------------*/
00041 --  convert rexx code to browsable HTML pages
00042 --
00043 --  extract and try to make sense of contained docs
00044 --
00045  
00046 -- conditions
00047 ::REQUIRES 'condhandler.cls'
00048  
00049 -- for all the boilerplate
00050 ::REQUIRES 'fsobjects.cls'
00051  
00052 -- to generate unique ids
00053 ::REQUIRES 'hashfunction.cls'
00054  
00055 -- rexx program parser
00056 ::REQUIRES 'rexxprogram.cls'
00057  
00058 -- html output
00059 ::REQUIRES 'htmlout.cls'
00060  
00061 -- files, folders, rexx and text documents
00062 ::REQUIRES 'documents.cls'
00063  
00064 -- html images to build the tree view
00065 ::REQUIRES 'nodes.cls'
00066  
00067 -- build tree html
00068 ::REQUIRES 'htmltree.cls'
00069  
00070 -- index html
00071 ::REQUIRES 'htmlindex.cls'
00072  
00073 -- fs path separator
00074 ::REQUIRES 'pathsep.cls'
00075  
00076 -- flyweight for configuration
00077 ::CLASS rexxliterateconfig PUBLIC
00078 ::ATTRIBUTE title          -- title for report
00079 ::ATTRIBUTE rsource        -- path to rexx source
00080 ::ATTRIBUTE hdest          -- path to html output
00081 ::ATTRIBUTE prefixcomment  -- array of lines to remove from comment prefix
00082 ::ATTRIBUTE trailericon    -- string inserted into left hand side of page trailers
00083 ::ATTRIBUTE recurse        -- boolean, when .true recurse into subfolders of rsource
00084 ::ATTRIBUTE dynamicmethods -- boolean, when .true cross reference dynamic methods
00085 ::METHOD init
00086   self~title = ''
00087   self~rsource = ''
00088   self~hdest = ''
00089   self~prefixcomment = .array~new
00090   self~trailericon = ''
00091   self~recurse = .true
00092   self~dynamicmethods = .true
00093  
00094 -- flyweight for global lists of features
00095 ::CLASS globalindex
00096 ::ATTRIBUTE folders     -- list of all folders as .folder
00097 ::ATTRIBUTE files       -- list of all files as .file
00098 ::ATTRIBUTE filix       -- relation of all files as .file, key filename
00099 ::ATTRIBUTE labels      -- list of all labels as .feature
00100 ::ATTRIBUTE procedures  -- list of all procedures as .rdprocedure
00101 ::ATTRIBUTE requires    -- list of all requires as .rdrerquires
00102 ::ATTRIBUTE routines    -- list of all routines as .rdroutine
00103 ::ATTRIBUTE routinix    -- relation of all routines as .rdroutine, key rexx name
00104 ::ATTRIBUTE classes     -- list of all classes as .rdclass
00105 ::ATTRIBUTE classix     -- relation of all classes as .rdclass, key rexx name
00106 ::ATTRIBUTE methods     -- list of all methods as .rdmethod
00107 ::ATTRIBUTE methix      -- relation of all methods as .rdmethod, key rexx name
00108 ::ATTRIBUTE attributes  -- list of all attributes as .rdattribute
00109 ::ATTRIBUTE attrix      -- relation of all attributes as .rdmethod, key rexx name
00110 ::ATTRIBUTE constants   -- list of all constants as .rdconstant
00111 ::ATTRIBUTE constix     -- relation of all constants as .rdconstant, key rexx name
00112 ::ATTRIBUTE options     -- list of all options as .rdoption
00113 ::ATTRIBUTE dynamicmethods -- when .true, cross reference method calls
00114  
00115 ::METHOD init
00116   self~folders = .queue~new
00117   self~files = .queue~new
00118   self~filix = .relation~new
00119   self~labels = .queue~new
00120   self~procedures = .queue~new
00121   self~requires = .queue~new
00122   self~routines = .queue~new
00123   self~routinix = .relation~new
00124   self~classes = .queue~new
00125   self~classix = .relation~new
00126   self~methix = .relation~new
00127   self~attrix = .relation~new
00128   self~methods = .queue~new
00129   self~attributes = .queue~new
00130   self~constants = .queue~new
00131   self~constix = .relation~new
00132   self~options = .queue~new
00133   self~dynamicmethods = .false
00134  
00135 -- render tree of rexx files as HTML, optional tree view
00136 ::CLASS rexxliterate PUBLIC
00137 ::ATTRIBUTE rsource     -- path to rex source
00138 ::ATTRIBUTE hdest       -- path to html output
00139 ::ATTRIBUTE tree        -- tree of folders and files from rsource
00140 ::ATTRIBUTE title       -- title for report
00141 ::ATTRIBUTE prefixcomment -- remove from comment prefix
00142 ::ATTRIBUTE trailericon  -- inserted into left hand side of page trailers
00143 ::ATTRIBUTE pversion PRIVATE -- my version
00144  
00145 ::ATTRIBUTE globalix    -- global lists of features and files
00146  
00147 ::ATTRIBUTE recursive   -- when true, recurses into folder tree
00148  
00149 ::ATTRIBUTE rexxdocs    -- rexxdocs harvested from text 
00150  
00151 ::ATTRIBUTE modules     -- .directory of module rexxdocs harvested from text 
00152  
00153 ::ATTRIBUTE htmlout     -- html output object
00154  
00155 -- build the tree of folders and files
00156 -- @param config  - configuration object
00157 --
00158 ::METHOD init
00159   use strict arg config
00160   self~pversion = '0.0.1'
00161  
00162   self~rsource = config~rsource
00163   self~hdest = config~hdest
00164   self~title = config~title
00165   self~recursive = config~recurse
00166   self~trailericon = config~trailericon
00167   self~prefixcomment = config~prefixcomment
00168  
00169   self~rexxdocs = .queue~new
00170   self~modules  = .directory~new
00171  
00172   self~globalix = .globalindex~new()
00173   self~globalix~dynamicmethods = config~dynamicmethods
00174  
00175   -- build tree from root directory
00176   self~tree = self~buildtree(self~rsource)
00177   if self~tree~folders~items = 0,
00178    & self~tree~files~items = 0
00179     then do
00180            raise SYNTAX 93 ARRAY('no input files in' self~rsource)
00181            exit
00182          end
00183  
00184   say 'parsing source'
00185   -- process file system tree
00186   -- recursively walk tree, parsing source and text
00187   self~parser(self~tree)
00188  
00189   -- cross reference instantiations
00190   say 'cross referencing'
00191   self~xref(self~tree)
00192  
00193   -- we should now have all the interesting rexx source and text in the source
00194   -- in a tree of .folder, each .folder containing a list of .file, each .file
00195   -- containing a .rexxdocument or a .textdocument
00196   -- .globalindex self~globalix is fully up to date and all cross referencing
00197   -- has been done
00198  
00199 -- produce HTML output
00200 -- @param treeframe - when .true produce frameset and HTML tree
00201 --                    when .false main.html = index.html and no HTML tree
00202 ::METHOD emit
00203   use strict arg treeframe
00204  
00205   say 'writing boilerplate'
00206   -- prepare to emit html
00207   -- write all binary files required
00208   call bwritefiles self~hdest
00209  
00210   say 'adding html nature to documents'
00211   self~addnature(self~tree)
00212  
00213   -- emit rexxdocs
00214   self~htmlout = .htmlout~new(self, self~hdest, self~pversion, self~title, self~prefixcomment, self~trailericon)
00215  
00216   say 'emitting html'
00217   -- recursively walk tree, emitting html page(s)
00218   -- for each parsed program and text file
00219   -- attaching details to the file objects
00220   self~html(self~tree)
00221  
00222   say 'emitting indices'
00223   -- whomp up some index pages
00224   .htmlindex~emit(self~htmlout, self~globalix)
00225  
00226  
00227   -- prepare main.html, or index.html if no tree
00228   self~htmlout~firstpage(self~rexxdocs, treeframe)
00229  
00230   self~htmlout~modules(self~modules)
00231  
00232   if treeframe
00233     then do
00234            t = .htmltree~new(self~title, self~tree, self~hdest)
00235            -- produce HTML representation of file tree
00236            t~maketreehtml
00237          end
00238  
00239   -- report problems
00240   if self~htmlout~pwrongdoc~items > 0
00241     then do
00242            say 'Documentation doesn''t match parameters in code:'
00243            do i over self~htmlout~pwrongdoc
00244              say '  'i
00245             end
00246          end
00247   if self~htmlout~pmissingdoc~items > 0
00248     then do
00249            say 'Code parameters lack documentation:'
00250            do i over self~htmlout~pmissingdoc
00251              say '  'i
00252             end
00253          end
00254  
00255 -- walk tree, xref document
00256 -- @param f - folder tree to walk
00257 ::METHOD xref PRIVATE
00258   use arg f
00259 --  say f~foldername
00260  
00261   -- parse files first to order rexxdocs from top
00262   do i over f~files
00263     say 'xreffing' f~folderpath||i~filename
00264     select
00265       when i~isrexx
00266         then do
00267                i~document~xref(self~globalix)
00268              end
00269       when i~istxt
00270         then nop
00271       otherwise raise SYNTAX 93 ARRAY('Unrecognized filetype' i~filepath i~filename)
00272     end
00273   end
00274  
00275   -- recurse over folders
00276   do i over f~folders
00277     self~xref(i)
00278   end
00279  
00280 -- walk tree, add HTML methods to documents and contents
00281 -- @param f - folder tree to walk
00282 ::METHOD addnature PRIVATE
00283   use arg f
00284  
00285   do i over f~files
00286     say 'addnature' f~folderpath||i~filename
00287     select
00288       when i~isrexx
00289         then do
00290                i~document~addattribute('HDOCURL')
00291                i~document~addattribute('HSRCURL')
00292  
00293  
00294                i~document~hdocurl = i~document~prefix'_doc_'i~document~uniqueid'.html'
00295                i~document~hsrcurl = i~document~prefix'_src_'i~document~uniqueid'.html'
00296  
00297                do e over i~document~featurelist
00298                  e~addattribute('HDOCURL')
00299                  e~addattribute('HDOCANCHOR')
00300                  e~addattribute('HSRCANCHOR')
00301                  e~hsrcanchor = 'SRC'e~feature~startline~right(5,'0')
00302  
00303  
00304                  if e~type = 'COMT' | e~feature~objectname = 'QUOT'
00305                    then preanchor = 'LITS'
00306                    else do
00307                           preanchor = e~feature~rname~translate('  ','''"')
00308                           preanchor = preanchor~space(0)
00309                         end
00310                  e~hdocanchor = preanchor || e~feature~startline || e~feature~startcol,
00311                                 || e~feature~endline || e~feature~endcol
00312                  select
00313                    when e~type = 'CLAS'
00314                      then e~hdocurl = 'CL_'e~hdocanchor||i~document~hdocurl
00315                    when e~type = 'METH' | e~type = 'ATTR'
00316                      then e~hdocurl = e~owner~hdocurl
00317                    otherwise e~hdocurl = i~document~hdocurl
00318                  end
00319                end
00320                do c over i~document~clauses
00321                  if c~isreferenced
00322                    then do
00323                           c~addattribute('HDOCANCHOR')
00324                           c~addattribute('HSRCANCHOR')
00325                           c~hdocanchor = 'docanchor?'
00326                           c~hsrcanchor = 'SRC'c~feature~startline~right(5,'0')
00327                         end
00328                end
00329              end
00330       when i~istxt
00331         then do
00332                i~document~addattribute('HSRCURL')
00333                i~document~hsrcurl = i~document~prefix'_src_'i~document~uniqueid'.html'
00334              end
00335       otherwise raise SYNTAX 93 ARRAY('Unrecognized filetype' i~filepath i~filename)
00336     end
00337   end
00338  
00339   -- recurse over folders
00340   do i over f~folders
00341     self~addnature(i)
00342   end
00343  
00344 -- walk tree, parse document
00345 -- @param f - folder tree to walk
00346 ::METHOD parser PRIVATE
00347   use arg f
00348   -- parse files first to order rexxdocs from top
00349   do i over f~files
00350     say 'parsing' f~folderpath||i~filename
00351     select
00352       when i~isrexx
00353         then do
00354                i~document = .rexxdocument~new(i, self~rsource, self~globalix)
00355              end
00356       when i~istxt
00357         then do
00358                i~document = .textdocument~new(i, self~rsource, self~rexxdocs, self~modules)
00359              end
00360       otherwise raise SYNTAX 93 ARRAY('Unrecognized filetype' i~filepath i~filename)
00361     end
00362   end
00363  
00364   -- recurse over folders
00365   do i over f~folders
00366     self~parser(i)
00367   end
00368  
00369   return
00370  
00371 -- walk tree, emit per document HTML
00372 -- @param f - folder tree to walk
00373 ::METHOD html PRIVATE
00374   use arg f
00375  
00376   do i over f~folders
00377     self~html(i)
00378   end
00379  
00380   -- if there's a crap file we can have problems
00381   -- recover from any errors during emit, and
00382   -- attempt to restart
00383  
00384   -- init loop
00385   j = 1                                                                                                                              
00386  
00387   signal on ANY name fubar
00388   -- resume here
00389   resume:
00390   do j = j to f~files~items
00391     i = f~files[j]
00392     say 'emitting' f~folderpath||i~filename
00393     select
00394       when i~isrexx
00395         then do
00396                -- emit html pages for a rexx program
00397                self~htmlout~rhtmlpage(f, i, self~globalix)
00398              end
00399       when i~istxt
00400         then do
00401                -- emit html page for a text document
00402                self~htmlout~thtmlpage(f, i)
00403              end
00404       otherwise raise SYNTAX 93 ARRAY('Unrecognized filetype' i~filepath i~filename)
00405     end
00406     iterate
00407   end
00408   return
00409  
00410   fubar:
00411   say '-- unable to emit because'
00412   call conditionhandler condition('O'), sigl, sourceline(sigl)
00413   say '-- you may have found a bug in this program'
00414   say '-- or the input file named above may not be a valid Rexx program'
00415   say 'hit enter to continue'
00416   pull .
00417   j = j + 1
00418   signal resume
00419  
00420  
00421 -- return a tree of folders and files
00422 -- @return top folder of tree
00423 ::METHOD buildtree
00424  
00425   top = .folder~new(self~rsource)
00426  
00427   -- recurse over tree
00428   self~treewalk(top)
00429  
00430   return top
00431  
00432 -- recursively walk folders in a tree
00433 -- @param f - current folder
00434 ::METHOD treewalk PRIVATE
00435   use arg f
00436  
00437   -- record in global list
00438   self~globalix~folders~queue(f)
00439  
00440   rexxfiles = 'REX REXX CLS RTN'
00441   txtfiles = 'TXT NOTES'
00442  
00443   -- get files
00444   rc = sysfiletree(f~folderpath'*', 'files.', 'F')
00445  
00446   sep = .pathsep~sep
00447   do j = 1 to files.0
00448     parse value reverse(files.j) with fn (sep) .
00449     parse var fn ft '.' 
00450     fn = fn~reverse
00451     ft = ft~reverse~translate
00452     if rexxfiles~wordpos(ft) > 0,
00453      | txtfiles~wordpos(ft) > 0
00454       then do
00455              i = .file~new(fn, f)
00456              -- folder list
00457              f~files~queue(i)
00458              -- global list
00459              self~globalix~files~queue(i)
00460              self~globalix~filix[i~filename] = i
00461            end
00462   end
00463  
00464   if \self~recursive
00465     then return
00466  
00467   -- get folders
00468   rc = sysfiletree(f~folderpath'*', 'folders.', 'D')
00469   do j = 1 to folders.0
00470     parse value reverse(folders.j) with o (sep) .
00471     parse var folders.j . . . . fp
00472     o = o~reverse
00473     if o~left(1) <> '.'
00474       then do
00475              n = .folder~new(fp||.pathsep~sep)
00476              f~folders~queue(n)
00477            end
00478   end
00479  
00480   -- recurse into folders
00481   do i over f~folders
00482     self~treewalk(i)
00483   end
00484  
00485   return
00486  
00487  
00488  
00489 -- sort a queue of Comparables and return its array
00490 -- @param q - the queue to sort
00491 -- @return sorted array
00492 ::ROUTINE sortq
00493   use strict arg q
00494  
00495   a = q~makearray
00496  
00497   a~sort
00498  
00499   return a
00500  

Get RexxLiterate at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on 31 Aug 2010 05:20:32 for RexxLiterate by rexxliterate  0.0.1