loader/config.c
static CHAR16 *ReadLine(REFIT_FILE *File)
{
    CHAR16  *Line, *q;
    UINTN   LineLength;

    if (File->Buffer == NULL)
        return NULL;

    if (File->Encoding == ENCODING_ISO8859_1 || File->Encoding == ENCODING_UTF8) {

        CHAR8 *p, *LineStart, *LineEnd;

        p = File->Current8Ptr;
        if (p >= File->End8Ptr)
            return NULL;

        LineStart = p;
        for (; p < File->End8Ptr; p++)
            if (*p == 13 || *p == 10)
                break;
        LineEnd = p;
        for (; p < File->End8Ptr; p++)
            if (*p != 13 && *p != 10)
                break;
        File->Current8Ptr = p;

        LineLength = (UINTN)(LineEnd - LineStart) + 1;
        Line = AllocatePool(LineLength * sizeof(CHAR16));
        if (Line == NULL)
            return NULL;

        q = Line;
        if (File->Encoding == ENCODING_ISO8859_1) {
            for (p = LineStart; p < LineEnd; )
                *q++ = *p++;
        } else if (File->Encoding == ENCODING_UTF8) {
            // TODO: actually handle UTF-8
            for (p = LineStart; p < LineEnd; )
                *q++ = *p++;
        }
        *q = 0;

    } else if (File->Encoding == ENCODING_UTF16_LE) {

        CHAR16 *p, *LineStart, *LineEnd;

        p = File->Current16Ptr;
        if (p >= File->End16Ptr)
            return NULL;

        LineStart = p;
        for (; p < File->End16Ptr; p++)
            if (*p == 13 || *p == 10)
                break;
        LineEnd = p;
        for (; p < File->End16Ptr; p++)
            if (*p != 13 && *p != 10)
                break;
        File->Current16Ptr = p;

        LineLength = (UINTN)(LineEnd - LineStart) + 1;
        Line = AllocatePool(LineLength * sizeof(CHAR16));
        if (Line == NULL)
            return NULL;

        for (p = LineStart, q = Line; p < LineEnd; )
            *q++ = *p++;
        *q = 0;

    } else
        return NULL;   // unsupported encoding

    return Line;
}
//
// get a single line of text from a file
//
get a single line of text from a file
get a single line of text from a file
static CHAR16 *ReadLine(REFIT_FILE *File)
{
    CHAR16  *Line, *q;
    UINTN   LineLength;
    if (File->Buffer == NULL)
        return NULL;
    if (File->Encoding == ENCODING_ISO8859_1 || File->Encoding == ENCODING_UTF8) {
        CHAR8 *p, *LineStart, *LineEnd;
        p = File->Current8Ptr;
        if (p >= File->End8Ptr)
            return NULL;
        LineStart = p;
        for (; p < File->End8Ptr; p++)
            if (*p == 13 || *p == 10)
                break;
        LineEnd = p;
        for (; p < File->End8Ptr; p++)
            if (*p != 13 && *p != 10)
                break;
        File->Current8Ptr = p;
        LineLength = (UINTN)(LineEnd - LineStart) + 1;
        Line = AllocatePool(LineLength * sizeof(CHAR16));
        if (Line == NULL)
            return NULL;
        q = Line;
        if (File->Encoding == ENCODING_ISO8859_1) {
            for (p = LineStart; p < LineEnd; )
                *q++ = *p++;
        } else if (File->Encoding == ENCODING_UTF8) {
            for (p = LineStart; p < LineEnd; )
                *q++ = *p++;
        }
        *q = 0;
    } else if (File->Encoding == ENCODING_UTF16_LE) {
        CHAR16 *p, *LineStart, *LineEnd;
        p = File->Current16Ptr;
        if (p >= File->End16Ptr)
            return NULL;
        LineStart = p;
        for (; p < File->End16Ptr; p++)
            if (*p == 13 || *p == 10)
                break;
        LineEnd = p;
        for (; p < File->End16Ptr; p++)
            if (*p != 13 && *p != 10)
                break;
        File->Current16Ptr = p;
        LineLength = (UINTN)(LineEnd - LineStart) + 1;
        Line = AllocatePool(LineLength * sizeof(CHAR16));
        if (Line == NULL)
            return NULL;
        for (p = LineStart, q = Line; p < LineEnd; )
            *q++ = *p++;
        *q = 0;
    } else
        return NULL;   
    return Line;
}
static CHAR16 * ReadLine ( REFIT_FILE * File ) { CHAR16 * Line , * q ; UINTN LineLength ; if ( File -> Buffer == NULL ) return NULL ; if ( File -> Encoding == ENCODING_ISO8859_1 || File -> Encoding == ENCODING_UTF8 ) { CHAR8 * p , * LineStart , * LineEnd ; p = File -> Current8Ptr ; if ( p >= File -> End8Ptr ) return NULL ; LineStart = p ; for ( ; p < File -> End8Ptr ; p ++ ) if ( * p == 13 || * p == 10 ) break ; LineEnd = p ; for ( ; p < File -> End8Ptr ; p ++ ) if ( * p != 13 && * p != 10 ) break ; File -> Current8Ptr = p ; LineLength = ( UINTN ) ( LineEnd - LineStart ) + 1 ; Line = AllocatePool ( LineLength * sizeof ( CHAR16 ) ) ; if ( Line == NULL ) return NULL ; q = Line ; if ( File -> Encoding == ENCODING_ISO8859_1 ) { for ( p = LineStart ; p < LineEnd ; ) * q ++ = * p ++ ; } else if ( File -> Encoding == ENCODING_UTF8 ) { for ( p = LineStart ; p < LineEnd ; ) * q ++ = * p ++ ; } * q = 0 ; } else if ( File -> Encoding == ENCODING_UTF16_LE ) { CHAR16 * p , * LineStart , * LineEnd ; p = File -> Current16Ptr ; if ( p >= File -> End16Ptr ) return NULL ; LineStart = p ; for ( ; p < File -> End16Ptr ; p ++ ) if ( * p == 13 || * p == 10 ) break ; LineEnd = p ; for ( ; p < File -> End16Ptr ; p ++ ) if ( * p != 13 && * p != 10 ) break ; File -> Current16Ptr = p ; LineLength = ( UINTN ) ( LineEnd - LineStart ) + 1 ; Line = AllocatePool ( LineLength * sizeof ( CHAR16 ) ) ; if ( Line == NULL ) return NULL ; for ( p = LineStart , q = Line ; p < LineEnd ; ) * q ++ = * p ++ ; * q = 0 ; } else return NULL ; return Line ; }
get a single line of text from a file
get a single line of text from a file
// TODO: actually handle UTF-8 // unsupported encoding