Skip to content

Building glbind.h on Windows through MinGW mixes CRLF lines with LF lines #2

@Nostress767

Description

@Nostress767

Since glbOpenAndReadFileWithExtraData uses "rb" mode to open files, on Windows they will retain their CR (\r).

result = glbFOpen(filePath, "rb", &pFile);

This causes a problem, because despite tinyxml2 also opening the (.xml) file in "rb" mode
FILE* fp = callfopen( filename, "rb" );

they strip the CR's before parsing
if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
// CR-LF pair becomes LF
// CR alone becomes LF
// LF-CR becomes LF
if ( *(p+1) == LF ) {
p += 2;
}
else {
++p;
}
*q = LF;
++q;
}

So, when the tags in the template file are replaced

glbind/source/glbind_build.cpp

Lines 1698 to 1706 in bb63d02

for (size_t iTag = 0; iTag < sizeof(tags)/sizeof(tags[0]); ++iTag) {
std::string generatedCode;
result = glbBuildGenerateCode_C(context, tags[iTag], generatedCode);
if (result != GLB_SUCCESS) {
return result;
}
glbReplaceAllInline(outputStr, tags[iTag], generatedCode);
}

they have only LF line endings.

You can check this is the case by compiling and running the build code with MinGW.
Checking with git:

glbind $ git ls-files --eol
i/lf    w/crlf  attr/                   .gitignore
i/lf    w/crlf  attr/                   README.md
i/lf    w/crlf  attr/                   build/README.md
i/lf    w/crlf  attr/                   examples/01_Triangle/01_Triangle.c
i/lf    w/crlf  attr/                   examples/99_ARB_shaders/99_ARB_shaders.c
i/lf    w/crlf  attr/                   examples/99_ARB_shaders/resources/FragmentShader.txt
i/lf    w/crlf  attr/                   examples/99_ARB_shaders/resources/VertexShader.txt
i/lf    w/crlf  attr/                   examples/glbExamplesCommon.c
i/lf    w/mixed attr/                   glbind.h
i/lf    w/crlf  attr/                   resources/README.md
i/lf    w/crlf  attr/                   source/external/tinyxml2.cpp
i/lf    w/crlf  attr/                   source/external/tinyxml2.h
i/lf    w/crlf  attr/                   source/glbind_build.cpp
i/lf    w/crlf  attr/                   source/glbind_template.h

I made a fix by stripping the CR's #1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions