| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
#define _CRT_SECURE_NO_WARNINGS |
| 60 |
|
| 61 |
#include <stdlib.h> |
| 62 |
#include <stdio.h> |
| 63 |
#include <stdbool.h> |
| 64 |
#include <ctype.h> |
| 65 |
|
| 66 |
#define MAX_DEFINES_TO_PARSE 2048 // Maximum number of defines to parse |
| 67 |
#define MAX_STRUCTS_TO_PARSE 64 // Maximum number of structures to parse |
| 68 |
#define MAX_ALIASES_TO_PARSE 64 // Maximum number of aliases to parse |
| 69 |
#define MAX_ENUMS_TO_PARSE 64 // Maximum number of enums to parse |
| 70 |
#define MAX_CALLBACKS_TO_PARSE 64 // Maximum number of callbacks to parse |
| 71 |
#define MAX_FUNCS_TO_PARSE 1024 // Maximum number of functions to parse |
| 72 |
|
| 73 |
#define MAX_LINE_LENGTH 1024 // Maximum length of one line (including comments) |
| 74 |
|
| 75 |
#define MAX_STRUCT_FIELDS 64 // Maximum number of struct fields |
| 76 |
#define MAX_ENUM_VALUES 512 // Maximum number of enum values |
| 77 |
#define MAX_FUNCTION_PARAMETERS 12 // Maximum number of function parameters |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
typedef enum { |
| 85 |
UNKNOWN = 0, |
| 86 |
MACRO, |
| 87 |
GUARD, |
| 88 |
INT, |
| 89 |
INT_MATH, |
| 90 |
LONG, |
| 91 |
LONG_MATH, |
| 92 |
FLOAT, |
| 93 |
FLOAT_MATH, |
| 94 |
DOUBLE, |
| 95 |
DOUBLE_MATH, |
| 96 |
CHAR, |
| 97 |
STRING, |
| 98 |
COLOR |
| 99 |
} DefineType; |
| 100 |
|
| 101 |
|
| 102 |
typedef struct DefineInfo { |
| 103 |
char name[64]; |
| 104 |
int type; |
| 105 |
char value[256]; |
| 106 |
char desc[128]; |
| 107 |
bool isHex; |
| 108 |
} DefineInfo; |
| 109 |
|
| 110 |
|
| 111 |
typedef struct StructInfo { |
| 112 |
char name[64]; |
| 113 |
char desc[128]; |
| 114 |
int fieldCount; |
| 115 |
char fieldType[MAX_STRUCT_FIELDS][64]; |
| 116 |
char fieldName[MAX_STRUCT_FIELDS][64]; |
| 117 |
char fieldDesc[MAX_STRUCT_FIELDS][128]; |
| 118 |
} StructInfo; |
| 119 |
|
| 120 |
|
| 121 |
typedef struct AliasInfo { |
| 122 |
char type[64]; |
| 123 |
char name[64]; |
| 124 |
char desc[128]; |
| 125 |
} AliasInfo; |
| 126 |
|
| 127 |
|
| 128 |
typedef struct EnumInfo { |
| 129 |
char name[64]; |
| 130 |
char desc[128]; |
| 131 |
int valueCount; |
| 132 |
char valueName[MAX_ENUM_VALUES][64]; |
| 133 |
int valueInteger[MAX_ENUM_VALUES]; |
| 134 |
char valueDesc[MAX_ENUM_VALUES][128]; |
| 135 |
} EnumInfo; |
| 136 |
|
| 137 |
|
| 138 |
typedef struct FunctionInfo { |
| 139 |
char name[64]; |
| 140 |
char desc[512]; |
| 141 |
char retType[32]; |
| 142 |
int paramCount; |
| 143 |
char paramType[MAX_FUNCTION_PARAMETERS][32]; |
| 144 |
char paramName[MAX_FUNCTION_PARAMETERS][32]; |
| 145 |
char paramDesc[MAX_FUNCTION_PARAMETERS][128]; |
| 146 |
} FunctionInfo; |
| 147 |
|
| 148 |
|
| 149 |
typedef enum { DEFAULT = 0, JSON, XML, LUA, CODE } OutputFormat; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
static int defineCount = 0; |
| 155 |
static int structCount = 0; |
| 156 |
static int aliasCount = 0; |
| 157 |
static int enumCount = 0; |
| 158 |
static int callbackCount = 0; |
| 159 |
static int funcCount = 0; |
| 160 |
static DefineInfo *defines = NULL; |
| 161 |
static StructInfo *structs = NULL; |
| 162 |
static AliasInfo *aliases = NULL; |
| 163 |
static EnumInfo *enums = NULL; |
| 164 |
static FunctionInfo *callbacks = NULL; |
| 165 |
static FunctionInfo *funcs = NULL; |
| 166 |
|
| 167 |
|
| 168 |
static char apiDefine[32] = { 0 }; |
| 169 |
static char truncAfter[32] = { 0 }; |
| 170 |
static int outputFormat = DEFAULT; |
| 171 |
|
| 172 |
|
| 173 |
static char inFileName[512] = { 0 }; |
| 174 |
static char outFileName[512] = { 0 }; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
static void ShowCommandLineInfo(void); |
| 180 |
static void ProcessCommandLine(int argc, char *argv[]); |
| 181 |
|
| 182 |
static char *LoadFileText(const char *fileName, int *length); |
| 183 |
static void UnloadFileText(char *text); |
| 184 |
static char **LoadTextLines(const char *buffer, int length, int *lineCount); |
| 185 |
static void UnloadTextLines(char **lines, int lineCount); |
| 186 |
static void GetDataTypeAndName(const char *typeName, int typeNameLen, char *type, char *name); |
| 187 |
static void GetDescription(const char *source, char *description); |
| 188 |
static void MoveArraySize(char *name, char *type); |
| 189 |
static unsigned int TextLength(const char *text); |
| 190 |
static bool IsTextEqual(const char *text1, const char *text2, unsigned int count); |
| 191 |
static int TextFindIndex(const char *text, const char *find); |
| 192 |
static void MemoryCopy(void *dest, const void *src, unsigned int count); |
| 193 |
static char *EscapeBackslashes(char *text); |
| 194 |
static const char *StrDefineType(DefineType type); |
| 195 |
|
| 196 |
static void ExportParsedData(const char *fileName, int format); |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
int main(int argc, char *argv[]) |
| 202 |
{ |
| 203 |
if (argc > 1) ProcessCommandLine(argc, argv); |
| 204 |
|
| 205 |
const char *raylibhPath = "../src/raylib.h\0"; |
| 206 |
const char *raylibapiPath = "raylib_api.txt\0"; |
| 207 |
const char *rlapiPath = "RLAPI\0"; |
| 208 |
if (inFileName[0] == '\0') MemoryCopy(inFileName, raylibhPath, TextLength(raylibhPath) + 1); |
| 209 |
if (outFileName[0] == '\0') MemoryCopy(outFileName, raylibapiPath, TextLength(raylibapiPath) + 1); |
| 210 |
if (apiDefine[0] == '\0') MemoryCopy(apiDefine, rlapiPath, TextLength(rlapiPath) + 1); |
| 211 |
|
| 212 |
int length = 0; |
| 213 |
char *buffer = LoadFileText(inFileName, &length); |
| 214 |
|
| 215 |
if (buffer == NULL) |
| 216 |
{ |
| 217 |
printf("Could not read input file: %s\n", inFileName); |
| 218 |
return 1; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
int lineCount = 0; |
| 224 |
char **lines = LoadTextLines(buffer, length, &lineCount); |
| 225 |
|
| 226 |
|
| 227 |
if (truncAfter[0] != '\0') |
| 228 |
{ |
| 229 |
int newCount = -1; |
| 230 |
for (int i = 0; i < lineCount; i++) |
| 231 |
{ |
| 232 |
if (newCount > -1) free(lines[i]); |
| 233 |
else if (TextFindIndex(lines[i], truncAfter) > -1) newCount = i; |
| 234 |
} |
| 235 |
if (newCount > -1) lineCount = newCount; |
| 236 |
printf("Number of truncated text lines: %i\n", lineCount); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
int *defineLines = (int *)malloc(MAX_DEFINES_TO_PARSE*sizeof(int)); |
| 241 |
|
| 242 |
|
| 243 |
int *structLines = (int *)malloc(MAX_STRUCTS_TO_PARSE*sizeof(int)); |
| 244 |
|
| 245 |
|
| 246 |
int *aliasLines = (int *)malloc(MAX_ALIASES_TO_PARSE*sizeof(int)); |
| 247 |
|
| 248 |
|
| 249 |
int *enumLines = (int *)malloc(MAX_ENUMS_TO_PARSE*sizeof(int)); |
| 250 |
|
| 251 |
|
| 252 |
int *callbackLines = (int *)malloc(MAX_CALLBACKS_TO_PARSE*sizeof(int)); |
| 253 |
|
| 254 |
|
| 255 |
int *funcLines = (int *)malloc(MAX_FUNCS_TO_PARSE*sizeof(int)); |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
for (int i = 0; i < lineCount; i++) |
| 261 |
{ |
| 262 |
int j = 0; |
| 263 |
while ((lines[i][j] == ' ') || (lines[i][j] == '\t')) j++; |
| 264 |
|
| 265 |
if (IsTextEqual(lines[i]+j, "#define ", 8)) |
| 266 |
{ |
| 267 |
|
| 268 |
|
| 269 |
defineLines[defineCount] = i; |
| 270 |
defineCount++; |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
for (int i = 0; i < lineCount; i++) |
| 276 |
{ |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
if (IsTextEqual(lines[i], "typedef struct", 14)) |
| 282 |
{ |
| 283 |
bool validStruct = IsTextEqual(lines[i + 1], "struct", 6); |
| 284 |
if (!validStruct) |
| 285 |
{ |
| 286 |
for (int c = 0; c < MAX_LINE_LENGTH; c++) |
| 287 |
{ |
| 288 |
char v = lines[i][c]; |
| 289 |
if (v == '{') validStruct = true; |
| 290 |
if ((v == '{') || (v == ';') || (v == '\0')) break; |
| 291 |
} |
| 292 |
} |
| 293 |
if (!validStruct) continue; |
| 294 |
structLines[structCount] = i; |
| 295 |
while (lines[i][0] != '}') i++; |
| 296 |
while (lines[i][0] != '\0') i++; |
| 297 |
structCount++; |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
for (int i = 0; i < lineCount; i++) |
| 303 |
{ |
| 304 |
|
| 305 |
if (IsTextEqual(lines[i], "typedef", 7)) |
| 306 |
{ |
| 307 |
int spaceCount = 0; |
| 308 |
bool validAlias = false; |
| 309 |
|
| 310 |
for (int c = 0; c < MAX_LINE_LENGTH; c++) |
| 311 |
{ |
| 312 |
char v = lines[i][c]; |
| 313 |
if (v == ' ') spaceCount++; |
| 314 |
if ((v == ';') && (spaceCount == 2)) validAlias = true; |
| 315 |
if ((v == ';') || (v == '(') || (v == '\0')) break; |
| 316 |
} |
| 317 |
if (!validAlias) continue; |
| 318 |
aliasLines[aliasCount] = i; |
| 319 |
aliasCount++; |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
for (int i = 0; i < lineCount; i++) |
| 325 |
{ |
| 326 |
|
| 327 |
if (IsTextEqual(lines[i], "typedef enum {", 14) && (lines[i][TextLength(lines[i])-1] != ';')) |
| 328 |
{ |
| 329 |
|
| 330 |
|
| 331 |
enumLines[enumCount] = i; |
| 332 |
enumCount++; |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
for (int i = 0; i < lineCount; i++) |
| 338 |
{ |
| 339 |
|
| 340 |
if (IsTextEqual(lines[i], "typedef", 7)) |
| 341 |
{ |
| 342 |
bool hasBeginning = false; |
| 343 |
bool hasMiddle = false; |
| 344 |
bool hasEnd = false; |
| 345 |
|
| 346 |
for (int c = 0; c < MAX_LINE_LENGTH; c++) |
| 347 |
{ |
| 348 |
if ((lines[i][c] == '(') && (lines[i][c + 1] == '*')) hasBeginning = true; |
| 349 |
if ((lines[i][c] == ')') && (lines[i][c + 1] == '(')) hasMiddle = true; |
| 350 |
if ((lines[i][c] == ')') && (lines[i][c + 1] == ';')) hasEnd = true; |
| 351 |
if (hasEnd) break; |
| 352 |
} |
| 353 |
|
| 354 |
if (hasBeginning && hasMiddle && hasEnd) |
| 355 |
{ |
| 356 |
callbackLines[callbackCount] = i; |
| 357 |
callbackCount++; |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
for (int i = 0; i < lineCount; i++) |
| 364 |
{ |
| 365 |
|
| 366 |
if (IsTextEqual(lines[i], apiDefine, TextLength(apiDefine))) |
| 367 |
{ |
| 368 |
funcLines[funcCount] = i; |
| 369 |
funcCount++; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
UnloadFileText(buffer); |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
int defineIndex = 0; |
| 381 |
defines = (DefineInfo *)calloc(MAX_DEFINES_TO_PARSE, sizeof(DefineInfo)); |
| 382 |
|
| 383 |
for (int i = 0; i < defineCount; i++) |
| 384 |
{ |
| 385 |
char *linePtr = lines[defineLines[i]]; |
| 386 |
int j = 0; |
| 387 |
|
| 388 |
while ((linePtr[j] == ' ') || (linePtr[j] == '\t')) j++; |
| 389 |
j += 8; |
| 390 |
while ((linePtr[j] == ' ') || (linePtr[j] == '\t')) j++; |
| 391 |
|
| 392 |
|
| 393 |
int defineNameStart = j; |
| 394 |
int openBraces = 0; |
| 395 |
while (linePtr[j] != '\0') |
| 396 |
{ |
| 397 |
if (((linePtr[j] == ' ') || (linePtr[j] == '\t')) && (openBraces == 0)) break; |
| 398 |
if (linePtr[j] == '(') openBraces++; |
| 399 |
if (linePtr[j] == ')') openBraces--; |
| 400 |
j++; |
| 401 |
} |
| 402 |
int defineNameEnd = j-1; |
| 403 |
|
| 404 |
|
| 405 |
unsigned int nameLen = defineNameEnd - defineNameStart + 1; |
| 406 |
bool isDuplicate = false; |
| 407 |
for (int k = 0; k < defineIndex; k++) |
| 408 |
{ |
| 409 |
if ((nameLen == TextLength(defines[k].name)) && IsTextEqual(defines[k].name, &linePtr[defineNameStart], nameLen)) |
| 410 |
{ |
| 411 |
isDuplicate = true; |
| 412 |
break; |
| 413 |
} |
| 414 |
} |
| 415 |
if (isDuplicate) continue; |
| 416 |
|
| 417 |
MemoryCopy(defines[defineIndex].name, &linePtr[defineNameStart], nameLen); |
| 418 |
|
| 419 |
|
| 420 |
if (linePtr[defineNameEnd] == ')') defines[defineIndex].type = MACRO; |
| 421 |
|
| 422 |
while ((linePtr[j] == ' ') || (linePtr[j] == '\t')) j++; |
| 423 |
|
| 424 |
int defineValueStart = j; |
| 425 |
if ((linePtr[j] == '\0') || (linePtr[j] == '/')) defines[defineIndex].type = GUARD; |
| 426 |
if (linePtr[j] == '"') defines[defineIndex].type = STRING; |
| 427 |
else if (linePtr[j] == '\'') defines[defineIndex].type = CHAR; |
| 428 |
else if (IsTextEqual(linePtr+j, "CLITERAL(Color)", 15)) defines[defineIndex].type = COLOR; |
| 429 |
else if (isdigit(linePtr[j])) |
| 430 |
{ |
| 431 |
bool isFloat = false, isNumber = true, isHex = false; |
| 432 |
while ((linePtr[j] != ' ') && (linePtr[j] != '\t') && (linePtr[j] != '\0')) |
| 433 |
{ |
| 434 |
char ch = linePtr[j]; |
| 435 |
if (ch == '.') isFloat = true; |
| 436 |
if (ch == 'x') isHex = true; |
| 437 |
if (!(isdigit(ch) || |
| 438 |
((ch >= 'a') && (ch <= 'f')) || |
| 439 |
((ch >= 'A') && (ch <= 'F')) || |
| 440 |
(ch == 'x') || |
| 441 |
(ch == 'L') || |
| 442 |
(ch == '.') || |
| 443 |
(ch == '+') || |
| 444 |
(ch == '-'))) isNumber = false; |
| 445 |
j++; |
| 446 |
} |
| 447 |
if (isNumber) |
| 448 |
{ |
| 449 |
if (isFloat) |
| 450 |
{ |
| 451 |
defines[defineIndex].type = (linePtr[j-1] == 'f')? FLOAT : DOUBLE; |
| 452 |
} |
| 453 |
else |
| 454 |
{ |
| 455 |
defines[defineIndex].type = (linePtr[j-1] == 'L')? LONG : INT; |
| 456 |
defines[defineIndex].isHex = isHex; |
| 457 |
} |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
while ((linePtr[j] != '\\') && (linePtr[j] != '\0') && !((linePtr[j] == '/') && (linePtr[j+1] == '/'))) j++; |
| 463 |
int defineValueEnd = j-1; |
| 464 |
while ((linePtr[defineValueEnd] == ' ') || (linePtr[defineValueEnd] == '\t')) defineValueEnd--; |
| 465 |
if ((defines[defineIndex].type == LONG) || (defines[defineIndex].type == FLOAT)) defineValueEnd--; |
| 466 |
int valueLen = defineValueEnd - defineValueStart + 1; |
| 467 |
if (valueLen > 255) valueLen = 255; |
| 468 |
|
| 469 |
if (valueLen > 0) MemoryCopy(defines[defineIndex].value, &linePtr[defineValueStart], valueLen); |
| 470 |
|
| 471 |
|
| 472 |
if ((linePtr[j] == '/') && linePtr[j + 1] == '/') |
| 473 |
{ |
| 474 |
j += 2; |
| 475 |
while (linePtr[j] == ' ') j++; |
| 476 |
int commentStart = j; |
| 477 |
while ((linePtr[j] != '\\') && (linePtr[j] != '\0')) j++; |
| 478 |
int commentEnd = j-1; |
| 479 |
int commentLen = commentEnd - commentStart + 1; |
| 480 |
if (commentLen > 127) commentLen = 127; |
| 481 |
|
| 482 |
MemoryCopy(defines[defineIndex].desc, &linePtr[commentStart], commentLen); |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
if (defines[defineIndex].type == UNKNOWN) |
| 487 |
{ |
| 488 |
int largestType = UNKNOWN; |
| 489 |
bool isMath = true; |
| 490 |
char *valuePtr = defines[defineIndex].value; |
| 491 |
|
| 492 |
for (unsigned int c = 0; c < TextLength(valuePtr); c++) |
| 493 |
{ |
| 494 |
char ch = valuePtr[c]; |
| 495 |
|
| 496 |
|
| 497 |
if ((ch == '(') || |
| 498 |
(ch == ')') || |
| 499 |
(ch == '+') || |
| 500 |
(ch == '-') || |
| 501 |
(ch == '*') || |
| 502 |
(ch == '/') || |
| 503 |
(ch == ' ') || |
| 504 |
(ch == '\t')) continue; |
| 505 |
|
| 506 |
|
| 507 |
else if (isdigit(ch)) |
| 508 |
{ |
| 509 |
bool isNumber = true, isFloat = false; |
| 510 |
while (!((ch == '(') || |
| 511 |
(ch == ')') || |
| 512 |
(ch == '*') || |
| 513 |
(ch == '/') || |
| 514 |
(ch == ' ') || |
| 515 |
(ch == '\t') || |
| 516 |
(ch == '\0'))) |
| 517 |
{ |
| 518 |
if (ch == '.') isFloat = true; |
| 519 |
if (!(isdigit(ch) || |
| 520 |
((ch >= 'a') && (ch <= 'f')) || |
| 521 |
((ch >= 'A') && (ch <= 'F')) || |
| 522 |
(ch == 'x') || |
| 523 |
(ch == 'L') || |
| 524 |
(ch == '.') || |
| 525 |
(ch == '+') || |
| 526 |
(ch == '-'))) |
| 527 |
{ |
| 528 |
isNumber = false; |
| 529 |
break; |
| 530 |
} |
| 531 |
c++; |
| 532 |
ch = valuePtr[c]; |
| 533 |
} |
| 534 |
if (isNumber) |
| 535 |
{ |
| 536 |
|
| 537 |
int numberType; |
| 538 |
if (isFloat) numberType = (valuePtr[c - 1] == 'f')? FLOAT_MATH : DOUBLE_MATH; |
| 539 |
else numberType = (valuePtr[c - 1] == 'L')? LONG_MATH : INT_MATH; |
| 540 |
|
| 541 |
if (numberType > largestType) largestType = numberType; |
| 542 |
} |
| 543 |
else |
| 544 |
{ |
| 545 |
isMath = false; |
| 546 |
break; |
| 547 |
} |
| 548 |
} |
| 549 |
else |
| 550 |
{ |
| 551 |
int operandStart = c; |
| 552 |
while (!((ch == '\0') || |
| 553 |
(ch == ' ') || |
| 554 |
(ch == '(') || |
| 555 |
(ch == ')') || |
| 556 |
(ch == '+') || |
| 557 |
(ch == '-') || |
| 558 |
(ch == '*') || |
| 559 |
(ch == '/'))) |
| 560 |
{ |
| 561 |
c++; |
| 562 |
ch = valuePtr[c]; |
| 563 |
} |
| 564 |
int operandEnd = c; |
| 565 |
int operandLength = operandEnd - operandStart; |
| 566 |
|
| 567 |
|
| 568 |
bool foundOperand = false; |
| 569 |
for (int previousDefineIndex = 0; previousDefineIndex < defineIndex; previousDefineIndex++) |
| 570 |
{ |
| 571 |
if (IsTextEqual(defines[previousDefineIndex].name, &valuePtr[operandStart], operandLength)) |
| 572 |
{ |
| 573 |
if ((defines[previousDefineIndex].type >= INT) && (defines[previousDefineIndex].type <= DOUBLE_MATH)) |
| 574 |
{ |
| 575 |
|
| 576 |
if (defines[previousDefineIndex].type > largestType) largestType = defines[previousDefineIndex].type; |
| 577 |
foundOperand = true; |
| 578 |
} |
| 579 |
break; |
| 580 |
} |
| 581 |
} |
| 582 |
if (!foundOperand) |
| 583 |
{ |
| 584 |
isMath = false; |
| 585 |
break; |
| 586 |
} |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
if (isMath) |
| 591 |
{ |
| 592 |
|
| 593 |
if (largestType == INT) largestType = INT_MATH; |
| 594 |
else if (largestType == LONG) largestType = LONG_MATH; |
| 595 |
else if (largestType == FLOAT) largestType = FLOAT_MATH; |
| 596 |
else if (largestType == DOUBLE) largestType = DOUBLE_MATH; |
| 597 |
defines[defineIndex].type = largestType; |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
defineIndex++; |
| 602 |
} |
| 603 |
defineCount = defineIndex; |
| 604 |
free(defineLines); |
| 605 |
|
| 606 |
|
| 607 |
structs = (StructInfo *)calloc(MAX_STRUCTS_TO_PARSE, sizeof(StructInfo)); |
| 608 |
|
| 609 |
for (int i = 0; i < structCount; i++) |
| 610 |
{ |
| 611 |
char **linesPtr = &lines[structLines[i]]; |
| 612 |
|
| 613 |
|
| 614 |
GetDescription(linesPtr[-1], structs[i].desc); |
| 615 |
|
| 616 |
|
| 617 |
const int TDS_LEN = 15; |
| 618 |
for (int c = TDS_LEN; c < 64 + TDS_LEN; c++) |
| 619 |
{ |
| 620 |
if ((linesPtr[0][c] == '{') || (linesPtr[0][c] == ' ')) |
| 621 |
{ |
| 622 |
int nameLen = c - TDS_LEN; |
| 623 |
while (linesPtr[0][TDS_LEN + nameLen - 1] == ' ') nameLen--; |
| 624 |
MemoryCopy(structs[i].name, &linesPtr[0][TDS_LEN], nameLen); |
| 625 |
break; |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
int l = 1; |
| 631 |
while (linesPtr[l][0] != '}') |
| 632 |
{ |
| 633 |
|
| 634 |
if ((linesPtr[l][0] != ' ') && (linesPtr[l][0] != '\0')) |
| 635 |
{ |
| 636 |
|
| 637 |
char *fieldLine = linesPtr[l]; |
| 638 |
int fieldEndPos = 0; |
| 639 |
while (fieldLine[fieldEndPos] != ';') fieldEndPos++; |
| 640 |
|
| 641 |
if ((fieldLine[0] != '/') && !IsTextEqual(fieldLine, "struct", 6)) |
| 642 |
{ |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
GetDataTypeAndName(fieldLine, fieldEndPos, structs[i].fieldType[structs[i].fieldCount], structs[i].fieldName[structs[i].fieldCount]); |
| 647 |
|
| 648 |
|
| 649 |
GetDescription(&fieldLine[fieldEndPos], structs[i].fieldDesc[structs[i].fieldCount]); |
| 650 |
|
| 651 |
structs[i].fieldCount++; |
| 652 |
|
| 653 |
|
| 654 |
int additionalFields = 0; |
| 655 |
int originalIndex = structs[i].fieldCount - 1; |
| 656 |
for (unsigned int c = 0; c < TextLength(structs[i].fieldName[originalIndex]); c++) |
| 657 |
{ |
| 658 |
if (structs[i].fieldName[originalIndex][c] == ',') additionalFields++; |
| 659 |
} |
| 660 |
|
| 661 |
if (additionalFields > 0) |
| 662 |
{ |
| 663 |
int originalLength = -1; |
| 664 |
int lastStart; |
| 665 |
for (unsigned int c = 0; c < TextLength(structs[i].fieldName[originalIndex]) + 1; c++) |
| 666 |
{ |
| 667 |
char v = structs[i].fieldName[originalIndex][c]; |
| 668 |
bool isEndOfString = (v == '\0'); |
| 669 |
if ((v == ',') || isEndOfString) |
| 670 |
{ |
| 671 |
if (originalLength == -1) |
| 672 |
{ |
| 673 |
|
| 674 |
|
| 675 |
originalLength = c; |
| 676 |
} |
| 677 |
else |
| 678 |
{ |
| 679 |
|
| 680 |
int nameLength = c - lastStart; |
| 681 |
MemoryCopy(structs[i].fieldName[structs[i].fieldCount], &structs[i].fieldName[originalIndex][lastStart], nameLength); |
| 682 |
MemoryCopy(structs[i].fieldType[structs[i].fieldCount], &structs[i].fieldType[originalIndex][0], TextLength(structs[i].fieldType[originalIndex])); |
| 683 |
MemoryCopy(structs[i].fieldDesc[structs[i].fieldCount], &structs[i].fieldDesc[originalIndex][0], TextLength(structs[i].fieldDesc[originalIndex])); |
| 684 |
structs[i].fieldCount++; |
| 685 |
} |
| 686 |
if (!isEndOfString) |
| 687 |
{ |
| 688 |
|
| 689 |
c++; |
| 690 |
while (structs[i].fieldName[originalIndex][c] == ' ') c++; |
| 691 |
|
| 692 |
|
| 693 |
lastStart = c; |
| 694 |
} |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
structs[i].fieldName[originalIndex][originalLength] = '\0'; |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
additionalFields = 0; |
| 703 |
originalIndex = structs[i].fieldCount - 1; |
| 704 |
for (unsigned int c = 0; c < TextLength(structs[i].fieldType[originalIndex]); c++) |
| 705 |
{ |
| 706 |
if (structs[i].fieldType[originalIndex][c] == ',') additionalFields++; |
| 707 |
} |
| 708 |
|
| 709 |
if (additionalFields > 0) |
| 710 |
{ |
| 711 |
|
| 712 |
structs[i].fieldCount += additionalFields; |
| 713 |
MemoryCopy(structs[i].fieldName[originalIndex + additionalFields], &structs[i].fieldName[originalIndex][0], TextLength(structs[i].fieldName[originalIndex])); |
| 714 |
|
| 715 |
|
| 716 |
int fieldsRemaining = additionalFields; |
| 717 |
int nameStart = -1; |
| 718 |
int nameEnd = -1; |
| 719 |
for (int k = TextLength(structs[i].fieldType[originalIndex]); k > 0; k--) |
| 720 |
{ |
| 721 |
char v = structs[i].fieldType[originalIndex][k]; |
| 722 |
if ((v == '*') || (v == ' ') || (v == ',')) |
| 723 |
{ |
| 724 |
if (nameEnd != -1) |
| 725 |
{ |
| 726 |
|
| 727 |
if (fieldsRemaining != additionalFields) |
| 728 |
{ |
| 729 |
nameStart = k + 1; |
| 730 |
MemoryCopy(structs[i].fieldName[originalIndex + fieldsRemaining], &structs[i].fieldType[originalIndex][nameStart], nameEnd - nameStart + 1); |
| 731 |
} |
| 732 |
nameEnd = -1; |
| 733 |
fieldsRemaining--; |
| 734 |
} |
| 735 |
} |
| 736 |
else if (nameEnd == -1) nameEnd = k; |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
int fieldTypeLength = nameStart; |
| 741 |
structs[i].fieldType[originalIndex][fieldTypeLength] = '\0'; |
| 742 |
|
| 743 |
|
| 744 |
for (int j = 1; j <= additionalFields; j++) |
| 745 |
{ |
| 746 |
MemoryCopy(structs[i].fieldType[originalIndex + j], &structs[i].fieldType[originalIndex][0], fieldTypeLength); |
| 747 |
MemoryCopy(structs[i].fieldDesc[originalIndex + j], &structs[i].fieldDesc[originalIndex][0], TextLength(structs[i].fieldDesc[originalIndex])); |
| 748 |
} |
| 749 |
} |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
l++; |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
for (int j = 0; j < structs[i].fieldCount; j++) |
| 758 |
{ |
| 759 |
MoveArraySize(structs[i].fieldName[j], structs[i].fieldType[j]); |
| 760 |
} |
| 761 |
} |
| 762 |
free(structLines); |
| 763 |
|
| 764 |
|
| 765 |
aliases = (AliasInfo *)calloc(MAX_ALIASES_TO_PARSE, sizeof(AliasInfo)); |
| 766 |
|
| 767 |
for (int i = 0; i < aliasCount; i++) |
| 768 |
{ |
| 769 |
|
| 770 |
GetDescription(lines[aliasLines[i] - 1], aliases[i].desc); |
| 771 |
|
| 772 |
char *linePtr = lines[aliasLines[i]]; |
| 773 |
|
| 774 |
|
| 775 |
int c = 8; |
| 776 |
|
| 777 |
|
| 778 |
int typeStart = c; |
| 779 |
while(linePtr[c] != ' ') c++; |
| 780 |
int typeLen = c - typeStart; |
| 781 |
MemoryCopy(aliases[i].type, &linePtr[typeStart], typeLen); |
| 782 |
|
| 783 |
|
| 784 |
c++; |
| 785 |
|
| 786 |
|
| 787 |
int nameStart = c; |
| 788 |
while(linePtr[c] != ';') c++; |
| 789 |
int nameLen = c - nameStart; |
| 790 |
MemoryCopy(aliases[i].name, &linePtr[nameStart], nameLen); |
| 791 |
|
| 792 |
|
| 793 |
GetDescription(&linePtr[c], aliases[i].desc); |
| 794 |
} |
| 795 |
free(aliasLines); |
| 796 |
|
| 797 |
|
| 798 |
enums = (EnumInfo *)calloc(MAX_ENUMS_TO_PARSE, sizeof(EnumInfo)); |
| 799 |
|
| 800 |
for (int i = 0; i < enumCount; i++) |
| 801 |
{ |
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
for (int j = enumLines[i] - 1; j > 0; j--) |
| 807 |
{ |
| 808 |
char *linePtr = lines[j]; |
| 809 |
if ((linePtr[0] != '/') || (linePtr[2] != ' ')) |
| 810 |
{ |
| 811 |
GetDescription(&lines[j + 1][0], enums[i].desc); |
| 812 |
break; |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
for (int j = 1; j < MAX_ENUM_VALUES*2; j++) |
| 817 |
{ |
| 818 |
char *linePtr = lines[enumLines[i] + j]; |
| 819 |
|
| 820 |
if ((linePtr[0] >= 'A') && (linePtr[0] <= 'Z')) |
| 821 |
{ |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
int c = 0; |
| 831 |
while ((linePtr[c] != ',') && |
| 832 |
(linePtr[c] != ' ') && |
| 833 |
(linePtr[c] != '=') && |
| 834 |
(linePtr[c] != '\0')) |
| 835 |
{ |
| 836 |
enums[i].valueName[enums[i].valueCount][c] = linePtr[c]; |
| 837 |
c++; |
| 838 |
} |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
if ((linePtr[c] != ',') && (linePtr[c] != '\0')) |
| 848 |
{ |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
bool foundValue = false; |
| 853 |
while ((linePtr[c] != '\0') && (linePtr[c] != '/')) |
| 854 |
{ |
| 855 |
if (linePtr[c] == '=') |
| 856 |
{ |
| 857 |
foundValue = true; |
| 858 |
break; |
| 859 |
} |
| 860 |
c++; |
| 861 |
} |
| 862 |
|
| 863 |
if (foundValue) |
| 864 |
{ |
| 865 |
if (linePtr[c + 1] == ' ') c += 2; |
| 866 |
else c++; |
| 867 |
|
| 868 |
|
| 869 |
int n = 0; |
| 870 |
char integer[16] = { 0 }; |
| 871 |
|
| 872 |
while ((linePtr[c] != ',') && (linePtr[c] != ' ') && (linePtr[c] != '\0')) |
| 873 |
{ |
| 874 |
integer[n] = linePtr[c]; |
| 875 |
c++; n++; |
| 876 |
} |
| 877 |
|
| 878 |
if (integer[1] == 'x') enums[i].valueInteger[enums[i].valueCount] = (int)strtol(integer, NULL, 16); |
| 879 |
else enums[i].valueInteger[enums[i].valueCount] = atoi(integer); |
| 880 |
} |
| 881 |
else enums[i].valueInteger[enums[i].valueCount] = (enums[i].valueInteger[enums[i].valueCount - 1] + 1); |
| 882 |
} |
| 883 |
else enums[i].valueInteger[enums[i].valueCount] = (enums[i].valueInteger[enums[i].valueCount - 1] + 1); |
| 884 |
|
| 885 |
|
| 886 |
GetDescription(&linePtr[c], enums[i].valueDesc[enums[i].valueCount]); |
| 887 |
|
| 888 |
enums[i].valueCount++; |
| 889 |
} |
| 890 |
else if (linePtr[0] == '}') |
| 891 |
{ |
| 892 |
|
| 893 |
int c = 0; |
| 894 |
while (linePtr[2 + c] != ';') |
| 895 |
{ |
| 896 |
enums[i].name[c] = linePtr[2 + c]; |
| 897 |
c++; |
| 898 |
} |
| 899 |
|
| 900 |
break; |
| 901 |
} |
| 902 |
} |
| 903 |
} |
| 904 |
free(enumLines); |
| 905 |
|
| 906 |
|
| 907 |
callbacks = (FunctionInfo *)calloc(MAX_CALLBACKS_TO_PARSE, sizeof(FunctionInfo)); |
| 908 |
|
| 909 |
for (int i = 0; i < callbackCount; i++) |
| 910 |
{ |
| 911 |
char *linePtr = lines[callbackLines[i]]; |
| 912 |
|
| 913 |
|
| 914 |
unsigned int c = 8; |
| 915 |
|
| 916 |
|
| 917 |
int retTypeStart = c; |
| 918 |
while(linePtr[c] != '(') c++; |
| 919 |
int retTypeLen = c - retTypeStart; |
| 920 |
while(linePtr[retTypeStart + retTypeLen - 1] == ' ') retTypeLen--; |
| 921 |
MemoryCopy(callbacks[i].retType, &linePtr[retTypeStart], retTypeLen); |
| 922 |
|
| 923 |
|
| 924 |
c += 2; |
| 925 |
|
| 926 |
|
| 927 |
int nameStart = c; |
| 928 |
while(linePtr[c] != ')') c++; |
| 929 |
int nameLen = c - nameStart; |
| 930 |
MemoryCopy(callbacks[i].name, &linePtr[nameStart], nameLen); |
| 931 |
|
| 932 |
|
| 933 |
c += 2; |
| 934 |
|
| 935 |
|
| 936 |
int paramStart = c; |
| 937 |
for (; c < MAX_LINE_LENGTH; c++) |
| 938 |
{ |
| 939 |
if ((linePtr[c] == ',') || (linePtr[c] == ')')) |
| 940 |
{ |
| 941 |
|
| 942 |
int paramLen = c - paramStart; |
| 943 |
GetDataTypeAndName(&linePtr[paramStart], paramLen, callbacks[i].paramType[callbacks[i].paramCount], callbacks[i].paramName[callbacks[i].paramCount]); |
| 944 |
callbacks[i].paramCount++; |
| 945 |
paramStart = c + 1; |
| 946 |
while(linePtr[paramStart] == ' ') paramStart++; |
| 947 |
} |
| 948 |
if (linePtr[c] == ')') break; |
| 949 |
} |
| 950 |
|
| 951 |
|
| 952 |
GetDescription(&linePtr[c], callbacks[i].desc); |
| 953 |
|
| 954 |
|
| 955 |
for (int j = 0; j < callbacks[i].paramCount; j++) |
| 956 |
{ |
| 957 |
MoveArraySize(callbacks[i].paramName[j], callbacks[i].paramType[j]); |
| 958 |
} |
| 959 |
} |
| 960 |
free(callbackLines); |
| 961 |
|
| 962 |
|
| 963 |
funcs = (FunctionInfo *)calloc(MAX_FUNCS_TO_PARSE, sizeof(FunctionInfo)); |
| 964 |
|
| 965 |
for (int i = 0; i < funcCount; i++) |
| 966 |
{ |
| 967 |
char *linePtr = lines[funcLines[i]]; |
| 968 |
|
| 969 |
int funcParamsStart = 0; |
| 970 |
int funcEnd = 0; |
| 971 |
|
| 972 |
|
| 973 |
for (int c = 0; (c < MAX_LINE_LENGTH) && (linePtr[c] != '\n'); c++) |
| 974 |
{ |
| 975 |
if (linePtr[c] == '(') |
| 976 |
{ |
| 977 |
funcParamsStart = c + 1; |
| 978 |
|
| 979 |
|
| 980 |
char funcRetTypeName[128] = { 0 }; |
| 981 |
int dc = TextLength(apiDefine) + 1; |
| 982 |
int funcRetTypeNameLen = c - dc; |
| 983 |
MemoryCopy(funcRetTypeName, &linePtr[dc], funcRetTypeNameLen); |
| 984 |
|
| 985 |
GetDataTypeAndName(funcRetTypeName, funcRetTypeNameLen, funcs[i].retType, funcs[i].name); |
| 986 |
break; |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
|
| 991 |
for (int c = funcParamsStart; c < MAX_LINE_LENGTH; c++) |
| 992 |
{ |
| 993 |
if (linePtr[c] == ',') |
| 994 |
{ |
| 995 |
|
| 996 |
char funcParamTypeName[128] = { 0 }; |
| 997 |
int funcParamTypeNameLen = c - funcParamsStart; |
| 998 |
MemoryCopy(funcParamTypeName, &linePtr[funcParamsStart], funcParamTypeNameLen); |
| 999 |
|
| 1000 |
GetDataTypeAndName(funcParamTypeName, funcParamTypeNameLen, funcs[i].paramType[funcs[i].paramCount], funcs[i].paramName[funcs[i].paramCount]); |
| 1001 |
|
| 1002 |
funcParamsStart = c + 1; |
| 1003 |
if (linePtr[c + 1] == ' ') funcParamsStart += 1; |
| 1004 |
funcs[i].paramCount++; |
| 1005 |
} |
| 1006 |
else if (linePtr[c] == ')') |
| 1007 |
{ |
| 1008 |
funcEnd = c + 2; |
| 1009 |
|
| 1010 |
|
| 1011 |
if ((funcEnd - funcParamsStart == 2) || |
| 1012 |
((linePtr[c - 4] == 'v') && |
| 1013 |
(linePtr[c - 3] == 'o') && |
| 1014 |
(linePtr[c - 2] == 'i') && |
| 1015 |
(linePtr[c - 1] == 'd'))) |
| 1016 |
{ |
| 1017 |
break; |
| 1018 |
} |
| 1019 |
|
| 1020 |
|
| 1021 |
char funcParamTypeName[128] = { 0 }; |
| 1022 |
int funcParamTypeNameLen = c - funcParamsStart; |
| 1023 |
MemoryCopy(funcParamTypeName, &linePtr[funcParamsStart], funcParamTypeNameLen); |
| 1024 |
|
| 1025 |
GetDataTypeAndName(funcParamTypeName, funcParamTypeNameLen, funcs[i].paramType[funcs[i].paramCount], funcs[i].paramName[funcs[i].paramCount]); |
| 1026 |
|
| 1027 |
funcs[i].paramCount++; |
| 1028 |
break; |
| 1029 |
} |
| 1030 |
} |
| 1031 |
|
| 1032 |
|
| 1033 |
GetDescription(&linePtr[funcEnd], funcs[i].desc); |
| 1034 |
|
| 1035 |
|
| 1036 |
for (int j = 0; j < funcs[i].paramCount; j++) |
| 1037 |
{ |
| 1038 |
MoveArraySize(funcs[i].paramName[j], funcs[i].paramType[j]); |
| 1039 |
} |
| 1040 |
} |
| 1041 |
free(funcLines); |
| 1042 |
|
| 1043 |
UnloadTextLines(lines, lineCount); |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
printf("\nInput file: %s", inFileName); |
| 1060 |
printf("\nOutput file: %s", outFileName); |
| 1061 |
if (outputFormat == DEFAULT) printf("\nOutput format: DEFAULT\n\n"); |
| 1062 |
else if (outputFormat == JSON) printf("\nOutput format: JSON\n\n"); |
| 1063 |
else if (outputFormat == XML) printf("\nOutput format: XML\n\n"); |
| 1064 |
else if (outputFormat == LUA) printf("\nOutput format: LUA\n\n"); |
| 1065 |
else if (outputFormat == CODE) printf("\nOutput format: CODE\n\n"); |
| 1066 |
|
| 1067 |
ExportParsedData(outFileName, outputFormat); |
| 1068 |
|
| 1069 |
free(defines); |
| 1070 |
free(structs); |
| 1071 |
free(aliases); |
| 1072 |
free(enums); |
| 1073 |
free(callbacks); |
| 1074 |
free(funcs); |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
static void ShowCommandLineInfo(void) |
| 1082 |
{ |
| 1083 |
printf("\n//////////////////////////////////////////////////////////////////////////////////\n"); |
| 1084 |
printf("// //\n"); |
| 1085 |
printf("// rlparser - raylib header API parser //\n"); |
| 1086 |
printf("// //\n"); |
| 1087 |
printf("// more info and bugs-report: github.com/raysan5/raylib/tools/rlparser //\n"); |
| 1088 |
printf("// //\n"); |
| 1089 |
printf("// Copyright (c) 2021-2026 Ramon Santamaria (@raysan5) //\n"); |
| 1090 |
printf("// //\n"); |
| 1091 |
printf("//////////////////////////////////////////////////////////////////////////////////\n\n"); |
| 1092 |
|
| 1093 |
printf("USAGE:\n\n"); |
| 1094 |
printf(" > rlparser [--help] [--input <filename.h>] [--output <filename.ext>] [--format <type>]\n"); |
| 1095 |
|
| 1096 |
printf("\nOPTIONS:\n\n"); |
| 1097 |
printf(" -h, --help : Show tool version and command line usage help\n\n"); |
| 1098 |
printf(" -i, --input <filename.h> : Define input header file to parse.\n"); |
| 1099 |
printf(" NOTE: If not specified, defaults to: raylib.h\n\n"); |
| 1100 |
printf(" -o, --output <filename.ext> : Define output file and format.\n"); |
| 1101 |
printf(" Supported extensions: .txt, .json, .xml, .lua, .h\n"); |
| 1102 |
printf(" NOTE: If not specified, defaults to: raylib_api.txt\n\n"); |
| 1103 |
printf(" -f, --format <type> : Define output format for parser data.\n"); |
| 1104 |
printf(" Supported types: DEFAULT, JSON, XML, LUA, CODE\n\n"); |
| 1105 |
printf(" -d, --define <DEF> : Define functions specifiers (i.e. RLAPI for raylib.h, RMAPI for raymath.h, etc.)\n"); |
| 1106 |
printf(" NOTE: If no specifier defined, defaults to: RLAPI\n\n"); |
| 1107 |
printf(" -t, --truncate <after> : Define string to truncate input after (i.e. \"RLGL IMPLEMENTATION\" for rlgl.h)\n"); |
| 1108 |
printf(" NOTE: If not specified, the full input file is parsed.\n\n"); |
| 1109 |
|
| 1110 |
printf("\nEXAMPLES:\n\n"); |
| 1111 |
printf(" > rlparser --input raylib.h --output api.json\n"); |
| 1112 |
printf(" Process <raylib.h> to generate <api.json>\n\n"); |
| 1113 |
printf(" > rlparser --output raylib_data.info --format XML\n"); |
| 1114 |
printf(" Process <raylib.h> to generate <raylib_data.info> as XML text data\n\n"); |
| 1115 |
printf(" > rlparser --input raymath.h --output raymath_data.info --format XML --define RMAPI\n"); |
| 1116 |
printf(" Process <raymath.h> to generate <raymath_data.info> as XML text data\n\n"); |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
static void ProcessCommandLine(int argc, char *argv[]) |
| 1121 |
{ |
| 1122 |
for (int i = 1; i < argc; i++) |
| 1123 |
{ |
| 1124 |
if (IsTextEqual(argv[i], "-h", 2) || IsTextEqual(argv[i], "--help", 6)) |
| 1125 |
{ |
| 1126 |
|
| 1127 |
ShowCommandLineInfo(); |
| 1128 |
exit(0); |
| 1129 |
} |
| 1130 |
else if (IsTextEqual(argv[i], "-i", 2) || IsTextEqual(argv[i], "--input", 7)) |
| 1131 |
{ |
| 1132 |
|
| 1133 |
if (((i + 1) < argc) && (argv[i + 1][0] != '-')) |
| 1134 |
{ |
| 1135 |
MemoryCopy(inFileName, argv[i + 1], TextLength(argv[i + 1])); |
| 1136 |
i++; |
| 1137 |
} |
| 1138 |
else printf("WARNING: No input file provided\n"); |
| 1139 |
} |
| 1140 |
else if (IsTextEqual(argv[i], "-o", 2) || IsTextEqual(argv[i], "--output", 8)) |
| 1141 |
{ |
| 1142 |
if (((i + 1) < argc) && (argv[i + 1][0] != '-')) |
| 1143 |
{ |
| 1144 |
MemoryCopy(outFileName, argv[i + 1], TextLength(argv[i + 1])); |
| 1145 |
i++; |
| 1146 |
} |
| 1147 |
else printf("WARNING: No output file provided\n"); |
| 1148 |
} |
| 1149 |
else if (IsTextEqual(argv[i], "-f", 2) || IsTextEqual(argv[i], "--format", 8)) |
| 1150 |
{ |
| 1151 |
if (((i + 1) < argc) && (argv[i + 1][0] != '-')) |
| 1152 |
{ |
| 1153 |
if (IsTextEqual(argv[i + 1], "DEFAULT\0", 8)) outputFormat = DEFAULT; |
| 1154 |
else if (IsTextEqual(argv[i + 1], "JSON\0", 5)) outputFormat = JSON; |
| 1155 |
else if (IsTextEqual(argv[i + 1], "XML\0", 4)) outputFormat = XML; |
| 1156 |
else if (IsTextEqual(argv[i + 1], "LUA\0", 4)) outputFormat = LUA; |
| 1157 |
else if (IsTextEqual(argv[i + 1], "CODE\0", 4)) outputFormat = CODE; |
| 1158 |
} |
| 1159 |
else printf("WARNING: No format parameters provided\n"); |
| 1160 |
} |
| 1161 |
else if (IsTextEqual(argv[i], "-d", 2) || IsTextEqual(argv[i], "--define", 8)) |
| 1162 |
{ |
| 1163 |
if (((i + 1) < argc) && (argv[i + 1][0] != '-')) |
| 1164 |
{ |
| 1165 |
MemoryCopy(apiDefine, argv[i + 1], TextLength(argv[i + 1])); |
| 1166 |
apiDefine[TextLength(argv[i + 1])] = '\0'; |
| 1167 |
i++; |
| 1168 |
} |
| 1169 |
else printf("WARNING: No define key provided\n"); |
| 1170 |
} |
| 1171 |
else if (IsTextEqual(argv[i], "-t", 2) || IsTextEqual(argv[i], "--truncate", 10)) |
| 1172 |
{ |
| 1173 |
if (((i + 1) < argc) && (argv[i + 1][0] != '-')) |
| 1174 |
{ |
| 1175 |
MemoryCopy(truncAfter, argv[i + 1], TextLength(argv[i + 1])); |
| 1176 |
truncAfter[TextLength(argv[i + 1])] = '\0'; |
| 1177 |
i++; |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
static char *LoadFileText(const char *fileName, int *length) |
| 1186 |
{ |
| 1187 |
char *text = NULL; |
| 1188 |
|
| 1189 |
if (fileName != NULL) |
| 1190 |
{ |
| 1191 |
FILE *file = fopen(fileName, "rt"); |
| 1192 |
|
| 1193 |
if (file != NULL) |
| 1194 |
{ |
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
fseek(file, 0, SEEK_END); |
| 1199 |
int size = ftell(file); |
| 1200 |
fseek(file, 0, SEEK_SET); |
| 1201 |
|
| 1202 |
if (size > 0) |
| 1203 |
{ |
| 1204 |
text = (char *)calloc((size + 1), sizeof(char)); |
| 1205 |
unsigned int count = (unsigned int)fread(text, sizeof(char), size, file); |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
if (count < (unsigned int)size) |
| 1210 |
{ |
| 1211 |
text = realloc(text, count + 1); |
| 1212 |
*length = count; |
| 1213 |
} |
| 1214 |
else *length = size; |
| 1215 |
|
| 1216 |
|
| 1217 |
text[count] = '\0'; |
| 1218 |
} |
| 1219 |
|
| 1220 |
fclose(file); |
| 1221 |
} |
| 1222 |
} |
| 1223 |
|
| 1224 |
return text; |
| 1225 |
} |
| 1226 |
|
| 1227 |
|
| 1228 |
static void UnloadFileText(char *text) |
| 1229 |
{ |
| 1230 |
free(text); |
| 1231 |
} |
| 1232 |
|
| 1233 |
|
| 1234 |
static char **LoadTextLines(const char *buffer, int length, int *lineCount) |
| 1235 |
{ |
| 1236 |
|
| 1237 |
int count = 0; |
| 1238 |
for (int i = 0; i < length; i++) if (buffer[i] == '\n') count++; |
| 1239 |
|
| 1240 |
printf("Number of text lines in buffer: %i\n", count); |
| 1241 |
|
| 1242 |
|
| 1243 |
char **lines = (char **)malloc(count*sizeof(char **)); |
| 1244 |
|
| 1245 |
char *bufferPtr = (char *)buffer; |
| 1246 |
|
| 1247 |
for (int i = 0; (i < count) || (bufferPtr[0] != '\0'); i++) |
| 1248 |
{ |
| 1249 |
lines[i] = (char *)calloc(MAX_LINE_LENGTH, sizeof(char)); |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
int index = 0; |
| 1254 |
while ((bufferPtr[index] == ' ') || (bufferPtr[index] == '\t')) index++; |
| 1255 |
|
| 1256 |
int j = 0; |
| 1257 |
while (bufferPtr[index + j] != '\n' && bufferPtr[index + j] != '\0') |
| 1258 |
{ |
| 1259 |
lines[i][j] = bufferPtr[index + j]; |
| 1260 |
j++; |
| 1261 |
} |
| 1262 |
|
| 1263 |
bufferPtr += (index + j + 1); |
| 1264 |
} |
| 1265 |
|
| 1266 |
*lineCount = count; |
| 1267 |
return lines; |
| 1268 |
} |
| 1269 |
|
| 1270 |
|
| 1271 |
static void UnloadTextLines(char **lines, int lineCount) |
| 1272 |
{ |
| 1273 |
for (int i = 0; i < lineCount; i++) free(lines[i]); |
| 1274 |
free(lines); |
| 1275 |
} |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
static void GetDataTypeAndName(const char *typeName, int typeNameLen, char *type, char *name) |
| 1280 |
{ |
| 1281 |
for (int k = typeNameLen; k > 0; k--) |
| 1282 |
{ |
| 1283 |
if ((typeName[k] == ' ') && (typeName[k - 1] != ',')) |
| 1284 |
{ |
| 1285 |
|
| 1286 |
MemoryCopy(type, typeName, k); |
| 1287 |
MemoryCopy(name, typeName + k + 1, typeNameLen - k - 1); |
| 1288 |
break; |
| 1289 |
} |
| 1290 |
else if (typeName[k] == '*') |
| 1291 |
{ |
| 1292 |
MemoryCopy(type, typeName, k + 1); |
| 1293 |
MemoryCopy(name, typeName + k + 1, typeNameLen - k - 1); |
| 1294 |
break; |
| 1295 |
} |
| 1296 |
else if ((typeName[k] == '.') && (typeNameLen == 3)) |
| 1297 |
{ |
| 1298 |
const char *varargsDots = "..."; |
| 1299 |
const char *varargsArg = "args"; |
| 1300 |
MemoryCopy(type, varargsDots, TextLength(varargsDots)); |
| 1301 |
MemoryCopy(name, varargsArg, TextLength(varargsArg)); |
| 1302 |
break; |
| 1303 |
} |
| 1304 |
} |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
static void GetDescription(const char *line, char *description) |
| 1309 |
{ |
| 1310 |
int c = 0; |
| 1311 |
int descStart = -1; |
| 1312 |
int lastSlash = -2; |
| 1313 |
bool isValid = false; |
| 1314 |
while (line[c] != '\0') |
| 1315 |
{ |
| 1316 |
if (isValid && (descStart == -1) && (line[c] != ' ')) descStart = c; |
| 1317 |
else if (line[c] == '/') |
| 1318 |
{ |
| 1319 |
if (lastSlash == c - 1) isValid = true; |
| 1320 |
lastSlash = c; |
| 1321 |
} |
| 1322 |
c++; |
| 1323 |
} |
| 1324 |
if (descStart != -1) MemoryCopy(description, &line[descStart], c - descStart); |
| 1325 |
} |
| 1326 |
|
| 1327 |
|
| 1328 |
static void MoveArraySize(char *name, char *type) |
| 1329 |
{ |
| 1330 |
int nameLength = TextLength(name); |
| 1331 |
if (name[nameLength - 1] == ']') |
| 1332 |
{ |
| 1333 |
for (int k = nameLength; k > 0; k--) |
| 1334 |
{ |
| 1335 |
if (name[k] == '[') |
| 1336 |
{ |
| 1337 |
int sizeLength = nameLength - k; |
| 1338 |
MemoryCopy(&type[TextLength(type)], &name[k], sizeLength); |
| 1339 |
name[k] = '\0'; |
| 1340 |
} |
| 1341 |
} |
| 1342 |
} |
| 1343 |
} |
| 1344 |
|
| 1345 |
|
| 1346 |
static unsigned int TextLength(const char *text) |
| 1347 |
{ |
| 1348 |
unsigned int length = 0; |
| 1349 |
|
| 1350 |
if (text != NULL) while (*text++) length++; |
| 1351 |
|
| 1352 |
return length; |
| 1353 |
} |
| 1354 |
|
| 1355 |
|
| 1356 |
static bool IsTextEqual(const char *text1, const char *text2, unsigned int count) |
| 1357 |
{ |
| 1358 |
bool result = true; |
| 1359 |
|
| 1360 |
for (unsigned int i = 0; i < count; i++) |
| 1361 |
{ |
| 1362 |
if (text1[i] != text2[i]) |
| 1363 |
{ |
| 1364 |
result = false; |
| 1365 |
break; |
| 1366 |
} |
| 1367 |
} |
| 1368 |
|
| 1369 |
return result; |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
int TextFindIndex(const char *text, const char *find) |
| 1374 |
{ |
| 1375 |
int textLen = TextLength(text); |
| 1376 |
int findLen = TextLength(find); |
| 1377 |
|
| 1378 |
for (int i = 0; i <= textLen - findLen; i++) |
| 1379 |
{ |
| 1380 |
if (IsTextEqual(&text[i], find, findLen)) return i; |
| 1381 |
} |
| 1382 |
|
| 1383 |
return -1; |
| 1384 |
} |
| 1385 |
|
| 1386 |
|
| 1387 |
static void MemoryCopy(void *dest, const void *src, unsigned int count) |
| 1388 |
{ |
| 1389 |
char *srcPtr = (char *)src; |
| 1390 |
char *destPtr = (char *)dest; |
| 1391 |
|
| 1392 |
for (unsigned int i = 0; i < count; i++) destPtr[i] = srcPtr[i]; |
| 1393 |
} |
| 1394 |
|
| 1395 |
|
| 1396 |
static char *EscapeBackslashes(char *text) |
| 1397 |
{ |
| 1398 |
static char buffer[256] = { 0 }; |
| 1399 |
|
| 1400 |
int count = 0; |
| 1401 |
|
| 1402 |
for (int i = 0; (text[i] != '\0') && (i < 255); i++, count++) |
| 1403 |
{ |
| 1404 |
buffer[count] = text[i]; |
| 1405 |
|
| 1406 |
if (text[i] == '\\') |
| 1407 |
{ |
| 1408 |
buffer[count + 1] = '\\'; |
| 1409 |
count++; |
| 1410 |
} |
| 1411 |
} |
| 1412 |
|
| 1413 |
buffer[count] = '\0'; |
| 1414 |
|
| 1415 |
return buffer; |
| 1416 |
} |
| 1417 |
|
| 1418 |
|
| 1419 |
static const char *StrDefineType(DefineType type) |
| 1420 |
{ |
| 1421 |
switch (type) |
| 1422 |
{ |
| 1423 |
case UNKNOWN: return "UNKNOWN"; |
| 1424 |
case GUARD: return "GUARD"; |
| 1425 |
case MACRO: return "MACRO"; |
| 1426 |
case INT: return "INT"; |
| 1427 |
case INT_MATH: return "INT_MATH"; |
| 1428 |
case LONG: return "LONG"; |
| 1429 |
case LONG_MATH: return "LONG_MATH"; |
| 1430 |
case FLOAT: return "FLOAT"; |
| 1431 |
case FLOAT_MATH: return "FLOAT_MATH"; |
| 1432 |
case DOUBLE: return "DOUBLE"; |
| 1433 |
case DOUBLE_MATH: return "DOUBLE_MATH"; |
| 1434 |
case CHAR: return "CHAR"; |
| 1435 |
case STRING: return "STRING"; |
| 1436 |
case COLOR: return "COLOR"; |
| 1437 |
} |
| 1438 |
return ""; |
| 1439 |
} |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
static void ExportParsedData(const char *fileName, int format) |
| 1495 |
{ |
| 1496 |
FILE *outFile = fopen(fileName, "wt"); |
| 1497 |
|
| 1498 |
switch (format) |
| 1499 |
{ |
| 1500 |
case DEFAULT: |
| 1501 |
{ |
| 1502 |
|
| 1503 |
fprintf(outFile, "\nDefines found: %i\n\n", defineCount); |
| 1504 |
for (int i = 0; i < defineCount; i++) |
| 1505 |
{ |
| 1506 |
fprintf(outFile, "Define %03i: %s\n", i + 1, defines[i].name); |
| 1507 |
fprintf(outFile, " Name: %s\n", defines[i].name); |
| 1508 |
fprintf(outFile, " Type: %s\n", StrDefineType(defines[i].type)); |
| 1509 |
fprintf(outFile, " Value: %s\n", defines[i].value); |
| 1510 |
fprintf(outFile, " Description: %s\n", defines[i].desc); |
| 1511 |
} |
| 1512 |
|
| 1513 |
|
| 1514 |
fprintf(outFile, "\nStructures found: %i\n\n", structCount); |
| 1515 |
for (int i = 0; i < structCount; i++) |
| 1516 |
{ |
| 1517 |
fprintf(outFile, "Struct %02i: %s (%i fields)\n", i + 1, structs[i].name, structs[i].fieldCount); |
| 1518 |
fprintf(outFile, " Name: %s\n", structs[i].name); |
| 1519 |
fprintf(outFile, " Description: %s\n", structs[i].desc); |
| 1520 |
for (int f = 0; f < structs[i].fieldCount; f++) |
| 1521 |
{ |
| 1522 |
fprintf(outFile, " Field[%i]: %s %s ", f + 1, structs[i].fieldType[f], structs[i].fieldName[f]); |
| 1523 |
if (structs[i].fieldDesc[f][0]) fprintf(outFile, "// %s\n", structs[i].fieldDesc[f]); |
| 1524 |
else fprintf(outFile, "\n"); |
| 1525 |
} |
| 1526 |
} |
| 1527 |
|
| 1528 |
|
| 1529 |
fprintf(outFile, "\nAliases found: %i\n\n", aliasCount); |
| 1530 |
for (int i = 0; i < aliasCount; i++) |
| 1531 |
{ |
| 1532 |
fprintf(outFile, "Alias %03i: %s\n", i + 1, aliases[i].name); |
| 1533 |
fprintf(outFile, " Type: %s\n", aliases[i].type); |
| 1534 |
fprintf(outFile, " Name: %s\n", aliases[i].name); |
| 1535 |
fprintf(outFile, " Description: %s\n", aliases[i].desc); |
| 1536 |
} |
| 1537 |
|
| 1538 |
|
| 1539 |
fprintf(outFile, "\nEnums found: %i\n\n", enumCount); |
| 1540 |
for (int i = 0; i < enumCount; i++) |
| 1541 |
{ |
| 1542 |
fprintf(outFile, "Enum %02i: %s (%i values)\n", i + 1, enums[i].name, enums[i].valueCount); |
| 1543 |
fprintf(outFile, " Name: %s\n", enums[i].name); |
| 1544 |
fprintf(outFile, " Description: %s\n", enums[i].desc); |
| 1545 |
for (int e = 0; e < enums[i].valueCount; e++) fprintf(outFile, " Value[%s]: %i\n", enums[i].valueName[e], enums[i].valueInteger[e]); |
| 1546 |
} |
| 1547 |
|
| 1548 |
|
| 1549 |
fprintf(outFile, "\nCallbacks found: %i\n\n", callbackCount); |
| 1550 |
for (int i = 0; i < callbackCount; i++) |
| 1551 |
{ |
| 1552 |
fprintf(outFile, "Callback %03i: %s() (%i input parameters)\n", i + 1, callbacks[i].name, callbacks[i].paramCount); |
| 1553 |
fprintf(outFile, " Name: %s\n", callbacks[i].name); |
| 1554 |
fprintf(outFile, " Return type: %s\n", callbacks[i].retType); |
| 1555 |
fprintf(outFile, " Description: %s\n", callbacks[i].desc); |
| 1556 |
for (int p = 0; p < callbacks[i].paramCount; p++) fprintf(outFile, " Param[%i]: %s (type: %s)\n", p + 1, callbacks[i].paramName[p], callbacks[i].paramType[p]); |
| 1557 |
if (callbacks[i].paramCount == 0) fprintf(outFile, " No input parameters\n"); |
| 1558 |
} |
| 1559 |
|
| 1560 |
|
| 1561 |
fprintf(outFile, "\nFunctions found: %i\n\n", funcCount); |
| 1562 |
for (int i = 0; i < funcCount; i++) |
| 1563 |
{ |
| 1564 |
fprintf(outFile, "Function %03i: %s() (%i input parameters)\n", i + 1, funcs[i].name, funcs[i].paramCount); |
| 1565 |
fprintf(outFile, " Name: %s\n", funcs[i].name); |
| 1566 |
fprintf(outFile, " Return type: %s\n", funcs[i].retType); |
| 1567 |
fprintf(outFile, " Description: %s\n", funcs[i].desc); |
| 1568 |
for (int p = 0; p < funcs[i].paramCount; p++) fprintf(outFile, " Param[%i]: %s (type: %s)\n", p + 1, funcs[i].paramName[p], funcs[i].paramType[p]); |
| 1569 |
if (funcs[i].paramCount == 0) fprintf(outFile, " No input parameters\n"); |
| 1570 |
} |
| 1571 |
} break; |
| 1572 |
case JSON: |
| 1573 |
{ |
| 1574 |
fprintf(outFile, "{\n"); |
| 1575 |
|
| 1576 |
|
| 1577 |
fprintf(outFile, " \"defines\": [\n"); |
| 1578 |
for (int i = 0; i < defineCount; i++) |
| 1579 |
{ |
| 1580 |
fprintf(outFile, " {\n"); |
| 1581 |
fprintf(outFile, " \"name\": \"%s\",\n", defines[i].name); |
| 1582 |
fprintf(outFile, " \"type\": \"%s\",\n", StrDefineType(defines[i].type)); |
| 1583 |
if (defines[i].isHex) |
| 1584 |
{ |
| 1585 |
fprintf(outFile, " \"value\": %ld,\n", strtol(defines[i].value, NULL, 16)); |
| 1586 |
} |
| 1587 |
else if ((defines[i].type == INT) || |
| 1588 |
(defines[i].type == LONG) || |
| 1589 |
(defines[i].type == FLOAT) || |
| 1590 |
(defines[i].type == DOUBLE) || |
| 1591 |
(defines[i].type == STRING)) |
| 1592 |
{ |
| 1593 |
fprintf(outFile, " \"value\": %s,\n", defines[i].value); |
| 1594 |
} |
| 1595 |
else |
| 1596 |
{ |
| 1597 |
fprintf(outFile, " \"value\": \"%s\",\n", defines[i].value); |
| 1598 |
} |
| 1599 |
fprintf(outFile, " \"description\": \"%s\"\n", defines[i].desc); |
| 1600 |
fprintf(outFile, " }"); |
| 1601 |
|
| 1602 |
if (i < defineCount - 1) fprintf(outFile, ",\n"); |
| 1603 |
else fprintf(outFile, "\n"); |
| 1604 |
} |
| 1605 |
fprintf(outFile, " ],\n"); |
| 1606 |
|
| 1607 |
|
| 1608 |
fprintf(outFile, " \"structs\": [\n"); |
| 1609 |
for (int i = 0; i < structCount; i++) |
| 1610 |
{ |
| 1611 |
fprintf(outFile, " {\n"); |
| 1612 |
fprintf(outFile, " \"name\": \"%s\",\n", structs[i].name); |
| 1613 |
fprintf(outFile, " \"description\": \"%s\",\n", EscapeBackslashes(structs[i].desc)); |
| 1614 |
fprintf(outFile, " \"fields\": [\n"); |
| 1615 |
for (int f = 0; f < structs[i].fieldCount; f++) |
| 1616 |
{ |
| 1617 |
fprintf(outFile, " {\n"); |
| 1618 |
fprintf(outFile, " \"type\": \"%s\",\n", structs[i].fieldType[f]); |
| 1619 |
fprintf(outFile, " \"name\": \"%s\",\n", structs[i].fieldName[f]); |
| 1620 |
fprintf(outFile, " \"description\": \"%s\"\n", EscapeBackslashes(structs[i].fieldDesc[f])); |
| 1621 |
fprintf(outFile, " }"); |
| 1622 |
if (f < structs[i].fieldCount - 1) fprintf(outFile, ",\n"); |
| 1623 |
else fprintf(outFile, "\n"); |
| 1624 |
} |
| 1625 |
fprintf(outFile, " ]\n"); |
| 1626 |
fprintf(outFile, " }"); |
| 1627 |
if (i < structCount - 1) fprintf(outFile, ",\n"); |
| 1628 |
else fprintf(outFile, "\n"); |
| 1629 |
} |
| 1630 |
fprintf(outFile, " ],\n"); |
| 1631 |
|
| 1632 |
|
| 1633 |
fprintf(outFile, " \"aliases\": [\n"); |
| 1634 |
for (int i = 0; i < aliasCount; i++) |
| 1635 |
{ |
| 1636 |
fprintf(outFile, " {\n"); |
| 1637 |
fprintf(outFile, " \"type\": \"%s\",\n", aliases[i].type); |
| 1638 |
fprintf(outFile, " \"name\": \"%s\",\n", aliases[i].name); |
| 1639 |
fprintf(outFile, " \"description\": \"%s\"\n", aliases[i].desc); |
| 1640 |
fprintf(outFile, " }"); |
| 1641 |
|
| 1642 |
if (i < aliasCount - 1) fprintf(outFile, ",\n"); |
| 1643 |
else fprintf(outFile, "\n"); |
| 1644 |
} |
| 1645 |
fprintf(outFile, " ],\n"); |
| 1646 |
|
| 1647 |
|
| 1648 |
fprintf(outFile, " \"enums\": [\n"); |
| 1649 |
for (int i = 0; i < enumCount; i++) |
| 1650 |
{ |
| 1651 |
fprintf(outFile, " {\n"); |
| 1652 |
fprintf(outFile, " \"name\": \"%s\",\n", enums[i].name); |
| 1653 |
fprintf(outFile, " \"description\": \"%s\",\n", EscapeBackslashes(enums[i].desc)); |
| 1654 |
fprintf(outFile, " \"values\": [\n"); |
| 1655 |
for (int e = 0; e < enums[i].valueCount; e++) |
| 1656 |
{ |
| 1657 |
fprintf(outFile, " {\n"); |
| 1658 |
fprintf(outFile, " \"name\": \"%s\",\n", enums[i].valueName[e]); |
| 1659 |
fprintf(outFile, " \"value\": %i,\n", enums[i].valueInteger[e]); |
| 1660 |
fprintf(outFile, " \"description\": \"%s\"\n", EscapeBackslashes(enums[i].valueDesc[e])); |
| 1661 |
fprintf(outFile, " }"); |
| 1662 |
if (e < enums[i].valueCount - 1) fprintf(outFile, ",\n"); |
| 1663 |
else fprintf(outFile, "\n"); |
| 1664 |
} |
| 1665 |
fprintf(outFile, " ]\n"); |
| 1666 |
fprintf(outFile, " }"); |
| 1667 |
if (i < enumCount - 1) fprintf(outFile, ",\n"); |
| 1668 |
else fprintf(outFile, "\n"); |
| 1669 |
} |
| 1670 |
fprintf(outFile, " ],\n"); |
| 1671 |
|
| 1672 |
|
| 1673 |
fprintf(outFile, " \"callbacks\": [\n"); |
| 1674 |
for (int i = 0; i < callbackCount; i++) |
| 1675 |
{ |
| 1676 |
fprintf(outFile, " {\n"); |
| 1677 |
fprintf(outFile, " \"name\": \"%s\",\n", callbacks[i].name); |
| 1678 |
fprintf(outFile, " \"description\": \"%s\",\n", EscapeBackslashes(callbacks[i].desc)); |
| 1679 |
fprintf(outFile, " \"returnType\": \"%s\"", callbacks[i].retType); |
| 1680 |
|
| 1681 |
if (callbacks[i].paramCount == 0) fprintf(outFile, "\n"); |
| 1682 |
else |
| 1683 |
{ |
| 1684 |
fprintf(outFile, ",\n \"params\": [\n"); |
| 1685 |
for (int p = 0; p < callbacks[i].paramCount; p++) |
| 1686 |
{ |
| 1687 |
fprintf(outFile, " {\n"); |
| 1688 |
fprintf(outFile, " \"type\": \"%s\",\n", callbacks[i].paramType[p]); |
| 1689 |
fprintf(outFile, " \"name\": \"%s\"\n", callbacks[i].paramName[p]); |
| 1690 |
fprintf(outFile, " }"); |
| 1691 |
if (p < callbacks[i].paramCount - 1) fprintf(outFile, ",\n"); |
| 1692 |
else fprintf(outFile, "\n"); |
| 1693 |
} |
| 1694 |
fprintf(outFile, " ]\n"); |
| 1695 |
} |
| 1696 |
fprintf(outFile, " }"); |
| 1697 |
|
| 1698 |
if (i < callbackCount - 1) fprintf(outFile, ",\n"); |
| 1699 |
else fprintf(outFile, "\n"); |
| 1700 |
} |
| 1701 |
fprintf(outFile, " ],\n"); |
| 1702 |
|
| 1703 |
|
| 1704 |
fprintf(outFile, " \"functions\": [\n"); |
| 1705 |
for (int i = 0; i < funcCount; i++) |
| 1706 |
{ |
| 1707 |
fprintf(outFile, " {\n"); |
| 1708 |
fprintf(outFile, " \"name\": \"%s\",\n", funcs[i].name); |
| 1709 |
fprintf(outFile, " \"description\": \"%s\",\n", EscapeBackslashes(funcs[i].desc)); |
| 1710 |
fprintf(outFile, " \"returnType\": \"%s\"", funcs[i].retType); |
| 1711 |
|
| 1712 |
if (funcs[i].paramCount == 0) fprintf(outFile, "\n"); |
| 1713 |
else |
| 1714 |
{ |
| 1715 |
fprintf(outFile, ",\n \"params\": [\n"); |
| 1716 |
for (int p = 0; p < funcs[i].paramCount; p++) |
| 1717 |
{ |
| 1718 |
fprintf(outFile, " {\n"); |
| 1719 |
fprintf(outFile, " \"type\": \"%s\",\n", funcs[i].paramType[p]); |
| 1720 |
fprintf(outFile, " \"name\": \"%s\"\n", funcs[i].paramName[p]); |
| 1721 |
fprintf(outFile, " }"); |
| 1722 |
if (p < funcs[i].paramCount - 1) fprintf(outFile, ",\n"); |
| 1723 |
else fprintf(outFile, "\n"); |
| 1724 |
} |
| 1725 |
fprintf(outFile, " ]\n"); |
| 1726 |
} |
| 1727 |
fprintf(outFile, " }"); |
| 1728 |
|
| 1729 |
if (i < funcCount - 1) fprintf(outFile, ",\n"); |
| 1730 |
else fprintf(outFile, "\n"); |
| 1731 |
} |
| 1732 |
fprintf(outFile, " ]\n"); |
| 1733 |
fprintf(outFile, "}\n"); |
| 1734 |
} break; |
| 1735 |
case XML: |
| 1736 |
{ |
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
fprintf(outFile, "<?xml version=\"1.0\" encoding=\"Windows-1252\" ?>\n"); |
| 1775 |
fprintf(outFile, "<raylibAPI>\n"); |
| 1776 |
|
| 1777 |
|
| 1778 |
fprintf(outFile, " <Defines count=\"%i\">\n", defineCount); |
| 1779 |
for (int i = 0; i < defineCount; i++) |
| 1780 |
{ |
| 1781 |
fprintf(outFile, " <Define name=\"%s\" type=\"%s\" ", defines[i].name, StrDefineType(defines[i].type)); |
| 1782 |
if (defines[i].type == STRING) |
| 1783 |
{ |
| 1784 |
fprintf(outFile, "value=%s", defines[i].value); |
| 1785 |
} |
| 1786 |
else |
| 1787 |
{ |
| 1788 |
fprintf(outFile, "value=\"%s\"", defines[i].value); |
| 1789 |
} |
| 1790 |
fprintf(outFile, " desc=\"%s\" />\n", defines[i].desc); |
| 1791 |
} |
| 1792 |
fprintf(outFile, " </Defines>\n"); |
| 1793 |
|
| 1794 |
|
| 1795 |
fprintf(outFile, " <Structs count=\"%i\">\n", structCount); |
| 1796 |
for (int i = 0; i < structCount; i++) |
| 1797 |
{ |
| 1798 |
fprintf(outFile, " <Struct name=\"%s\" fieldCount=\"%i\" desc=\"%s\">\n", structs[i].name, structs[i].fieldCount, structs[i].desc); |
| 1799 |
for (int f = 0; f < structs[i].fieldCount; f++) |
| 1800 |
{ |
| 1801 |
fprintf(outFile, " <Field type=\"%s\" name=\"%s\" desc=\"%s\" />\n", structs[i].fieldType[f], structs[i].fieldName[f], structs[i].fieldDesc[f]); |
| 1802 |
} |
| 1803 |
fprintf(outFile, " </Struct>\n"); |
| 1804 |
} |
| 1805 |
fprintf(outFile, " </Structs>\n"); |
| 1806 |
|
| 1807 |
|
| 1808 |
fprintf(outFile, " <Aliases count=\"%i\">\n", aliasCount); |
| 1809 |
for (int i = 0; i < aliasCount; i++) |
| 1810 |
{ |
| 1811 |
fprintf(outFile, " <Alias type=\"%s\" name=\"%s\" desc=\"%s\" />\n", aliases[i].name, aliases[i].type, aliases[i].desc); |
| 1812 |
} |
| 1813 |
fprintf(outFile, " </Aliases>\n"); |
| 1814 |
|
| 1815 |
|
| 1816 |
fprintf(outFile, " <Enums count=\"%i\">\n", enumCount); |
| 1817 |
for (int i = 0; i < enumCount; i++) |
| 1818 |
{ |
| 1819 |
fprintf(outFile, " <Enum name=\"%s\" valueCount=\"%i\" desc=\"%s\">\n", enums[i].name, enums[i].valueCount, enums[i].desc); |
| 1820 |
for (int v = 0; v < enums[i].valueCount; v++) |
| 1821 |
{ |
| 1822 |
fprintf(outFile, " <Value name=\"%s\" integer=\"%i\" desc=\"%s\" />\n", enums[i].valueName[v], enums[i].valueInteger[v], enums[i].valueDesc[v]); |
| 1823 |
} |
| 1824 |
fprintf(outFile, " </Enum>\n"); |
| 1825 |
} |
| 1826 |
fprintf(outFile, " </Enums>\n"); |
| 1827 |
|
| 1828 |
|
| 1829 |
fprintf(outFile, " <Callbacks count=\"%i\">\n", callbackCount); |
| 1830 |
for (int i = 0; i < callbackCount; i++) |
| 1831 |
{ |
| 1832 |
fprintf(outFile, " <Callback name=\"%s\" retType=\"%s\" paramCount=\"%i\" desc=\"%s\">\n", callbacks[i].name, callbacks[i].retType, callbacks[i].paramCount, callbacks[i].desc); |
| 1833 |
for (int p = 0; p < callbacks[i].paramCount; p++) |
| 1834 |
{ |
| 1835 |
fprintf(outFile, " <Param type=\"%s\" name=\"%s\" desc=\"%s\" />\n", callbacks[i].paramType[p], callbacks[i].paramName[p], callbacks[i].paramDesc[p]); |
| 1836 |
} |
| 1837 |
fprintf(outFile, " </Callback>\n"); |
| 1838 |
} |
| 1839 |
fprintf(outFile, " </Callbacks>\n"); |
| 1840 |
|
| 1841 |
|
| 1842 |
fprintf(outFile, " <Functions count=\"%i\">\n", funcCount); |
| 1843 |
for (int i = 0; i < funcCount; i++) |
| 1844 |
{ |
| 1845 |
fprintf(outFile, " <Function name=\"%s\" retType=\"%s\" paramCount=\"%i\" desc=\"%s\">\n", funcs[i].name, funcs[i].retType, funcs[i].paramCount, funcs[i].desc); |
| 1846 |
for (int p = 0; p < funcs[i].paramCount; p++) |
| 1847 |
{ |
| 1848 |
fprintf(outFile, " <Param type=\"%s\" name=\"%s\" desc=\"%s\" />\n", funcs[i].paramType[p], funcs[i].paramName[p], funcs[i].paramDesc[p]); |
| 1849 |
} |
| 1850 |
fprintf(outFile, " </Function>\n"); |
| 1851 |
} |
| 1852 |
fprintf(outFile, " </Functions>\n"); |
| 1853 |
|
| 1854 |
fprintf(outFile, "</raylibAPI>\n"); |
| 1855 |
|
| 1856 |
} break; |
| 1857 |
case LUA: |
| 1858 |
{ |
| 1859 |
fprintf(outFile, "return {\n"); |
| 1860 |
|
| 1861 |
|
| 1862 |
fprintf(outFile, " defines = {\n"); |
| 1863 |
for (int i = 0; i < defineCount; i++) |
| 1864 |
{ |
| 1865 |
fprintf(outFile, " {\n"); |
| 1866 |
fprintf(outFile, " name = \"%s\",\n", defines[i].name); |
| 1867 |
fprintf(outFile, " type = \"%s\",\n", StrDefineType(defines[i].type)); |
| 1868 |
if ((defines[i].type == INT) || |
| 1869 |
(defines[i].type == LONG) || |
| 1870 |
(defines[i].type == FLOAT) || |
| 1871 |
(defines[i].type == DOUBLE) || |
| 1872 |
(defines[i].type == STRING)) |
| 1873 |
{ |
| 1874 |
fprintf(outFile, " value = %s,\n", defines[i].value); |
| 1875 |
} |
| 1876 |
else |
| 1877 |
{ |
| 1878 |
fprintf(outFile, " value = \"%s\",\n", defines[i].value); |
| 1879 |
} |
| 1880 |
fprintf(outFile, " description = \"%s\"\n", defines[i].desc); |
| 1881 |
fprintf(outFile, " }"); |
| 1882 |
|
| 1883 |
if (i < defineCount - 1) fprintf(outFile, ",\n"); |
| 1884 |
else fprintf(outFile, "\n"); |
| 1885 |
} |
| 1886 |
fprintf(outFile, " },\n"); |
| 1887 |
|
| 1888 |
|
| 1889 |
fprintf(outFile, " structs = {\n"); |
| 1890 |
for (int i = 0; i < structCount; i++) |
| 1891 |
{ |
| 1892 |
fprintf(outFile, " {\n"); |
| 1893 |
fprintf(outFile, " name = \"%s\",\n", structs[i].name); |
| 1894 |
fprintf(outFile, " description = \"%s\",\n", EscapeBackslashes(structs[i].desc)); |
| 1895 |
fprintf(outFile, " fields = {\n"); |
| 1896 |
for (int f = 0; f < structs[i].fieldCount; f++) |
| 1897 |
{ |
| 1898 |
fprintf(outFile, " {\n"); |
| 1899 |
fprintf(outFile, " type = \"%s\",\n", structs[i].fieldType[f]); |
| 1900 |
fprintf(outFile, " name = \"%s\",\n", structs[i].fieldName[f]); |
| 1901 |
fprintf(outFile, " description = \"%s\"\n", EscapeBackslashes(structs[i].fieldDesc[f])); |
| 1902 |
fprintf(outFile, " }"); |
| 1903 |
if (f < structs[i].fieldCount - 1) fprintf(outFile, ",\n"); |
| 1904 |
else fprintf(outFile, "\n"); |
| 1905 |
} |
| 1906 |
fprintf(outFile, " }\n"); |
| 1907 |
fprintf(outFile, " }"); |
| 1908 |
if (i < structCount - 1) fprintf(outFile, ",\n"); |
| 1909 |
else fprintf(outFile, "\n"); |
| 1910 |
} |
| 1911 |
fprintf(outFile, " },\n"); |
| 1912 |
|
| 1913 |
|
| 1914 |
fprintf(outFile, " aliases = {\n"); |
| 1915 |
for (int i = 0; i < aliasCount; i++) |
| 1916 |
{ |
| 1917 |
fprintf(outFile, " {\n"); |
| 1918 |
fprintf(outFile, " type = \"%s\",\n", aliases[i].type); |
| 1919 |
fprintf(outFile, " name = \"%s\",\n", aliases[i].name); |
| 1920 |
fprintf(outFile, " description = \"%s\"\n", aliases[i].desc); |
| 1921 |
fprintf(outFile, " }"); |
| 1922 |
|
| 1923 |
if (i < aliasCount - 1) fprintf(outFile, ",\n"); |
| 1924 |
else fprintf(outFile, "\n"); |
| 1925 |
} |
| 1926 |
fprintf(outFile, " },\n"); |
| 1927 |
|
| 1928 |
|
| 1929 |
fprintf(outFile, " enums = {\n"); |
| 1930 |
for (int i = 0; i < enumCount; i++) |
| 1931 |
{ |
| 1932 |
fprintf(outFile, " {\n"); |
| 1933 |
fprintf(outFile, " name = \"%s\",\n", enums[i].name); |
| 1934 |
fprintf(outFile, " description = \"%s\",\n", EscapeBackslashes(enums[i].desc)); |
| 1935 |
fprintf(outFile, " values = {\n"); |
| 1936 |
for (int e = 0; e < enums[i].valueCount; e++) |
| 1937 |
{ |
| 1938 |
fprintf(outFile, " {\n"); |
| 1939 |
fprintf(outFile, " name = \"%s\",\n", enums[i].valueName[e]); |
| 1940 |
fprintf(outFile, " value = %i,\n", enums[i].valueInteger[e]); |
| 1941 |
fprintf(outFile, " description = \"%s\"\n", EscapeBackslashes(enums[i].valueDesc[e])); |
| 1942 |
fprintf(outFile, " }"); |
| 1943 |
if (e < enums[i].valueCount - 1) fprintf(outFile, ",\n"); |
| 1944 |
else fprintf(outFile, "\n"); |
| 1945 |
} |
| 1946 |
fprintf(outFile, " }\n"); |
| 1947 |
fprintf(outFile, " }"); |
| 1948 |
if (i < enumCount - 1) fprintf(outFile, ",\n"); |
| 1949 |
else fprintf(outFile, "\n"); |
| 1950 |
} |
| 1951 |
fprintf(outFile, " },\n"); |
| 1952 |
|
| 1953 |
|
| 1954 |
fprintf(outFile, " callbacks = {\n"); |
| 1955 |
for (int i = 0; i < callbackCount; i++) |
| 1956 |
{ |
| 1957 |
fprintf(outFile, " {\n"); |
| 1958 |
fprintf(outFile, " name = \"%s\",\n", callbacks[i].name); |
| 1959 |
fprintf(outFile, " description = \"%s\",\n", EscapeBackslashes(callbacks[i].desc)); |
| 1960 |
fprintf(outFile, " returnType = \"%s\"", callbacks[i].retType); |
| 1961 |
|
| 1962 |
if (callbacks[i].paramCount == 0) fprintf(outFile, "\n"); |
| 1963 |
else |
| 1964 |
{ |
| 1965 |
fprintf(outFile, ",\n params = {\n"); |
| 1966 |
for (int p = 0; p < callbacks[i].paramCount; p++) |
| 1967 |
{ |
| 1968 |
fprintf(outFile, " {type = \"%s\", name = \"%s\"}", callbacks[i].paramType[p], callbacks[i].paramName[p]); |
| 1969 |
if (p < callbacks[i].paramCount - 1) fprintf(outFile, ",\n"); |
| 1970 |
else fprintf(outFile, "\n"); |
| 1971 |
} |
| 1972 |
fprintf(outFile, " }\n"); |
| 1973 |
} |
| 1974 |
fprintf(outFile, " }"); |
| 1975 |
|
| 1976 |
if (i < callbackCount - 1) fprintf(outFile, ",\n"); |
| 1977 |
else fprintf(outFile, "\n"); |
| 1978 |
} |
| 1979 |
fprintf(outFile, " },\n"); |
| 1980 |
|
| 1981 |
|
| 1982 |
fprintf(outFile, " functions = {\n"); |
| 1983 |
for (int i = 0; i < funcCount; i++) |
| 1984 |
{ |
| 1985 |
fprintf(outFile, " {\n"); |
| 1986 |
fprintf(outFile, " name = \"%s\",\n", funcs[i].name); |
| 1987 |
fprintf(outFile, " description = \"%s\",\n", EscapeBackslashes(funcs[i].desc)); |
| 1988 |
fprintf(outFile, " returnType = \"%s\"", funcs[i].retType); |
| 1989 |
|
| 1990 |
if (funcs[i].paramCount == 0) fprintf(outFile, "\n"); |
| 1991 |
else |
| 1992 |
{ |
| 1993 |
fprintf(outFile, ",\n params = {\n"); |
| 1994 |
for (int p = 0; p < funcs[i].paramCount; p++) |
| 1995 |
{ |
| 1996 |
fprintf(outFile, " {type = \"%s\", name = \"%s\"}", funcs[i].paramType[p], funcs[i].paramName[p]); |
| 1997 |
if (p < funcs[i].paramCount - 1) fprintf(outFile, ",\n"); |
| 1998 |
else fprintf(outFile, "\n"); |
| 1999 |
} |
| 2000 |
fprintf(outFile, " }\n"); |
| 2001 |
} |
| 2002 |
fprintf(outFile, " }"); |
| 2003 |
|
| 2004 |
if (i < funcCount - 1) fprintf(outFile, ",\n"); |
| 2005 |
else fprintf(outFile, "\n"); |
| 2006 |
} |
| 2007 |
fprintf(outFile, " }\n"); |
| 2008 |
fprintf(outFile, "}\n"); |
| 2009 |
} break; |
| 2010 |
case CODE: |
| 2011 |
default: break; |
| 2012 |
} |
| 2013 |
|
| 2014 |
fclose(outFile); |
| 2015 |
} |