Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for crlf.pl

(view source code of crlf.pl as plain text)

  1. #! perl
  2.  
  3. # Store on screen help text in a variable
  4. $syntax = "\nCrLf.pl, Version 1.10\n";
  5. $syntax = $syntax."Replace orphaned carriage returns (CR, 0Dx) and line feeds (LF, 0Ax) with\n";
  6. $syntax = $syntax."CR/LF pairs (0D0Ax)\n\n";
  7. $syntax = $syntax."Usage:  CRLF.PL [ infile [ outfile ] ]\n";
  8. $syntax = $syntax."or:     any_command | PERL.EXE CRLF.PL > outfile\n";
  9. $syntax = $syntax."or:     CRLF.PL /?\n\n";
  10. $syntax = $syntax."Where:  \"any_command\"  is a command that's standard output is used\n";
  11. $syntax = $syntax."                       instead of \"infile\"\n";
  12. $syntax = $syntax."        \"infile\"       is an ASCII file with improper line terminations\n";
  13. $syntax = $syntax."                       (default: standard input)\n";
  14. $syntax = $syntax."        \"outfile\"      is the corrected ASCII file\n";
  15. $syntax = $syntax."                       (default: standard output)\n\n";
  16. $syntax = $syntax."Written by Rob van der Woude\n";
  17. $syntax = $syntax."http://www.robvanderwoude.com\n";
  18.  
  19. $out = 0;
  20. if ( @ARGV[1] ) {
  21. 	open( OUT, ">@ARGV[1]" ) || die "Cannot open file @ARGV[1]:\n$!\n\n$syntax";
  22. 	$out = 1;
  23. } elsif ( @ARGV[0] eq "/?" ) {
  24. 	print $syntax;
  25. 	exit(1);
  26. }
  27.  
  28. while ( <> ) {
  29. 	$line = $_;
  30. 	$line =~ s/\015(>!\012)/\015\012/g;
  31. 	$line =~ s/(<!\015)\012/\015\012/g;
  32. 	if ( $out == 1 ) {
  33. 		print OUT $line;
  34. 	} else {
  35. 		print STDOUT $line;
  36. 	}
  37. }
  38.  
  39. if ( $out == 1 ) {
  40. 	close( OUT );
  41. }
  42.  

page last modified: 2024-04-16; loaded in 0.0209 seconds