View Raw SPL
/*****************************************************************************
*                                                                            *
*   UNIX2DOS.SPL  Copyright (C) 2009 DSP Development Corporation             *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:       Randy Race                                                 *
*                                                                            *
*   Synopsis:     Converts Unix style linfeeds to CR-LF pairs                *
*                                                                            *
*   Revisions:    21 Jul 2009  RRR  Creation                                 *
*                                                                            *
*****************************************************************************/


#if @HELP_UNIX2DOS

    UNIX2DOS

    Purpose: Converts a files of Unix style linefeeds to CR-LF pairs.

    Syntax:  UNIX2DOS(infile, outfile)

                infile - A string, the file to convert.

               outfile - Optional, a string, the name of the output
                         file. Defaults to infile.
           

    Returns: 1 if successful. Each linefeed character is converted to
             carriage return-linefeed pairs.

    Example:
             unix2dos("myfile.txt")

             converts each linefeed character to CR-LF.
    Remarks:
             Text files produced under Unix systems often use a single
             linefeed character (10) to indicate a new line. Windows
             systems use carriage return-linefeed pairs (13 10).

    See Also:
             filestrrep
             strchars
             strrep
#endif


/* convert unix linefeeds to CR-LF pair */
unix2dos(fname = "", outname = fname, recurse = 0)
{
        local status;

        if (not(isstring(fname)) || strlen(fname) == 0)
        {
                error(sprintf("%s - filename required", __FUNC__));
        }

        if (not(outname == fname))
        {
                copyfile(fname, outname, 0);
        }

        /* let filestrrep handle wildcards */
        status = filestrrep(outname, strchar(10), strescape("\r\n"));

        return(status);
}