From a895dad6d954ea540a5e1942d18cfd951b5ad3d3 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 1 Mar 2018 07:51:39 +0000 Subject: [PATCH] Tidy headers update. --- src/test/atlasTest.c | 6 ++-- tools/tidyHeaders.sh | 78 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index c5834f4..78e8461 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -26,10 +26,10 @@ void initAtlasTest(void) dev.debug = 0; dev.cheatStatic = 0; - dev.cheatBlind = 0; + dev.cheatBlind = 1; dev.cheatNoEnemies = 0; dev.cheatKeys = 0; - dev.cheatPower = 1; + dev.cheatPower = 0; dev.cheatHealth = 0; dev.cheatLevels = 0; dev.takeScreenshots = 0; @@ -49,7 +49,7 @@ void initAtlasTest(void) break; case 1: - STRNCPY(game.worldId, "beachFront2", MAX_NAME_LENGTH); + STRNCPY(game.worldId, "beachApproach", MAX_NAME_LENGTH); initWorld(); break; diff --git a/tools/tidyHeaders.sh b/tools/tidyHeaders.sh index f9e2552..ae4a31f 100755 --- a/tools/tidyHeaders.sh +++ b/tools/tidyHeaders.sh @@ -3,7 +3,7 @@ 1 || (strlen($line) == 1 && !$wasBlank)) + { + $newHeader[] = $line; + } + + $wasBlank = strlen($line) == 1; + } + + if (count($defines) > 0) + { + $newHeader = array_merge($newHeader, $defines); + $newHeader[] = "\n"; + } + + if (count($functions) > 0) + { + $newHeader = array_merge($newHeader, $functions); + $newHeader[] = "\n"; + } + + if (count($structs) > 0) + { + $newHeader = array_merge($newHeader, $structs); + $newHeader[] = "\n"; + } + + return $newHeader; +} + function cleanHeader($headerFile) { global $UPDATE_FILES; @@ -40,6 +91,9 @@ function cleanHeader($headerFile) $header = file($headerFile); $body = file_get_contents($bodyFile); $lines = []; + $defines = []; + $functions = []; + $structs = []; $i = 0; $hasChanges = false; @@ -52,6 +106,8 @@ function cleanHeader($headerFile) if (count($matches) == 3) { + unset($header[$i]); + $extern = $matches[2]; if (!preg_match_all("/\b[(]?${extern}[\\(;,)\\n]/", $body)) @@ -62,12 +118,11 @@ function cleanHeader($headerFile) $hasChanges = true; } echo "\t- $line"; - unset($header[$i]); } if (!in_array($line, $lines)) { - $lines[] = $line; + $functions[] = $line; } else { @@ -77,7 +132,6 @@ function cleanHeader($headerFile) $hasChanges = true; } echo "\t- $line"; - unset($header[$i]); } } @@ -85,6 +139,8 @@ function cleanHeader($headerFile) if (count($matches) == 2) { + unset($header[$i]); + $extern = $matches[1]; $externs[] = $extern; @@ -97,12 +153,11 @@ function cleanHeader($headerFile) $hasChanges = true; } echo "\t- $line"; - unset($header[$i]); } if (!in_array($line, $lines)) { - $lines[] = $line; + $structs[] = $line; } else { @@ -112,7 +167,6 @@ function cleanHeader($headerFile) $hasChanges = true; } echo "\t- $line"; - unset($header[$i]); } } @@ -120,6 +174,8 @@ function cleanHeader($headerFile) if (count($matches) == 2) { + unset($header[$i]); + $extern = $matches[1]; $externs[] = $extern; @@ -132,12 +188,11 @@ function cleanHeader($headerFile) $hasChanges = true; } echo "\t- $line"; - unset($header[$i]); } if (!in_array($line, $lines)) { - $lines[] = $line; + $defines[] = $line; } else { @@ -147,7 +202,6 @@ function cleanHeader($headerFile) $hasChanges = true; } echo "\t- $line"; - unset($header[$i]); } } } @@ -155,7 +209,9 @@ function cleanHeader($headerFile) $i++; } - if ($UPDATE_FILES && $hasChanges) + $header = updateExterns($header, $defines, $functions, $structs); + + if ($UPDATE_FILES) { file_put_contents($headerFile, $header); }