home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / linux / apache / docs / expand.pl < prev    next >
Encoding:
Perl Script  |  1998-06-12  |  4.0 KB  |  105 lines

  1. #!/usr/local/bin/perl5
  2.  
  3. # This is a very simple Perl script to expand server-side includes
  4. # in the directory it is run, and direct subdirectories. It will
  5. # work only on SSI directives of the form
  6. #
  7. # <!--#include virtual="filename" -->
  8. #
  9. # Filename must be relative to the directory the file appears in.
  10. #
  11. # Nov 30, 1996 - Alexei Kosut <akosut@apache.org>
  12.  
  13. # ====================================================================
  14. # Copyright (c) 1996-1998 The Apache Group.  All rights reserved.
  15. #
  16. # Redistribution and use in source and binary forms, with or without
  17. # modification, are permitted provided that the following conditions
  18. # are met:
  19. #
  20. # 1. Redistributions of source code must retain the above copyright
  21. #    notice, this list of conditions and the following disclaimer. 
  22. #
  23. # 2. Redistributions in binary form must reproduce the above copyright
  24. #    notice, this list of conditions and the following disclaimer in
  25. #    the documentation and/or other materials provided with the
  26. #    distribution.
  27. #
  28. # 3. All advertising materials mentioning features or use of this
  29. #    software must display the following acknowledgment:
  30. #    "This product includes software developed by the Apache Group
  31. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  32. #
  33. # 4. The names "Apache Server" and "Apache Group" must not be used to
  34. #    endorse or promote products derived from this software without
  35. #    prior written permission.
  36. #
  37. # 5. Products derived from this software may not be called "Apache"
  38. #    nor may "Apache" appear in their names without prior written
  39. #    permission of the Apache Group.
  40. #
  41. # 6. Redistributions of any form whatsoever must retain the following
  42. #    acknowledgment:
  43. #    "This product includes software developed by the Apache Group
  44. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  45. #
  46. # THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  47. # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  48. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  49. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  50. # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  51. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  52. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  53. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  54. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  55. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  57. # OF THE POSSIBILITY OF SUCH DAMAGE.
  58. # ====================================================================
  59. #
  60. # This software consists of voluntary contributions made by many
  61. # individuals on behalf of the Apache Group and was originally based
  62. # on public domain software written at the National Center for
  63. # Supercomputing Applications, University of Illinois, Urbana-Champaign.
  64. # For more information on the Apache Group and the Apache HTTP server
  65. # project, please see <http://www.apache.org/>.
  66.  
  67. # Put a list of dirs (except ..) into @dirs
  68.  
  69. opendir DIR, "." or die "Could not open directory: $!";
  70. @dirs = grep !/^\.\.$/, (grep -d, readdir DIR);
  71. closedir DIR;
  72.  
  73. foreach $dir (@dirs) {
  74.     print "Entering directory $dir\n";
  75.     opendir SUBDIR, "$dir" or die "Could not open subdir $dir: $!";
  76.     foreach $file (grep /\.html$/, readdir SUBDIR) {
  77.     print "Expanding file $dir/$file\n";
  78.     rename "$dir/$file", "$dir/${file}.old";
  79.     open READ, "$dir/${file}.old" or die "Couldn't read $dir/$file: $!";
  80.     open WRITE, ">$dir/$file" or die "Couldn't write $dir/$file: $!";
  81.     while ($r = <READ>) {
  82.         if ($r =~ /<!--#include virtual="(.*)" -->/) {
  83.         ($pre, $include, $post) = ($`, $1, $');
  84.         print WRITE $pre;
  85.  
  86.         open INC, "$dir/$include" or
  87.             print "Could not include file $dir/$include: $!";
  88.         print WRITE while (<INC>);
  89.         close INC;
  90.  
  91.         print WRITE $post;
  92.         }
  93.         else {
  94.         print WRITE $r;
  95.         }
  96.     }
  97.     close READ;
  98.     close WRITE;
  99.     unlink "$dir/$file.old";
  100.     }
  101.     closedir SUBDIR;
  102. }
  103.  
  104.  
  105.