|
|
|
|
|
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 Swaps out tagged areas in all HTML files in a given directory. 00022 ** 00023 ** 00024 ** @ingroup tp_tools tp_nav 00025 ** 00026 ** @author Glenn C. Maxey 00027 ** 00028 **/ 00029 // # $Id: xml_2_html_txt.pl,v 1.2 2002/11/20 15:23:11 gmaxe Exp $ 00030 //# 00031 //# 2002 Created by Voyant Technologies, Inc., Westminster, Colorado, USA. 00032 //# 00033 //# Permission to use, copy, modify, and distribute this software and its 00034 //# documentation under the terms of the GNU General Public License is hereby 00035 //# granted. No representations are made about the suitability of this software 00036 //# for any purpose. It is provided "as is" without express or implied warranty. 00037 //# See the GNU General Public License (http://www.gnu.org/copyleft/gpl.html) 00038 //# for more details. 00039 //# 00040 //# Documents produced by this script are derivative works derived from the 00041 //# input used in their production; they are not affected by this license. 00042 //# 00043 //# Revision Information: 00044 //# 00045 //# $Log: xml_2_html_txt.pl,v $ 00046 //# Revision 1.2 2002/11/20 15:23:11 gmaxe 00047 // //# Added exit codes so that wrapper scripts can catch errors properly. 00048 //# 00049 //# Revision 1.1 2002/08/02 21:43:53 gmaxe 00050 //# Added generation facilities for man as well as improved HTML topics. 00051 //# 00052 //# 00053 //############################################################################# 00054 00055 00056 //############################################################################# 00057 /** @fn int BEGIN 00058 ** @brief Code to execute when first entered. 00059 ** 00060 ** @param None. 00061 ** 00062 ** @return None. 00063 ** 00064 ** @lim None 00065 ** @ingroup tp_nav 00066 **/ 00067 // ############################################################################# 00068 int BEGIN ( ) { 00069 // print "\n============ Starting xml_2_html_txt.pl ==================================\n"; 00070 $_file_list = "_file_list"; 00071 $_toc_file = "tree.html"; 00072 $_index_file = "_index_list"; 00073 $scope_pm = "globe.pm"; 00074 $in_file = "tree.js"; 00075 $f_type = "tp"; 00076 00077 push (@INC, `pwd`); 00078 push (@INC, '../perl'); 00079 if (0){ 00080 // print (@INC, "\n"); 00081 } 00082 // #### 00083 // All global variables are defined in the following file 00084 // #### 00085 unless (open ( IN_LIST, $scope_pm)) { 00086 unless (open ( IN_LIST, "../perl/$scope_pm")) { 00087 push (@file_errors, "Cannot open file \"$scope_pm\" or \"../perl/$scope_pm\"\n"); 00088 $no_scope_file++; 00089 } 00090 } 00091 // close (IN_LIST); 00092 push (@INC, $scope_pm); 00093 push (@INC, "../perl/$scope_pm"); 00094 00095 if (!@file_errors) { 00096 // #### 00097 // All global variables are defined in the following file 00098 // #### 00099 require $scope_pm; 00100 00101 if (&globe::declare_variables()) { 00102 // print "Variables initialized from $scope_pm.\n"; 00103 } else { 00104 push (@file_errors, "Could not initialize variables from $scope_pm.\n"); 00105 } 00106 } // if not @file_errors 00107 00108 if (@ARGV < 1) { 00109 push (@file_errors, "No path specified as first argument.\n"); 00110 } 00111 00112 // Get path if there is one. 00113 if (@ARGV > 0) { 00114 $globe::path = @ARGV[0]; 00115 if ($globe::path =~ /\//) { 00116 // print "The path specified is $globe::path\n"; 00117 00118 @path_chunks = split ( /\//, $globe::path); 00119 if (@path_chunks < 2) { 00120 $globe::rel_path_to_start_point = "./"; 00121 } else { 00122 $globe::rel_path_to_start_point = "../"; 00123 } 00124 } else { 00125 push (@file_errors, "The input argument \"$globe::path\" requires a forward slash (\/).\n"); 00126 } 00127 } // if 1 or more arguments 00128 00129 if (@ARGV <= 1) { 00130 push (@globe::file_errors, "ERROR: 2nd argument master HTML file is required."); 00131 } // if 2 or more arguments 00132 00133 if (@ARGV > 1) { 00134 $in_file = @ARGV[1]; 00135 // print "The input file is $in_file.\n"; 00136 unless (open ( IN_MASTER, "$in_file")) { 00137 push (@file_errors, "Cannot open file \"$in_file\"\n"); 00138 } 00139 } // if 2 or more arguments 00140 00141 00142 00143 } // BEGIN 00144 00145 //############################################################################# 00146 /** @fn int main 00147 ** @brief The main program. 00148 ** 00149 ** @param None. 00150 ** 00151 ** @return None. 00152 ** 00153 ** @lim None 00154 ** @ingroup tp_nav 00155 **/ 00156 // ############################################################################# 00157 // sub main { 00158 { 00159 // ############################################################################# 00160 // # Program start 00161 // ############################################################################# 00162 00163 if (0){ 00164 // print "=== Definitions 3 \n"; 00165 // exit(1); 00166 } 00167 00168 if (@file_errors) { 00169 // Makes no sense to go on if input parameters are off. 00170 // print "\n============ Summary of errors ==================================\n"; 00171 for ($i=0; $i<@file_errors; $i++){ 00172 // print "$i = $file_errors[$i]\n"; 00173 } 00174 &using_voy_nav(); 00175 // exit(1); 00176 } 00177 00178 00179 &get_input_file ("$in_file"); 00180 if (0) { 00181 // print "got this far...\n"; 00182 } 00183 00184 if (@ARGV > 2) { 00185 &output_toc_script (@ARGV[2]); 00186 } else { 00187 $temp = "$globe::path$_toc_file"; 00188 push (@globe::file_errors, "WARNING: Using default $temp for output toc."); 00189 $temp = "$globe::path$_toc_file"; 00190 &output_toc_script ($temp); 00191 } // if 3 or more arguments 00192 00193 00194 // ############################################################################# 00195 // # End of Program 00196 // ############################################################################# 00197 // exit(0); 00198 } // the main routine 00199 00200 //############################################################################# 00201 /** @fn int using_voy_nav ( ) 00202 ** @brief What to do when no arguments are given. 00203 ** @param None 00204 ** @return None 00205 ** 00206 ** @lim None 00207 ** @ingroup tp_nav 00208 **/ 00209 // ############################################################################# 00210 int using_voy_nav ( ) { 00211 // print "\nxml_2_html_txt.pl operates on text files that indicate heirarchical \n"; 00212 // print "structure of the system. \n"; 00213 // print "1st argument is the root path; required. \n"; 00214 // print "2nd argument name of tree js file; optional. \n"; 00215 // print "3nd argument of the output toc script file; optional. \n"; 00216 00217 return; 00218 } 00219 00220 00221 //############################################################################# 00222 /** @fn int get_input_file 00223 ** @brief Grabs the information from the input file and puts into an array 00224 ** of hash elements. 00225 ** 00226 ** The index into the array is a number that signifies it's placement. 00227 ** Each index element can have three hashes: 00228 ** 00229 ** {level} An indication of the heirarchical placement. 00230 ** {title} The plain text title. 00231 ** {url} The associated URL for the title. 00232 ** 00233 ** @ingroup tp_nav 00234 **/ 00235 // ############################################################################# 00236 int get_input_file ( ) { 00237 $tp_file = $_[0]; 00238 $entire_file = ""; 00239 $folderstree = "foldersTree"; 00240 $aux = "aux"; 00241 $glnk = "gLnk"; 00242 $gfld = "gFld"; 00243 $insfld = "insFld"; 00244 00245 // print "The tp input file is $tp_file\n"; 00246 unless (open ( IN_FILE, $tp_file)) { 00247 // print "Cannot open file \"$tp_file\"\n"; 00248 push (@globe::file_errors, "Cannot open file \"$tp_file\"."); 00249 // exit(1); 00250 } 00251 $_comment = 0; 00252 $_cnt = -1; 00253 // Get the definitions 00254 TP_LINE: while (<IN_FILE>){ // entire file into memory. 00255 $entire_file .= $_; 00256 } 00257 // close (IN_FILE); 00258 00259 @ft = split (/\n/, $entire_file); 00260 for ($i=1; $i <= $// ft; $i++) { 00261 // we are purposely ignoring the 0 element, because this is retrieved elsewhere 00262 // from voy_order in a later process. 00263 &get_gfld_title ($ft[$i], $i); 00264 if (0) { 00265 foreach $ddd (keys %{$tp[$index]} ) { 00266 // print "$index = $ddd = $tp[$index]{$ddd}\n"; 00267 } 00268 } 00269 } 00270 00271 00272 } // get_input_file 00273 00274 00275 //############################################################################# 00276 /** @fn int get_gfld_title 00277 ** @brief 00278 ** 00279 ** 00280 ** 00281 ** @ingroup tp_nav 00282 **/ 00283 // ############################################################################# 00284 int get_gfld_title ( ) { 00285 $in_chunk = $_[0]; 00286 $index = $_[1]; 00287 00288 // split on closing parenthesis 00289 @t_chunk = split (/$glnk|$gfld/, $in_chunk, 2); 00290 if (0) { 00291 // print "$folderstree $aux Glenn, you are here..."; 00292 } 00293 00294 // Level 00295 if ($t_chunk[0] =~ /$folderstree/i) { 00296 $tp[$index]{level} = 1; 00297 if (0) { 00298 // print "what ya doin' here? $folderstree $t_chunk[0]\n"; 00299 } 00300 } elsif ($t_chunk[0] =~ /$aux/i) { 00301 if ($t_chunk[0] =~ /$insfld/i) { 00302 @t1_chunk = split (/$insfld/i, $t_chunk[0], 2); 00303 @t2_chunk = split (/$aux/i, $t1_chunk[1], 2); 00304 @t3_chunk = split (/\,/, $t2_chunk[1], 2); 00305 } else { 00306 @t2_chunk = split (/$aux/i, $t_chunk[0], 2); 00307 @t3_chunk = split (/\,/, $t2_chunk[1], 2); 00308 } 00309 $tp[$index]{level} = $t3_chunk[0]+1; 00310 if (0){ 00311 // print "hey $t3_chunk[0], $t3_chunk[1], $t3_chunk[2]\n"; 00312 } 00313 } else { 00314 if (0) { 00315 // print "You shouldn't be here...\n$t_chunk[0]\n"; 00316 } 00317 } 00318 00319 // Title & URL 00320 @t2_chunk = split (/\,/, $t_chunk[1], 3); 00321 00322 // Title 00323 @t3_chunk = split (/\"/, $t2_chunk[0], 3); 00324 $tp[$index]{title} = $t3_chunk[1]; 00325 if ((1) && (exists ($globe::dox_name_change{$t3_chunk[1]} ) ) ){ 00326 // Changes the name of items to be more meaningful to our environment 00327 $tp[$index]{title} = $globe::dox_name_change{$t3_chunk[1]}; 00328 } 00329 00330 // URL 00331 @t3_chunk = split (/\"/, $t2_chunk[2], 3); 00332 $tp[$index]{url} = $t3_chunk[1]; 00333 00334 if (0) { 00335 foreach $ddd (keys %{$tp[$index]} ) { 00336 // print "$index = $ddd = $tp[$index]{$ddd}\n"; 00337 } 00338 // exit(1); 00339 } 00340 00341 } // get_gfld_title 00342 00343 00344 00345 //############################################################################# 00346 /** @fn int output_toc_script 00347 ** @brief 00348 ** 00349 ** 00350 ** 00351 ** @ingroup tp_nav 00352 **/ 00353 // ############################################################################# 00354 int output_toc_script ( ) { 00355 #define $htree_file $_[0] 00356 00357 if (($htree_file =~ /(\.html)$/i) || ($htree_file =~ /(\.htm)$/i)){ 00358 @_name = split (/\.htm/i, $htree_file, 2); 00359 $htree_file = $_name[0]; 00360 } 00361 $htree_file .= ".script"; 00362 00363 // print "The output TOC script file is \"$htree_file\".\n"; 00364 00365 unless (open(OUT_SCRIPT, ">$htree_file")) { 00366 push (@file_errors, "Cannot open file \"$htree_file\"."); 00367 return(1); 00368 } 00369 00370 // ################################################# 00371 // Root level of tree. 00372 // ################################################# 00373 00374 // ################################################# 00375 // This is the main loop; it starts at a first topic and then traces the next 00376 // topics from there. When a next topic is determined to be a last topic for 00377 // that section, it then goes and gets the next first topic. 00378 // ################################################# 00379 for ($i=1; $i <= $// ft; $i++) { 00380 // we are purposely ignoring the 0 element, because this is retrieved elsewhere 00381 // from voy_order in a later process. 00382 if ((exists ($tp[$i]{url})) && ($tp[$i]{url} =~ /[\w+]/)) { 00383 // print (OUT_SCRIPT "Item level=$tp[$i]{level} "); 00384 // print (OUT_SCRIPT "image=nav_doc.gif "); 00385 // print (OUT_SCRIPT "url=$tp[$i]{url},basefrm "); 00386 // print (OUT_SCRIPT "selected=YES "); 00387 // print (OUT_SCRIPT "text=$tp[$i]{title}\r\n"); 00388 } else { 00389 // if it doesn't exist, don't hyperlink it. 00390 // print (OUT_SCRIPT "Item level=$tp[$i]{level} "); 00391 // // print (OUT_SCRIPT "image=nav_doc.gif "); 00392 // // print (OUT_SCRIPT "url=$tp[$i]{url},basefrm "); 00393 // // print (OUT_SCRIPT "selected=YES "); 00394 // print (OUT_SCRIPT "text=$tp[$i]{title}\r\n"); 00395 } 00396 00397 } // for $i 00398 00399 00400 // ################################################# 00401 // Clean up navigation. 00402 // ################################################# 00403 // close (OUT_SCRIPT); 00404 00405 } // output_toc_script 00406 00407 00408 00409 00410 //############################################################################# 00411 /** @fn int END 00412 ** @brief Code to execute when first entered. 00413 ** 00414 ** @param None. 00415 ** 00416 ** @return None. 00417 ** 00418 ** @lim None 00419 ** @ingroup tp_nav 00420 **/ 00421 // ############################################################################# 00422 int END ( ) { 00423 &globe::do_errors; 00424 // undef ($_file_list); // "_file_list"; 00425 // undef ($_index_file); // = "_index_list"; 00426 // undef ($in_file); // ""; 00427 // undef ($f_type); // "htm"; 00428 00429 00430 // ############################################################################# 00431 // # Memory clean-up. 00432 // ############################################################################# 00433 if ($no_scope_file > 0){ 00434 &globe::memory_clean_up(); 00435 } 00436 00437 if (@file_errors) { 00438 // print "\n============ Summary of errors ==================================\n"; 00439 for ($i=0; $i<@file_errors; $i++){ 00440 // print "$i = $file_errors[$i]\n"; 00441 } 00442 } 00443 00444 // print "\n============ Finished xml_2_html_txt.pl ==================================\n"; 00445 } // END 00446 00447
|
|
|
Open-Source tools compliments of Voyant Technologies, Inc. and Glenn C. Maxey.
01/13/2003
TP Tools v2-00-0a
# tpt-perl-hcr-02