| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

file_set_eoln

#include "sflfile.h"
dbyte
file_set_eoln (char *dst, const char *src, dbyte src_size, Bool add_cr)

Synopsis

Formats any end-of-line sequences in the buffer according to the value of the add_cr argument. If this is TRUE, all end-of- lines (LF or CRLF or LFCR) are represented by a CRLF sequence. If FALSE, all end-of-lines are represented by LF by itself. The target buffer must be large enough to accomodate the resulting line (twice the size of the source data). Returns the size of the resulting data in the target buffer not counting the final trailing null byte. The input data does not need to be null- terminated, but the output data is terminated with an extra null in any case.

Source Code - (sflfile.c)

{
    char
        *srcptr,                        /*  Current character in src         */
        *dstptr,                        /*  Current character in dst         */
        *last;                          /*  Last character in src            */

    ASSERT (src);
    ASSERT (dst);

    srcptr = (char *) src;
    dstptr = dst;
    last   = (char *) src + src_size;

    while (*srcptr && srcptr < last)
      {
        if (*srcptr == '\n')
          {
            if (add_cr)
                *dstptr++ = '\r';
            *dstptr++ = '\n';
          }
        else
        if (*srcptr != '\r' && *srcptr != 26)
            *dstptr++ = *srcptr;
        srcptr++;
      }
    *dstptr = '\0';
    return ((dbyte) (dstptr - dst));
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation