2
0

combineconf.pl 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/perl -w
  2. use strict;
  3. =head1 NAME
  4. combineconf.pl - expand #include PIs in a freeswitch conf file
  5. =head1 SYNOPSIS
  6. # cd conf
  7. # ../scripts/combineconf.pl freeswitch.xml > freeswitch_combined.xml
  8. =head1 DESCRIPTION
  9. This is recursive, and will take multiple input files on the command line.
  10. You need to run it from the working directory that the relative include paths
  11. except to be resolved from.
  12. =head1 AUTHOR
  13. Mark D. Anderson (mda@discerning.com)
  14. Released under same terms as Perl, or alternatively the MPL.
  15. =cut
  16. use IO::File;
  17. sub filter_file {
  18. my ($f) = @_;
  19. my $fh = $f eq '-' ? \*STDIN : IO::File->new($f, 'r');
  20. die "ERROR: Can't open $f: $!\n" unless $fh;
  21. while(<$fh>) {
  22. if (m/<!--#include\s+"(.*?)"/) {
  23. filter_file($1);
  24. }
  25. else {print;}
  26. }
  27. undef $fh;
  28. }
  29. sub main {
  30. die "Usage: $0 file1 ...\nCombined output goes to stdout. Use '-' as the filename to use stdin." unless @ARGV;
  31. for(@ARGV) {
  32. filter_file($_);
  33. }
  34. }
  35. main();