Contents 
 Index 
 "Perl Program Reference" 
 < Previous 
 Next > 

tree_js_2_script.pl

Go to the documentation of this file.
00001 // This file has been modified on-the-fly with an input filter
00002 // to change it from Perl syntax to C++ strictly for the purposes
00003 // of faking out Doxygen. Modifications include:
00004 
00005 // - changing local() definitions to C++ #define statements.
00006 // - commenting out undef statements.
00007 // - changing $globe'... variable names to $globe_...
00008 // - changing sub statements to look like C++ functions.
00009 // - changing # comments to C++ comments.
00010 // - ...
00011 
00012 // If you see other strangeness in the HTML version of the Perl file,
00013 // it comes from getting it to look more C++ like.
00014 
00015 
00016 // #!/usr/#define/bin/perl
00017 package gen_nav;
00018 
00019 //#############################################################################
00020 /** @file
00021  ** @brief Takes a tree js file from Doxygen and outputs a script file
00022  ** used by the TOC java applet.
00023  ** 
00024  **
00025  ** @ingroup tp_tools tp_nav
00026  **
00027  ** @author Glenn C. Maxey
00028  **
00029  **/
00030 // #    $Id: tree_js_2_script.pl,v 1.7 2002/12/24 15:05:53 gmaxe Exp $
00031 //#
00032 //# 2002 Created by Voyant Technologies, Inc., Westminster, Colorado, USA.
00033 //#
00034 //# Permission to use, copy, modify, and distribute this software and its 
00035 //# documentation under the terms of the GNU General Public License is hereby 
00036 //# granted. No representations are made about the suitability of this software 
00037 //# for any purpose. It is provided "as is" without express or implied warranty. 
00038 //# See the GNU General Public License (http://www.gnu.org/copyleft/gpl.html) 
00039 //# for more details.
00040 //# 
00041 //# Documents produced by this script are derivative works derived from the 
00042 //# input used in their production; they are not affected by this license.
00043 //#
00044 //#    Revision Information:
00045 //#
00046 //#    $Log: tree_js_2_script.pl,v $
00047 //#    Revision 1.7  2002/12/24 15:05:53  gmaxe
00048 //#    New name and tweaks to add full paths.
00049 //#
00050 //#    Revision 1.6  2002/11/20 15:23:05  gmaxe
00051 // //#    Added exit codes so that wrapper scripts can catch errors properly.
00052 //#
00053 //#    Revision 1.5  2002/11/20 01:49:14  gmaxe
00054 // //#    Minor changes to exit codes.
00055 //#
00056 //#    Revision 1.4  2002/03/29 00:19:41  gmaxe
00057 //#    Fixed it so that it handles dependencies in the build.
00058 //#    Relative paths are handled.
00059 //#
00060 //#    Revision 1.3  2002/03/05 02:05:30  gmaxe
00061 //#    Fixed so that it won't hyperlink to things that don't exist in directory.
00062 //#
00063 //#    Revision 1.2  2002/03/05 01:47:41  gmaxe
00064 //#    Supports previous/next on Doxygen files;
00065 //#    supports better script generation.
00066 //#
00067 //#    Revision 1.1  2002/03/02 01:30:03  gmaxe
00068 //#    Updated to support tree.js files.
00069 //#
00070 //#
00071 //#############################################################################
00072 
00073 
00074 //#############################################################################
00075 /** @fn int BEGIN
00076  ** @brief Code to execute when first entered.
00077  **
00078  ** @param None. 
00079  **
00080  ** @return None.
00081  **
00082  ** @lim None
00083  ** @ingroup tp_nav
00084  **/
00085 // #############################################################################
00086 int BEGIN  ( ) {
00087 //    print "\n============  Starting tree_js_2_script.pl ==================================\n";
00088    $_file_list = "_file_list";
00089    $_toc_file = "tree.html";
00090    $_index_file = "_index_list";
00091    $scope_pm = "globe.pm";
00092    $in_file = "tree.js";
00093    $f_type = "tp";
00094 
00095    push (@INC, `pwd`);
00096    push (@INC, '/rtfm/techpubs/perl');
00097    if (0){
00098 //       print (@INC, "\n");
00099    }
00100    // ####
00101    //  All global variables are defined in the following file
00102    // ####
00103    unless (open ( IN_LIST, $scope_pm)) {
00104       unless (open ( IN_LIST, "/rtfm/techpubs/perl/$scope_pm")) {
00105          push (@file_errors, "Cannot open file \"$scope_pm\" or \"/rtfm/techpubs/perl/$scope_pm\"\n");
00106          $no_scope_file++;
00107       }
00108    }
00109 //    close (IN_LIST);
00110    push (@INC, $scope_pm);
00111    push (@INC, "/rtfm/techpubs/perl/$scope_pm");
00112 
00113    if (!@file_errors) {
00114       // ####
00115       //  All global variables are defined in the following file
00116       // ####
00117       require $scope_pm;
00118    
00119       if (&globe::declare_variables()) {
00120 //          print "Variables initialized from $scope_pm.\n";
00121       } else {
00122          push (@file_errors, "Could not initialize variables from $scope_pm.\n");
00123       }
00124    } //  if not @file_errors
00125 
00126    if (@ARGV < 1) {
00127       push (@file_errors, "No path specified as first argument.\n");
00128    }
00129    
00130    //  Get path if there is one.
00131    if (@ARGV > 0) {
00132       $globe::path = @ARGV[0];
00133       if ($globe::path =~ /\//) {
00134 //          print "The path specified is $globe::path\n";
00135       
00136          @path_chunks = split ( /\//, $globe::path);
00137          if (@path_chunks < 2) {
00138             $globe::rel_path_to_start_point = "./";
00139          } else {
00140             $globe::rel_path_to_start_point = "../";
00141          }
00142       } else {
00143          push (@file_errors, "The input argument \"$globe::path\" requires a forward slash (\/).\n");
00144       }
00145    } //  if 1 or more arguments
00146    
00147    if (@ARGV <= 1) {
00148       push (@globe::file_errors, "ERROR: 2nd argument master HTML file is required.");
00149    } //  if 2 or more arguments
00150 
00151    if (@ARGV > 1) {
00152       $in_file = @ARGV[1];
00153 //       print "The input file is $in_file.\n";
00154       unless (open ( IN_MASTER, "$in_file")) {
00155          push (@file_errors, "Cannot open file \"$in_file\"\n");
00156       }
00157    } //  if 2 or more arguments
00158 
00159 
00160    
00161 } //  BEGIN
00162 
00163 //#############################################################################
00164 /** @fn int main
00165  ** @brief The main program.
00166  **
00167  ** @param None. 
00168  **
00169  ** @return None.
00170  **
00171  ** @lim None
00172  ** @ingroup tp_nav
00173  **/
00174 // #############################################################################
00175 // sub main {
00176 {
00177    // #############################################################################
00178    // # Program start
00179    // #############################################################################
00180 
00181    if (0){
00182 //       print "=== Definitions 3 \n";
00183 //       exit(1);
00184    }
00185 
00186    if (@file_errors) {
00187       //  Makes no sense to go on if input parameters are off.
00188 //       print "\n============  Summary of errors ==================================\n";
00189       for ($i=0; $i<@file_errors; $i++){
00190 //          print "$i = $file_errors[$i]\n";
00191       }
00192       &using_voy_nav();
00193 //       exit(1);
00194    }
00195 
00196 
00197    &get_input_file ("$in_file");
00198    if (0) {
00199 //       print "got this far...\n";
00200    }
00201 
00202    if (@ARGV > 2) {
00203       &output_toc_script (@ARGV[2]);
00204    } else {
00205       $temp = "$globe::path$_toc_file";
00206       push (@globe::file_errors, "WARNING: Using default $temp for output toc.");
00207       $temp = "$globe::path$_toc_file";
00208       &output_toc_script ($temp);
00209    } //  if 3 or more arguments
00210 
00211 
00212    // #############################################################################
00213    // # End of Program
00214    // #############################################################################
00215 //    exit(0);
00216 } //  the main routine
00217 
00218 //#############################################################################
00219 /** @fn int using_voy_nav  ( )
00220  ** @brief What to do when no arguments are given.
00221  ** @param None
00222  ** @return None
00223  ** 
00224  ** @lim None
00225  ** @ingroup tp_nav
00226  **/
00227 // #############################################################################
00228 int using_voy_nav  ( ) {
00229 //    print "\ntree_js_2_script.pl operates on text files that indicate heirarchical \n";
00230 //    print "structure of the system. \n";
00231 //    print "1st argument is the root path; required. \n";
00232 //    print "2nd argument name of tree js file; optional. \n";
00233 //    print "3nd argument of the output toc script file; optional. \n";
00234 
00235    return;
00236 }
00237 
00238 
00239 //#############################################################################
00240 /** @fn int get_input_file
00241  ** @brief Grabs the information from the input file and puts into an array
00242  ** of hash elements.
00243  **
00244  ** The index into the array is a number that signifies it's placement.
00245  ** Each index element can have three hashes:
00246  **
00247  ** {level} An indication of the heirarchical placement.
00248  ** {title} The plain text title.
00249  ** {url} The associated URL for the title.
00250  **
00251  ** @ingroup tp_nav
00252  **/
00253 // #############################################################################
00254 int get_input_file  ( ) {
00255    $tp_file = $_[0];
00256    $entire_file = "";
00257    $folderstree = "foldersTree";
00258    $aux = "aux";
00259    $glnk = "gLnk";
00260    $gfld = "gFld";
00261    $insfld = "insFld";
00262       
00263 //    print "The tp input file is $tp_file\n";
00264    unless (open ( IN_FILE, $tp_file)) {
00265 //       print "Cannot open file \"$tp_file\"\n";
00266       push (@globe::file_errors,  "Cannot open file \"$tp_file\".");
00267 //       exit(1);
00268    }
00269    $_comment = 0;
00270    $_cnt = -1;
00271    //  Get the definitions
00272    TP_LINE: while (<IN_FILE>){    //  entire file into memory.
00273       $entire_file .= $_;
00274    }
00275 //    close (IN_FILE);
00276    
00277    @ft = split (/\n/, $entire_file);
00278    for ($i=1; $i <= $// ft; $i++) {
00279       //  we are purposely ignoring the 0 element, because this is retrieved elsewhere
00280       //  from voy_order in a later process.
00281       &get_gfld_title ($ft[$i], $i);
00282       if (0) {
00283          foreach $ddd (keys %{$tp[$index]} ) {
00284 //             print "$index = $ddd = $tp[$index]{$ddd}\n";
00285          }
00286       }
00287    }
00288 
00289    
00290 } //  get_input_file
00291 
00292 
00293 //#############################################################################
00294 /** @fn int get_gfld_title
00295  ** @brief 
00296  **
00297  **
00298  **
00299  ** @ingroup tp_nav
00300  **/
00301 // #############################################################################
00302 int get_gfld_title  ( ) {
00303    $in_chunk = $_[0];
00304    $index = $_[1];
00305    
00306    //  split on closing parenthesis
00307    @t_chunk = split (/$glnk|$gfld/, $in_chunk, 2);
00308    if (0) {
00309 //       print "$folderstree $aux Glenn, you are here...";
00310    }
00311    
00312    //  Level
00313    if ($t_chunk[0] =~ /$folderstree/i) {
00314       $tp[$index]{level} = 1;
00315       if (0) {
00316 //          print "what ya doin' here? $folderstree $t_chunk[0]\n";
00317       }
00318    } elsif ($t_chunk[0] =~ /$aux/i) {
00319       if ($t_chunk[0] =~ /$insfld/i) {
00320          @t1_chunk = split (/$insfld/i, $t_chunk[0], 2);
00321          @t2_chunk = split (/$aux/i, $t1_chunk[1], 2);
00322          @t3_chunk = split (/\,/, $t2_chunk[1], 2);
00323       } else {
00324          @t2_chunk = split (/$aux/i, $t_chunk[0], 2);
00325          @t3_chunk = split (/\,/, $t2_chunk[1], 2);
00326       }
00327       $tp[$index]{level} = $t3_chunk[0]+1;
00328       if (0){
00329 //          print "hey $t3_chunk[0], $t3_chunk[1], $t3_chunk[2]\n";
00330       }
00331    } else {
00332       if (0) {
00333 //          print "You shouldn't be here...\n$t_chunk[0]\n";
00334       }
00335    }
00336    
00337    //  Title & URL
00338    @t2_chunk = split (/\,/, $t_chunk[1], 3);
00339 
00340    //  Title
00341    @t3_chunk = split (/\"/, $t2_chunk[0], 3);
00342    $tp[$index]{title} = $t3_chunk[1];
00343    if ((1) && (exists ($globe::dox_name_change{$t3_chunk[1]} ) ) ){
00344       //  Changes the name of items to be more meaningful to our environment
00345       $tp[$index]{title} = $globe::dox_name_change{$t3_chunk[1]};
00346    }
00347  
00348    //  URL
00349    @t3_chunk = split (/\"/, $t2_chunk[2], 3);
00350    $tp[$index]{url} = $t3_chunk[1];
00351 
00352    if (0) {
00353       foreach $ddd (keys %{$tp[$index]} ) {
00354 //          print "$index = $ddd = $tp[$index]{$ddd}\n";
00355       }
00356 //       exit(1);
00357    }
00358    
00359 } //  get_gfld_title
00360 
00361 
00362 
00363 //#############################################################################
00364 /** @fn int output_toc_script
00365  ** @brief 
00366  **
00367  **
00368  **
00369  ** @ingroup tp_nav
00370  **/
00371 // #############################################################################
00372 int output_toc_script  ( ) {
00373    #define $htree_file  $_[0]
00374    
00375    if (($htree_file =~ /(\.html)$/i) || ($htree_file =~ /(\.htm)$/i)){
00376       @_name = split (/\.htm/i, $htree_file, 2);
00377       $htree_file = $_name[0];
00378    }
00379    $htree_file .= ".script";
00380    
00381 //    print "The output TOC script file is \"$htree_file\".\n";
00382 
00383    unless (open(OUT_SCRIPT, ">$htree_file")) {
00384       push (@file_errors, "Cannot open file \"$htree_file\".");
00385       return(1);
00386    }
00387 
00388    // #################################################
00389    //  Root level of tree.
00390    // #################################################
00391 
00392    // #################################################
00393    //  This is the main loop; it starts at a first topic and then traces the next
00394    //  topics from there. When a next topic is determined to be a last topic for
00395    //  that section, it then goes and gets the next first topic.
00396    // #################################################
00397    for ($i=1; $i <= $// ft; $i++) {
00398       //  we are purposely ignoring the 0 element, because this is retrieved elsewhere
00399       //  from voy_order in a later process.
00400       if ((exists ($tp[$i]{url})) && ($tp[$i]{url} =~ /[\w+]/)) {
00401          if (!&html_exist($tp[$i]{url})) {
00402             //  It doesn't seem to exist
00403             //  check to see if it's a path to be fixed.
00404             if ($tp[$i]{url} =~ /$globe::fix_path_flag/){
00405                //  we go under the assumption that it exists
00406                //  and that it is a relative path issue.
00407                if (0) {
00408 //                   print "Fixing $tp[$i]{url}\n";
00409                }
00410                $tp[$i]{url} =~ s/$globe::fix_path_flag/$globe::fix_path_to/;
00411                if (0) {
00412 //                   print "Fixed $tp[$i]{url} to be relative.\n";
00413                }
00414 //                print (OUT_SCRIPT "Item level=$tp[$i]{level} ");
00415 //                print (OUT_SCRIPT "image=nav_doc.gif ");
00416 //                print (OUT_SCRIPT "url=$tp[$i]{url},basefrm ");
00417 //                print (OUT_SCRIPT "selected=YES ");
00418 //                print (OUT_SCRIPT "text=$tp[$i]{title}\r\n");
00419             } else { //  $globe::fix_path_flag
00420                //  it really doesn't exist
00421                //  if it doesn't exist, don't hyperlink it.
00422 //                print (OUT_SCRIPT "Item level=$tp[$i]{level} ");
00423 //                print (OUT_SCRIPT "text=$tp[$i]{title}\r\n");
00424             } //  $globe::fix_path_flag
00425          } else { //  (!&html_exist($tp[$i]{url})
00426             //  It does exist
00427 //             print (OUT_SCRIPT "Item level=$tp[$i]{level} ");
00428 //             print (OUT_SCRIPT "image=nav_doc.gif ");
00429 //             print (OUT_SCRIPT "url=$tp[$i]{url},basefrm ");
00430 //             print (OUT_SCRIPT "selected=YES ");
00431 //             print (OUT_SCRIPT "text=$tp[$i]{title}\r\n");
00432          }
00433       } else {
00434          //  it really doesn't exist
00435          //  if it doesn't exist, don't hyperlink it.
00436 //          print (OUT_SCRIPT "Item level=$tp[$i]{level} ");
00437 //          print (OUT_SCRIPT "text=$tp[$i]{title}\r\n");
00438       }
00439 
00440    } //  for $i
00441 
00442    
00443    // #################################################
00444    //  Clean up navigation.
00445    // #################################################
00446 //    close (OUT_SCRIPT);
00447 
00448 } //  output_toc_script
00449 
00450 
00451 //#############################################################################
00452 /** @fn int html_exist
00453  ** @brief Tests that the URL to a file exists.
00454  **
00455  ** Discovered that doxygen's installdox does not update the tree.js files,
00456  ** which leads to entries in the TOC that 404. Test it and return an 
00457  ** appropriate response.
00458  **
00459  ** @ingroup tp_nav
00460  **/
00461 // #############################################################################
00462 int html_exist  ( ) {
00463    //  Test the damn URL to make sure the file even exists.
00464    $test_file = $_[0];
00465 
00466    unless (open(TEST, "$globe::path$test_file")) {
00467       if (0){
00468 //          print "$globe::path$test_file doesn't exist.\n";
00469       }
00470       return(0);
00471    }
00472 //    close (TEST);
00473    return (1);
00474 
00475 
00476 } //  html_exist
00477 
00478 
00479 //#############################################################################
00480 /** @fn int END
00481  ** @brief Code to execute when first entered.
00482  **
00483  ** @param None. 
00484  **
00485  ** @return None.
00486  **
00487  ** @lim None
00488  ** @ingroup tp_nav
00489  **/
00490 // #############################################################################
00491 int END  ( ) {
00492    &globe::do_errors;
00493    // undef ($_file_list);     //  "_file_list";
00494    // undef ($_index_file); //  = "_index_list";
00495    // undef ($in_file);     //  "";
00496    // undef ($f_type);     //  "htm";
00497 
00498    
00499    // #############################################################################
00500    // # Memory clean-up.
00501    // #############################################################################
00502    if ($no_scope_file > 0){
00503       &globe::memory_clean_up();
00504    }
00505 
00506    if (@file_errors) {
00507 //       print "\n============  Summary of errors ==================================\n";
00508       for ($i=0; $i<@file_errors; $i++){
00509 //          print "$i = $file_errors[$i]\n";
00510       }
00511    }
00512 
00513 //    print "\n============  Finished tree_js_2_script.pl ==================================\n";
00514 } //  END
00515 
00516 


 "Perl Program Reference" 
 < Previous 
 Next > 


Open-Source tools compliments of Voyant Technologies, Inc. and Glenn C. Maxey.
01/13/2003

TP Tools v2-00-0a

# tpt-perl-hcr-02