Tidy #defines

This commit is contained in:
Steve 2020-03-28 13:56:49 +00:00
parent 7e14550cc1
commit 6b89d7e8e7
25 changed files with 115 additions and 89 deletions

View File

@ -33,9 +33,9 @@ extern char **getFileList(char *dir, int *count);
extern long lookup(char *name); extern long lookup(char *name);
extern void playSound(int id); extern void playSound(int id);
extern char *readFile(char *filename); extern char *readFile(char *filename);
extern void setAtlasColor(int r, int g, int b, int a);
extern void updateControlButton(char *name); extern void updateControlButton(char *name);
extern void updateControlKey(char *name); extern void updateControlKey(char *name);
extern void setAtlasColor(int r, int g, int b, int a);
extern App app; extern App app;
extern Colors colors; extern Colors colors;

View File

@ -84,7 +84,7 @@ function cleanHeader($headerFile)
{ {
$header = file($headerFile); $header = file($headerFile);
$body = file_get_contents($bodyFile); $body = file_get_contents($bodyFile);
$isMain = strpos($body, "int main(int argc, char *argv[])"); $isMain = strpos($body, "int main(");
$lines = []; $lines = [];
$defines = []; $defines = [];
$functions = []; $functions = [];
@ -197,6 +197,8 @@ function cleanHeader($headerFile)
$functions = array_unique($functions); $functions = array_unique($functions);
$structs = array_unique($structs); $structs = array_unique($structs);
$defines = alignDefines($defines);
$header = updateExterns($header, $defines, $functions, $structs); $header = updateExterns($header, $defines, $functions, $structs);
if ($UPDATE_FILES) if ($UPDATE_FILES)
@ -206,6 +208,30 @@ function cleanHeader($headerFile)
} }
} }
function alignDefines($defines)
{
$newAligns = [];
$largest = 0;
$defineName;
$defineValue;
foreach ($defines as $define)
{
sscanf($define, "%*s %s", $defineName);
$largest = max($largest, strlen($defineName) + 4);
}
foreach ($defines as $define)
{
sscanf($define, "%*s %s %[^\n]", $defineName, $defineValue);
$newAligns[] = "#define " . str_pad($defineName, $largest, " ") . $defineValue . "\n";
}
return $newAligns;
}
function recurseDir($dir) function recurseDir($dir)
{ {
if ($dir != "../src/json") if ($dir != "../src/json")