Reorder parser line reading
This commit is contained in:
parent
d6700680d8
commit
e3cafe1928
|
|
@ -196,11 +196,8 @@ int main(int argc, char* argv[])
|
||||||
int linesCount = 0;
|
int linesCount = 0;
|
||||||
char **lines = GetTextLines(buffer, length, &linesCount);
|
char **lines = GetTextLines(buffer, length, &linesCount);
|
||||||
|
|
||||||
// Function line indices
|
// Defines line indices
|
||||||
int *funcLines = (int *)malloc(MAX_FUNCS_TO_PARSE*sizeof(int));
|
int *defineLines = (int *)malloc(MAX_DEFINES_TO_PARSE*sizeof(int));
|
||||||
|
|
||||||
// Callbacks line indices
|
|
||||||
int *callbackLines = (int *)malloc(MAX_CALLBACKS_TO_PARSE*sizeof(int));
|
|
||||||
|
|
||||||
// Structs line indices
|
// Structs line indices
|
||||||
int *structLines = (int *)malloc(MAX_STRUCTS_TO_PARSE*sizeof(int));
|
int *structLines = (int *)malloc(MAX_STRUCTS_TO_PARSE*sizeof(int));
|
||||||
|
|
@ -211,46 +208,27 @@ int main(int argc, char* argv[])
|
||||||
// Enums line indices
|
// Enums line indices
|
||||||
int *enumLines = (int *)malloc(MAX_ENUMS_TO_PARSE*sizeof(int));
|
int *enumLines = (int *)malloc(MAX_ENUMS_TO_PARSE*sizeof(int));
|
||||||
|
|
||||||
// Defines line indices
|
// Callbacks line indices
|
||||||
int *defineLines = (int *)malloc(MAX_DEFINES_TO_PARSE*sizeof(int));
|
int *callbackLines = (int *)malloc(MAX_CALLBACKS_TO_PARSE*sizeof(int));
|
||||||
|
|
||||||
|
// Function line indices
|
||||||
|
int *funcLines = (int *)malloc(MAX_FUNCS_TO_PARSE*sizeof(int));
|
||||||
|
|
||||||
// Prepare required lines for parsing
|
// Prepare required lines for parsing
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Read function lines
|
// Read define lines
|
||||||
for (int i = 0; i < linesCount; i++)
|
for (int i = 0; i < linesCount; i++)
|
||||||
{
|
{
|
||||||
// Read function line (starting with `define`, i.e. for raylib.h "RLAPI")
|
int j = 0;
|
||||||
if (IsTextEqual(lines[i], apiDefine, TextLength(apiDefine)))
|
while ((lines[i][j] == ' ') || (lines[i][j] == '\t')) j++; // skip spaces and tabs in the begining
|
||||||
|
// Read define line
|
||||||
|
if (IsTextEqual(lines[i]+j, "#define ", 8))
|
||||||
{
|
{
|
||||||
funcLines[funcCount] = i;
|
// Keep the line position in the array of lines,
|
||||||
funcCount++;
|
// so, we can scan that position and following lines
|
||||||
}
|
defineLines[defineCount] = i;
|
||||||
}
|
defineCount++;
|
||||||
|
|
||||||
// Read callback lines
|
|
||||||
for (int i = 0; i < linesCount; i++)
|
|
||||||
{
|
|
||||||
// Find callbacks (lines with "typedef ... (* ... )( ... );")
|
|
||||||
if (IsTextEqual(lines[i], "typedef", 7))
|
|
||||||
{
|
|
||||||
bool hasBeginning = false;
|
|
||||||
bool hasMiddle = false;
|
|
||||||
bool hasEnd = false;
|
|
||||||
|
|
||||||
for (int c = 0; c < MAX_LINE_LENGTH; c++)
|
|
||||||
{
|
|
||||||
if ((lines[i][c] == '(') && (lines[i][c + 1] == '*')) hasBeginning = true;
|
|
||||||
if ((lines[i][c] == ')') && (lines[i][c + 1] == '(')) hasMiddle = true;
|
|
||||||
if ((lines[i][c] == ')') && (lines[i][c + 1] == ';')) hasEnd = true;
|
|
||||||
if (hasEnd) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasBeginning && hasMiddle && hasEnd)
|
|
||||||
{
|
|
||||||
callbackLines[callbackCount] = i;
|
|
||||||
callbackCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,18 +294,40 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read const lines
|
// Read callback lines
|
||||||
for (int i = 0; i < linesCount; i++)
|
for (int i = 0; i < linesCount; i++)
|
||||||
{
|
{
|
||||||
int j = 0;
|
// Find callbacks (lines with "typedef ... (* ... )( ... );")
|
||||||
while ((lines[i][j] == ' ') || (lines[i][j] == '\t')) j++; // skip spaces and tabs in the begining
|
if (IsTextEqual(lines[i], "typedef", 7))
|
||||||
// Read define line
|
|
||||||
if (IsTextEqual(lines[i]+j, "#define ", 8))
|
|
||||||
{
|
{
|
||||||
// Keep the line position in the array of lines,
|
bool hasBeginning = false;
|
||||||
// so, we can scan that position and following lines
|
bool hasMiddle = false;
|
||||||
defineLines[defineCount] = i;
|
bool hasEnd = false;
|
||||||
defineCount++;
|
|
||||||
|
for (int c = 0; c < MAX_LINE_LENGTH; c++)
|
||||||
|
{
|
||||||
|
if ((lines[i][c] == '(') && (lines[i][c + 1] == '*')) hasBeginning = true;
|
||||||
|
if ((lines[i][c] == ')') && (lines[i][c + 1] == '(')) hasMiddle = true;
|
||||||
|
if ((lines[i][c] == ')') && (lines[i][c + 1] == ';')) hasEnd = true;
|
||||||
|
if (hasEnd) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasBeginning && hasMiddle && hasEnd)
|
||||||
|
{
|
||||||
|
callbackLines[callbackCount] = i;
|
||||||
|
callbackCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read function lines
|
||||||
|
for (int i = 0; i < linesCount; i++)
|
||||||
|
{
|
||||||
|
// Read function line (starting with `define`, i.e. for raylib.h "RLAPI")
|
||||||
|
if (IsTextEqual(lines[i], apiDefine, TextLength(apiDefine)))
|
||||||
|
{
|
||||||
|
funcLines[funcCount] = i;
|
||||||
|
funcCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user