X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=shell_include;fp=shell_include;h=0000000000000000000000000000000000000000;hb=de93115ab4922bad8986ca891a1f71eb7176b2b9;hp=b404f85747b4d04e02bb8863fbf6b36603b49514;hpb=b78b4a0b9256d477c3bdb70693a66de3da3865d2;p=pingofdeath.git diff --git a/shell_include b/shell_include deleted file mode 100755 index b404f85..0000000 --- a/shell_include +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/perl - -use strict; -use Getopt::Long; - -my $source = ""; -my $destination = ""; -my $make; -my $help; - -my @lines; -my %included; - -######################################################################## -# -# usage -# - -sub usage() -{ - print "Usage: shell_include --source --destination [--make] [--help]\n"; - print "\n"; - print "--make will output makefile dependencies to stdout and exit\n"; - print "--help will output this text and exit\n"; - print "\n"; -} -######################################################################## -# -# check_options -# - -sub check_options() -{ - if ( !GetOptions( - 's|source=s' => \$source, - 'd|destination=s' => \$destination, - 'm|make' => \$make, - 'h|help' => \$help ) ) - { - &usage; - exit 1; - } - - if ( $help ) { - &usage; - exit 0; - }; - - die( "Missing input file - use --source " ) if ( $source eq "" ); - die( "Missing output file - use --destination ") if ( $destination eq "" ); -} - -######################################################################## -# -# read_input : Read in the initial input file into @lines -# - -sub read_input() -{ - open( SOURCE, $source ) || die ( "Cannot open input file : $source" ); - while ( ) { - @lines = ( @lines, $_ ); - }; - close( SOURCE ); -} - -######################################################################## -# -# Process #include directives -# -sub process_includes() -{ - my $changed = 0; - my @newlines; - - foreach my $line ( @lines ) { - - if ( $line =~ /^(\s*)\#include(\s+)(\S+)/ ) { - $changed = 1; - my $filename = $3; - if ( ! defined $included{ $filename } ) { - open( INC, $filename ) || die ( "Cannot open include file : $filename" ); - @newlines = ( @newlines, "########################################################################\n" ); - @newlines = ( @newlines, "#\n" ); - @newlines = ( @newlines, "# Included file : $filename\n" ); - @newlines = ( @newlines, "#\n" ); - while( ) { - @newlines = ( @newlines, $_ ); - } - close( INC ); - @newlines = ( @newlines, "#\n" ); - @newlines = ( @newlines, "# End of included file : $filename\n" ); - @newlines = ( @newlines, "#\n" ); - @newlines = ( @newlines, "########################################################################\n" ); - $included{ $filename } = ""; - } - } else { - @newlines = ( @newlines, $line ); - } - } - @lines = @newlines; - return $changed; -} - -######################################################################## -# -# write_output : write the final set of lines to the output file -# -sub write_output() -{ - open( DEST, ">$destination" ) || die( "Cannot open output file : $destination" ); - foreach my $line ( @lines ) { - print DEST $line; - } - close( DEST ); -} - -&check_options; -&read_input; -while ( &process_includes ) { }; -if ( $make ) { - print "$destination: $source "; - foreach my $inc ( sort( keys( %included ) ) ) { - print "$inc "; - }; - print "\n"; -} else { - &write_output; -}