Crlf Sample

Sample Overview

This sample tool is a line termination analyzer. It reads a text file and analyzes all line termination in the file.  It looks for linefeed-only characters or matched sets of carriage-return (CR) and linefeed (LF) characters.  It also finds carriage-return-only characters but treats these as errors.

The sample will convert files from CRLF format to linefeed-only and from linefeed-only to CRLF.  It will remove carriage-returns that aren't matched with linefeeds or convert them to the existing line termination, depending on user input.

The sample stores the locations to all line terminations in a specialized list type that allows walking the list from one line termination character to the next. So while the initial computation of the locations is relatively slow, subsequent modifications are relatively efficient.

The sample demonstrates binary file input and output.

Sample Source and Build Output Locations

The sample source is found in sscli\samples\utilities\crlf. 

The source file is:

The build output location is %TARGETCOMPLUS%\samples\utilities\crlf. The output file is an executable assembly named crlf.exe.

Building the Sample

All samples are built from the buildall script. 

You can also build all the samples by switching to the root of the sample directory, sscli\samples, and typing build -c.

You can build this specific sample by switching to the sample directory and typing build -c.

Running the Sample

These steps require that the Shared Source CLI (SSCLI) be already built and functional.

  1. Run env.bat or source the env.csh or env.sh script files, depending on your platform.
  2. Switch to the %TARGETCOMPLUS%\samples\utilities\crlf directory.
  3. Type the following command:

    clix crlf.exe files

where files is the name of the file in which you want line termination analysis or a wildcard expression that will match a set of files.


Copyright (c) 2002 Microsoft Corporation. All rights reserved.