Beispiel #1
0
char *DEH_ReadLine(deh_context_t *context)
{
    int c;
    int pos;

    for (pos = 0;;)
    {
        c = DEH_GetChar(context);

        if (c < 0)
        {
            // end of file

            return NULL;
        }

        // cope with lines of any length: increase the buffer size

        if (pos >= context->readbuffer_size)
        {
            IncreaseReadBuffer(context);
        }

        if (c == '\n')
        {
            // end of line: a full line has been read

            context->readbuffer[pos] = '\0';
            break;
        }
        else if (c != '\0')
        {
            // normal character; don't allow NUL characters to be
            // added.

            context->readbuffer[pos] = (char) c;
            ++pos;
        }
    }
    
    return context->readbuffer;
}
Beispiel #2
0
char *DEH_ReadLine(deh_context_t *context, boolean extended)
{
    int c;
    int pos;
    boolean escaped = false;

    for (pos = 0;;)
    {
        c = DEH_GetChar(context);

        if (c < 0 && pos == 0)
        {
            // end of file

            return NULL;
        }

        // cope with lines of any length: increase the buffer size

        if (pos >= context->readbuffer_size)
        {
            IncreaseReadBuffer(context);
        }

        // extended string support
        if (extended && c == '\\')
        {
            c = DEH_GetChar(context);

            // "\n" in the middle of a string indicates an internal linefeed
            if (c == 'n')
            {
                context->readbuffer[pos] = '\n';
                ++pos;
                continue;
            }

            // values to be assigned may be split onto multiple lines by ending
            // each line that is to be continued with a backslash
            if (c == '\n')
            {
                escaped = true;
                continue;
            }
        }

        // blanks before the backslash are included in the string
        // but indentation after the linefeed is not
        if (escaped && c >= 0 && isspace(c) && c != '\n')
        {
            continue;
        }
        else
        {
            escaped = false;
        }

        if (c == '\n' || c < 0)
        {
            // end of line: a full line has been read

            context->readbuffer[pos] = '\0';
            break;
        }
        else if (c != '\0')
        {
            // normal character; don't allow NUL characters to be
            // added.

            context->readbuffer[pos] = (char) c;
            ++pos;
        }
    }
    
    return context->readbuffer;
}