home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / patch / mbq090 / _conv.pl < prev    next >
Encoding:
Perl Script  |  1996-08-17  |  1.8 KB  |  56 lines

  1. #!/usr/bin/perl
  2.  
  3. #
  4. # conv.pl
  5. #
  6. # Copyright (C) 1996 Johannes Plass
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. # Author:   Johannes Plass (plass@dipmza.physik.uni-mainz.de)
  20. #
  21.  
  22. $addcr=0; # strip cr by default
  23. if ($ARGV[0] =~ /.*dos/) { $addcr=1; }
  24.  
  25. $qc_files = "*.qc *.qh progs.src progdefs.h";
  26. $listfile="sources.list";
  27. unlink($listfile);
  28. system("ls -1 $qc_files > $listfile");
  29. open (LISTFILE,  "<" . $listfile) || die "no list of files";
  30. while ($srcfile=<LISTFILE>) {
  31.     chop $srcfile;
  32.     $destfile = "$srcfile.tmp";
  33.     if ($addcr) { print("Adding CR to $srcfile.\n"); }
  34.     else        { print("Stripping CR from $srcfile.\n"); }
  35.     unlink($destfile);
  36.     open (DESTFILE,  ">" . "$destfile") || die "cannot open destfile";
  37.     if (open (SRCFILE,  "<" . "$srcfile") || die "cannot open srcfile") {
  38.     while ($line = <SRCFILE>) {
  39.         if ($addcr) {
  40.         if ($line =~ /^.*[^\r]$/) { $line =~ s/^(.*)$/$1\r/;   }        
  41.         } else {
  42.         if ($line =~ /^.*\r+$/)   { $line =~ s/^(.*?)\r+$/$1/; }
  43.         }
  44.         print DESTFILE $line;
  45.         }
  46.     }
  47.     close SRCFILE;
  48.     close DESTFILE;
  49.     system("mv $destfile $srcfile");
  50. }
  51. close LISTFILE;
  52. unlink($listfile);
  53.