HavenRock.com: home
 
Asia ... Documentation ... Downloads ... DSSSL ... EFL/ESL ... HTML tools ... Japanese text ... Linux ... Photography ... Python ... SGML ... Tcl/Tk ... TeX ... Tips ... Typography ... Word processing

Or, for those who prefer Perl:

Peter Samuelson responded with the following, posted in the September issue of Linux Gazette.

In LG31 you published a 2c tip for a unix2dos replacement written in Tcl. The author asserts that "It turned out to be really easy to do this in Tcl." Even easier in Perl, I say. Symlink the following code to the same names (d2u, u2d, m2d, m2u, u2m, d2m) Matt used. Make sure this file has execute permission, of course.

Also, if you just want Perl to edit the input files in place, change the "perl -wp" to something like "perl -wpi.orig"....

Peter Samuelson

 
#!/usr/bin/perl -wp
#
# Simpler unix2dos2mac utility for 2-cent tip,
# mainly because Tcl is ugly.
# No comments that Perl is ugly too, please.
#
# Usage: a standard Unix filter:
#   input:  filename(s) or stdin
#   output: stdout
# Buglet: u2m leaves lone CR at the end of file
#   if it didn't end in LF
#   (Fixing it would use more memory.)

BEGIN {
  $_=$0 =~ s|.*/||;
  $pcmd='s/$/\r/'       if ($0 eq 'u2d');
  $pcmd='s/\r$//'       if ($0 eq 'd2u');
  $pcmd='s/$/\r/;chop'  if ($0 eq 'u2m');
  $pcmd='s/\r/\n/g'     if ($0 eq 'm2u');
  $pcmd='chomp'         if ($0 eq 'd2m');
  $pcmd='s/\r/\r\n/g'   if ($0 eq 'm2d');
  unless($pcmd) {
    print STDERR "This script must be invoked\n
under one of the names:\n",
                 "  u2d, d2u, u2m, m2u, d2m, m2d\n";
    exit 1;
  }
}

eval $pcmd;
	      

Tcl is ugly?! Oh well, de gustibus non disputandum est.


	      
Matt Gushee

Last modified: Sun Oct 17 11:26:48 EDT 1999