The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

nlcvt - convert foreign line terminators

SYNOPSIS

nlcvt src2dst [file ...]

unix2mac [file ...]

unix2cpm [file ...]

cpm2unix [file ...]

cpm2mac [file ...]

mac2unix [file ...]

mac2cpm [file ...]

DESCRIPTION

Mike O'Dell said, only half-jokingly, that "the most brilliant decision in all of Unix was the choice of a single character for the newline sequence." But legacy systems live on past their days, and these programs can help that. Note, however, that if you've downloaded a binary file in "text" mode rather than "binary", your mileage may vary.

The nlcvt program, or any of its many aliases, is a filter to convert from one system's notion of proper line terminators to that of another. This usually happens because you've downloaded or otherwise directly transferred a text file in so-called "binary" rather than "text" mode.

Unix format considers a lone Control-J to be the end of line. Mac format considers a lone Control-M to be the end of line. The archaic CP/M format considers a Control-M and a Control-J to be the end of line.

This program expects its first argument to be of the form src2dst, where src and dst are both one of unix, mac, or cpm. (That's speaking canonically--many aliases for those systems exist: call nlcvt without arguments to see what names are accepted.) The converted data is written to the standard output. nlcvt does not do destructive, in-place modification of its source files. Do this instead:

    cpm2unix < file.bad > file.good 
    mv file.good file.bad

This program can also be called by the name of the conversion itself. Just create links to the nlcvt program for each systems, and the program use its own name to determine the conversion. For example:

    #!/usr/bin/perl
    # make nlcvt links
    chomp($path = `which nlcvt`);
    @systems = qw(unix mac cpm);
    for $src (@systems) {
        for $dst (@systems) {
            next if $src eq $dst;
            ln($path, "${src}2$dst") || die $!;
        } 
    } 

DIAGNOSTICS

Any of the following diagnostics cause nlcvt to exit non-zero.

insufficient args

You called the program by its canonical name, and supplied no other arguments. You must supply a conversion argument.

no conversion specified

Neither the name of the program nor its first argument were of the form src2dst.

unknown input format: %s

The specified input format, %s, was unknown. Call nlcvt without arguments for a list of valid conversion formats.

unknown output format: %s

The specified output format, %s, was unknown. Call nlcvt without arguments for a list of valid conversion formats.

cannot open %s: %m

The input file %s could not be opened for the reason listed in %m.

cannot close %s: %m

The input file %s could not be close for the reason listed in %m. This error is rare.

can't close stdout: %m

The filter could not finish writing to its standard output for the reason listed in %m. This could be caused by a full or temporarily unreachable file system.

WARNING: last line of %s truncated, correcting

Text files contain zero or more variable-length, newline-terminated records. Occasionally, the final record terminator is missing, perhaps due to an incomplete transfer, perhaps due to an aberrant emacs user. A newline sequence appropriate to the destination system is appended. This would be a valid use of a unix2unix conversion. And no, you can't call it as emacs2vi.

WARNING: %s appears to be a binary file

Perl's -T operator did not think the input file was a text file. The conversion is still performed, but is of dubious value. If the file really was binary, the resulting output may be mangled. Garbage in, garbage out.

AUTHOR

Tom Christiansen, tchrist@perl.com.

COPYRIGHT

This program is copyright (c) 1999 by Tom Christiansen.

This program is free and open software. You may use, copy, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same.